Commit df408704 authored by Karl Denninger's avatar Karl Denninger

ZP-1284 Commit for cleanups - no functional changes. Released under the Affero...

ZP-1284 Commit for cleanups - no functional changes. Released under the Affero GNU General Public License (AGPL) version 3.
parent 6ff84eeb
create table note create table note
(ordinal int primary key, login text, domain text, (ordinal integer primary key, login text, domain text,
inserted timestamp with time zone default now(), inserted timestamp with time zone default now(),
modified timestamp with time zone default now(), modified timestamp with time zone default now(),
deleted boolean default false, subject text, content text); deleted boolean default false, subject text, content text);
create table categories create table categories
(ordinal int references note(ordinal) on update cascade (ordinal integer references note(ordinal) on update cascade
on delete cascade, tag text); on delete cascade, tag text);
create index note_login on note using btree(login, domain); create index note_login on note using btree(login, domain);
......
...@@ -158,7 +158,7 @@ class BackendStickyNote extends BackendDiff { ...@@ -158,7 +158,7 @@ class BackendStickyNote extends BackendDiff {
public function StatFolder($id) { public function StatFolder($id) {
ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendStickyNote->StatFolder('%s')", $id)); ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendStickyNote->StatFolder('%s')", $id));
// Return the Display Name of the folder. No parent, as there's only one. // Return the Display Name of the folder. No parent, as there's only one.
$folder = array(); $folder = array();
$folder["mod"] = "Notes"; $folder["mod"] = "Notes";
...@@ -202,9 +202,10 @@ class BackendStickyNote extends BackendDiff { ...@@ -202,9 +202,10 @@ class BackendStickyNote extends BackendDiff {
$this->_result = pg_query_params($this->_dbconn, "select ordinal, extract(epoch from modified)::integer from note where login=$1 and domain=$2 and deleted is false", $_param); $this->_result = pg_query_params($this->_dbconn, "select ordinal, extract(epoch from modified)::integer from note where login=$1 and domain=$2 and deleted is false", $_param);
} }
if (pg_result_status($this->_result) != PGSQL_TUPLES_OK) { if (pg_result_status($this->_result) != PGSQL_TUPLES_OK) {
ZLog::Write(LOGLEVEL_WARN, sprintf("BackendStickyNote->GetMessageList(Failed to return a valid message list from database)")); ZLog::Write(LOGLEVEL_WARN, sprintf("BackendStickyNote->GetMessageList(Failed to return a valid message list, Postgres error [%s])", pg_last_error($this->_dbconn)));
} else { } else {
for ($_count = 0; $_count < pg_affected_rows($this->_result); $_count++) { $_affected = pg_affected_rows($this->_result);
for ($_count = 0; $_count < $_affected; $_count++) {
$message = array(); $message = array();
$message["id"] = pg_fetch_result($this->_result, $_count, 0); $message["id"] = pg_fetch_result($this->_result, $_count, 0);
$message["mod"] = pg_fetch_result($this->_result, $_count, 1); $message["mod"] = pg_fetch_result($this->_result, $_count, 1);
...@@ -224,7 +225,7 @@ class BackendStickyNote extends BackendDiff { ...@@ -224,7 +225,7 @@ class BackendStickyNote extends BackendDiff {
public function GetMessage($folderid, $id, $contentparameters) { public function GetMessage($folderid, $id, $contentparameters) {
ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendStickyNote->GetMessage('%s','%s')", $folderid, $id)); ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendStickyNote->GetMessage('%s','%s')", $folderid, $id));
// Look up the message in the database // Look up the message in the database
$_params = array(); $_params = array();
array_push($_params, $id, $this->_user, $this->_domain); array_push($_params, $id, $this->_user, $this->_domain);
...@@ -239,7 +240,7 @@ class BackendStickyNote extends BackendDiff { ...@@ -239,7 +240,7 @@ class BackendStickyNote extends BackendDiff {
return false; return false;
} }
// Build the packet for a StickyNote // Build the packet for a StickyNote
$_content = pg_fetch_result($this->_result, 0, "content"); $_content = pg_fetch_result($this->_result, 0, "content");
...@@ -252,18 +253,19 @@ class BackendStickyNote extends BackendDiff { ...@@ -252,18 +253,19 @@ class BackendStickyNote extends BackendDiff {
unset($_content); unset($_content);
$message->subject = pg_fetch_result($this->_result, 0, "subject"); $message->subject = pg_fetch_result($this->_result, 0, "subject");
$message->lastmodified = pg_fetch_result($this->_result, 0, "changed"); $message->lastmodified = pg_fetch_result($this->_result, 0, "changed");
$message->type = 'IPW.StickyNote'; $message->type = 'IPM.StickyNote';
pg_free_result($this->_result); pg_free_result($this->_result);
unset($_params); unset($_params);
// Get categories, if any, for this note and add them to the SyncObject // Get categories, if any, for this note and add them to the SyncObject
$_params = array(); $_params = array();
array_push($_params, $id); array_push($_params, $id);
$this->_result = pg_query_params($this->_dbconn, "select tag from categories where ordinal=$1", $_params); $this->_result = pg_query_params($this->_dbconn, "select tag from categories where ordinal=$1", $_params);
if (pg_affected_rows($this->_result) > 0) { $_affected = pg_affected_rows($this->_result);
if ($_affected > 0) {
$_categories = array(); $_categories = array();
for ($_count = 0; $_count < pg_affected_rows($this->_result); $_count++) { for ($_count = 0; $_count < $_affected; $_count++) {
$_categories[] = pg_fetch_result($this->_result, $_count, 0); $_categories[] = pg_fetch_result($this->_result, $_count, 0);
} }
$message->categories = $_categories; $message->categories = $_categories;
...@@ -307,10 +309,11 @@ class BackendStickyNote extends BackendDiff { ...@@ -307,10 +309,11 @@ class BackendStickyNote extends BackendDiff {
ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendStickyNote->ChangeMessage('%s','%s')", $folderid, $id)); ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendStickyNote->ChangeMessage('%s','%s')", $folderid, $id));
ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendStickyNote->ChangeMessage(Message '%s')", $message)); ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendStickyNote->ChangeMessage(Message '%s')", $message));
// If we have a null ID then it's a new note; allocate an ordinal for it, // If we have a null ID then it's a new note; allocate an ordinal for
// Then insert into the database and return the stat pointer for it. // it. Then insert into the database and return the stat pointer for it.
// If we get an ID then it's an update; perform it and return stat pointer. // If we get an ID then it's an update; perform it and return stat
// // pointer.
//
$_contents = stream_get_contents($message->asbody->data, 1024000); $_contents = stream_get_contents($message->asbody->data, 1024000);
if (!$id) { if (!$id) {
$this->_result = pg_query($this->_dbconn, "select nextval('ordinal')"); $this->_result = pg_query($this->_dbconn, "select nextval('ordinal')");
...@@ -434,11 +437,11 @@ class BackendStickyNote extends BackendDiff { ...@@ -434,11 +437,11 @@ class BackendStickyNote extends BackendDiff {
ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendStickyNote->DeleteMessage('%s','%s')", $folderid, $id)); ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendStickyNote->DeleteMessage('%s','%s')", $folderid, $id));
$_params = array(); $_params = array();
array_push($_params, $id, $this->_user, $this->_domain); array_push($_params, $id, $this->_user, $this->_domain);
//
// Relation (foreign key) constraint deletes category entries when
// the parent is removed.
//
if (defined('STICKYNOTE_REALLYDELETE')) { if (defined('STICKYNOTE_REALLYDELETE')) {
//
// Relation (foreign key) constraint deletes category entries when
// the parent is removed.
//
$this->_result = pg_query_params($this->_dbconn, "delete from note where ordinal=$1 and login=$2 and domain=$3"); $this->_result = pg_query_params($this->_dbconn, "delete from note where ordinal=$1 and login=$2 and domain=$3");
if (pg_affected_rows($this->_result) != 1) { if (pg_affected_rows($this->_result) != 1) {
ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendStickyNote->DeleteMessage('%s','%s' failed)", $folderid, $id)); ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendStickyNote->DeleteMessage('%s','%s' failed)", $folderid, $id));
...@@ -507,6 +510,7 @@ class BackendStickyNote extends BackendDiff { ...@@ -507,6 +510,7 @@ class BackendStickyNote extends BackendDiff {
// Apparently this can get called before we've initialized, which in // Apparently this can get called before we've initialized, which in
// our case wouldn't matter, but for consistency return nothing if // our case wouldn't matter, but for consistency return nothing if
// that happens - or if it gets called before the database is connected. // that happens - or if it gets called before the database is connected.
if ((!$this->_changessinkinit) || ($this->_dbconn == false)) { if ((!$this->_changessinkinit) || ($this->_dbconn == false)) {
ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendStickyNote->ChangesSink - Not initialized ChangesSink, sleep and exit")); ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendStickyNote->ChangesSink - Not initialized ChangesSink, sleep and exit"));
sleep($timeout); sleep($timeout);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment