private static function _call() { ignore_user_abort(true); set_time_limit(0); header("Content-Type: text/plain; charset=utf-8"); $current_ver = self::get_current_version(); $max_ver = self::get_max_version(); self::out("Current OKAPI database version: {$current_ver}\n"); if ($current_ver == 0 && (!isset($_GET['install']) || $_GET['install'] != 'true')) { self::out("Current OKAPI settings are:\n\n" . Settings::describe_settings() . "\n\n" . "Make sure they are correct, then append '?install=true' to your query."); try { Db::select_value("select 1 from caches limit 1"); } catch (Exception $e) { self::out("\n\n" . "IMPORTANT: If you're trying to install OKAPI on an empty database then\n" . "you will fail. OKAPI is not a standalone application, it is a plugin\n" . "for Opencaching sites. Please read this:\n\n" . "https://github.com/opencaching/okapi/issues/299"); } return; } elseif ($max_ver == $current_ver) { self::out("It is up-to-date.\n\n"); } elseif ($max_ver < $current_ver) { throw new Exception(); } else { self::out("Updating to version {$max_ver}... PLEASE WAIT\n\n"); while ($current_ver < $max_ver) { $version_to_apply = $current_ver + 1; self::out("Applying mutation #{$version_to_apply}..."); try { call_user_func(array(__CLASS__, "ver" . $version_to_apply)); self::out(" OK!\n"); Okapi::set_var('db_version', $version_to_apply); $current_ver += 1; } catch (Exception $e) { self::out(" ERROR\n\n"); throw $e; } } self::out("\nDatabase updated.\n\n"); } self::out("Registering new cronjobs...\n"); # Validate all cronjobs (some might have been added). Okapi::set_var("cron_nearest_event", 0); Okapi::execute_prerequest_cronjobs(); self::out("\nUpdate complete.\n"); }