Commit fd1c4a66 authored by Karl Denninger's avatar Karl Denninger

ZP-1284 Change tabs to spaces. Released under the Affero GNU General Public...

ZP-1284 Change tabs to spaces. Released under the Affero GNU General Public License (AGPL) version 3.
parent 06140c80
create table note create table note
(ordinal int primary key, login text, domain text, (ordinal int 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);
categories text);
create table categories create table categories
(ordinal int references note(ordinal) on update cascade (ordinal int 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);
create index tag_ordinal on categories using btree(ordinal); create index tag_ordinal on categories using btree(ordinal);
......
...@@ -51,8 +51,8 @@ class BackendStickyNote extends BackendDiff { ...@@ -51,8 +51,8 @@ class BackendStickyNote extends BackendDiff {
throw new FatalException("BackendStickyNote(): Postgres extension php-pgsql not found", 0, null, LOGLEVEL_FATAL); throw new FatalException("BackendStickyNote(): Postgres extension php-pgsql not found", 0, null, LOGLEVEL_FATAL);
} }
$this->_changessinkinit = false; $this->_changessinkinit = false;
$this->_sinkdata = 0; $this->_sinkdata = 0;
} }
/** /**
...@@ -64,22 +64,22 @@ class BackendStickyNote extends BackendDiff { ...@@ -64,22 +64,22 @@ class BackendStickyNote extends BackendDiff {
* @see IBackend::Logon() * @see IBackend::Logon()
*/ */
public function Logon($username, $domain, $password) { public function Logon($username, $domain, $password) {
if (defined('STICKYNOTE_MUSTNOTBESET')) if (defined('STICKYNOTE_MUSTNOTBESET'))
throw new FatalException("BackendStickyNote(): Configuration file has not been set up; review REQUIREMENTS and edit config.php.", 0, NULL, LOGLEVEL_FATAL); throw new FatalException("BackendStickyNote(): Configuration file has not been set up; review REQUIREMENTS and edit config.php.", 0, NULL, LOGLEVEL_FATAL);
$this->_user = $username; $this->_user = $username;
$this->_domain = $domain; $this->_domain = $domain;
$_connstring = sprintf("host='%s' port='%s' dbname='%s' user='%s' password='%s'", STICKYNOTE_SERVER, STICKYNOTE_PORT, STICKYNOTE_DATABASE, STICKYNOTE_USER, STICKYNOTE_PASSWORD); $_connstring = sprintf("host='%s' port='%s' dbname='%s' user='%s' password='%s'", STICKYNOTE_SERVER, STICKYNOTE_PORT, STICKYNOTE_DATABASE, STICKYNOTE_USER, STICKYNOTE_PASSWORD);
ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendStickyNote->pg_conn(): '%s'", $_connstring)); ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendStickyNote->pg_conn(): '%s'", $_connstring));
$this->_dbconn = pg_connect($_connstring); $this->_dbconn = pg_connect($_connstring);
if ($this->_dbconn == false) if ($this->_dbconn == false)
throw new FatalException("BackendStickyNote(): Connection to Postgres backend failed", 0, NULL, LOGLEVEL_FATAL); throw new FatalException("BackendStickyNote(): Connection to Postgres backend failed", 0, NULL, LOGLEVEL_FATAL);
ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendStickyNote->Logon(): User '%s' Domain '%s' accepted on StickyNote", $username, $domain)); ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendStickyNote->Logon(): User '%s' Domain '%s' accepted on StickyNote", $username, $domain));
return true; return true;
} }
/** /**
...@@ -88,15 +88,15 @@ class BackendStickyNote extends BackendDiff { ...@@ -88,15 +88,15 @@ class BackendStickyNote extends BackendDiff {
* @see IBackend::Logoff() * @see IBackend::Logoff()
*/ */
public function Logoff() { public function Logoff() {
if ($this->_dbconn != null) { if ($this->_dbconn != null) {
pg_close($this->_dbconn); pg_close($this->_dbconn);
$this->_dbconn = false; $this->_dbconn = false;
} }
$this->SaveStorages(); $this->SaveStorages();
ZLog::Write(LOGLEVEL_DEBUG, "BackendStickyNote->Logoff(): disconnected from Postgres server"); ZLog::Write(LOGLEVEL_DEBUG, "BackendStickyNote->Logoff(): disconnected from Postgres server");
unset($this->_sinkdata); unset($this->_sinkdata);
return true; return true;
} }
...@@ -132,8 +132,8 @@ class BackendStickyNote extends BackendDiff { ...@@ -132,8 +132,8 @@ class BackendStickyNote extends BackendDiff {
*/ */
public function GetFolderList() { public function GetFolderList() {
$folders = array(); $folders = array();
$folder = $this->StatFolder("N"); $folder = $this->StatFolder("N");
$folders[] = $folder; $folders[] = $folder;
return $folders; return $folders;
} }
...@@ -161,7 +161,7 @@ class BackendStickyNote extends BackendDiff { ...@@ -161,7 +161,7 @@ class BackendStickyNote extends BackendDiff {
// 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";
$folder["id"] = $id; $folder["id"] = $id;
$folder["parent"] = "0"; $folder["parent"] = "0";
return $folder; return $folder;
...@@ -193,27 +193,27 @@ class BackendStickyNote extends BackendDiff { ...@@ -193,27 +193,27 @@ class BackendStickyNote extends BackendDiff {
ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendStickyNote->GetMessageList('%s','%s')", $folderid, $cutoffdate)); ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendStickyNote->GetMessageList('%s','%s')", $folderid, $cutoffdate));
$messages = array(); $messages = array();
$_param = array(); $_param = array();
if ($cutoffdate) { if ($cutoffdate) {
array_push($_param, $this->_user, $this->_domain, $cutoffdate); array_push($_param, $this->_user, $this->_domain, $cutoffdate);
$this->_result = pg_query_params($this->_dbconn, "select ordinal, extract(epoch from modified)::integer from note where modified <= timestamptz 'epoch' + $3 * interval '1 second' and 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 modified <= timestamptz 'epoch' + $3 * interval '1 second' and login=$1 and domain=$2 and deleted is false", $_param);
} else { } else {
array_push($_param, $this->_user, $this->_domain); array_push($_param, $this->_user, $this->_domain);
$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 from database)"));
} else { } else {
for ($_count = 0; $_count < pg_affected_rows($this->_result); $_count++) { for ($_count = 0; $_count < pg_affected_rows($this->_result); $_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);
$message["flags"] = 1; // Always mark as 'seen' $message["flags"] = 1; // Always mark as 'seen'
$messages[] = $message; $messages[] = $message;
} }
} }
pg_free_result($this->_result); pg_free_result($this->_result);
return $messages; return $messages;
} }
...@@ -226,49 +226,49 @@ class BackendStickyNote extends BackendDiff { ...@@ -226,49 +226,49 @@ class BackendStickyNote extends BackendDiff {
// 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);
$this->_result = pg_query_params($this->_dbconn, "select *, extract(epoch from modified)::integer as changed from note where ordinal = $1 and login = $2 and domain = $3 and deleted is false", $_params); $this->_result = pg_query_params($this->_dbconn, "select *, extract(epoch from modified)::integer as changed from note where ordinal = $1 and login = $2 and domain = $3 and deleted is false", $_params);
if (pg_result_status($this->_result) != PGSQL_TUPLES_OK) { if (pg_result_status($this->_result) != PGSQL_TUPLES_OK) {
ZLog::Write(LOGLEVEL_ERROR, sprintf("BackendStickyNote->GetMessage(FAILED query for '%s','%s')", $folderid, $id)); ZLog::Write(LOGLEVEL_ERROR, sprintf("BackendStickyNote->GetMessage(FAILED query for '%s','%s')", $folderid, $id));
return false; return false;
} }
if (pg_affected_rows($this->_result) != 1) { if (pg_affected_rows($this->_result) != 1) {
ZLog::Write(LOGLEVEL_ERROR, sprintf("BackendStickyNote->GetMessage(FAILED lookup for '%s','%s')", $folderid, $id)); ZLog::Write(LOGLEVEL_ERROR, sprintf("BackendStickyNote->GetMessage(FAILED lookup for '%s','%s')", $folderid, $id));
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");
$message = new SyncNote(); $message = new SyncNote();
$message->asbody = new SyncBaseBody(); $message->asbody = new SyncBaseBody();
$message->asbody->type = 2; $message->asbody->type = 2;
$message->asbody->estimatedDataSize = strlen($_content); $message->asbody->estimatedDataSize = strlen($_content);
$message->asbody->data = StringStreamWrapper::Open($_content); $message->asbody->data = StringStreamWrapper::Open($_content);
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 = 'IPW.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) { if (pg_affected_rows($this->_result) > 0) {
$_categories = array(); $_categories = array();
for ($_count = 0; $_count < pg_affected_rows($this->_result); $_count++) { for ($_count = 0; $_count < pg_affected_rows($this->_result); $_count++) {
$_categories[] = pg_fetch_result($this->_result, $_count, 0); $_categories[] = pg_fetch_result($this->_result, $_count, 0);
} }
$message->categories = $_categories; $message->categories = $_categories;
} }
pg_free_result($this->_result); pg_free_result($this->_result);
return $message; return $message;
} }
...@@ -281,19 +281,19 @@ class BackendStickyNote extends BackendDiff { ...@@ -281,19 +281,19 @@ class BackendStickyNote extends BackendDiff {
ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendStickyNote->StatMessage('%s','%s')", $folderid, $id)); ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendStickyNote->StatMessage('%s','%s')", $folderid, $id));
$message = array(); $message = array();
$_params = array(); $_params = array();
array_push($_params, $id, $this->_user, $this->_domain); array_push($_params, $id, $this->_user, $this->_domain);
$this->_result = pg_query_params($this->_dbconn, "select extract(epoch from modified)::integer from note where ordinal=$1 and login=$2 and domain=$3 and deleted is false", $_params); $this->_result = pg_query_params($this->_dbconn, "select extract(epoch from modified)::integer from note where ordinal=$1 and login=$2 and domain=$3 and deleted is false", $_params);
if (pg_result_status($this->_result) != PGSQL_TUPLES_OK) { if (pg_result_status($this->_result) != PGSQL_TUPLES_OK) {
ZLog::Write(LOGLEVEL_ERROR, sprintf("BackendStickyNote->StatMessage(Stat call failed for '%s')", $id)); ZLog::Write(LOGLEVEL_ERROR, sprintf("BackendStickyNote->StatMessage(Stat call failed for '%s')", $id));
return $message; return $message;
} }
if (!pg_num_rows($this->_result)) { if (!pg_num_rows($this->_result)) {
ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendStickyNote->StatMessage(Stat for empty note '%s')", $id)); ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendStickyNote->StatMessage(Stat for empty note '%s')", $id));
return $message; return $message;
} }
$message['mod'] = pg_fetch_result($this->_result, 0, 0); $message['mod'] = pg_fetch_result($this->_result, 0, 0);
pg_free_result($this->_result); pg_free_result($this->_result);
$message['id'] = $id; $message['id'] = $id;
$message['flags'] = "1"; $message['flags'] = "1";
return $message; return $message;
...@@ -311,110 +311,110 @@ class BackendStickyNote extends BackendDiff { ...@@ -311,110 +311,110 @@ class BackendStickyNote extends BackendDiff {
// Then insert into the database and return the stat pointer for 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')");
if (pg_result_status($this->_result) != PGSQL_TUPLES_OK) { if (pg_result_status($this->_result) != PGSQL_TUPLES_OK) {
ZLog::Write(LOGLEVEL_ERROR, sprintf("BackendStickyNote->ChangeMessage('Cannot get new sequence number for item')")); ZLog::Write(LOGLEVEL_ERROR, sprintf("BackendStickyNote->ChangeMessage('Cannot get new sequence number for item')"));
return false; return false;
} }
$id = pg_fetch_result($this->_result, 0, 0); $id = pg_fetch_result($this->_result, 0, 0);
pg_free_result($this->_result); pg_free_result($this->_result);
$this->_result = pg_query($this->_dbconn, "Begin"); $this->_result = pg_query($this->_dbconn, "Begin");
if (pg_result_status($this->_result) != PGSQL_COMMAND_OK) { if (pg_result_status($this->_result) != PGSQL_COMMAND_OK) {
ZLog::Write(LOGLEVEL_ERROR, sprintf("BackendStickyNote->ChangeMessage('Transaction start failure!')")); ZLog::Write(LOGLEVEL_ERROR, sprintf("BackendStickyNote->ChangeMessage('Transaction start failure!')"));
pg_free_result($this->_result); pg_free_result($this->_result);
return false; return false;
} }
pg_free_result($this->_result); pg_free_result($this->_result);
$_params = array(); $_params = array();
array_push($_params, $id, $message->subject, $_contents, $this->_user, $this->_domain); array_push($_params, $id, $message->subject, $_contents, $this->_user, $this->_domain);
$this->_result = pg_query_params($this->_dbconn, "insert into note (ordinal, subject, content, login, domain) values ($1, $2, $3, $4, $5)", $_params); $this->_result = pg_query_params($this->_dbconn, "insert into note (ordinal, subject, content, login, domain) values ($1, $2, $3, $4, $5)", $_params);
if (pg_result_status($this->_result) != PGSQL_COMMAND_OK) { if (pg_result_status($this->_result) != PGSQL_COMMAND_OK) {
ZLog::Write(LOGLEVEL_ERROR, sprintf("BackendStickyNote->ChangeMessage('Cannot insert new item; fail!')")); ZLog::Write(LOGLEVEL_ERROR, sprintf("BackendStickyNote->ChangeMessage('Cannot insert new item; fail!')"));
pg_free_result($this->_result); pg_free_result($this->_result);
$this->_result = pg_query($this->_dbconn, "Rollback"); $this->_result = pg_query($this->_dbconn, "Rollback");
pg_free_result($this->_result); pg_free_result($this->_result);
return false; return false;
} }
if (pg_affected_rows($this->_result) == 1) { if (pg_affected_rows($this->_result) == 1) {
ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendStickyNote->ChangeMessage('Insert of item %s (subj '%s') succeded')", $id, $message->subject)); ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendStickyNote->ChangeMessage('Insert of item %s (subj '%s') succeded')", $id, $message->subject));
} else { } else {
ZLog::Write(LOGLEVEL_ERROR, sprintf("BackendStickyNote->ChangeMessage('Insert of item %s (subj '%s') failed')", $id, $message->subject)); ZLog::Write(LOGLEVEL_ERROR, sprintf("BackendStickyNote->ChangeMessage('Insert of item %s (subj '%s') failed')", $id, $message->subject));
pg_free_result($this->_result); pg_free_result($this->_result);
$this->_result = pg_query($this->_dbconn, "Rollback"); $this->_result = pg_query($this->_dbconn, "Rollback");
pg_free_result($this->_result); pg_free_result($this->_result);
return false; return false;
} }
unset ($_params); unset ($_params);
pg_free_result($this->_result); pg_free_result($this->_result);
if ($message->categories) { if ($message->categories) {
foreach ($message->categories as $_category) { foreach ($message->categories as $_category) {
$_params = array(); $_params = array();
array_push($_params, $id, $_category); array_push($_params, $id, $_category);
$this->_result = pg_query_params($this->_dbconn, "insert into categories (ordinal, tag) values ($1, $2)", $_params); $this->_result = pg_query_params($this->_dbconn, "insert into categories (ordinal, tag) values ($1, $2)", $_params);
if (pg_result_status($this->_result) != PGSQL_COMMAND_OK) { if (pg_result_status($this->_result) != PGSQL_COMMAND_OK) {
ZLog::Write(LOGLEVEL_ERROR, sprintf("BackendStickyNote->ChangeMessage('Cannot insert category for item; fail!')")); ZLog::Write(LOGLEVEL_ERROR, sprintf("BackendStickyNote->ChangeMessage('Cannot insert category for item; fail!')"));
pg_free_result($this->_result); pg_free_result($this->_result);
$this->_result = pg_query($this->_dbconn, "Rollback"); $this->_result = pg_query($this->_dbconn, "Rollback");
pg_free_result($this->_result); pg_free_result($this->_result);
return(false); return(false);
} }
pg_free_result($this->_result); pg_free_result($this->_result);
} }
unset ($_category); unset ($_category);
} }
} else { } else {
$_params = array(); $_params = array();
array_push($_params, $message->subject, $_contents, $id, $this->_user, $this->_domain); array_push($_params, $message->subject, $_contents, $id, $this->_user, $this->_domain);
$this->_result = pg_query_params($this->_dbconn, "update note set subject=$1, content=$2, modified=now() where ordinal=$3 and login=$4 and domain=$5", $_params); $this->_result = pg_query_params($this->_dbconn, "update note set subject=$1, content=$2, modified=now() where ordinal=$3 and login=$4 and domain=$5", $_params);
if (pg_result_status($this->_result) != PGSQL_COMMAND_OK) { if (pg_result_status($this->_result) != PGSQL_COMMAND_OK) {
ZLog::Write(LOGLEVEL_ERROR, sprintf("BackendStickyNote->ChangeMessage('Update of item %s failed!')", $id)); ZLog::Write(LOGLEVEL_ERROR, sprintf("BackendStickyNote->ChangeMessage('Update of item %s failed!')", $id));
} }
if (pg_affected_rows($this->_result) == 1) { if (pg_affected_rows($this->_result) == 1) {
ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendStickyNote->ChangeMessage('Update of item %s (subj '%s') succeded')", $id, $message->subject)); ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendStickyNote->ChangeMessage('Update of item %s (subj '%s') succeded')", $id, $message->subject));
} else { } else {
ZLog::Write(LOGLEVEL_ERROR, sprintf("BackendStickyNote->ChangeMessage('Update of item %s (subj '%s') failed (credential mismatch)')", $id, $message->subject)); ZLog::Write(LOGLEVEL_ERROR, sprintf("BackendStickyNote->ChangeMessage('Update of item %s (subj '%s') failed (credential mismatch)')", $id, $message->subject));
} }
pg_free_result($this->_result); pg_free_result($this->_result);
unset ($_params); unset ($_params);
if ($message->categories) { if ($message->categories) {
$_params = array(); $_params = array();
array_push($_params, $id); array_push($_params, $id);
$this->_result = pg_query_params($this->_dbconn, "delete from categories where ordinal=$1", $_params); $this->_result = pg_query_params($this->_dbconn, "delete from categories where ordinal=$1", $_params);
if (pg_result_status($this->_result) != PGSQL_COMMAND_OK) { if (pg_result_status($this->_result) != PGSQL_COMMAND_OK) {
ZLog::Write(LOGLEVEL_ERROR, sprintf("BackendStickyNote->ChangeMessage('Cannot clear category for item; fail!')")); ZLog::Write(LOGLEVEL_ERROR, sprintf("BackendStickyNote->ChangeMessage('Cannot clear category for item; fail!')"));
pg_free_result($this->_result); pg_free_result($this->_result);
$this->_result = pg_query($this->_dbconn, "Rollback"); $this->_result = pg_query($this->_dbconn, "Rollback");
pg_free_result($this->_result); pg_free_result($this->_result);
return(false); return(false);
} }
unset ($_params); unset ($_params);
foreach ($message->categories as $_category) { foreach ($message->categories as $_category) {
$_params = array(); $_params = array();
array_push($_params, $id, $_category); array_push($_params, $id, $_category);
$this->_result = pg_query_params($this->_dbconn, "insert into categories (ordinal, tag) values ($1, $2)", $_params); $this->_result = pg_query_params($this->_dbconn, "insert into categories (ordinal, tag) values ($1, $2)", $_params);
if (pg_result_status($this->_result) != PGSQL_COMMAND_OK) { if (pg_result_status($this->_result) != PGSQL_COMMAND_OK) {
ZLog::Write(LOGLEVEL_ERROR, sprintf("BackendStickyNote->ChangeMessage('Cannot insert category for item; fail!')")); ZLog::Write(LOGLEVEL_ERROR, sprintf("BackendStickyNote->ChangeMessage('Cannot insert category for item; fail!')"));
pg_free_result($this->_result); pg_free_result($this->_result);
$this->_result = pg_query($this->_dbconn, "Rollback"); $this->_result = pg_query($this->_dbconn, "Rollback");
pg_free_result($this->_result); pg_free_result($this->_result);
return(false); return(false);
} }
pg_free_result($this->_result); pg_free_result($this->_result);
} }
unset ($_category); unset ($_category);
} }
} }
$this->_result = pg_query($this->_dbconn, "COMMIT"); $this->_result = pg_query($this->_dbconn, "COMMIT");
if (pg_result_status($this->_result) != PGSQL_COMMAND_OK) { if (pg_result_status($this->_result) != PGSQL_COMMAND_OK) {
ZLog::Write(LOGLEVEL_ERROR, sprintf("BackendStickyNote->ChangeMessage('Transaction commit FAIL!')")); ZLog::Write(LOGLEVEL_ERROR, sprintf("BackendStickyNote->ChangeMessage('Transaction commit FAIL!')"));
pg_free_result($this->_result); pg_free_result($this->_result);
return false; return false;
} }
pg_free_result($this->_result); pg_free_result($this->_result);
return $this->StatMessage($folderid, $id); return $this->StatMessage($folderid, $id);
} }
...@@ -432,29 +432,29 @@ class BackendStickyNote extends BackendDiff { ...@@ -432,29 +432,29 @@ class BackendStickyNote extends BackendDiff {
*/ */
public function DeleteMessage($folderid, $id, $contentParameters) { public function DeleteMessage($folderid, $id, $contentParameters) {
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);
if (defined('STICKYNOTE_REALLYDELETE')) { if (defined('STICKYNOTE_REALLYDELETE')) {
// //
// Relation (foreign key) constraint deletes category entries when // Relation (foreign key) constraint deletes category entries when
// the parent is removed. // 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));
pg_free_result($this->_result); pg_free_result($this->_result);
return false; return false;
} }
} else { } else {
$this->_result = pg_query_params($this->_dbconn, "update note set deleted = true where ordinal=$1 and login=$2 and domain=$3", $_params); $this->_result = pg_query_params($this->_dbconn, "update note set deleted = true where ordinal=$1 and login=$2 and domain=$3", $_params);
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));
pg_free_result($this->_result); pg_free_result($this->_result);
return false; return false;
} }
} }
pg_free_result($this->_result); pg_free_result($this->_result);
return true; return true;
} }
/** /**
...@@ -480,15 +480,15 @@ class BackendStickyNote extends BackendDiff { ...@@ -480,15 +480,15 @@ class BackendStickyNote extends BackendDiff {
/* /*
* Initialize the sink for a folder (there's only one) * Initialize the sink for a folder (there's only one)
* *
* @param string $folderid * @param string $folderid
* *
* @access public * @access public
* return boolean Always true since there's only one folder * return boolean Always true since there's only one folder
*/ */
public function ChangesSinkInitialize($folderid) { public function ChangesSinkInitialize($folderid) {
ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendStickyNote->ChangesSinkInitialize(): folderid '%s'", $folderid)); ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendStickyNote->ChangesSinkInitialize(): folderid '%s'", $folderid));
$this->_changessinkinit = true; $this->_changessinkinit = true;
return $this->_changessinkinit; return $this->_changessinkinit;
} }
/* /*
...@@ -496,43 +496,43 @@ class BackendStickyNote extends BackendDiff { ...@@ -496,43 +496,43 @@ class BackendStickyNote extends BackendDiff {
* If there's nothing to return in changes, wait 30 seconds. Otherwise * If there's nothing to return in changes, wait 30 seconds. Otherwise
* send back the FolderId -- there's only one. * send back the FolderId -- there's only one.
* *
* @param int $timeout How long to block if specified * @param int $timeout How long to block if specified
* *
* @access public * @access public
* @return array * @return array
*/ */
public function ChangesSink($timeout = 30) { public function ChangesSink($timeout = 30) {
$_notifications = array(); $_notifications = array();
// 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);
return $_notifications; return $_notifications;
} }
$_param = array(); $_param = array();
array_push($_param, $this->_user, $this->_domain); array_push($_param, $this->_user, $this->_domain);
$this->_result = pg_query_params($this->_dbconn, "select extract(epoch from modified)::integer from note where login=$1 and domain=$2 and deleted is false order by modified desc limit 1", $_param); $this->_result = pg_query_params($this->_dbconn, "select extract(epoch from modified)::integer from note where login=$1 and domain=$2 and deleted is false order by modified desc limit 1", $_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->ChangesSink(Failed to return a valid change list)")); ZLog::Write(LOGLEVEL_WARN, sprintf("BackendStickyNote->ChangesSink(Failed to return a valid change list)"));
} else { } else {
if (pg_affected_rows($this->_result) == 1) { if (pg_affected_rows($this->_result) == 1) {
ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendStickyNote->ChangesSink(There are valid notes stored)")); ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendStickyNote->ChangesSink(There are valid notes stored)"));
$_lastchange = pg_fetch_result($this->_result, 0, 0); $_lastchange = pg_fetch_result($this->_result, 0, 0);
if ($_lastchange != $this->_sinkdata) { if ($_lastchange != $this->_sinkdata) {
ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendStickyNote->ChangesSink(Change noted; tell the upper layers)")); ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendStickyNote->ChangesSink(Change noted; tell the upper layers)"));
array_push($_notifications, "N"); array_push($_notifications, "N");
$this->_sinkdata = $_lastchange; $this->_sinkdata = $_lastchange;
} }
} }
} }
pg_free_result($this->_result); pg_free_result($this->_result);
if (empty($_notifications)) { if (empty($_notifications)) {
sleep($timeout); sleep($timeout);
} }
return($_notifications); return($_notifications);
} }
/** /**
......
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