From 252019f52d8b68598c950f82724564f5df35dfd3 Mon Sep 17 00:00:00 2001 From: following Date: Fri, 22 Mar 2013 09:53:49 +0100 Subject: [PATCH] fixed another trigger recursion when updating a cache record function touchCache() in lib/clicompatbase.inc.php updated e.g. cache_desc.last_modified in the same statement with an access to caches table. As the cacheDescAfterUpdate trigger updates caches.listing_last_modified, the read & write access to caches table collided. function touchCache() is obsolete, as touching on status change is done by triggers for all depending tables (via SQL function sp_touch_cache). --- htdocs/doc/sql/stored-proc/maintain.php | 6 ++++++ htdocs/editcache.php | 5 ++--- htdocs/lib/clicompatbase.inc.php | 10 ---------- htdocs/util/archive/top.php | 2 +- htdocs/util/attributes/top.php | 2 -- htdocs/util/publish_caches/run_publish.php | 2 +- 6 files changed, 10 insertions(+), 17 deletions(-) diff --git a/htdocs/doc/sql/stored-proc/maintain.php b/htdocs/doc/sql/stored-proc/maintain.php index e1cbcd3c..61d6f539 100644 --- a/htdocs/doc/sql/stored-proc/maintain.php +++ b/htdocs/doc/sql/stored-proc/maintain.php @@ -192,6 +192,12 @@ UPDATE `caches` SET `last_modified`=NOW() WHERE `cache_id`=nCacheId; END IF; + /* This is a hack for the XML interface which delivers cache-related records + * like descriptions and pictures only depending on their last_modified date. + * Data may not have been deliverd or stored somewhere depending on the cache + * status, so when status changes, all has to be sent (again) via XML. + */ + UPDATE `cache_desc` SET `last_modified`=NOW() WHERE `cache_id`=nCacheId; UPDATE `cache_logs` SET `last_modified`=NOW() WHERE `cache_id`=nCacheId; UPDATE `coordinates` SET `last_modified`=NOW() WHERE `cache_id`=nCacheId AND `type`=1; diff --git a/htdocs/editcache.php b/htdocs/editcache.php index 12b5e84c..d6a91a78 100644 --- a/htdocs/editcache.php +++ b/htdocs/editcache.php @@ -447,7 +447,8 @@ function getWaypoints($cacheid) $activation_date = 'NULL'; } - //save to DB + // save to DB + // status update will trigger touching the last_modified date of all depending records sql("UPDATE `caches` SET `name`='&1', `longitude`='&2', `latitude`='&3', `type`='&4', `date_hidden`='&5', `country`='&6', `size`='&7', `difficulty`='&8', `terrain`='&9', `status`='&10', `search_time`='&11', `way_length`='&12', `logpw`='&13', `wp_gc`='&14', `wp_nc`='&15', `date_activate` = $activation_date WHERE `cache_id`='&16'", $cache_name, $cache_lon, $cache_lat, $cache_type, date('Y-m-d', mktime(0, 0, 0, $cache_hidden_month, $cache_hidden_day, $cache_hidden_year)), $cache_country, $sel_size, $cache_difficulty, $cache_terrain, $status, $search_time, $way_length, $log_pw, $wp_gc, $wp_nc, $cache_id); // do not use slave server for the next time ... @@ -475,8 +476,6 @@ function getWaypoints($cacheid) // if old status is not yet published and new status is published => notify-event if ($status_old == 5 && $status != 5) { - touchCache($cache_id); - // send new cache event event_notify_new_cache($cache_id); } diff --git a/htdocs/lib/clicompatbase.inc.php b/htdocs/lib/clicompatbase.inc.php index c8556346..b97af8e4 100644 --- a/htdocs/lib/clicompatbase.inc.php +++ b/htdocs/lib/clicompatbase.inc.php @@ -81,16 +81,6 @@ sql("UPDATE `caches` SET `last_found`='&1' WHERE `cache_id`=&2", $r['date'], $cacheid); } - // update last_modified=NOW() for every object depending on that cacheid - function touchCache($cacheid) - { - sql("UPDATE `caches` SET `last_modified`=NOW() WHERE `cache_id`='&1'", $cacheid); - sql("UPDATE `caches`, `cache_logs` SET `cache_logs`.`last_modified`=NOW() WHERE `caches`.`cache_id`=`cache_logs`.`cache_id` AND `caches`.`cache_id`='&1'", $cacheid); - sql("UPDATE `caches`, `cache_desc` SET `cache_desc`.`last_modified`=NOW() WHERE `caches`.`cache_id`=`cache_desc`.`cache_id` AND `caches`.`cache_id`='&1'", $cacheid); - sql("UPDATE `caches`, `pictures` SET `pictures`.`last_modified`=NOW() WHERE `caches`.`cache_id`=`pictures`.`object_id` AND `pictures`.`object_type`=2 AND `caches`.`cache_id`='&1'", $cacheid); - sql("UPDATE `caches`, `cache_logs`, `pictures` SET `pictures`.`last_modified`=NOW() WHERE `caches`.`cache_id`=`cache_logs`.`cache_id` AND `cache_logs`.`id`=`pictures`.`object_id` AND `pictures`.`object_type`=1 AND `caches`.`cache_id`='&1'", $cacheid); - } - // read a file and return it as a string // WARNING: no huge files! function read_file($file='') diff --git a/htdocs/util/archive/top.php b/htdocs/util/archive/top.php index d9d9ea11..32529433 100644 --- a/htdocs/util/archive/top.php +++ b/htdocs/util/archive/top.php @@ -13,7 +13,7 @@ if (isset($_REQUEST['post'])) { - sql("UPDATE `caches` SET `status`=3, `last_modified`=NOW() WHERE `wp_oc`='&1'", $wp); + sql("UPDATE `caches` SET `status`=3 WHERE `wp_oc`='&1'", $wp); } ?> diff --git a/htdocs/util/attributes/top.php b/htdocs/util/attributes/top.php index dd72b22a..369651bd 100644 --- a/htdocs/util/attributes/top.php +++ b/htdocs/util/attributes/top.php @@ -23,8 +23,6 @@ sql("DELETE FROM `caches_attributes` WHERE `cache_id`='&1'", $cache_id); foreach ($attrs AS $attr) sql("INSERT INTO `caches_attributes` (`cache_id`, `attrib_id`) VALUES ('&1', '&2')", $cache_id, $attr); - - sql("UPDATE `caches` SET `last_modified`=NOW() WHERE `cache_id`='&1'", $cache_id); } $attrs = array(); diff --git a/htdocs/util/publish_caches/run_publish.php b/htdocs/util/publish_caches/run_publish.php index 0042dd15..2e269c23 100644 --- a/htdocs/util/publish_caches/run_publish.php +++ b/htdocs/util/publish_caches/run_publish.php @@ -48,10 +48,10 @@ $cacheid = $rPublish['cache_id']; // update cache status to active + // will touch the last_modified date of all depending records sql("UPDATE `caches` SET `status`=1, `date_activate`=NULL WHERE `cache_id`='&1'", $cacheid); // send events - touchCache($cacheid); event_new_cache($userid); event_notify_new_cache($cacheid); }