From afd473aaff7b6139f4935bee1d8da3bac8543d32 Mon Sep 17 00:00:00 2001 From: Quitta Date: Thu, 27 Jun 2013 04:54:41 +0200 Subject: [PATCH] Syncing basics, need refactoring though --HG-- branch : quitta-gsoc-2013 --- .../ryzom_ams/ams_lib/autoload/sync.php | 65 +++++++++++++++++++ .../ryzom_ams/ams_lib/autoload/users.php | 4 +- .../ryzom_ams/ams_lib/cron/sync_cron.php | 6 ++ 3 files changed, 73 insertions(+), 2 deletions(-) create mode 100644 code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/sync.php create mode 100644 code/ryzom/tools/server/ryzom_ams/ams_lib/cron/sync_cron.php 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 new file mode 100644 index 000000000..302d4dc14 --- /dev/null +++ b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/sync.php @@ -0,0 +1,65 @@ +setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + $statement = $dbl->prepare("SELECT * FROM ams_querycache"); + $statement->execute(); + $rows = $statement->fetchAll(); + + $dbs = new PDO("mysql:host=$SHARDDBHOST;port=$SHARDDBPORT;dbname=$SHARDDBNAME", $SHARDDBUSERNAME, $SHARDDBPASSWORD); + $dbs->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + + foreach ($rows as $record) { + + switch($record['type']) { + case 'createPermissions': + case 'user_edit': + case 'createUser': + $query = json_decode($record['query']); + //make connection with and put into shard db + $statement = $dbs->prepare("INSERT INTO user (Login, Password, Email) VALUES (?, ?, ?)"); + $statement->execute($query); + + $statement = $dbl->prepare("DELETE FROM ams_querycache WHERE SID=:SID"); + $query = array('SID' => $record['SID']); + $statement->execute($query); + + + } + } + print('Syncing completed'); + } + catch (PDOException $e) { + print('Something went wrong!'); + print_r($e); + } + + } +} diff --git a/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/users.php b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/users.php index 876f8d285..1d6c62177 100644 --- a/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/users.php +++ b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/users.php @@ -236,7 +236,7 @@ class Users{ return $salt; } - function create_Server_User($params) + /*function create_Server_User($params) { try { $hostname = 'localhost'; @@ -254,7 +254,7 @@ class Users{ return "fail"; } // createPermissions(array($login)); - } + }*/ function createUser($values){ diff --git a/code/ryzom/tools/server/ryzom_ams/ams_lib/cron/sync_cron.php b/code/ryzom/tools/server/ryzom_ams/ams_lib/cron/sync_cron.php new file mode 100644 index 000000000..477b139d4 --- /dev/null +++ b/code/ryzom/tools/server/ryzom_ams/ams_lib/cron/sync_cron.php @@ -0,0 +1,6 @@ +