From 371894d177a6c66d2f08ac8391313150e80f4800 Mon Sep 17 00:00:00 2001 From: following Date: Sun, 23 Jun 2013 20:45:43 +0200 Subject: [PATCH] XML interface and rating fixes and changes; updates #244 - XML interface update to v1.4 -- added listing_last_modified and log_last_modified fields -- changed and fixed handling of ratings for multiple found logs of one user -- resend log records after editing (only) rating or withdrawing rating via mytop5 -- logtype fix: convert type > 8 to 3 in XML versions < 1.3 - fixed rating handling when deleting one of multiple found logs -- added dbmaintain update procedure for this fix - show only one rating star when a user logged multiple founds - added trigger update function to database versioning --- bin/dbsv-update.php | 19 +++ htdocs/dbmaintain.php | 3 + htdocs/doc/sql/static-data/data.sql | 4 +- htdocs/doc/sql/stored-proc/maintain.php | 30 ++++- htdocs/doc/xml/xml11.htm | 48 +++++--- htdocs/editlog.php | 28 ++++- htdocs/lib/recommendation.inc.php | 67 ++++++++++ htdocs/lib2/logic/cache.class.php | 2 +- htdocs/removelog.php | 10 +- htdocs/templates2/ocstyle/dbmaintain.tpl | 5 +- htdocs/xml/ocxml11.php | 20 ++- htdocs/xml/ocxml14.dtd | 148 +++++++++++++++++++++++ htdocs/xml/ocxml14.php | 14 +++ 13 files changed, 363 insertions(+), 35 deletions(-) create mode 100644 htdocs/lib/recommendation.inc.php create mode 100644 htdocs/xml/ocxml14.dtd create mode 100644 htdocs/xml/ocxml14.php diff --git a/bin/dbsv-update.php b/bin/dbsv-update.php index 4249d5ac..080e6e51 100644 --- a/bin/dbsv-update.php +++ b/bin/dbsv-update.php @@ -44,6 +44,20 @@ } while ($db_version > 0); + // Now and then a maintain.php update should be inserted, because multiple + // mutations may be run in one batch, and future mutations may depend on + // changed triggers, which may not be obvious. + // Of course, a trigger update mutation can also be inserted directly before a + // mutation which needs it. (But take care that maintain.php at that point does + // not depend on database changes which will be done by that mutation ...) + + function update_triggers() + { + global $opt; + system('php ' . $opt['rootpath'] . 'doc/sql/stored-proc/maintain.php'); + } + + // Database mutations // - must be consecutively numbered // - should behave well if run multiple times @@ -246,4 +260,9 @@ sql("ALTER TABLE `caches` ADD INDEX `wp_gc_maintained` (`wp_gc_maintained`)"); } + function dbv_113() // preventive trigger update + { + update_triggers(); + } + ?> \ No newline at end of file diff --git a/htdocs/dbmaintain.php b/htdocs/dbmaintain.php index f8bc7feb..75ebf60f 100644 --- a/htdocs/dbmaintain.php +++ b/htdocs/dbmaintain.php @@ -27,6 +27,7 @@ $procedures[] = 'sp_updateall_cachelog_picturestat'; $procedures[] = 'sp_updateall_cache_listingdates'; $procedures[] = 'sp_updateall_cachelog_logdates'; + $procedures[] = 'sp_updateall_rating_dates'; $tpl->assign('procedures', $procedures); @@ -58,6 +59,8 @@ sql("CALL sp_updateall_cache_listingdates(@c)"); else if ($proc == 'sp_updateall_cachelog_logdates') sql("CALL sp_updateall_cachelog_logdates(@c)"); + else if ($proc == 'sp_updateall_rating_dates') + sql("CALL sp_updateall_rating_dates(@c)"); else { $bError = true; diff --git a/htdocs/doc/sql/static-data/data.sql b/htdocs/doc/sql/static-data/data.sql index b698f2e1..42f926f8 100644 --- a/htdocs/doc/sql/static-data/data.sql +++ b/htdocs/doc/sql/static-data/data.sql @@ -2507,6 +2507,7 @@ INSERT INTO `sys_trans` (`id`, `text`, `last_modified`) VALUES ('2086', 'unknown INSERT INTO `sys_trans` (`id`, `text`, `last_modified`) VALUES ('2087', 'Show on map', '2013-04-25 23:00:00'); INSERT INTO `sys_trans` (`id`, `text`, `last_modified`) VALUES ('2089', 'disabled[pl]', '2013-04-25 23:00:00'); INSERT INTO `sys_trans` (`id`, `text`, `last_modified`) VALUES ('2090', 'archived[pl]', '2013-04-25 23:00:00'); +INSERT INTO `sys_trans` (`id`, `text`, `last_modified`) VALUES ('2091', 'Test for and fix inconsistencies in database tables', '2013-04-25 23:00:00'); -- Table sys_trans_ref SET NAMES 'utf8'; @@ -5496,7 +5497,7 @@ INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUE INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUES ('670', 'DE', 'Trefferquote', '2010-08-28 11:48:06'); INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUES ('671', 'DE', 'Es können keine Empfehlungen gegeben werden, da keine weiteren Bewertungen vorliegen.', '2010-08-28 11:48:06'); INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUES ('672', 'DE', 'Datenbankwartung', '2010-08-28 11:48:06'); -INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUES ('673', 'DE', 'DB Maintainance', '2010-08-28 11:48:06'); +INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUES ('673', 'DE', 'Datenbankwartung', '2010-08-28 11:48:06'); INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUES ('674', 'DE', '%1 hat %2 Einträge korrigiert', '2010-08-28 11:48:06'); INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUES ('675', 'DE', 'Ausführen', '2010-08-28 11:48:06'); INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUES ('676', 'DE', 'Senden', '2010-08-28 11:48:06'); @@ -6465,6 +6466,7 @@ INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUE INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUES ('2087', 'DE', 'auf Karte anzeigen', '2013-04-25 23:00:00'); INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUES ('2089', 'DE', 'deaktivierte', '2013-04-25 23:00:00'); INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUES ('2090', 'DE', 'archivierte', '2013-04-25 23:00:00'); +INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUES ('2091', 'DE', 'Sucht und behebt Inkonsistenzen in Datenbanktabellen', '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'); diff --git a/htdocs/doc/sql/stored-proc/maintain.php b/htdocs/doc/sql/stored-proc/maintain.php index c07ca724..eb6a1424 100644 --- a/htdocs/doc/sql/stored-proc/maintain.php +++ b/htdocs/doc/sql/stored-proc/maintain.php @@ -8,7 +8,7 @@ ***************************************************************************/ - $opt['rootpath'] = '../../../'; + $opt['rootpath'] = dirname(__FILE__) . '/../../../'; require_once($opt['rootpath'] . 'lib/clicompatbase.inc.php'); if (!file_exists($opt['rootpath'] . 'util/mysql_root/sql_root.inc.php')) @@ -252,6 +252,17 @@ SET nModified = nModified + ROW_COUNT(); END;"); + /* update log modification date when rating changed, so that it is resent via + XML interface; see issue #244 */ + sql_dropProcedure('sp_update_cachelog_rating'); + sql("CREATE PROCEDURE sp_update_cachelog_rating (IN nCacheId INT, IN nUserID INT, IN dRatingDate DATETIME) + BEGIN + IF (ISNULL(@XMLSYNC) OR @XMLSYNC!=1) THEN + UPDATE `cache_logs` SET `last_modified`=NOW() + WHERE `cache_logs`.`cache_id`=nCacheId AND `cache_logs`.`user_id`=nUserID AND `cache_logs`.`date`=dRatingDate; + END IF; + 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) @@ -515,6 +526,19 @@ SET nModified=nModified+ROW_COUNT(); END;"); + // Update out-of-sync rating dates. These probably were caused by rating-related + // bugs when deleting one of multiple found logs and when changing the log type + // (9 mismatches within ~9 months up to June 2013). + sql_dropProcedure('sp_updateall_rating_dates'); + sql("CREATE PROCEDURE sp_updateall_rating_dates (OUT nModified INT) + BEGIN + UPDATE `cache_rating` SET `rating_date` = + (SELECT `date` FROM `cache_logs` WHERE `cache_logs`.`cache_id`=`cache_rating`.`cache_id` AND `cache_logs`.`user_id`=`cache_rating`.`user_id` AND `cache_logs`.`type` IN (1,7) ORDER BY `date` LIMIT 1) + WHERE (SELECT COUNT(*) FROM `cache_logs` WHERE `cache_logs`.`cache_id`=`cache_rating`.`cache_id` AND `cache_logs`.`user_id`=`cache_rating`.`user_id` AND `cache_logs`.`date`=`cache_rating`.`rating_date` AND `type` IN (1,7))=0; + /* will set rating_date to 0000-00...:00 for orphan records */ + SET nModified=ROW_COUNT(); + END;"); + // notify users with matching watch radius about this cache sql_dropProcedure('sp_notify_new_cache'); sql("CREATE PROCEDURE sp_notify_new_cache (IN nCacheId INT(10) UNSIGNED, IN nLongitude DOUBLE, IN nLatitude DOUBLE) @@ -966,6 +990,7 @@ FOR EACH ROW BEGIN CALL sp_update_topratingstat(NEW.`cache_id`, FALSE); + CALL sp_update_cachelog_rating(NEW.`cache_id`, NEW.`user_id`, NEW.`rating_date`); END;"); sql_dropTrigger('cacheRatingAfterUpdate'); @@ -975,6 +1000,8 @@ IF NEW.`cache_id`!=OLD.`cache_id` THEN CALL sp_update_topratingstat(OLD.`cache_id`, TRUE); CALL sp_update_topratingstat(NEW.`cache_id`, FALSE); + CALL sp_update_cachelog_rating(OLD.`cache_id`, OLD.`user_id`, OLD.`rating_date`); + CALL sp_update_cachelog_rating(NEW.`cache_id`, NEW.`user_id`, NEW.`rating_date`); END IF; END;"); @@ -983,6 +1010,7 @@ FOR EACH ROW BEGIN CALL sp_update_topratingstat(OLD.`cache_id`, TRUE); + CALL sp_update_cachelog_rating(OLD.`cache_id`, OLD.`user_id`, OLD.`rating_date`); END;"); sql_dropTrigger('cacheVisitsBeforeInsert'); diff --git a/htdocs/doc/xml/xml11.htm b/htdocs/doc/xml/xml11.htm index 70521ed0..f69d520a 100644 --- a/htdocs/doc/xml/xml11.htm +++ b/htdocs/doc/xml/xml11.htm @@ -44,9 +44,17 @@
  • Das <date>-Element von Logs enthält nun auch die Uhrzeit. 00:00:00 bedeutet, dass keine Uhrzeit geloggt wurde; alles andere bedeutet, dass mit Stunde und Minute geloggt wurde.
  • Element für Bildeigenschaften von <attributes> in <picattr> umbenannt, um Kollisionen mit dem Cache-Attribut-Element zu vermeiden.
  • Vorschaubild-Flag (preview) zu <picattr> hinzugefügt.
  • -
  • zusätzliche Logtypen 9 (archiviert), 10 (kann gesucht werden), 11 (momentan nicht verfügbar) und 13 (gesperrt)
  • +
  • zusätzliche Logtypen 9 (archiviert), 10 (kann gesucht werden), 11 (momentan nicht verfügbar) und 13 (gesperrt); Ausgabe als Typ 3 (Hinweis) in älteren XML-Versionen
  • teamcomment-Flag zum <logtype> hinzugefügt
  • +

    Änderungen in Version 1.4 (Juni 2013)

    +

    Der XML-Doctype lautet in allen Versionen "oc11xml".

    Ausgabeformat

    @@ -74,8 +82,9 @@

    Allgemeine XML-Elemente

    lastmodified

    Datum an dem dieser Datensatz zuletzt geändert wurde. Es werden keine - Abhängigkeiten berücksichtigt. D.h. Wenn eine Cachebeschreibung geändert wird, - ändert sich nur deren lastmodified, nicht jedoch das des Caches. Datumsangaben + Abhängigkeiten berücksichtigt. D.h. Wenn z.B. eine Cachebeschreibung geändert wird, + ändert sich nur deren lastmodified, nicht jedoch das des Caches (hierfür gibt es + das separate Feld listing_last_modified.) Datumsangaben sind immer in der Form "yyyy-mm-dd hh:mm:ss" oder "yyyy-mm-dd"

    datecreated

    Datum an dem dieser Datensatz angelegt wurde.

    @@ -146,6 +155,7 @@   <datehidden>2005-08-01</datehidden>
      <datecreated ispublishdate="0">2005-09-08 15:45:02</datecreated>
      <lastmodified>2005-12-20 20:58:41</lastmodified>
    +   <listing_lastmodified>2006-04-13 16:31:58</listing_lastmodified>
      <attributes>
        <attribute id="6"><![CDATA[Nur bei Opencaching]]></attribute>
      </attributes>
    @@ -154,7 +164,7 @@     <wpt id="26" type="2" typename="Stage or reference point" longitude="8.02333" latitude="50.01544"><![CDATA[Station 1]]></wpt>
      </wpts>
    </cache>

    -

    lastmodified 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.

    +

    lastmodified ist das letzte Änderungsdatum des cache-Datensatzes, ohne Änderungen an Cachebeschreibungen oder Bildern. Das Gesamt-Änderungsdatum steht im Feld listing_lastmodified.

    datecreated 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 ispublishdate="1" an, dass es sich um das Veröffentlichungsdatum handelt.

    Ab XML-Version 1.2 werden im size-Feld auch Nano-Größen zurückgeliefert. In älteren Interface-Versionen wird stattdessen "micro" ausgegeben.

    Es fehlen noch Empfehlungen und zusätzliche Wegpunkte; wird bei Bedarf eingebaut.

    @@ -196,8 +206,10 @@ Volker]]></text>
      <datecreated>2005-12-24 06:24:07</datecreated>
      <lastmodified>2005-12-24 06:24:07</lastmodified>
    +   <log_lastmodified>2005-12-24 06:41:30</log_lastmodified>
    </cachelog>

    +

    lastmodified ist das letzte Änderungsdatum des Log-Datensatzes, ohne Änderungen an Bildern. Das Gesamt-Änderungsdatum steht im Feld log_lastmodified.

    picture (Bilder)

    <picture>
    @@ -271,20 +283,20 @@

    Paramter uuid ... wie cacheid, ausser dass statt der cacheid die UUID des Caches verwendet wird.

    Beispiele

    1. Alle Daten inkrementell abrufen
    - http://www.opencaching.de/xml/ocxml13.php?modifiedsince=<date>&user=1&cache=1&cachedesc=1&cachelog=1&picture=1&removedobject=1

    + http://www.opencaching.de/xml/ocxml14.php?modifiedsince=<date>&user=1&cache=1&cachedesc=1&cachelog=1&picture=1&removedobject=1

    2. Alle Daten von Deutschland inkrementell abrufen
    - http://www.opencaching.de/xml/ocxml13.php?modifiedsince=<date>&cache=1&cachedesc=1&cachelog=1&picture=1&removedobject=0&country=DE&picturefromcachelog=1

    + http://www.opencaching.de/xml/ocxml14.php?modifiedsince=<date>&cache=1&cachedesc=1&cachelog=1&picture=1&removedobject=0&country=DE&picturefromcachelog=1

    3. Alle Caches ohne Logs von Deutschland inkrementell abrufen
    - http://www.opencaching.de/xml/ocxml13.php?modifiedsince=<date>&cache=1&cachedesc=1&picture=1&removedobject=0&country=DE

    + http://www.opencaching.de/xml/ocxml14.php?modifiedsince=<date>&cache=1&cachedesc=1&picture=1&removedobject=0&country=DE

    4. Alle Daten im Umkreis von 15 km abrufen
    - http://www.opencaching.de/xml/ocxml13.php?modifiedsince=<date>&cache=1&cachedesc=1&cachelog=1&picture=1&removedobject=0&lat=48&lon=9&distance=15&picturefromcachelog=1

    + http://www.opencaching.de/xml/ocxml14.php?modifiedsince=<date>&cache=1&cachedesc=1&cachelog=1&picture=1&removedobject=0&lat=48&lon=9&distance=15&picturefromcachelog=1

    5. Alle Bilder abrufen
    - http://www.opencaching.de/xml/ocxml13.php?modifiedsince=<date>&picture=1

    + http://www.opencaching.de/xml/ocxml14.php?modifiedsince=<date>&picture=1

    6. Alle Bilder von Caches abrufen die in Deutschland versteckt sind
    http://www.opencaching.de/xml/ocxml2.php?modifiedsince=<date>&picture=1&country=DE

    7. Alle Bilder von Caches und deren Logs abrufen die in Deutschland versteckt sind
    - http://www.opencaching.de/xml/ocxml13.php?modifiedsince=<date>&picture=1&country=DE&picturefromcachelog=1

    + http://www.opencaching.de/xml/ocxml14.php?modifiedsince=<date>&picture=1&country=DE&picturefromcachelog=1

    Mit ocxml11.php kann stattdessen die Interface-Version 1.1 verwendet werden.

    Diese Anfragen werden mit einem kurzen XML-Stream beantwortet, der die XML-Session-Id zurückgibt. Mit dieser Id können dann die Daten abgerufen @@ -300,9 +312,9 @@ Summe der Datensätze ist in diesem Beispiel 1205 - es werden also 3 Aufrufe benötigt (500, 500, 205 Datensätze).

    Die Daten können dann mit folgender Anfrage abgerufen werden:
    - http://www.opencaching.de/xml/ocxml13.php?sessionid=12345&file=1
    - http://www.opencaching.de/xml/ocxml13.php?sessionid=12345&file=2
    - http://www.opencaching.de/xml/ocxml13.php?sessionid=12345&file=3

    + http://www.opencaching.de/xml/ocxml14.php?sessionid=12345&file=1
    + http://www.opencaching.de/xml/ocxml14.php?sessionid=12345&file=2
    + http://www.opencaching.de/xml/ocxml14.php?sessionid=12345&file=3

    Die Sessionid ist zwei Stunden lang gültig, wobei sich dieser Zeitraum mit jedem einzelnen Dateiabruf verlängert – zwischen den Einzelabrufen dürfen also maximal zwei Stunden vergehen. Dauert es länger, müsste eine neue sessionid @@ -311,14 +323,14 @@

    Um alle Ergebnisse in einer Datei abzurufen muss bei dem Aufruf der Paramter session auf 0 gesetzt werden.

    Beispeil:
    - http://www.opencaching.de/xml/ocxml13.php?modifiedsince=<date>&user=1&cache=1&cachedesc=1&cachelog=1&picture=1&removedobject=1&session=0

    + http://www.opencaching.de/xml/ocxml14.php?modifiedsince=<date>&user=1&cache=1&cachedesc=1&cachelog=1&picture=1&removedobject=1&session=0

    Dateikomprimierung einstellen

    Dei Dateikomprimierung kann mit dem Paramter zip eingestellt weren. Mögliche Werte sind 0, zip, bzip2, gzip. Null bedeutet hier keine Kompression. Wird keine Kompression angegeben, wird zip verwendet.

    Beispeil:
    - http://www.opencaching.de/xml/ocxml13.php?modifiedsince=<date>&user=1&cache=1&cachedesc=1&cachelog=1&picture=1&removedobject=1&session=0&zip=bzip2
    - http://www.opencaching.de/xml/ocxml13.php?sessionid=12345&file=1&zip=gzip

    + http://www.opencaching.de/xml/ocxml14.php?modifiedsince=<date>&user=1&cache=1&cachedesc=1&cachelog=1&picture=1&removedobject=1&session=0&zip=bzip2
    + http://www.opencaching.de/xml/ocxml14.php?sessionid=12345&file=1&zip=gzip

    XML-Optionen

    Die folgenden XML-Optionen müssen bei jedem Aufruf übergeben werden.

    @@ -332,8 +344,8 @@ charset ... (Default) iso-8859-1 / utf-8
    attrlist ... (Default) 0 = keine Attributliste übertragen / 1 = Attributliste übertragen

    Beispiele

    -

    http://www.opencaching.de/xml/ocxml13.php?modifiedsince=20060320000000&user=1&cache=1&cachelog=1&cachedesc=1&picture=1&removedobject=1&session=1&charset=utf-8&cdata=1&xmldecl=0&ocxmltag=0&doctype=0
    - http://www.opencaching.de/xml/ocxml13.php?sessionid=4711&file=1&charset=utf-8&cdata=1&xmldecl=0&ocxmltag=0&doctype=0

    +

    http://www.opencaching.de/xml/ocxml14.php?modifiedsince=20060320000000&user=1&cache=1&cachelog=1&cachedesc=1&picture=1&removedobject=1&session=1&charset=utf-8&cdata=1&xmldecl=0&ocxmltag=0&doctype=0
    + http://www.opencaching.de/xml/ocxml14.php?sessionid=4711&file=1&charset=utf-8&cdata=1&xmldecl=0&ocxmltag=0&doctype=0

    Sonstige Anmerkungen