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 {
$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');
}

View file

@ -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";

View file

@ -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';

View file

@ -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
);