added db parameter to the syncing

--HG--
branch : quitta-gsoc-2013
This commit is contained in:
Quitta 2013-08-01 18:20:40 +02:00
parent 1c6cdfd7a7
commit 2d1a07c787
4 changed files with 16 additions and 17 deletions

View file

@ -17,34 +17,32 @@ class Sync{
try { try {
$dbl = new DBLayer("lib"); $dbl = new DBLayer("lib");
$statement = $dbl->executeWithoutParams("SELECT * FROM ams_querycache"); $statement = $dbl->executeWithoutParams("SELECT * FROM ams_querycache");
$rows = $statement->fetchAll(); $rows = $statement->fetchAll();
$dbs = new DBLayer("shard");
foreach ($rows as $record) { foreach ($rows as $record) {
$db = new DBLayer($record['db']);
switch($record['type']) { switch($record['type']) {
case 'createPermissions': case 'createPermissions':
case 'change_pass': case 'change_pass':
$decode = json_decode($record['query']); $decode = json_decode($record['query']);
$values = array('user' => $decode[0], 'pass' => $decode[1]); $values = array('user' => $decode[0], 'pass' => $decode[1]);
//make connection with and put into shard db & delete from the lib //make connection with and put into shard db & delete from the lib
$dbs->execute("UPDATE user SET Password = :pass WHERE Login = :user",$values); $db->execute("UPDATE user SET Password = :pass WHERE Login = :user",$values);
$dbl->execute("DELETE FROM ams_querycache WHERE SID=:SID",array('SID' => $record['SID']));
break; break;
case 'change_mail': case 'change_mail':
$decode = json_decode($record['query']); $decode = json_decode($record['query']);
$values = array('user' => $decode[0], 'mail' => $decode[1]); $values = array('user' => $decode[0], 'mail' => $decode[1]);
//make connection with and put into shard db & delete from the lib //make connection with and put into shard db & delete from the lib
$dbs->execute("UPDATE user SET Email = :mail WHERE Login = :user",$values); $db->execute("UPDATE user SET Email = :mail WHERE Login = :user",$values);
$dbl->execute("DELETE FROM ams_querycache WHERE SID=:SID",array('SID' => $record['SID']));
break; break;
case 'createUser': case 'createUser':
$decode = json_decode($record['query']); $decode = json_decode($record['query']);
$values = array('login' => $decode[0], 'pass' => $decode[1], 'mail' => $decode[2] ); $values = array('login' => $decode[0], 'pass' => $decode[1], 'mail' => $decode[2] );
//make connection with and put into shard db & delete from the lib //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); $db->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']));
break; break;
} }
$dbl->execute("DELETE FROM ams_querycache WHERE SID=:SID",array('SID' => $record['SID']));
} }
print('Syncing completed'); print('Syncing completed');
} }

View file

@ -296,8 +296,8 @@ class Users{
//oh noooz, the shard is offline! Put in query queue at ams_lib db! //oh noooz, the shard is offline! Put in query queue at ams_lib db!
try { try {
$dbl = new DBLayer("lib"); $dbl = new DBLayer("lib");
$dbl->execute("INSERT INTO ams_querycache (type, query) VALUES (:type, :query)",array("type" => "createUser", $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"])))); "query" => json_encode(array($values["name"],$values["pass"],$values["mail"])), "db" => "shard"));
ticket_user::createTicketUser( $user_id , 1 ); ticket_user::createTicketUser( $user_id , 1 );
return "shardoffline"; return "shardoffline";
}catch (PDOException $e) { }catch (PDOException $e) {
@ -380,8 +380,8 @@ class Users{
//oh noooz, the shard is offline! Put in query queue at ams_lib db! //oh noooz, the shard is offline! Put in query queue at ams_lib db!
try { try {
$dbl = new DBLayer("lib"); $dbl = new DBLayer("lib");
$dbl->execute("INSERT INTO ams_querycache (type, query) VALUES (:type, :query)",array("type" => "change_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"])))); "query" => json_encode(array($values["user"],$values["pass"])), "db" => "shard"));
return "shardoffline"; return "shardoffline";
}catch (PDOException $e) { }catch (PDOException $e) {
return "liboffline"; return "liboffline";
@ -403,8 +403,8 @@ class Users{
//oh noooz, the shard is offline! Put in query queue at ams_lib db! //oh noooz, the shard is offline! Put in query queue at ams_lib db!
try { try {
$dbl = new DBLayer("lib"); $dbl = new DBLayer("lib");
$dbl->execute("INSERT INTO ams_querycache (type, query) VALUES (:type, :query)",array("type" => "change_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"])))); "query" => json_encode(array($values["user"],$values["mail"])), "db" => "shard"));
return "shardoffline"; return "shardoffline";
}catch (PDOException $e) { }catch (PDOException $e) {
return "liboffline"; return "liboffline";

View file

@ -19,7 +19,7 @@ $cfg['db']['lib']['name'] = 'ryzom_ams_lib';
$cfg['db']['lib']['user'] = 'shard'; $cfg['db']['lib']['user'] = 'shard';
$cfg['db']['lib']['pass'] = ''; $cfg['db']['lib']['pass'] = '';
$cfg['db']['shard']['host'] = 'localhosti'; $cfg['db']['shard']['host'] = 'localhost';
$cfg['db']['shard']['port'] = '3306'; $cfg['db']['shard']['port'] = '3306';
$cfg['db']['shard']['name'] = 'nel'; $cfg['db']['shard']['name'] = 'nel';
$cfg['db']['shard']['user'] = 'shard'; $cfg['db']['shard']['user'] = 'shard';

View file

@ -42,7 +42,8 @@
CREATE TABLE ams_querycache ( CREATE TABLE ams_querycache (
`SID` INT NOT NULL AUTO_INCREMENT PRIMARY KEY , `SID` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`type` VARCHAR( 64 ) NOT NULL , `type` VARCHAR( 64 ) NOT NULL ,
`query` VARCHAR( 512 ) NOT NULL `query` VARCHAR( 512 ) NOT NULL,
`db` VARCHAR( 80 ) NOT NULL
); );