From 7617bd3edc39993ee82c64ca9957fa73eb1d1a5f Mon Sep 17 00:00:00 2001 From: Botanic Date: Wed, 23 Oct 2013 15:06:41 -0700 Subject: [PATCH] Implimented lazy cron and fixed syncronize button. --- .../tools/server/ryzom_ams/ams_lib/autoload/sync.php | 12 ++++++++---- code/ryzom/tools/server/ryzom_ams/www/html/index.php | 10 ++++++++++ .../ryzom/tools/server/ryzom_ams/www/html/js/help.js | 8 +++++++- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/sync.php b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/sync.php index 5e8d2d37d..c41985cfc 100644 --- a/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/sync.php +++ b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/sync.php @@ -13,7 +13,7 @@ class Sync{ * This is done because the shard could have been offline and we want changes made on the website (which is still online) to eventually hit the shard. * These changes are: createPermissions, createUser, change_pass, change_mail */ - static public function syncdata () { + static public function syncdata ($display = true) { try { $dbl = new DBLayer("lib"); @@ -56,11 +56,15 @@ class Sync{ } $dbl->execute("DELETE FROM ams_querycache WHERE SID=:SID",array('SID' => $record['SID'])); } - print('Syncing completed'); + if ($display == true) { + print('Syncing completed'); + } } catch (PDOException $e) { - print('Something went wrong! The shard is probably still offline!'); - print_r($e); + if ($display == true) { + print('Something went wrong! The shard is probably still offline!'); + print_r($e); + } } } diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/index.php b/code/ryzom/tools/server/ryzom_ams/www/html/index.php index 50d8227be..65faef428 100644 --- a/code/ryzom/tools/server/ryzom_ams/www/html/index.php +++ b/code/ryzom/tools/server/ryzom_ams/www/html/index.php @@ -23,6 +23,16 @@ if (!@include '../config.php') { } session_start(); +//Running Cron? +if ( isset( $_GET["cron"]) ){ + if ($_GET["cron"] == "true"){ + Sync::syncdata(false); + } +} + +//Always try to sync on page load, ie "lazy" cron +Sync::syncdata(false); + //Decide what page to load if ( ! isset( $_GET["page"]) ){ if(isset($_SESSION['user'])){ diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/js/help.js b/code/ryzom/tools/server/ryzom_ams/www/html/js/help.js index 3c1fad7b3..2dc0773c0 100644 --- a/code/ryzom/tools/server/ryzom_ams/www/html/js/help.js +++ b/code/ryzom/tools/server/ryzom_ams/www/html/js/help.js @@ -25,4 +25,10 @@ function show_help(help_tip) } -$("#sync").click(function() {alert("Handler for .click() called.");}); \ No newline at end of file +function syncRun() +{ + $.get("index.php?cron=true"); + alert("Sync function called."); +} + +$("#sync").click(function() {syncRun();}); \ No newline at end of file