diff --git a/data/schema/7-postgresql.sql b/data/schema/7-postgresql.sql new file mode 100644 index 00000000..3639fee1 --- /dev/null +++ b/data/schema/7-postgresql.sql @@ -0,0 +1,2 @@ +ALTER TABLE sc_users ADD bLastDelete timestamp with time zone NOT NULL; +UPDATE sc_version SET schema_version=7; diff --git a/data/schema/7.sql b/data/schema/7.sql new file mode 100644 index 00000000..dc1e42b1 --- /dev/null +++ b/data/schema/7.sql @@ -0,0 +1,2 @@ +ALTER TABLE `sc_users` ADD `bLastDelete` DATETIME NOT NULL; +UPDATE `sc_version` SET `schema_version`='7'; diff --git a/data/tables-postgresql.sql b/data/tables-postgresql.sql index b0ada11a..9e8ddd1f 100644 --- a/data/tables-postgresql.sql +++ b/data/tables-postgresql.sql @@ -194,7 +194,8 @@ CREATE TABLE sc_users ( email varchar(50) NOT NULL DEFAULT '', homepage varchar(255) DEFAULT NULL, uContent text, - privateKey varchar(33) DEFAULT NULL + privateKey varchar(33) DEFAULT NULL, + bLastDelete timestamp with time zone DEFAULT now() NOT NULL ); CREATE UNIQUE INDEX privateKey on sc_users (privateKey); @@ -225,6 +226,7 @@ CREATE TABLE sc_users_sslclientcerts ( CREATE TABLE sc_version ( schema_version integer NOT NULL ); +INSERT INTO sc_version (schema_version) VALUES (7); -- -- Table structure for table "sc_votes" diff --git a/data/tables.sql b/data/tables.sql index 68d5ba97..cda2ab31 100644 --- a/data/tables.sql +++ b/data/tables.sql @@ -73,6 +73,7 @@ CREATE TABLE `sc_users` ( `homepage` varchar(255) default NULL, `uContent` text, `privateKey` varchar(33) default NULL, + `bLastDelete` datetime NOT NULL default '0000-00-00 00:00:00', PRIMARY KEY (`uId`), UNIQUE KEY `privateKey` (`privateKey`) ) CHARACTER SET utf8 COLLATE utf8_general_ci ; @@ -200,4 +201,4 @@ CREATE TABLE `sc_votes` ( CREATE TABLE `sc_version` ( `schema_version` int(11) NOT NULL ) DEFAULT CHARSET=utf8; -INSERT INTO `sc_version` (`schema_version`) VALUES ('6'); +INSERT INTO `sc_version` (`schema_version`) VALUES ('7'); diff --git a/doc/UPGRADE.txt b/doc/UPGRADE.txt index 511748ee..98dcd8b5 100644 --- a/doc/UPGRADE.txt +++ b/doc/UPGRADE.txt @@ -4,6 +4,16 @@ Upgrading SemanticScuttle from a previous version .. contents:: +From version 0.98 to 0.99 +========================= +Database updates +---------------- +Apply ``data/schema/7.sql`` + + ALTER TABLE `sc_users` ADD `bLastDelete` DATETIME NOT NULL; + UPDATE `sc_version` SET `schema_version`='7'; + + From version 0.94-0.98.1 to 0.98.3 ================================== Run ``scripts/fix-unfiled-tags.php`` to fix old bookmarks that miss the diff --git a/src/SemanticScuttle/Service/Bookmark.php b/src/SemanticScuttle/Service/Bookmark.php index 13153503..faa4e3e9 100644 --- a/src/SemanticScuttle/Service/Bookmark.php +++ b/src/SemanticScuttle/Service/Bookmark.php @@ -1001,6 +1001,17 @@ public function deleteBookmark($bookmark) ); } + // update ´last_delete´ date + $userservice = SemanticScuttle_Service_Factory::get('User'); + $uId = $userservice->getCurrentUserId(); + if( !$this->updateLastDelete($uId) ) { + $this->db->sql_transaction('rollback'); + message_die( + GENERAL_ERROR, 'Could not update the time of the last deletion', + '', __LINE__, __FILE__, $query, $this->db + ); + } + $this->db->sql_transaction('commit'); return true; @@ -1027,10 +1038,70 @@ public function deleteBookmarksForUser($uId) ); } + // update ´last_delete´ date + if( !$this->updateLastDelete($uId) ) { + message_die( + GENERAL_ERROR, 'Could not update the time of the last deletion', + '', __LINE__, __FILE__, $query, $this->db + ); + } + return true; } + /** + * Update Timestamp of last deletion to current timestamp + * + * @param integer $uId User ID + * + * @return boolean true when all went well + */ + private function updateLastDelete($uId) + { + $deldatetime = gmdate('Y-m-d H:i:s', time()); + + $updates = array( + 'bLastDelete' => $deldatetime, + ); + + $query = 'UPDATE '. $GLOBALS['tableprefix'] . 'users' + . ' SET '. $this->db->sql_build_array('UPDATE', $updates) + . ' WHERE uId = ' . intval($uId); + + if (!($dbresult = $this->db->sql_query($query))) { + return false; + } + + return true; + } + + /** + * Get the timestamp of the last deletion + * Used for the ´posts_update´ API-function if last deletion is + * more recent than last modification of an existing bookmark + * + * @param integer $uId User ID + * + * @return string representing the time, parsable with strtotime() + */ + public function getLastDelete($uId) + { + $query = 'SELECT bLastDelete as lastDelete' + . ' FROM '. $GLOBALS['tableprefix'] . 'users' + . ' WHERE uId = ' . intval($uId); + + if (!($dbresult = $this->db->sql_query($query))) { + message_die( + GENERAL_ERROR, 'Could not get LastDelete', '', + __LINE__, __FILE__, $sql, $this->db + ); + } + + return $this->db->sql_fetchfield(0, 0); + } + + /** * Counts the number of bookmarks that have the same address diff --git a/www/api/posts_update.php b/www/api/posts_update.php index 0e08ee75..8d406fd0 100644 --- a/www/api/posts_update.php +++ b/www/api/posts_update.php @@ -34,25 +34,31 @@ // parameter "datemode=modified" will get last modified date // instead of last created date -$orderby = null; -$timeField = 'bDatetime'; -if (isset($_GET['datemode']) && $_GET['datemode'] == 'modified') { - $orderby = 'modified_desc'; - $timeField = 'bModified'; +$orderby = 'modified_desc'; +$timeField = 'bModified'; +if (isset($_GET['datemode']) && $_GET['datemode'] == 'created') { + $orderby = null; + $timeField = 'bDatetime'; } +$uID = $userservice->getCurrentUserId(); $bs = SemanticScuttle_Service_Factory::get('Bookmark'); -$bookmarks = $bs->getBookmarks(0, 1, $userservice->getCurrentUserId(), null, null, $orderby); +$bookmarks = $bs->getBookmarks(0, 1, $uID, null, null, $orderby); +$lastDelete = $bs->getLastDelete($uID); -// Set up the XML file and output all the tags. -echo '\r\n"; +// get time of most recent change (modification or deletion) //foreach is used in case there are no bookmarks +$time = 0; foreach ($bookmarks['bookmarks'] as $row) { + $time = max( strtotime($row[$timeField]), strtotime($lastDelete) ); +} + +// Set up the XML file and output all the tags. +echo '\r\n"; echo ''; -} ?>