Skip to content
Permalink
Browse files

improved geokrety waypoint check; added fixing tool

  • Loading branch information...
following5 committed Jun 12, 2013
1 parent ee85072 commit 449eb0b3649f7a36da1f9cd9110fd25b720a33f9
Showing with 60 additions and 4 deletions.
  1. +12 −4 htdocs/util2/geokrety/check-waypoints.php
  2. +48 −0 htdocs/util2/geokrety/fix-waypoints.php
@@ -5,7 +5,7 @@
* Unicode Reminder メモ
*
* Tests for consistency of gk_item_waypoint und gk_move_waypoint tables.
*
* See http://redmine.opencaching.de/issues/18.
***************************************************************************/
$opt['rootpath'] = '../../';
@@ -25,7 +25,7 @@
{
$lastmove = sql_value("
SELECT `id` FROM `gk_move`
WHERE `itemid`='&1'
WHERE `itemid`='&1' AND `logtypeid`<>2
ORDER BY `datemoved` DESC, `id` DESC
LIMIT 1",
0, $rItem['id']);
@@ -46,8 +46,16 @@
foreach ($itemwps as $itemid => $wps)
foreach ($wps as $wp => $flags)
if (isset($flags['itemwp']) && !isset($flags['movewp']))
echo "item ".$itemid.": ".$wp." is not the current wp in gk_move_waypoint\n";
if (sql_value("SELECT COUNT(*) FROM `gk_move`, `gk_move_waypoint`
WHERE `gk_move`.`itemid`='&1'
AND `gk_move`.`logtypeid`<>2
AND `gk_move_waypoint`.`id`=`gk_move`.`id`
AND `gk_move_waypoint`.`wp`='&2'",
0, $itemid, $wp) == 0)
echo "item ".$itemid.": ".$wp." is missing in gk_move_waypoint\n";
else
echo "item ".$itemid.": ".$wp." is not the current wp in gk_move_waypoint\n";
else if (isset($flags['movewp']) && !isset($flags['itemwp']))
echo "item ".$itemid.": current wp ".$wp." is missing in gk_item_waypoint\n";
echo "item ".$itemid.": ".$wp." is missing in gk_item_waypoint\n";
?>
@@ -0,0 +1,48 @@
<?php
/***************************************************************************
* For license information see doc/license.txt
*
* Unicode Reminder メモ
*
* Regenerates gk_item_waypoint from gk_move_waypoint.
* See http://redmine.opencaching.de/issues/18.
***************************************************************************/
$opt['rootpath'] = '../../';
require_once($opt['rootpath'] . 'lib2/cli.inc.php');
if (count($argv) != 2 || $argv[1] != 'run')
die("\n".
"Please verify that runcron.php is disabled in crontab;\n".
"then run this script with\n".
"\n".
" php fix-waypoints.php run\n".
"\n".
"Don't forget to re-enable cronjobs afterwards!\n".
"\n");
sql("DELETE FROM `gk_item_waypoint`");
$rsItems = sql("SELECT DISTINCT `itemid` AS `id` FROM `gk_move`");
while ($rItem = sql_fetch_assoc($rsItems))
{
$lastmove = sql_value("
SELECT `id` FROM `gk_move`
WHERE `itemid`='&1' AND `logtypeid`<>2
/* TODO: How does Geokrety.org order moves with same date? We assume by ID: */
ORDER BY `datemoved` DESC, `id` DESC
LIMIT 1",
0, $rItem['id']);
$rsWp = sql("
INSERT INTO `gk_item_waypoint`
(SELECT `gk_move`.`itemid`, `gk_move_waypoint`.`wp`
FROM `gk_move_waypoint`
LEFT JOIN `gk_move` ON `gk_move`.`id`=`gk_move_waypoint`.`id`
WHERE `gk_move`.`id`='&1' AND `logtypeid` IN (0,3) AND `wp`<>''
)",
$lastmove);
}
sql_free_result($rsItems);
?>

0 comments on commit 449eb0b

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