diff --git a/bin/dbsv-update.php b/bin/dbsv-update.php index 20ada60a..e33a62fc 100644 --- a/bin/dbsv-update.php +++ b/bin/dbsv-update.php @@ -187,4 +187,40 @@ sql("ALTER TABLE `user` ADD COLUMN `first_email_problem` date default NULL AFTER `email_problems`"); } + function dbv_110() // move adoption history to separate table + { + if (!sql_table_exists('cache_adoptions')) + { + sql( + "CREATE TABLE `cache_adoptions` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `cache_id` int(10) unsigned NOT NULL, + `date` datetime NOT NULL, + `from_user_id` int(10) unsigned NOT NULL, + `to_user_id` int(10) unsigned NOT NULL, + PRIMARY KEY (`id`), + KEY `cache_id` (`cache_id`,`date`) + ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1"); + + $rs = sql("SELECT `id`, `date_created`, `objectid1`, `logtext` + FROM `logentries` + WHERE `eventid`=5 + ORDER BY `date_created`, `id`"); + while ($rLog = sql_fetch_assoc($rs)) + { + preg_match('/Cache (\d+) has changed the owner from userid (\d+) to (\d+) by (\d+)/', + $rLog['logtext'], $matches); + if (count($matches) != 5) + die("unknown adoption log entry format for ID " . $rLog['id'] . "\n"); + sql("INSERT INTO `cache_adoptions` + (`cache_id`,`date`,`from_user_id`,`to_user_id`) + VALUES ('&1','&2','&3','&4')", + $rLog['objectid1'], $rLog['date_created'], $matches[2], $matches[3]); + } + sql_free_result($rs); + + // We keep the old entries in 'logentries' for the case something went wrong here. + } + } + ?> \ No newline at end of file diff --git a/htdocs/doc/sql/static-data/data.sql b/htdocs/doc/sql/static-data/data.sql index 95060111..dda9bd2a 100644 --- a/htdocs/doc/sql/static-data/data.sql +++ b/htdocs/doc/sql/static-data/data.sql @@ -2492,6 +2492,10 @@ INSERT INTO `sys_trans` (`id`, `text`, `last_modified`) VALUES ('2070', 'One ore INSERT INTO `sys_trans` (`id`, `text`, `last_modified`) VALUES ('2071', 'This cache has been \"temporarily unavailable\" for more than one year now; therefore it is being archived automatically. The owner may decide to maintain the cache and re-enable the listing.', '2013-05-28 16:51:40'); INSERT INTO `sys_trans` (`id`, `text`, `last_modified`) VALUES ('2072', 'This event took place more than five weeks ago; therefore it is being archived automatically. The owner may re-enable the listing if it should stay active for some exceptional reason.', '2013-05-28 16:51:40'); INSERT INTO `sys_trans` (`id`, `text`, `last_modified`) VALUES ('2073', 'This user account is disabled.', '2013-05-28 16:51:40'); +INSERT INTO `sys_trans` (`id`, `text`, `last_modified`) VALUES ('2074', 'Adoptions_', '2013-05-28 16:51:40'); +INSERT INTO `sys_trans` (`id`, `text`, `last_modified`) VALUES ('2075', 'since September 2012', '2013-05-28 16:51:40'); +INSERT INTO `sys_trans` (`id`, `text`, `last_modified`) VALUES ('2076', 'From Owner', '2013-05-28 16:51:40'); +INSERT INTO `sys_trans` (`id`, `text`, `last_modified`) VALUES ('2077', 'To Owner', '2013-05-28 16:51:40'); -- Table sys_trans_ref SET NAMES 'utf8'; @@ -6436,6 +6440,10 @@ INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUE INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUES ('2071', 'DE', 'Dieser Cache ist seit mehr als einem Jahr „momentan nicht verfügbar“; daher wird er automatisch archiviert. Er kann vom Besitzer jederzeit instand gesetzt und reaktiviert werden.', '2013-04-25 23:00:00'); INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUES ('2072', 'DE', 'Dieses Event fand vor über fünf Wochen statt; daher wird es automatisch archiviert. Das Listing kann vom Owner selbst reaktiviert werden, falls es aus besonderen Gründen weiter aktiv bleiben soll.', '2013-04-25 23:00:00'); INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUES ('2073', 'DE', 'Dieser Benutzer ist deaktiviert.', '2013-04-25 23:00:00'); +INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUES ('2074', 'DE', 'Adoptionen', '2013-04-25 23:00:00'); +INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUES ('2075', 'DE', 'seit September 2012', '2013-04-25 23:00:00'); +INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUES ('2076', 'DE', 'Alter Besitzer', '2013-04-25 23:00:00'); +INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUES ('2077', 'DE', 'Neuer Besitzer', '2013-04-25 23:00:00'); INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUES ('1', 'EN', 'Reorder IDs \r', '2010-09-02 00:15:30'); INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUES ('2', 'EN', 'The database could not be reconnected.', '2010-08-28 11:48:07'); INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUES ('3', 'EN', 'Testing – please do not login', '2010-08-28 11:48:07'); @@ -8000,6 +8008,10 @@ INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUE INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUES ('2071', 'EN', 'This cache has been \"temporarily unavailable\" for more than one year now; therefore it is being archived automatically. The owner may decide to maintain the cache and re-enable the listing.', '2013-04-25 23:00:00'); INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUES ('2072', 'EN', 'This event took place more than five weeks ago; therefore it is being archived automatically. The owner may re-enable the listing if it should stay active for some exceptional reason.', '2013-04-25 23:00:00'); INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUES ('2073', 'EN', 'This user account is disabled.', '2013-04-25 23:00:00'); +INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUES ('2074', 'EN', 'Adoptions', '2013-04-25 23:00:00'); +INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUES ('2075', 'EN', 'since September 2012', '2013-04-25 23:00:00'); +INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUES ('2076', 'EN', 'From Owner', '2013-04-25 23:00:00'); +INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUES ('2077', 'EN', 'To Owner', '2013-04-25 23:00:00'); INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUES ('1', 'ES', 'Reordenar ID', '2010-12-09 00:17:55'); INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUES ('2', 'ES', 'La base de datos no se pudo conectar.', '2010-12-09 00:17:55'); INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUES ('3', 'ES', 'En pruebas - por favor, no entre.', '2010-12-09 00:17:55'); diff --git a/htdocs/doc/sql/stored-proc/maintain.php b/htdocs/doc/sql/stored-proc/maintain.php index 2419f17c..a780e5ca 100644 --- a/htdocs/doc/sql/stored-proc/maintain.php +++ b/htdocs/doc/sql/stored-proc/maintain.php @@ -710,6 +710,10 @@ /* logpw needs not to be saved */ /* for further explanation see restorecaches.php */ END IF; + IF NEW.`user_id`!=OLD.`user_id` THEN + INSERT INTO `cache_adoptions` (`cache_id`,`date`,`from_user_id`,`to_user_id`) + VALUES (NEW.`cache_id`, NEW.`last_modified`, OLD.`user_id`, NEW.`user_id`); + END IF; IF NEW.`user_id`!=OLD.`user_id` OR NEW.`status`!=OLD.`status` THEN CALL sp_update_hiddenstat(OLD.`user_id`, OLD.`status`, TRUE); CALL sp_update_hiddenstat(NEW.`user_id`, NEW.`status`, FALSE); diff --git a/htdocs/doc/sql/tables/cache_adoptions.sql b/htdocs/doc/sql/tables/cache_adoptions.sql new file mode 100644 index 00000000..5e907cd1 --- /dev/null +++ b/htdocs/doc/sql/tables/cache_adoptions.sql @@ -0,0 +1,11 @@ +SET NAMES 'utf8'; +DROP TABLE IF EXISTS `cache_adoptions`; +CREATE TABLE IF NOT EXISTS `cache_adoptions` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `cache_id` int(10) unsigned NOT NULL, + `date` datetime NOT NULL, + `from_user_id` int(10) unsigned NOT NULL, + `to_user_id` int(10) unsigned NOT NULL, + PRIMARY KEY (`id`), + KEY `cache_id` (`cache_id`,`date`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ; diff --git a/htdocs/lib2/logic/cache.class.php b/htdocs/lib2/logic/cache.class.php index 0e727fd4..6d1752c3 100644 --- a/htdocs/lib2/logic/cache.class.php +++ b/htdocs/lib2/logic/cache.class.php @@ -413,6 +413,9 @@ class cache VALUES ('cache', 5, '&1', '&2', '&3', '&4')", $login->userid, $this->nCacheId, 0, 'Cache ' . sql_escape($this->nCacheId) . ' has changed the owner from userid ' . sql_escape($this->getUserId()) . ' to ' . sql_escape($userid) . ' by ' . sql_escape($login->userid)); + // Adoptions now are recorded by trigger in cache_adoptions table. + // Recording adoptions in 'logentries' may be discarded after ensuring that the + // log entries are not used anywhere. sql("UPDATE `caches` SET `user_id`='&1' WHERE `cache_id`='&2'", $userid, $this->nCacheId); sql("DELETE FROM `cache_adoption` WHERE `cache_id`='&1'", $this->nCacheId); @@ -529,6 +532,21 @@ class cache ORDER BY `date_modified` DESC", $this->getCacheId(), $opt['template']['locale']); $tpl->assign_rs('status_changes',$rs); sql_free_result($rs); + + // Adoptions + $rs = sql("SELECT `cache_adoptions`.`date`, + `cache_adoptions`.`from_user_id`, + `cache_adoptions`.`to_user_id`, + `from_user`.`username` AS `from_username`, + `to_user`.`username` AS `to_username` + FROM `cache_adoptions` + LEFT JOIN `user` `from_user` ON `from_user`.`user_id`=`from_user_id` + LEFT JOIN `user` `to_user` ON `to_user`.`user_id`=`to_user_id` + WHERE `cache_id`='&1' + ORDER BY `cache_adoptions`.`date`, `cache_adoptions`.`id`", + $this->getCacheId()); + $tpl->assign_rs('adoptions',$rs); + sql_free_result($rs); } } diff --git a/htdocs/templates2/ocstyle/adminhistory.tpl b/htdocs/templates2/ocstyle/adminhistory.tpl index eced3521..92089222 100644 --- a/htdocs/templates2/ocstyle/adminhistory.tpl +++ b/htdocs/templates2/ocstyle/adminhistory.tpl @@ -88,7 +88,7 @@
-| {t}Date{/t} | @@ -106,6 +106,37 @@
|---|
+ {/if} + + {if !$reportdisplay || $adoptions|@count} +
+
+ {t}Adoptions_{/t} {t}since September 2012{/t}
+
| {t}Date{/t} | +{t}From Owner{/t} | ++ | {t}To Owner{/t} | +
|---|---|---|---|
| {$adoption.date|date_format:$opt.format.date} | +{$adoption.from_username} + | → | +{$adoption.to_username} + |