3 * handler for performing changes when shard is back online after being offline.
4 * the sync class is responsible for the syncdata function, which will synchronise the website with the shard
5 * (when the shard is offline, users can still change their password, email or even register)
6 * @author Daan Janssens, mentored by Matthew Lagoe
16 * performs the actions listed in the querycache.
17 * All entries in the querycache will be read and performed depending on their type.
18 * This is done because the shard could have been offline and we want changes made on the website (which is still online) to eventually hit the shard.
19 * These changes are: createPermissions, createUser, change_pass, change_mail
21 static public function syncdata ($display = false) {
23 if (function_exists('pcntl_fork')) {
27 $pidfile = $AMS_TMPDIR.'/ams_cron_pid';
29 if(isset($pid) and function_exists('pcntl_fork') ) {
30 // We're the main process.
33 if(Sync
::check_for_pid(@file_get_contents
($pidfile))) {
34 $file = fopen($pidfile, 'w+');
36 echo $pidfile.' is not writeable.';
37 error_log($pidfile.' is not writeable.');
38 throw new SystemExit();
44 $dbl = new DBLayer("lib");
45 $statement = $dbl->executeWithoutParams("SELECT * FROM ams_querycache");
46 $rows = $statement->fetchAll();
47 foreach ($rows as $record) {
49 $db = new DBLayer($record['db']);
50 switch($record['type']) {
51 case 'createPermissions':
52 $decode = json_decode($record['query']);
53 $values = array('username' => $decode[0]);
54 //make connection with and put into shard db & delete from the lib
55 $sth=$db->selectWithParameter("UId", "user", $values, "Login= :username" );
56 $result = $sth->fetchAll();
57 /*foreach ($result as $UId) {
58 $ins_values = array('UId' => $UId['UId']);
59 $ins_values['ClientApplication'] = "r2";
60 $ins_values['AccessPrivilege'] = "OPEN";
61 $db->insert("permission", $ins_values);
62 $ins_values['ClientApplication'] = 'ryzom_open';
63 $db->insert("permission",$ins_values);
67 $decode = json_decode($record['query']);
68 $values = array('Password' => $decode[1]);
69 //make connection with and put into shard db & delete from the lib
70 $db->update("user", $values, "Login = '$decode[0]'");
73 $decode = json_decode($record['query']);
74 $values = array('Email' => $decode[1]);
75 //make connection with and put into shard db & delete from the lib
76 $db->update("user", $values, "Login = '$decode[0]'");
79 $decode = json_decode($record['query']);
80 $values = array('Login' => $decode[0], 'Password' => $decode[1], 'Email' => $decode[2] );
81 //make connection with and put into shard db & delete from the lib
82 $db->insert("user", $values);
85 $dbl->delete("ams_querycache", array('SID' => $record['SID']), "SID=:SID");
87 if ($display == true) {
88 print('Syncing completed');
91 catch (PDOException
$e) {
92 if ($display == true) {
93 print('Something went wrong! The shard is probably still offline!');
103 public static function check_for_pid($pid){
108 $processes = explode( "\n", shell_exec( "tasklist.exe" ));
109 foreach( $processes as $key => $value )
111 if( empty($value) != '1' && strpos( "Image Name", $value ) === 0
112 ||
empty($value) != '1' && strpos( "===", $value ) === 0 )
115 preg_match( "/(.*?)\s+(\d+).*$/", $value, $matches );
116 if (isset($matches[ 2 ]) && $pid = $matches[ 2 ]) {
121 return file_exists( "/proc/".$pid );
124 static public function getOS() {
126 case stristr(PHP_OS
, 'DAR'): return self
::OS_OSX
;
127 case stristr(PHP_OS
, 'WIN'): return self
::OS_WIN
;
128 case stristr(PHP_OS
, 'LINUX'): return self
::OS_LINUX
;
129 default : return self
::OS_UNKNOWN
;