2013-06-27 02:54:41 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class Sync{
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Function syncdata
|
|
|
|
*
|
|
|
|
* @takes Nothing
|
|
|
|
* @return array $values
|
|
|
|
*
|
|
|
|
* Info: Runs functions to finish syncing data when shard is offline
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
static public function syncdata () {
|
|
|
|
|
|
|
|
try {
|
2013-07-10 10:36:14 +00:00
|
|
|
$dbl = new DBLayer("lib");
|
2013-06-27 16:06:09 +00:00
|
|
|
$statement = $dbl->executeWithoutParams("SELECT * FROM ams_querycache");
|
2013-08-01 16:20:40 +00:00
|
|
|
$rows = $statement->fetchAll();
|
2013-06-27 02:54:41 +00:00
|
|
|
foreach ($rows as $record) {
|
2013-08-01 16:20:40 +00:00
|
|
|
|
|
|
|
$db = new DBLayer($record['db']);
|
2013-06-27 02:54:41 +00:00
|
|
|
switch($record['type']) {
|
|
|
|
case 'createPermissions':
|
2013-07-05 01:50:43 +00:00
|
|
|
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
|
2013-08-01 16:20:40 +00:00
|
|
|
$db->execute("UPDATE user SET Password = :pass WHERE Login = :user",$values);
|
2013-07-05 01:50:43 +00:00
|
|
|
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
|
2013-08-01 16:20:40 +00:00
|
|
|
$db->execute("UPDATE user SET Email = :mail WHERE Login = :user",$values);
|
2013-07-05 01:50:43 +00:00
|
|
|
break;
|
2013-06-27 02:54:41 +00:00
|
|
|
case 'createUser':
|
2013-06-27 16:06:09 +00:00
|
|
|
$decode = json_decode($record['query']);
|
2013-07-05 01:50:43 +00:00
|
|
|
$values = array('login' => $decode[0], 'pass' => $decode[1], 'mail' => $decode[2] );
|
2013-06-27 16:06:09 +00:00
|
|
|
//make connection with and put into shard db & delete from the lib
|
2013-08-01 16:20:40 +00:00
|
|
|
$db->execute("INSERT INTO user (Login, Password, Email) VALUES (:login, :pass, :mail)",$values);
|
2013-07-05 01:50:43 +00:00
|
|
|
break;
|
2013-06-27 02:54:41 +00:00
|
|
|
}
|
2013-08-01 16:20:40 +00:00
|
|
|
$dbl->execute("DELETE FROM ams_querycache WHERE SID=:SID",array('SID' => $record['SID']));
|
2013-06-27 02:54:41 +00:00
|
|
|
}
|
|
|
|
print('Syncing completed');
|
|
|
|
}
|
|
|
|
catch (PDOException $e) {
|
|
|
|
print('Something went wrong!');
|
|
|
|
print_r($e);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|