From 2d1a07c7876ee15b8e01d9d298b4d4946eb038f7 Mon Sep 17 00:00:00 2001 From: Quitta Date: Thu, 1 Aug 2013 18:20:40 +0200 Subject: [PATCH] added db parameter to the syncing --HG-- branch : quitta-gsoc-2013 --- .../server/ryzom_ams/ams_lib/autoload/sync.php | 16 +++++++--------- .../server/ryzom_ams/ams_lib/autoload/users.php | 12 ++++++------ code/ryzom/tools/server/ryzom_ams/www/config.php | 2 +- .../server/ryzom_ams/www/html/sql/install.php | 3 ++- 4 files changed, 16 insertions(+), 17 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 6bc661fc0..12376d9b4 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 @@ -17,34 +17,32 @@ class Sync{ try { $dbl = new DBLayer("lib"); $statement = $dbl->executeWithoutParams("SELECT * FROM ams_querycache"); - $rows = $statement->fetchAll(); - $dbs = new DBLayer("shard"); + $rows = $statement->fetchAll(); foreach ($rows as $record) { - + + $db = new DBLayer($record['db']); switch($record['type']) { case 'createPermissions': case 'change_pass': $decode = json_decode($record['query']); $values = array('user' => $decode[0], 'pass' => $decode[1]); //make connection with and put into shard db & delete from the lib - $dbs->execute("UPDATE user SET Password = :pass WHERE Login = :user",$values); - $dbl->execute("DELETE FROM ams_querycache WHERE SID=:SID",array('SID' => $record['SID'])); + $db->execute("UPDATE user SET Password = :pass WHERE Login = :user",$values); break; case 'change_mail': $decode = json_decode($record['query']); $values = array('user' => $decode[0], 'mail' => $decode[1]); //make connection with and put into shard db & delete from the lib - $dbs->execute("UPDATE user SET Email = :mail WHERE Login = :user",$values); - $dbl->execute("DELETE FROM ams_querycache WHERE SID=:SID",array('SID' => $record['SID'])); + $db->execute("UPDATE user SET Email = :mail WHERE Login = :user",$values); break; case 'createUser': $decode = json_decode($record['query']); $values = array('login' => $decode[0], 'pass' => $decode[1], 'mail' => $decode[2] ); //make connection with and put into shard db & delete from the lib - $dbs->execute("INSERT INTO user (Login, Password, Email) VALUES (:login, :pass, :mail)",$values); - $dbl->execute("DELETE FROM ams_querycache WHERE SID=:SID",array('SID' => $record['SID'])); + $db->execute("INSERT INTO user (Login, Password, Email) VALUES (:login, :pass, :mail)",$values); break; } + $dbl->execute("DELETE FROM ams_querycache WHERE SID=:SID",array('SID' => $record['SID'])); } print('Syncing completed'); } 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 8376e7d54..ac01d724b 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 @@ -296,8 +296,8 @@ class Users{ //oh noooz, the shard is offline! Put in query queue at ams_lib db! try { $dbl = new DBLayer("lib"); - $dbl->execute("INSERT INTO ams_querycache (type, query) VALUES (:type, :query)",array("type" => "createUser", - "query" => json_encode(array($values["name"],$values["pass"],$values["mail"])))); + $dbl->execute("INSERT INTO ams_querycache (type, query, db) VALUES (:type, :query, :db)",array("type" => "createUser", + "query" => json_encode(array($values["name"],$values["pass"],$values["mail"])), "db" => "shard")); ticket_user::createTicketUser( $user_id , 1 ); return "shardoffline"; }catch (PDOException $e) { @@ -380,8 +380,8 @@ class Users{ //oh noooz, the shard is offline! Put in query queue at ams_lib db! try { $dbl = new DBLayer("lib"); - $dbl->execute("INSERT INTO ams_querycache (type, query) VALUES (:type, :query)",array("type" => "change_pass", - "query" => json_encode(array($values["user"],$values["pass"])))); + $dbl->execute("INSERT INTO ams_querycache (type, query, db) VALUES (:type, :query, :db)",array("type" => "change_pass", + "query" => json_encode(array($values["user"],$values["pass"])), "db" => "shard")); return "shardoffline"; }catch (PDOException $e) { return "liboffline"; @@ -403,8 +403,8 @@ class Users{ //oh noooz, the shard is offline! Put in query queue at ams_lib db! try { $dbl = new DBLayer("lib"); - $dbl->execute("INSERT INTO ams_querycache (type, query) VALUES (:type, :query)",array("type" => "change_mail", - "query" => json_encode(array($values["user"],$values["mail"])))); + $dbl->execute("INSERT INTO ams_querycache (type, query, db) VALUES (:type, :query, :db)",array("type" => "change_mail", + "query" => json_encode(array($values["user"],$values["mail"])), "db" => "shard")); return "shardoffline"; }catch (PDOException $e) { return "liboffline"; diff --git a/code/ryzom/tools/server/ryzom_ams/www/config.php b/code/ryzom/tools/server/ryzom_ams/www/config.php index 8bace0f68..b75c50fa8 100644 --- a/code/ryzom/tools/server/ryzom_ams/www/config.php +++ b/code/ryzom/tools/server/ryzom_ams/www/config.php @@ -19,7 +19,7 @@ $cfg['db']['lib']['name'] = 'ryzom_ams_lib'; $cfg['db']['lib']['user'] = 'shard'; $cfg['db']['lib']['pass'] = ''; -$cfg['db']['shard']['host'] = 'localhosti'; +$cfg['db']['shard']['host'] = 'localhost'; $cfg['db']['shard']['port'] = '3306'; $cfg['db']['shard']['name'] = 'nel'; $cfg['db']['shard']['user'] = 'shard'; diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/sql/install.php b/code/ryzom/tools/server/ryzom_ams/www/html/sql/install.php index a95d5dbcc..317f22f06 100644 --- a/code/ryzom/tools/server/ryzom_ams/www/html/sql/install.php +++ b/code/ryzom/tools/server/ryzom_ams/www/html/sql/install.php @@ -42,7 +42,8 @@ CREATE TABLE ams_querycache ( `SID` INT NOT NULL AUTO_INCREMENT PRIMARY KEY , `type` VARCHAR( 64 ) NOT NULL , - `query` VARCHAR( 512 ) NOT NULL + `query` VARCHAR( 512 ) NOT NULL, + `db` VARCHAR( 80 ) NOT NULL );