Skip to content
Permalink
Browse files

added safety measures and documentation to geokrety import cronjob

updates 18
  • Loading branch information...
following5 committed Jun 12, 2013
1 parent dc9e333 commit 8ebcfc7fc3fde3af3391ee63983f395041c2ff81
@@ -3,10 +3,16 @@
* For license information see doc/license.txt
*
* Unicode Reminder メモ
*
* Import new data from geokrety.org.
*
* See util2/geokrety for check and repair functions.
* See discussion in http://redmine.opencaching.de/issues/18.
***************************************************************************/
checkJob(new geokrety());
class geokrety
{
var $name = 'geokrety';
@@ -39,8 +45,9 @@ function loadXML()
$this->removeXML($path);
// changed default-value for getSysConfig() from '2005-01-01 00:00:00' to 'NOW - 9d 23:59:59' to stay in api-limit
$modifiedsince = strtotime(getSysConfig('geokrety_lastupdate', date($opt['db']['dateformat'], time()-(60*60*24*10)+1)));
// Changed default-value for getSysConfig() from '2005-01-01 00:00:00' to 'NOW - 9d 12h'
// to safely stay in api-limit, even when client and server are in different time zones.
$modifiedsince = strtotime(getSysConfig('geokrety_lastupdate', date($opt['db']['dateformat'], time() - 60*60*24*9.5)));
if (!@copy('http://geokrety.org/export.php?modifiedsince=' . date('YmdHis', $modifiedsince - 1), $path))
return false;
@@ -146,13 +153,18 @@ function importGeoKret($element)
('&1', '&2', '&3', '&4', '&5', '&6', '&7', '&8', '&9', '&10')
ON DUPLICATE KEY UPDATE
`name`='&2', `description`='&3', `userid`='&4', `datecreated`='&5', `distancetravelled`='&6', `latitude`='&7', `longitude`='&8', `typeid`='&9', `stateid`='&10'",
$id, $name, $description, $userid, date($opt['db']['dateformat'], $datecreated), $distancetravelled, $latitude, $longitude, $typeid, $state);
$id, $name, $description, $userid, date($opt['db']['dateformat'], $datecreated), $distancetravelled, $latitude, $longitude, $typeid, $state);
// Deleting and inserting item-waypoints if they have not changed will
// update caches.meta_last_modified -> caches.okapi_syncbase and thus trigger
// OKAPI changelog actions. This probably can be ignored as OKAPI will verify
// if data has really changed.
// remove waypoints for this krety
sql("DELETE FROM `gk_item_waypoint` WHERE id='&1'", $id);
// update associated waypoints
$waypoints = $element->getElementsByTagName('waypoints');
if ($waypoints->length == 1)
if ($waypoints->length > 0)
{
$wpItems = $waypoints->item(0)->getElementsByTagName('waypoint');
for ($i = 0; $i < $wpItems->length; $i++)
@@ -166,9 +178,9 @@ function importGeoKret($element)
$id, $wp);
}
}
}
function importMove($element)
{
global $opt;
@@ -204,7 +216,7 @@ function importMove($element)
// update associated waypoints
$waypoints = $element->getElementsByTagName('waypoints');
if ($waypoints->length == 1)
if ($waypoints->length > 0)
{
$wpItems = $waypoints->item(0)->getElementsByTagName('waypoint');
for ($i = 0; $i < $wpItems->length; $i++)
@@ -214,25 +226,54 @@ function importMove($element)
sql("INSERT INTO `gk_move_waypoint` (`id`, `wp`) VALUES ('&1', '&2')", $id, $wp);
}
}
/**
* This Code is buggy; it produces wrong gk_item_waypoint entries (why?).
* See http://redmine.opencaching.de/issues/18.
* We use geokret.waypoints information instead, see importGeoKret().
* That's preferrable anyway, because it does not mage assumptions on internal
* Geokrety.org behaviour (e.g. the order of moves with identical datetime).
// now update the current gk-waypoints based on the last move
sql("DELETE FROM `gk_item_waypoint` WHERE `id`='&1'", $gkid);
$rs = sql("SELECT * FROM `gk_move` WHERE `itemid`='&1' AND `logtypeid`!=2 ORDER BY `datemoved` DESC LIMIT 1", $gkid);
$r = sql_fetch_assoc($rs);
sql_free_result($rs);
if ($r === false) return;
if ($r['logtypeid'] == 0 || $r['logtypeid'] == 3)
{
sql("INSERT INTO `gk_item_waypoint` (`id`, `wp`) SELECT '&1' AS `id`, `wp` FROM `gk_move_waypoint` WHERE `id`='&2' AND `wp`!=''", $gkid, $id);
}
else
{
// do nothing
}
*/
}
function checkGeoKretType($id, $name)
{
sql("INSERT INTO `gk_item_type` (`id`, `name`) VALUES ('&1', '&2') ON DUPLICATE KEY UPDATE `name`='&2'", $id, $name);
}
function checkUser($id, $name)
{
if ($id == 0) return;
sql("INSERT INTO `gk_user` (`id`, `name`) VALUES ('&1', '&2') ON DUPLICATE KEY UPDATE `name`='&2'", $id, $name);
}
function checkMoveType($id, $name)
{
sql("INSERT INTO `gk_move_type` (`id`, `name`) VALUES ('&1', '&2') ON DUPLICATE KEY UPDATE `name`='&2'", $id, $name);
}
function GetNodeValue(&$domnode, $element)
{
$subnode = $domnode->getElementsByTagName($element);
@@ -242,6 +283,7 @@ function GetNodeValue(&$domnode, $element)
return $subnode->item(0)->nodeValue;
}
function GetNodeAttribute(&$domnode, $element, $attr)
{
$subnode = $domnode->getElementsByTagName($element);
@@ -6,6 +6,8 @@
*
* Tests for consistency of gk_item_waypoint und gk_move_waypoint tables.
* See http://redmine.opencaching.de/issues/18.
*
* Data import functions are in util2/cron/modules/geokrety.class.php.
***************************************************************************/
$opt['rootpath'] = '../../';
@@ -6,6 +6,8 @@
*
* Regenerates gk_item_waypoint from gk_move_waypoint.
* See http://redmine.opencaching.de/issues/18.
*
* Data import functions are in util2/cron/modules/geokrety.class.php.
***************************************************************************/
$opt['rootpath'] = '../../';

0 comments on commit 8ebcfc7

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