Skip to content
Permalink
Browse files

added caches.listing_last_modified; db-changelog fixes

  • Loading branch information...
following
following committed Mar 20, 2013
1 parent d5ee4ba commit 085c13983f3c49c1afa2f3cc5bb74856e5ec9e2d
@@ -25,6 +25,7 @@
$procedures[] = 'sp_updateall_topratingstat';
$procedures[] = 'sp_updateall_cache_picturestat';
$procedures[] = 'sp_updateall_cachelog_picturestat';
$procedures[] = 'sp_updateall_cache_listingdates';
$tpl->assign('procedures', $procedures);
@@ -52,6 +53,8 @@
sql("CALL sp_updateall_cache_picturestat(@c)");
else if ($proc == 'sp_updateall_cachelog_picturestat')
sql("CALL sp_updateall_cachelog_picturestat(@c)");
else if ($proc == 'sp_updateall_cache_listingdates')
sql("CALL sp_updateall_cache_listingdates(@c)");
else
{
$bError = true;
@@ -29,7 +29,7 @@ date commit ID change
2013-02-15 92e522f6 adjusted developer and production system:
- added index logentries:userid
- changed user.password length to 32
- removed sqlsession.remote_addr and index remote_addr
- removed xmlsession.remote_addr and index remote_addr
2013-02-16 06d832c3 new table data_licenses
added user.data_license
2013-02-17 b7b51eab added user.email_problems
@@ -45,12 +45,15 @@ date commit ID change
- modified lots of triggers
2013-03-09 09b51ecc added field 'restored_by' to cache_coordinates, cache_countries,
cache_logs_archived, all new tables and to triggers
removed table listing_restored
discarded table listing_restored
added index cache_logs_archived:user_id

2013-03-10 f8738936 added field 'mappreview' in pictures and pictures_modified
2013-03-10 f8738936 added field pictures.mappreview
2013-03-14 69abeb67 added fields coordinates_type.preposition and pp_trans_id
2013-03-15 a15b5582 discarded table 'data_license'
2013-03-16 added fields coordinates.date_created and .last_modified
2013-03-18 added table 'saved_texts' + triggers
2013-03-15 a15b5582 discarded table 'data_licenses'
2013-03-16 80b89939 added fields coordinates.date_created and .last_modified
2013-03-18 37b5268a added table 'saved_texts' + triggers
added triggers to table 'coordinates'

2013-03-20 added field caches.listing_last_modified;
must be initialized once via Admin / DB Maintenance / sp_updateall_cache_listingdates
@@ -200,6 +200,27 @@
UPDATE `mp3` SET `last_modified`=NOW() WHERE `object_id`=nCacheId;
END;");
// update listing modification date
sql_dropProcedure('sp_update_cache_listingdate');
sql("CREATE PROCEDURE sp_update_cache_listingdate (IN nCacheId INT(10) UNSIGNED)
BEGIN
IF ISNULL(@XMLSYNC) OR @XMLSYNC!=1 THEN
UPDATE `caches` SET `listing_last_modified`=NOW() WHERE `cache_id`=nCacheId LIMIT 1;
END IF;
END;");
sql_dropProcedure('sp_updateall_cache_listingdates');
sql("CREATE PROCEDURE sp_updateall_cache_listingdates (OUT nModified INT)
BEGIN
UPDATE `caches` SET `listing_last_modified` =
GREATEST(`last_modified`,
GREATEST(IFNULL((SELECT MAX(`last_modified`) FROM `cache_desc` WHERE `cache_desc`.`cache_id`=`caches`.`cache_id`),'0'),
GREATEST(IFNULL((SELECT MAX(`last_modified`) FROM `coordinates` WHERE `coordinates`.`type`=1 AND `coordinates`.`cache_id`=`caches`.`cache_id`),'0'),
IFNULL((SELECT MAX(`last_modified`) FROM `pictures` WHERE `pictures`.`object_type`=2 AND `pictures`.`object_id` = `caches`.`cache_id`),'0')
)));
SET nModified = ROW_COUNT();
END;");
// set caches.desc_languages of given cacheid and fill cache_desc_prefered
sql_dropProcedure('sp_update_caches_descLanguages');
sql("CREATE PROCEDURE sp_update_caches_descLanguages (IN nCacheId INT(10) UNSIGNED)
@@ -214,9 +235,8 @@
sql_dropProcedure('sp_updateall_caches_descLanguages');
sql("CREATE PROCEDURE sp_updateall_caches_descLanguages (OUT nModified INT)
BEGIN
SET nModified = 0;
UPDATE `caches`, (SELECT `cache_id`, GROUP_CONCAT(DISTINCT `language` ORDER BY `language` SEPARATOR ',') AS `dl` FROM `cache_desc` GROUP BY `cache_id`) AS `tbl` SET `caches`.`desc_languages`=`tbl`.`dl`, `caches`.`default_desclang`=PREFERED_LANG(`tbl`.`dl`, '&1') WHERE `caches`.`cache_id`=`tbl`.`cache_id`;
SET nModified = nModified + ROW_COUNT() ;
SET nModified = ROW_COUNT() ;
END;", strtoupper($lang . ',EN'));
// update found, last_found, notfound and note of stat_cache_logs, stat_caches and stat_user
@@ -513,6 +533,7 @@
IF ISNULL(@XMLSYNC) OR @XMLSYNC!=1 THEN
SET NEW.`date_created`=NOW();
SET NEW.`last_modified`=NOW();
SET NEW.`listing_last_modified`=NOW();
END IF;
IF NEW.`status` <> 5 THEN
SET NEW.`is_publishdate`=1;
@@ -589,6 +610,7 @@
OLD.`uuid`!=NEW.`uuid` OR
OLD.`node`!=NEW.`node` OR
OLD.`date_created`!=NEW.`date_created` OR
OLD.`is_publishdate`!=NEW.`is_publishdate` OR
OLD.`user_id`!=NEW.`user_id` OR
OLD.`name`!=NEW.`name` OR
OLD.`longitude`!=NEW.`longitude` OR
@@ -612,6 +634,10 @@
SET NEW.`last_modified`=NOW();
END IF;
IF NEW.`last_modified` != OLD.`last_modified` THEN
SET NEW.`listing_last_modified`=NOW();
END IF;
IF OLD.`status`!=NEW.`status` THEN
CALL sp_touch_cache(OLD.`cache_id`, FALSE);
END IF;
@@ -690,6 +716,7 @@
sql("CREATE TRIGGER `cacheDescAfterInsert` AFTER INSERT ON `cache_desc`
FOR EACH ROW
BEGIN
CALL sp_update_cache_listingdate(NEW.`cache_id`);
IF (SELECT `date_created` FROM `caches` WHERE `cache_id`=NEW.`cache_id`) < LEFT(NOW(),10) AND
(SELECT `status` FROM `caches` WHERE `caches`.`cache_id`=NEW.`cache_id`) != 5 THEN
INSERT IGNORE INTO `cache_desc_modified` (`cache_id`, `language`, `date_modified`, `desc`, `restored_by`) VALUES (NEW.`cache_id`, NEW.`language`, NOW(), NULL, IFNULL(@restoredby,0));
@@ -714,9 +741,11 @@
IF OLD.`language`!=NEW.`language` OR OLD.`cache_id`!=NEW.`cache_id` THEN
IF OLD.`cache_id`!=NEW.`cache_id` THEN
CALL sp_update_caches_descLanguages(OLD.`cache_id`);
CALL sp_update_cache_listingdate(OLD.`cache_id`);
END IF;
CALL sp_update_caches_descLanguages(NEW.`cache_id`);
END IF;
CALL sp_update_cache_listingdate(NEW.`cache_id`);
/* changes at date of creation are ignored to save archive space */
IF NEW.`cache_id`=OLD.`cache_id` AND
(SELECT `status` FROM `caches` WHERE `caches`.`cache_id`=OLD.`cache_id`) != 5 THEN
@@ -733,6 +762,7 @@
sql("CREATE TRIGGER `cacheDescAfterDelete` AFTER DELETE ON `cache_desc`
FOR EACH ROW
BEGIN
CALL sp_update_cache_listingdate(OLD.`cache_id`);
INSERT IGNORE INTO `removed_objects` (`localId`, `uuid`, `type`, `node`) VALUES (OLD.`id`, OLD.`uuid`, 3, OLD.`node`);
/* changes at date of creation are ignored to save archive space */
IF (OLD.`date_created` < LEFT(NOW(),10)) AND
@@ -979,6 +1009,7 @@
CALL sp_update_cachelog_picturestat(NEW.`object_id`, FALSE);
ELSEIF NEW.`object_type`=2 THEN
CALL sp_update_cache_picturestat(NEW.`object_id`, FALSE);
CALL sp_update_cache_listingdate(NEW.`object_id`);
END IF;
END;");
@@ -1001,21 +1032,28 @@
CALL sp_update_cachelog_picturestat(OLD.`object_id`, TRUE);
ELSEIF OLD.`object_type`=2 THEN
CALL sp_update_cache_picturestat(OLD.`object_id`, TRUE);
CALL sp_update_cache_listingdate(OLD.`object_id`);
END IF;
IF NEW.`object_type`=1 THEN
CALL sp_update_cachelog_picturestat(NEW.`object_id`, FALSE);
ELSEIF NEW.`object_type`=2 THEN
CALL sp_update_cache_picturestat(NEW.`object_id`, FALSE);
CALL sp_update_cache_listingdate(NEW.`object_id`);
END IF;
ELSE
IF NEW.`object_type`=2 THEN
CALL sp_update_cache_listingdate(NEW.`object_id`);
END IF;
ELSEIF @archive_picop AND
IF @archive_picop AND
( ( NEW.`object_type`=2 AND
OLD.`date_created` < LEFT(NOW(),10) AND
(SELECT `status` FROM `caches` WHERE `caches`.`cache_id`=OLD.`object_id`) != 5
) OR
NEW.`object_type`=1 ) AND
(NEW.`title` != OLD.`title` OR NEW.`spoiler` != OLD.`spoiler` OR NEW.`display` != OLD.`display`) THEN
INSERT IGNORE INTO `pictures_modified` (`id`, `date_modified`, `operation`, `date_created`, `url`, `title`, `object_id`, `object_type`, `spoiler`, `unknown_format`, `display`, `restored_by`) VALUES (OLD.`id`, NOW(), 'U', OLD.`date_created`, OLD.`url`, OLD.`title`, OLD.`object_id`, OLD.`object_type`, OLD.`spoiler`, OLD.`unknown_format`, OLD.`display`, IFNULL(@restoredby,0));
/* mappreview is not archived, can be safely set to 0 on restore */
INSERT IGNORE INTO `pictures_modified` (`id`, `date_modified`, `operation`, `date_created`, `url`, `title`, `object_id`, `object_type`, `spoiler`, `unknown_format`, `display`, `restored_by`) VALUES (OLD.`id`, NOW(), 'U', OLD.`date_created`, OLD.`url`, OLD.`title`, OLD.`object_id`, OLD.`object_type`, OLD.`spoiler`, OLD.`unknown_format`, OLD.`display`, IFNULL(@restoredby,0));
/* mappreview is not archived, can be safely set to 0 on restore */
END IF;
END IF;
END;");
@@ -1038,6 +1076,7 @@
CALL sp_update_cachelog_picturestat(OLD.`object_id`, TRUE);
ELSEIF OLD.`object_type`=2 THEN
CALL sp_update_cache_picturestat(OLD.`object_id`, TRUE);
CALL sp_update_cache_listingdate(OLD.`object_id`);
END IF;
END;");
@@ -1247,7 +1286,10 @@
sql("CREATE TRIGGER `cacheAttributesAfterInsert` AFTER INSERT ON `caches_attributes`
FOR EACH ROW
BEGIN
UPDATE `caches` SET `last_modified`=NOW() WHERE `cache_id`=NEW.`cache_id`;
IF ISNULL(@XMLSYNC) OR @XMLSYNC!=1 THEN
UPDATE `caches` SET `last_modified`=NOW() WHERE `cache_id`=NEW.`cache_id`;
CALL sp_update_cache_listingdate(NEW.`cache_id`);
END IF;
IF (SELECT `status` FROM `caches` WHERE `cache_id`=NEW.`cache_id`) != 5 AND
(SELECT `date_created` FROM `caches` WHERE `cache_id`=NEW.`cache_id`) < LEFT(NOW(),10) THEN
INSERT IGNORE INTO `caches_attributes_modified` (`cache_id`, `attrib_id`, `date_modified`, `was_set`, `restored_by`) VALUES (NEW.`cache_id`, NEW.`attrib_id`, NOW(), 0, IFNULL(@restoredby,0));
@@ -1258,9 +1300,13 @@
sql("CREATE TRIGGER `cacheAttributesAfterUpdate` AFTER UPDATE ON `caches_attributes`
FOR EACH ROW
BEGIN
UPDATE `caches` SET `last_modified`=NOW() WHERE `cache_id`=NEW.`cache_id`;
IF OLD.`cache_id`!=NEW.`cache_id` THEN
UPDATE `caches` SET `last_modified`=NOW() WHERE `cache_id`=OLD.`cache_id`;
IF ISNULL(@XMLSYNC) OR @XMLSYNC!=1 THEN
UPDATE `caches` SET `last_modified`=NOW() WHERE `cache_id`=NEW.`cache_id`;
CALL sp_update_cache_listingdate(NEW.`cache_id`);
IF OLD.`cache_id`!=NEW.`cache_id` THEN
UPDATE `caches` SET `last_modified`=NOW() WHERE `cache_id`=OLD.`cache_id`;
CALL sp_update_cache_listingdate(OLD.`cache_id`);
END IF;
END IF;
/* is not called, otherweise cache_attributes_modified would have to be updated */
END;");
@@ -1269,7 +1315,10 @@
sql("CREATE TRIGGER `cacheAttributesAfterDelete` AFTER DELETE ON `caches_attributes`
FOR EACH ROW
BEGIN
UPDATE `caches` SET `last_modified`=NOW() WHERE `cache_id`=OLD.`cache_id`;
IF ISNULL(@XMLSYNC) OR @XMLSYNC!=1 THEN
UPDATE `caches` SET `last_modified`=NOW() WHERE `cache_id`=OLD.`cache_id`;
CALL sp_update_cache_listingdate(OLD.`cache_id`);
END IF;
IF (SELECT `status` FROM `caches` WHERE `cache_id`=OLD.`cache_id`) != 5 AND
(SELECT `date_created` FROM `caches` WHERE `cache_id`=OLD.`cache_id`) < LEFT(NOW(),10) THEN
INSERT IGNORE INTO `caches_attributes_modified` (`cache_id`, `attrib_id`, `date_modified`, `was_set`, `restored_by`) VALUES (OLD.`cache_id`, OLD.`attrib_id`, NOW(), 1, IFNULL(@restoredby,0));
@@ -1298,10 +1347,7 @@
sql("CREATE TRIGGER `coordinatesAfterInsert` AFTER INSERT ON `coordinates`
FOR EACH ROW
BEGIN
/* dont overwrite date values while XML client is running */
IF ISNULL(@XMLSYNC) OR @XMLSYNC!=1 AND NEW.`type`=1 THEN
UPDATE `caches` SET `last_modified`=NOW() WHERE `caches`.`cache_id`=NEW.`cache_id`;
END IF;
CALL sp_update_cache_listingdate(NEW.`cache_id`);
END;");
sql_dropTrigger('coordinatesBeforeUpdate');
@@ -1318,27 +1364,24 @@
sql("CREATE TRIGGER `coordinatesAfterUpdate` AFTER UPDATE ON `coordinates`
FOR EACH ROW
BEGIN
/* dont overwrite date values while XML client is running */
IF ISNULL(@XMLSYNC) OR @XMLSYNC!=1 AND NEW.`type`=1 THEN
UPDATE `caches` SET `last_modified`=NOW() WHERE `caches`.`cache_id`=NEW.`cache_id`;
CALL sp_update_cache_listingdate(NEW.`cache_id`);
IF OLD.`cache_id`!=NEW.`cache_id` THEN
CALL sp_update_cache_listingdate(OLD.`cache_id`);
END IF;
END;");
sql_dropTrigger('coordinatesAfterDelete');
sql("CREATE TRIGGER `coordinatesAfterDelete` AFTER DELETE ON `coordinates`
FOR EACH ROW
BEGIN
/* dont overwrite date values while XML client is running */
IF ISNULL(@XMLSYNC) OR @XMLSYNC!=1 AND OLD.`type`=1 THEN
UPDATE `caches` SET `last_modified`=NOW() WHERE `caches`.`cache_id`=OLD.`cache_id`;
END IF;
CALL sp_update_cache_listingdate(OLD.`cache_id`);
END;");
sql_dropTrigger('savedTextsBeforeInsert');
sql("CREATE TRIGGER `savedTextsBeforeInsert` BEFORE INSERT ON `saved_texts`
FOR EACH ROW
BEGIN
/* dont overwrite date values while XML client is running */
/* dont overwrite creation date while XML client is running */
IF ISNULL(@XMLSYNC) OR @XMLSYNC!=1 THEN
SET NEW.`date_created`=NOW();
END IF;
@@ -7,6 +7,7 @@ CREATE TABLE `caches` (
`date_created` datetime NOT NULL COMMENT 'via Trigger (caches)',
`is_publishdate` tinyint(1) NOT NULL default '0' COMMENT '1 = date_created is publication date',
`last_modified` datetime NOT NULL COMMENT 'via Trigger (caches)',
`listing_last_modified` datetime NOT NULL COMMENT 'via Trigger (caches, cache_desc, coordinates, pictures)',
`user_id` int(10) unsigned NOT NULL,
`name` varchar(255) NOT NULL,
`longitude` double NOT NULL,
@@ -17,7 +17,7 @@ CREATE TABLE `pictures` (
`local` tinyint(1) NOT NULL default '1',
`unknown_format` tinyint(1) NOT NULL default '0',
`display` tinyint(1) NOT NULL default '1',
`mappreview` tinyint(2) NOT NULL default '7',
`mappreview` tinyint(1) NOT NULL default '0',
PRIMARY KEY (`id`),
UNIQUE KEY `uuid` (`uuid`),
KEY `last_modified` (`last_modified`),
@@ -130,8 +130,10 @@ <h3>cache (Caches)</h3>
&nbsp;&nbsp;&nbsp;&nbsp;&lt;attribute id="6"&gt;&lt;![CDATA[ Nur bei Opencaching]]&gt;&lt;/attribute&gt;<br>
&nbsp; &lt;/attributes&gt;<br>
&lt;/cache&gt;</P>
<p><em>lastmodified</em> ist das letzte Änderungsdatum des cache-Datensatzes, ohne Änderungen an Cachebeschreibungen oder Bildern. Für das Gesamt-Änderungsdatum des Listings müssen Letztere also mit "eingerechnet" werden. Ein Gesamt-Änderungsdatum des Listings kann bei Bedarf eingebaut werden.</p>
<p><em>datecreated</em> ist bei mit OC Version 1 und 2 angelegten Caches das Datum, an dem das Listing angelegt wurde, bei mit Version 3 angelegten Caches das Veröffentlichungsdatum. Ab Interface Version 1.2 zeigt das Attribut <em>ispublishdate="1"</em> an, dass es sich um das Veröffentlichungsdatum handelt.</p>
<p>Ab XML-Version 1.2 werden im <em>size</em>-Feld auch Nano-Größen zurückgeliefert. In älteren Interface-Versionen wird stattdessen "micro" ausgegeben.</p>
<p>Es fehlen noch Empfehlungen und zusätzliche Wegpunkte; wird bei Bedarf eingebaut.</p>
<h3>cachedesc (Cachebeschreibungen)</h3>
<p>
&lt;cachedesc&gt;<br>
@@ -85,6 +85,7 @@ function __construct($nNewCacheId=ID_NEW)
$this->reCache->addInt('node', 0, false);
$this->reCache->addDate('date_created', time(), true, RE_INSERT_IGNORE);
$this->reCache->addDate('last_modified', time(), true, RE_INSERT_IGNORE);
$this->reCache->addDate('listing_last_modified', time(), true, RE_INSERT_IGNORE);
$this->reCache->addInt('user_id', 0, false);
$this->reCache->addString('name', '', false);
$this->reCache->addDouble('longitude', 0, false);
@@ -173,13 +174,17 @@ function getUUID()
{
return $this->reCache->getValue('uuid');
}
function getDateCreated()
{
return $this->reCache->getValue('date_created');
}
function getLastModified()
{
return $this->reCache->getValue('last_modified');
}
function getDateCreated()
function getListingLastModified()
{
return $this->reCache->getValue('date_created');
return $this->reCache->getValue('listing_last_modified');
}
function getNode()
{
@@ -49,7 +49,7 @@
{
echo "Changed name to: " . $name . "\n";
sql("UPDATE `caches` SET `last_modified`=NOW(), `name`='&1' WHERE `cache_id`=&2", $name, $r['cache_id']);
sql("UPDATE `caches` SET `name`='&1' WHERE `cache_id`=&2", $name, $r['cache_id']);
}
}
else
@@ -41,7 +41,7 @@
if ($rCache === false) die('Cache existiert nicht!');
if ($rUser === false) die('User existiert nicht!');
sql("UPDATE caches SET user_id='&1', last_modified=NOW() WHERE cache_id='&2'", $rUser['user_id'], $rCache['cache_id']);
sql("UPDATE caches SET user_id='&1' WHERE cache_id='&2'", $rUser['user_id'], $rCache['cache_id']);
// send event to delete statpic
event_change_statpic($rCache['user_id']);
@@ -48,7 +48,7 @@
$cacheid = $rPublish['cache_id'];
// update cache status to active
sql("UPDATE `caches` SET `status`=1, `date_activate`=NULL, `last_modified`=NOW() WHERE `cache_id`='&1'", $cacheid);
sql("UPDATE `caches` SET `status`=1, `date_activate`=NULL WHERE `cache_id`='&1'", $cacheid);
// send events
touchCache($cacheid);
@@ -132,9 +132,10 @@ function write_viewacache_urls()
WHERE `cache_status`.`allow_user_view`=1");
while ($r = sql_fetch_assoc($rs))
{
$dLastMod = sql_value("SELECT MAX(`last_modified`) `last_modified` FROM (SELECT `last_modified` FROM `caches` WHERE `cache_id` ='&1' UNION
SELECT `last_modified` FROM `cache_desc` WHERE `cache_id` ='&1' UNION
SELECT MAX(`last_modified`) AS `last_modified` FROM `cache_logs` WHERE `cache_id` ='&1') `tmp_result`", time(), $r['cache_id']);
$dLastMod = sql_value("SELECT MAX(`last_modified`) `last_modified` FROM
(SELECT `listing_last_modified` AS `last_modified` FROM `caches` WHERE `cache_id` ='&1' UNION
SELECT MAX(`last_modified`) AS `last_modified` FROM `cache_logs` WHERE `cache_id` ='&1') `tmp_result`",
time(), $r['cache_id']);
$this->oSitemapXML->write('viewcache.php?wp=' . $r['wp_oc'] . '&desclang=' . $r['language'], strtotime($dLastMod));
}
sql_free_result($rs);
Oops, something went wrong.

0 comments on commit 085c139

Please sign in to comment.
You can’t perform that action at this time.