cleanup sync

--HG--
branch : rc-botanic-webdev
hg/feature/sse2
Botanic 11 years ago
parent 3dbb08f1d1
commit 677c8fa251

@ -19,70 +19,71 @@ class Sync{
$pid = pcntl_fork(); $pid = pcntl_fork();
} }
$pidfile = '/tmp/ams_cron_pid'; $pidfile = '/tmp/ams_cron_pid';
if(isset($pid)) {
// We're the main process. if(isset($pid)) {
} else { // We're the main process.
if(!file_exists($pidfile)) { } else {
$pid = getmypid(); if(!file_exists($pidfile)) {
$file = fopen($pidfile, 'w'); $pid = getmypid();
$file = fopen($pidfile, 'w');
fwrite($file, $pid);
fclose($file);
try {
$dbl = new DBLayer("lib");
$statement = $dbl->executeWithoutParams("SELECT * FROM ams_querycache");
$rows = $statement->fetchAll();
foreach ($rows as $record) {
$db = new DBLayer($record['db']); fwrite($file, $pid);
switch($record['type']) { fclose($file);
case 'createPermissions':
$decode = json_decode($record['query']); try {
$values = array('username' => $decode[0]); $dbl = new DBLayer("lib");
//make connection with and put into shard db & delete from the lib $statement = $dbl->executeWithoutParams("SELECT * FROM ams_querycache");
$sth = $db->execute("SELECT UId FROM user WHERE Login= :username;", $values); $rows = $statement->fetchAll();
$result = $sth->fetchAll(); foreach ($rows as $record) {
foreach ($result as $UId) {
$ins_values = array('id' => $UId['UId']); $db = new DBLayer($record['db']);
$db->execute("INSERT INTO permission (UId, ClientApplication, AccessPrivilege) VALUES (:id, 'r2', 'OPEN');", $ins_values); switch($record['type']) {
$db->execute("INSERT INTO permission (UId, ClientApplication, AccessPrivilege) VALUES (:id , 'ryzom_open', 'OPEN');", $ins_values); case 'createPermissions':
} $decode = json_decode($record['query']);
break; $values = array('username' => $decode[0]);
case 'change_pass': //make connection with and put into shard db & delete from the lib
$decode = json_decode($record['query']); $sth = $db->execute("SELECT UId FROM user WHERE Login= :username;", $values);
$values = array('user' => $decode[0], 'pass' => $decode[1]); $result = $sth->fetchAll();
//make connection with and put into shard db & delete from the lib foreach ($result as $UId) {
$db->execute("UPDATE user SET Password = :pass WHERE Login = :user",$values); $ins_values = array('id' => $UId['UId']);
break; $db->execute("INSERT INTO permission (UId, ClientApplication, AccessPrivilege) VALUES (:id, 'r2', 'OPEN');", $ins_values);
case 'change_mail': $db->execute("INSERT INTO permission (UId, ClientApplication, AccessPrivilege) VALUES (:id , 'ryzom_open', 'OPEN');", $ins_values);
$decode = json_decode($record['query']); }
$values = array('user' => $decode[0], 'mail' => $decode[1]); break;
//make connection with and put into shard db & delete from the lib case 'change_pass':
$db->execute("UPDATE user SET Email = :mail WHERE Login = :user",$values); $decode = json_decode($record['query']);
break; $values = array('user' => $decode[0], 'pass' => $decode[1]);
case 'createUser': //make connection with and put into shard db & delete from the lib
$decode = json_decode($record['query']); $db->execute("UPDATE user SET Password = :pass WHERE Login = :user",$values);
$values = array('login' => $decode[0], 'pass' => $decode[1], 'mail' => $decode[2] ); break;
//make connection with and put into shard db & delete from the lib case 'change_mail':
$db->execute("INSERT INTO user (Login, Password, Email) VALUES (:login, :pass, :mail)",$values); $decode = json_decode($record['query']);
break; $values = array('user' => $decode[0], 'mail' => $decode[1]);
//make connection with and put into shard db & delete from the lib
$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
$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']));
}
if ($display == true) {
print('Syncing completed');
} }
$dbl->execute("DELETE FROM ams_querycache WHERE SID=:SID",array('SID' => $record['SID']));
}
if ($display == true) {
print('Syncing completed');
} }
} catch (PDOException $e) {
catch (PDOException $e) { if ($display == true) {
if ($display == true) { print('Something went wrong! The shard is probably still offline!');
print('Something went wrong! The shard is probably still offline!'); print_r($e);
print_r($e); }
} }
unlink($pidfile);
} }
unlink($pidfile);
}
} }
} }
} }

Loading…
Cancel
Save