From 538bef501a55a3d755cefb4f4a2c14f3f45e96f3 Mon Sep 17 00:00:00 2001 From: Wojciech Rygielski Date: Sat, 10 Nov 2012 11:29:13 +0100 Subject: [PATCH 1/2] OKAPI Project update (r495). --- htdocs/okapi/core.php | 83 +++++++++++- htdocs/okapi/cronjobs.php | 63 +++++++-- htdocs/okapi/services/apiref/method.php | 6 + htdocs/okapi/services/apiref/method.xml | 7 +- .../okapi/services/caches/formatters/gpx.php | 28 ++-- .../caches/formatters/gpxfile.tpl.php | 4 +- htdocs/okapi/services/caches/geocache.xml | 21 ++- htdocs/okapi/services/caches/geocaches.php | 20 ++- htdocs/okapi/services/caches/search/all.xml | 12 +- .../services/caches/search/searching.inc.php | 38 +++++- htdocs/okapi/services/logs/submit.xml | 2 - .../replicate/replicate_common.inc.php | 120 +++++++++++++++--- htdocs/okapi/static/tilemap/large_event.png | Bin 1694 -> 0 bytes htdocs/okapi/static/tilemap/large_multi.png | Bin 1783 -> 0 bytes htdocs/okapi/static/tilemap/large_other.png | Bin 1562 -> 0 bytes htdocs/okapi/static/tilemap/large_quiz.png | Bin 1819 -> 0 bytes .../static/tilemap/large_traditional.png | Bin 1703 -> 0 bytes htdocs/okapi/static/tilemap/large_virtual.png | Bin 1836 -> 0 bytes htdocs/okapi/views/attrlist.php | 45 ------- htdocs/okapi/views/update.php | 1 + 20 files changed, 342 insertions(+), 108 deletions(-) delete mode 100644 htdocs/okapi/static/tilemap/large_event.png delete mode 100644 htdocs/okapi/static/tilemap/large_multi.png delete mode 100644 htdocs/okapi/static/tilemap/large_other.png delete mode 100644 htdocs/okapi/static/tilemap/large_quiz.png delete mode 100644 htdocs/okapi/static/tilemap/large_traditional.png delete mode 100644 htdocs/okapi/static/tilemap/large_virtual.png delete mode 100644 htdocs/okapi/views/attrlist.php diff --git a/htdocs/okapi/core.php b/htdocs/okapi/core.php index 0cf1eded..7b28e004 100644 --- a/htdocs/okapi/core.php +++ b/htdocs/okapi/core.php @@ -759,7 +759,7 @@ class Okapi { public static $data_store; public static $server; - public static $revision = 483; # This gets replaced in automatically deployed packages + public static $revision = 495; # This gets replaced in automatically deployed packages private static $okapi_vars = null; /** Get a variable stored in okapi_vars. If variable not found, return $default. */ @@ -1449,10 +1449,6 @@ class Okapi ) ); - private static $cache_statuses = array( - 'Available' => 1, 'Temporarily unavailable' => 2, 'Archived' => 3 - ); - /** E.g. 'Traditional' => 2. For unknown names throw an Exception. */ public static function cache_type_name2id($name) { @@ -1479,6 +1475,10 @@ class Okapi return "Other"; } + private static $cache_statuses = array( + 'Available' => 1, 'Temporarily unavailable' => 2, 'Archived' => 3 + ); + /** E.g. 'Available' => 1. For unknown names throws an Exception. */ public static function cache_status_name2id($name) { @@ -1501,6 +1501,64 @@ class Okapi return $reversed[$id]; return 'Archived'; } + + private static $cache_sizes = array( + 'none' => 7, + 'nano' => 8, + 'micro' => 2, + 'small' => 3, + 'regular' => 4, + 'large' => 5, + 'xlarge' => 6, + 'other' => 1, + ); + + /** E.g. 'micro' => 2. For unknown names throw an Exception. */ + public static function cache_size2_to_sizeid($size2) + { + if (isset(self::$cache_sizes[$size2])) + return self::$cache_sizes[$size2]; + throw new Exception("Method cache_size2_to_sizeid called with invalid size2 '$size2'."); + } + + /** E.g. 2 => 'micro'. For unknown ids returns "other". */ + public static function cache_sizeid_to_size2($id) + { + static $reversed = null; + if ($reversed == null) + { + $reversed = array(); + foreach (self::$cache_sizes as $key => $value) + $reversed[$value] = $key; + } + if (isset($reversed[$id])) + return $reversed[$id]; + return "other"; + } + + /** Maps OKAPI's 'size2' values to opencaching.com (OX) size codes. */ + private static $cache_OX_sizes = array( + 'none' => null, + 'nano' => 1.3, + 'micro' => 2.0, + 'small' => 3.0, + 'regular' => 3.8, + 'large' => 4.6, + 'xlarge' => 4.9, + 'other' => null, + ); + + /** + * E.g. 'micro' => 2.0, 'other' => null. For unknown names throw an + * Exception. Note, that this is not a bijection ('none' are 'other' are + * both null). + */ + public static function cache_size2_to_oxsize($size2) + { + if (array_key_exists($size2, self::$cache_OX_sizes)) + return self::$cache_OX_sizes[$size2]; + throw new Exception("Method cache_size2_to_oxsize called with invalid size2 '$size2'."); + } /** * E.g. 'Found it' => 1. For unsupported names throws Exception. @@ -1578,9 +1636,18 @@ class Cache * Save object $value under the key $key. Store this object for * $timeout seconds. $key must be a string of max 64 characters in length. * $value might be any serializable PHP object. + * + * If $timeout is null, then the object will be treated as persistent + * (the Cache will do its best to NEVER remove it). */ public static function set($key, $value, $timeout) { + if ($timeout == null) + { + # The current cache implementation is ALWAYS persistent, so we will + # just replace it with a big value. + $timeout = 100*365*86400; + } Db::execute(" replace into okapi_cache (`key`, value, expires) values ( @@ -1613,6 +1680,12 @@ class Cache { if (count($dict) == 0) return; + if ($timeout == null) + { + # The current cache implementation is ALWAYS persistent, so we will + # just replace it with a big value. + $timeout = 100*365*86400; + } $entries = array(); foreach ($dict as $key => $value) { diff --git a/htdocs/okapi/cronjobs.php b/htdocs/okapi/cronjobs.php index 929027cc..ea56f5f6 100644 --- a/htdocs/okapi/cronjobs.php +++ b/htdocs/okapi/cronjobs.php @@ -16,6 +16,7 @@ namespace okapi\cronjobs; use Exception; use okapi\Okapi; +use okapi\BadRequest; use okapi\Settings; use okapi\OkapiLock; use okapi\OkapiExceptionHandler; @@ -43,6 +44,7 @@ class CronJobController new CheckCronTab2(), new ChangeLogWriterJob(), new ChangeLogCleanerJob(), + new ChangeLogCheckerJob(), new AdminStatsSender(), new LocaleChecker(), new FulldumpGeneratorJob(), @@ -93,13 +95,27 @@ class CronJobController $next_run = $cronjob->get_next_scheduled_run(isset($schedule[$name]) ? $schedule[$name] : time()); } $schedule[$name] = $next_run; + Cache::set("cron_schedule", $schedule, 30*86400); } } + + # Remove "stale" schedule keys (those which are no longer declared). + + $fixed_schedule = array(); + foreach (self::get_enabled_cronjobs() as $cronjob) + { + $name = $cronjob->get_name(); + $fixed_schedule[$name] = $schedule[$name]; + } + unset($schedule); + + # Return the nearest scheduled event time. + $nearest = time() + 3600; - foreach ($schedule as $name => $time) + foreach ($fixed_schedule as $name => $time) if ($time < $nearest) $nearest = $time; - Cache::set("cron_schedule", $schedule, 30*86400); + Cache::set("cron_schedule", $fixed_schedule, 30*86400); $lock->release(); return $nearest; } @@ -446,6 +462,22 @@ class ChangeLogWriterJob extends Cron5Job } } +/** + * Once per day, compares alle caches to the cached versions + * kept by the 'replicate' module. If it finds any inconsistencies, it + * emails the developers (such inconsistencies shouldn't happen) and it changes + * the okapi_syncbase column accordingly. See issue 157. + */ +class ChangeLogCheckerJob extends Cron5Job +{ + public function get_period() { return 86400; } + public function execute() + { + require_once($GLOBALS['rootpath']."okapi/services/replicate/replicate_common.inc.php"); + ReplicateCommon::verify_clog_consistency(); + } +} + /** * Once per week, generates the fulldump archive. */ @@ -473,17 +505,26 @@ class TileTreeUpdater extends Cron5Job # No update necessary. } elseif ($tiletree_revision < $current_clog_revision) { require_once($GLOBALS['rootpath']."okapi/services/caches/map/replicate_listener.inc.php"); - if ($current_clog_revision - $tiletree_revision < 100000) # In the middle of 2012, OCPL generated 30000 entries per week + if ($current_clog_revision - $tiletree_revision < 30000) # In the middle of 2012, OCPL generated 30000 entries per week { - for ($i=0; $i<100; $i++) # This gives us no more than 20000 (?) at a time. + for ($timeout = time() + 240; time() < $timeout; ) # Try to stop after 4 minutes. { - $response = OkapiServiceRunner::call('services/replicate/changelog', new OkapiInternalRequest( - new OkapiInternalConsumer(), null, array('since' => $tiletree_revision))); - \okapi\services\caches\map\ReplicateListener::receive($response['changelog']); - $tiletree_revision = $response['revision']; - Okapi::set_var('clog_followup_revision', $tiletree_revision); - if (!$response['more']) - break; + try { + $response = OkapiServiceRunner::call('services/replicate/changelog', new OkapiInternalRequest( + new OkapiInternalConsumer(), null, array('since' => $tiletree_revision))); + \okapi\services\caches\map\ReplicateListener::receive($response['changelog']); + $tiletree_revision = $response['revision']; + Okapi::set_var('clog_followup_revision', $tiletree_revision); + if (!$response['more']) + break; + } catch (BadRequest $e) { + # Invalid 'since' parameter? May happen whne crontab was + # not working for more than 10 days. Or, just after OKAPI + # is installed (and this is the first time this cronjob + # if being run). + \okapi\services\caches\map\ReplicateListener::reset(); + Okapi::set_var('clog_followup_revision', $current_clog_revision); + } } } else { # Some kind of bigger update. Resetting TileTree might be a better option. diff --git a/htdocs/okapi/services/apiref/method.php b/htdocs/okapi/services/apiref/method.php index 9928843f..600846f1 100644 --- a/htdocs/okapi/services/apiref/method.php +++ b/htdocs/okapi/services/apiref/method.php @@ -27,6 +27,7 @@ class WebService return array( 'name' => (string)$attrs['name'], 'is_required' => $arg_node->getName() == 'req', + 'is_deprecated' => (isset($attrs['class']) && (strpos($attrs['class'], 'deprecated') !== false)), 'class' => 'public', 'description' => (isset($attrs['default']) ? ("

Default value: ".$attrs['default']."

") : ""). @@ -120,16 +121,21 @@ class WebService $result['arguments'][] = array( 'name' => 'format', 'is_required' => false, + 'is_deprecated' => false, 'class' => 'common-formatting', 'description' => "Standard common formatting argument." ); $result['arguments'][] = array( 'name' => 'callback', 'is_required' => false, + 'is_deprecated' => false, 'class' => 'common-formatting', 'description' => "Standard common formatting argument." ); } + foreach ($result['arguments'] as &$arg_ref) + if ($arg_ref['is_deprecated']) + $arg_ref['class'] .= " deprecated"; if (!$docs->returns) throw new Exception("Missing element in the $methodname.xml file. ". "If your method does not return anything, you should document in nonetheless."); diff --git a/htdocs/okapi/services/apiref/method.xml b/htdocs/okapi/services/apiref/method.xml index 43d1c705..1ce6b1a0 100644 --- a/htdocs/okapi/services/apiref/method.xml +++ b/htdocs/okapi/services/apiref/method.xml @@ -38,11 +38,12 @@