@@ -10,8 +10,8 @@ discard block |
||
| 10 | 10 | * @param $dirPath |
| 11 | 11 | * @return bool |
| 12 | 12 | */ |
| 13 | - public static function createDirectory($dirPath){ |
|
| 14 | - if(!file_exists($dirPath)){ |
|
| 13 | + public static function createDirectory($dirPath) { |
|
| 14 | + if (!file_exists($dirPath)) { |
|
| 15 | 15 | return mkdir($dirPath, 0775, true, null); |
| 16 | 16 | } |
| 17 | 17 | return false; |
@@ -23,7 +23,7 @@ discard block |
||
| 23 | 23 | * @param string $msg |
| 24 | 24 | * @return void |
| 25 | 25 | */ |
| 26 | - public static function writeFile($path,$msg){ |
|
| 26 | + public static function writeFile($path, $msg) { |
|
| 27 | 27 | $f = fopen($path, "w+"); |
| 28 | 28 | fwrite($f, $msg); |
| 29 | 29 | fclose($f); |
@@ -42,15 +42,15 @@ discard block |
||
| 42 | 42 | * @param string $contents |
| 43 | 43 | * @return void |
| 44 | 44 | */ |
| 45 | - public static function saveAppointmentsFileByHistory($filePath,$contents){ |
|
| 45 | + public static function saveAppointmentsFileByHistory($filePath, $contents) { |
|
| 46 | 46 | $time = time(); |
| 47 | 47 | $file = pathinfo($filePath); |
| 48 | 48 | $fileNamebase = $file['filename']; |
| 49 | 49 | $filePath = $file['dirname'].'/'.$fileNamebase.'_'.$time.'.json'; |
| 50 | - if(!file_exists($filePath)){ |
|
| 51 | - self::writeFile($filePath,''); |
|
| 50 | + if (!file_exists($filePath)) { |
|
| 51 | + self::writeFile($filePath, ''); |
|
| 52 | 52 | } |
| 53 | - self::writeFile($filePath,$contents); |
|
| 53 | + self::writeFile($filePath, $contents); |
|
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | /** |
@@ -58,9 +58,9 @@ discard block |
||
| 58 | 58 | * @param $path |
| 59 | 59 | * @return string |
| 60 | 60 | */ |
| 61 | - public static function getContentFile($path){ |
|
| 62 | - if(!file_exists($path)){ |
|
| 63 | - self::writeFile($path,''); |
|
| 61 | + public static function getContentFile($path) { |
|
| 62 | + if (!file_exists($path)) { |
|
| 63 | + self::writeFile($path, ''); |
|
| 64 | 64 | } |
| 65 | 65 | $handle = fopen($path, "rb"); |
| 66 | 66 | if (FALSE === $handle) { |
@@ -79,7 +79,7 @@ discard block |
||
| 79 | 79 | * @param string $path |
| 80 | 80 | * @return mixed |
| 81 | 81 | */ |
| 82 | - public static function getJsonContentFromFile($path){ |
|
| 82 | + public static function getJsonContentFromFile($path) { |
|
| 83 | 83 | $contents = self::getContentFile($path); |
| 84 | 84 | return json_decode($contents, true); |
| 85 | 85 | } |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | * @param string $pathDir |
| 91 | 91 | * @return array |
| 92 | 92 | */ |
| 93 | - public static function getFilesListHistoryAppointmentsByEventCode($eventCode,$pathDir){ |
|
| 93 | + public static function getFilesListHistoryAppointmentsByEventCode($eventCode, $pathDir) { |
|
| 94 | 94 | $fileList = array(); |
| 95 | 95 | $files = glob($pathDir.'/appointments_'.$eventCode.'_*.json'); |
| 96 | 96 | foreach ($files as $file) { |
@@ -107,8 +107,8 @@ discard block |
||
| 107 | 107 | * @param string $pathDir |
| 108 | 108 | * @return string |
| 109 | 109 | */ |
| 110 | - public static function getTheLastAppointmentsSaved($eventCode,$pathDir){ |
|
| 111 | - $fileList = self::getFilesListHistoryAppointmentsByEventCode($eventCode,$pathDir); |
|
| 110 | + public static function getTheLastAppointmentsSaved($eventCode, $pathDir) { |
|
| 111 | + $fileList = self::getFilesListHistoryAppointmentsByEventCode($eventCode, $pathDir); |
|
| 112 | 112 | return array_shift($fileList); |
| 113 | 113 | } |
| 114 | 114 | |
@@ -128,20 +128,20 @@ discard block |
||
| 128 | 128 | |
| 129 | 129 | public static function commandIsLocked(string $pathDir): bool |
| 130 | 130 | { |
| 131 | - return file_exists($pathDir. '/command.lock'); |
|
| 131 | + return file_exists($pathDir.'/command.lock'); |
|
| 132 | 132 | } |
| 133 | 133 | |
| 134 | 134 | public static function lockCommand(string $pathDir): void |
| 135 | 135 | { |
| 136 | 136 | if (!self::commandIsLocked($pathDir)) { |
| 137 | - self::writeFile($pathDir. '/command.lock','1'); |
|
| 137 | + self::writeFile($pathDir.'/command.lock', '1'); |
|
| 138 | 138 | } |
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | public static function unlockCommand(string $pathDir): void |
| 142 | 142 | { |
| 143 | 143 | if (self::commandIsLocked($pathDir)) { |
| 144 | - self::removeFile($pathDir. '/command.lock'); |
|
| 144 | + self::removeFile($pathDir.'/command.lock'); |
|
| 145 | 145 | } |
| 146 | 146 | } |
| 147 | 147 | } |
| 148 | 148 | \ No newline at end of file |
@@ -29,22 +29,22 @@ discard block |
||
| 29 | 29 | * @param array $elements |
| 30 | 30 | * @return void |
| 31 | 31 | */ |
| 32 | - public function run(string $eventCode,array $elements, array $options = []) |
|
| 32 | + public function run(string $eventCode, array $elements, array $options = []) |
|
| 33 | 33 | { |
| 34 | - if(isset($elements['updated'])){ |
|
| 35 | - foreach ($elements['updated'] as $element){ |
|
| 36 | - if(!is_array($element)){ |
|
| 34 | + if (isset($elements['updated'])) { |
|
| 35 | + foreach ($elements['updated'] as $element) { |
|
| 36 | + if (!is_array($element)) { |
|
| 37 | 37 | $element = [$element]; |
| 38 | 38 | } |
| 39 | - $this->updateUpdateListFile($eventCode,$element); |
|
| 39 | + $this->updateUpdateListFile($eventCode, $element); |
|
| 40 | 40 | } |
| 41 | 41 | } |
| 42 | - if(isset($elements['deleted'])){ |
|
| 43 | - foreach ($elements['deleted'] as $element){ |
|
| 44 | - if(!is_array($element)){ |
|
| 42 | + if (isset($elements['deleted'])) { |
|
| 43 | + foreach ($elements['deleted'] as $element) { |
|
| 44 | + if (!is_array($element)) { |
|
| 45 | 45 | $element = [$element]; |
| 46 | 46 | } |
| 47 | - $this->updateDeleteListFile($eventCode,$element); |
|
| 47 | + $this->updateDeleteListFile($eventCode, $element); |
|
| 48 | 48 | } |
| 49 | 49 | } |
| 50 | 50 | } |
@@ -55,10 +55,10 @@ discard block |
||
| 55 | 55 | * @param array $element |
| 56 | 56 | * @return void |
| 57 | 57 | */ |
| 58 | - private function updateFile($filePath,array $element){ |
|
| 58 | + private function updateFile($filePath, array $element) { |
|
| 59 | 59 | $content = FileChangesHelper::getJsonContentFromFile($filePath); |
| 60 | 60 | $content[] = $element; |
| 61 | - FileChangesHelper::writeFile($filePath,json_encode($content)); |
|
| 61 | + FileChangesHelper::writeFile($filePath, json_encode($content)); |
|
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | /** |
@@ -66,10 +66,10 @@ discard block |
||
| 66 | 66 | * @param array $element |
| 67 | 67 | * @return void |
| 68 | 68 | */ |
| 69 | - private function updateUpdateListFile($eventCode,array $element){ |
|
| 69 | + private function updateUpdateListFile($eventCode, array $element) { |
|
| 70 | 70 | FileChangesHelper::createDirectory($this->dirPathChangings); |
| 71 | 71 | $fileName = 'update_'.$eventCode.'.json'; |
| 72 | - $this->updateFile($this->dirPathChangings.'/'.$fileName,$element); |
|
| 72 | + $this->updateFile($this->dirPathChangings.'/'.$fileName, $element); |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | /** |
@@ -77,9 +77,9 @@ discard block |
||
| 77 | 77 | * @param array $element |
| 78 | 78 | * @return void |
| 79 | 79 | */ |
| 80 | - private function updateDeleteListFile($eventCode,array $element){ |
|
| 80 | + private function updateDeleteListFile($eventCode, array $element) { |
|
| 81 | 81 | FileChangesHelper::createDirectory($this->dirPathChangings); |
| 82 | 82 | $fileName = 'delete_'.$eventCode.'.json'; |
| 83 | - $this->updateFile($this->dirPathChangings.'/'.$fileName,$element); |
|
| 83 | + $this->updateFile($this->dirPathChangings.'/'.$fileName, $element); |
|
| 84 | 84 | } |
| 85 | 85 | } |
| 86 | 86 | \ No newline at end of file |
@@ -101,7 +101,7 @@ discard block |
||
| 101 | 101 | { |
| 102 | 102 | if (is_object($object)) { |
| 103 | 103 | |
| 104 | - return (array)$object; |
|
| 104 | + return (array) $object; |
|
| 105 | 105 | } |
| 106 | 106 | return $object; |
| 107 | 107 | } |
@@ -246,15 +246,15 @@ discard block |
||
| 246 | 246 | } |
| 247 | 247 | $codeCheckDirectory = FileChangesHelper::checkDirectory($this->dirPathHistoryAppointments); |
| 248 | 248 | if ($codeCheckDirectory === 'no_directory') { |
| 249 | - $this->logger->error('Path ' . $this->dirPathHistoryAppointments . ' doesn\'t exists.'); |
|
| 249 | + $this->logger->error('Path '.$this->dirPathHistoryAppointments.' doesn\'t exists.'); |
|
| 250 | 250 | return; |
| 251 | 251 | } |
| 252 | 252 | if ($codeCheckDirectory === 'not_readable') { |
| 253 | - $this->logger->error('Path ' . $this->dirPathHistoryAppointments . ' is not readable.'); |
|
| 253 | + $this->logger->error('Path '.$this->dirPathHistoryAppointments.' is not readable.'); |
|
| 254 | 254 | return; |
| 255 | 255 | } |
| 256 | 256 | if ($codeCheckDirectory === 'not_writable') { |
| 257 | - $this->logger->error('Path ' . $this->dirPathHistoryAppointments . ' is not writable.'); |
|
| 257 | + $this->logger->error('Path '.$this->dirPathHistoryAppointments.' is not writable.'); |
|
| 258 | 258 | return; |
| 259 | 259 | } |
| 260 | 260 | $this->lock->acquireLock(); |
@@ -268,7 +268,7 @@ discard block |
||
| 268 | 268 | if (!$appointmentsOldHistoryFilePath) { |
| 269 | 269 | //No files so it's the first time we attempt to synchronize. |
| 270 | 270 | $appointmentsOld = []; |
| 271 | - } else { |
|
| 271 | + }else { |
|
| 272 | 272 | //Get the last old appointments data. |
| 273 | 273 | $appointmentsOldHistory = FileChangesHelper::getJsonContentFromFile($appointmentsOldHistoryFilePath); |
| 274 | 274 | $appointmentsOld = self::recursiveArrayObjectToFullArray($appointmentsOldHistory); |
@@ -278,14 +278,14 @@ discard block |
||
| 278 | 278 | // $listChangings = $this->detectAppointmentsChangings($appointmentsOld, $appointmentsNew, $timestamp); |
| 279 | 279 | $listChangings = $this->detectAppointmentsChanges($appointmentsOld, $appointmentsNew, $timestamp); |
| 280 | 280 | if (!$appointmentsOld || ((isset($listChangings['updated']) && !empty($listChangings['updated'])) |
| 281 | - || (isset($listChangings['deleted']) && !empty($listChangings['deleted'])) || (isset($listChangings['inserted']) && !empty($listChangings['inserted'])))) { |
|
| 281 | + || (isset($listChangings['deleted']) && !empty($listChangings['deleted'])) || (isset($listChangings['inserted']) && !empty($listChangings['inserted'])))) { |
|
| 282 | 282 | //Changes? So we save the new online appointments |
| 283 | - FileChangesHelper::saveAppointmentsFileByHistory($this->dirPathHistoryAppointments . '/appointments_' . $eventCode . '.json', json_encode($appointmentsNew)); |
|
| 283 | + FileChangesHelper::saveAppointmentsFileByHistory($this->dirPathHistoryAppointments.'/appointments_'.$eventCode.'.json', json_encode($appointmentsNew)); |
|
| 284 | 284 | $this->logger->info('Detect changes - Save Changes'); |
| 285 | - } else { |
|
| 285 | + }else { |
|
| 286 | 286 | $this->logger->info('Detect changes - No Changes'); |
| 287 | 287 | } |
| 288 | - FileChangesHelper::saveAppointmentsFileByHistory($this->dirPathHistoryAppointments . '/changes_' . $eventCode . '.json', json_encode($listChangings)); |
|
| 288 | + FileChangesHelper::saveAppointmentsFileByHistory($this->dirPathHistoryAppointments.'/changes_'.$eventCode.'.json', json_encode($listChangings)); |
|
| 289 | 289 | foreach ($this->listeners as $listener) { |
| 290 | 290 | //Run Listener. For instance,Here we can use ChangingsToFileListeners to save the changes in file. |
| 291 | 291 | $listener->run($eventCode, $listChangings); |