@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | * @param CertainListener[] $listeners |
| 48 | 48 | * @param null $name |
| 49 | 49 | */ |
| 50 | - public function __construct(DetectAppointmentsChangingsService $detectAppointmentsChangingsService,$filePathEventToCheck,$dirPathHistoryAppointments,$fileLockAuthorizeRun, array $listeners=[],$name=null) |
|
| 50 | + public function __construct(DetectAppointmentsChangingsService $detectAppointmentsChangingsService, $filePathEventToCheck, $dirPathHistoryAppointments, $fileLockAuthorizeRun, array $listeners = [], $name = null) |
|
| 51 | 51 | { |
| 52 | 52 | parent::__construct($name); |
| 53 | 53 | $this->detectAppointmentsChangingsService = $detectAppointmentsChangingsService; |
@@ -72,40 +72,40 @@ discard block |
||
| 72 | 72 | { |
| 73 | 73 | $eventCode = null; |
| 74 | 74 | //Get the EventCode we need to check. |
| 75 | - if($this->filePathEventToCheck && file_exists($this->filePathEventToCheck)){ |
|
| 75 | + if ($this->filePathEventToCheck && file_exists($this->filePathEventToCheck)) { |
|
| 76 | 76 | $eventCode = FileChangesHelper::getContentFile($this->filePathEventToCheck); |
| 77 | 77 | } |
| 78 | 78 | //That permits to stop the followings instructions when we are makings changes on Certain. |
| 79 | - if(!file_exists($this->fileLockAuthorizeRun.'/detect_appointments_changes.lock') && $eventCode){ |
|
| 79 | + if (!file_exists($this->fileLockAuthorizeRun.'/detect_appointments_changes.lock') && $eventCode) { |
|
| 80 | 80 | $output->writeln('Detect changes - Run.'); |
| 81 | 81 | //Get the online appointments. |
| 82 | 82 | $appointmentsNewCertain = $this->detectAppointmentsChangingsService->getCurrentAppoiments($eventCode); |
| 83 | 83 | $appointmentsNew = DetectAppointmentsChangingsService::recursiveArrayObjectToFullArray($appointmentsNewCertain); |
| 84 | 84 | //Get the last saved appointments to get old data. |
| 85 | - $appointmentsOldHistoryFilePath = FileChangesHelper::getTheLastAppointmentsSaved($eventCode,$this->dirPathHistoryAppointments); |
|
| 86 | - if(!$appointmentsOldHistoryFilePath){ |
|
| 85 | + $appointmentsOldHistoryFilePath = FileChangesHelper::getTheLastAppointmentsSaved($eventCode, $this->dirPathHistoryAppointments); |
|
| 86 | + if (!$appointmentsOldHistoryFilePath) { |
|
| 87 | 87 | //No files so it's the first time we attempt to synchronize. |
| 88 | 88 | $appointmentsOld = []; |
| 89 | - }else{ |
|
| 89 | + }else { |
|
| 90 | 90 | //Get the last old appointments data. |
| 91 | 91 | $appointmentsOldHistory = FileChangesHelper::getJsonContentFromFile($appointmentsOldHistoryFilePath); |
| 92 | 92 | $appointmentsOld = DetectAppointmentsChangingsService::recursiveArrayObjectToFullArray($appointmentsOldHistory); |
| 93 | 93 | } |
| 94 | 94 | //Check if they are changes. |
| 95 | - $listChangings = $this->detectAppointmentsChangingsService->detectAppointmentsChangings($appointmentsOld,$appointmentsNew); |
|
| 96 | - if(!$appointmentsOld || ((isset($listChangings['updated']) && !empty($listChangings['updated'])) |
|
| 97 | - || (isset($listChangings['deleted']) && !empty($listChangings['deleted'])))){ |
|
| 95 | + $listChangings = $this->detectAppointmentsChangingsService->detectAppointmentsChangings($appointmentsOld, $appointmentsNew); |
|
| 96 | + if (!$appointmentsOld || ((isset($listChangings['updated']) && !empty($listChangings['updated'])) |
|
| 97 | + || (isset($listChangings['deleted']) && !empty($listChangings['deleted'])))) { |
|
| 98 | 98 | //Changes? So we save the new online appointments |
| 99 | - FileChangesHelper::saveAppointmentsFileByHistory($this->dirPathHistoryAppointments.'/appointments_'.$eventCode.'.json',json_encode($appointmentsNew)); |
|
| 99 | + FileChangesHelper::saveAppointmentsFileByHistory($this->dirPathHistoryAppointments.'/appointments_'.$eventCode.'.json', json_encode($appointmentsNew)); |
|
| 100 | 100 | $output->writeln('Detect changes - Save Changes'); |
| 101 | - }else{ |
|
| 101 | + }else { |
|
| 102 | 102 | $output->writeln('Detect changes - No Changes'); |
| 103 | 103 | } |
| 104 | - foreach ($this->listeners as $listener){ |
|
| 104 | + foreach ($this->listeners as $listener) { |
|
| 105 | 105 | //Run Listener. For instance,Here we can use ChangingsToFileListeners to save the changes in file. |
| 106 | - $listener->run($eventCode,$listChangings); |
|
| 106 | + $listener->run($eventCode, $listChangings); |
|
| 107 | 107 | } |
| 108 | - }else{ |
|
| 108 | + }else { |
|
| 109 | 109 | $output->writeln('Detect changes - Stop.'); |
| 110 | 110 | } |
| 111 | 111 | } |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | if(!$appointmentsOldHistoryFilePath){ |
| 87 | 87 | //No files so it's the first time we attempt to synchronize. |
| 88 | 88 | $appointmentsOld = []; |
| 89 | - }else{ |
|
| 89 | + } else{ |
|
| 90 | 90 | //Get the last old appointments data. |
| 91 | 91 | $appointmentsOldHistory = FileChangesHelper::getJsonContentFromFile($appointmentsOldHistoryFilePath); |
| 92 | 92 | $appointmentsOld = DetectAppointmentsChangingsService::recursiveArrayObjectToFullArray($appointmentsOldHistory); |
@@ -98,14 +98,14 @@ discard block |
||
| 98 | 98 | //Changes? So we save the new online appointments |
| 99 | 99 | FileChangesHelper::saveAppointmentsFileByHistory($this->dirPathHistoryAppointments.'/appointments_'.$eventCode.'.json',json_encode($appointmentsNew)); |
| 100 | 100 | $output->writeln('Detect changes - Save Changes'); |
| 101 | - }else{ |
|
| 101 | + } else{ |
|
| 102 | 102 | $output->writeln('Detect changes - No Changes'); |
| 103 | 103 | } |
| 104 | 104 | foreach ($this->listeners as $listener){ |
| 105 | 105 | //Run Listener. For instance,Here we can use ChangingsToFileListeners to save the changes in file. |
| 106 | 106 | $listener->run($eventCode,$listChangings); |
| 107 | 107 | } |
| 108 | - }else{ |
|
| 108 | + } else{ |
|
| 109 | 109 | $output->writeln('Detect changes - Stop.'); |
| 110 | 110 | } |
| 111 | 111 | } |
@@ -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); |
@@ -35,15 +35,15 @@ discard block |
||
| 35 | 35 | * @param string $contents |
| 36 | 36 | * @return void |
| 37 | 37 | */ |
| 38 | - public static function saveAppointmentsFileByHistory($filePath,$contents){ |
|
| 38 | + public static function saveAppointmentsFileByHistory($filePath, $contents) { |
|
| 39 | 39 | $time = time(); |
| 40 | 40 | $file = pathinfo($filePath); |
| 41 | 41 | $fileNamebase = $file['filename']; |
| 42 | 42 | $filePath = $file['dirname'].'/'.$fileNamebase.'_'.$time.'.json'; |
| 43 | - if(!file_exists($filePath)){ |
|
| 44 | - self::writeFile($filePath,''); |
|
| 43 | + if (!file_exists($filePath)) { |
|
| 44 | + self::writeFile($filePath, ''); |
|
| 45 | 45 | } |
| 46 | - self::writeFile($filePath,$contents); |
|
| 46 | + self::writeFile($filePath, $contents); |
|
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | /** |
@@ -51,9 +51,9 @@ discard block |
||
| 51 | 51 | * @param $path |
| 52 | 52 | * @return string |
| 53 | 53 | */ |
| 54 | - public static function getContentFile($path){ |
|
| 55 | - if(!file_exists($path)){ |
|
| 56 | - self::writeFile($path,''); |
|
| 54 | + public static function getContentFile($path) { |
|
| 55 | + if (!file_exists($path)) { |
|
| 56 | + self::writeFile($path, ''); |
|
| 57 | 57 | } |
| 58 | 58 | $handle = fopen($path, "rb"); |
| 59 | 59 | if (FALSE === $handle) { |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | * @param string $path |
| 73 | 73 | * @return mixed |
| 74 | 74 | */ |
| 75 | - public static function getJsonContentFromFile($path){ |
|
| 75 | + public static function getJsonContentFromFile($path) { |
|
| 76 | 76 | $contents = self::getContentFile($path); |
| 77 | 77 | return json_decode($contents, true); |
| 78 | 78 | } |
@@ -83,7 +83,7 @@ discard block |
||
| 83 | 83 | * @param string $pathDir |
| 84 | 84 | * @return array |
| 85 | 85 | */ |
| 86 | - public static function getFilesListHistoryAppointmentsByEventCode($eventCode,$pathDir){ |
|
| 86 | + public static function getFilesListHistoryAppointmentsByEventCode($eventCode, $pathDir) { |
|
| 87 | 87 | $fileList = array(); |
| 88 | 88 | $files = glob($pathDir.'/appointments_'.$eventCode.'_*.json'); |
| 89 | 89 | foreach ($files as $file) { |
@@ -100,8 +100,8 @@ discard block |
||
| 100 | 100 | * @param string $pathDir |
| 101 | 101 | * @return string |
| 102 | 102 | */ |
| 103 | - public static function getTheLastAppointmentsSaved($eventCode,$pathDir){ |
|
| 104 | - $fileList = self::getFilesListHistoryAppointmentsByEventCode($eventCode,$pathDir); |
|
| 103 | + public static function getTheLastAppointmentsSaved($eventCode, $pathDir) { |
|
| 104 | + $fileList = self::getFilesListHistoryAppointmentsByEventCode($eventCode, $pathDir); |
|
| 105 | 105 | return array_shift($fileList); |
| 106 | 106 | } |
| 107 | 107 | } |
| 108 | 108 | \ No newline at end of file |
@@ -1,6 +1,6 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | if (file_exists(__DIR__.'/../vendor/autoload.php')) { |
| 3 | 3 | require_once __DIR__.'/../vendor/autoload.php'; |
| 4 | -} else { |
|
| 4 | +}else { |
|
| 5 | 5 | require_once __DIR__.'/../../../../vendor/autoload.php'; |
| 6 | 6 | } |
| 7 | 7 | \ No newline at end of file |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | * Personal Object to test |
| 30 | 30 | * @return array |
| 31 | 31 | */ |
| 32 | - private function personalAppointment(){ |
|
| 32 | + private function personalAppointment() { |
|
| 33 | 33 | return [ |
| 34 | 34 | "appointmentId"=> 52, |
| 35 | 35 | "startDate"=> "2015-16-07 11:00:00", |
@@ -68,23 +68,23 @@ discard block |
||
| 68 | 68 | |
| 69 | 69 | protected function setUp() |
| 70 | 70 | { |
| 71 | - $certainApiClient = new CertainApiClient(null,$GLOBALS['username'],$GLOBALS['password'],$GLOBALS['accountCode']); |
|
| 72 | - $this->certainApiService = new CertainApiService($certainApiClient); |
|
| 71 | + $certainApiClient = new CertainApiClient(null, $GLOBALS['username'], $GLOBALS['password'], $GLOBALS['accountCode']); |
|
| 72 | + $this->certainApiService = new CertainApiService($certainApiClient); |
|
| 73 | 73 | $this->appointmentsCertain = new AppointmentsCertain($this->certainApiService); |
| 74 | - $this->certainAppointmentsList = $this->appointmentsCertain->get($GLOBALS['eventCode'],['start_index'=>0,'max_results'=>10])->getResults()->appointments; |
|
| 74 | + $this->certainAppointmentsList = $this->appointmentsCertain->get($GLOBALS['eventCode'], ['start_index'=>0, 'max_results'=>10])->getResults()->appointments; |
|
| 75 | 75 | } |
| 76 | 76 | |
| 77 | - public function testDetectChangings(){ |
|
| 77 | + public function testDetectChangings() { |
|
| 78 | 78 | $detectService = new DetectAppointmentsChangingsService($this->appointmentsCertain); |
| 79 | 79 | $oldAppointments = $this->certainAppointmentsList; |
| 80 | 80 | $currentAppoiments = $oldAppointments; |
| 81 | 81 | unset($currentAppoiments[0]); |
| 82 | 82 | unset($currentAppoiments[1]); |
| 83 | - $hasChanged = $detectService->hasChanged($oldAppointments,$currentAppoiments); |
|
| 83 | + $hasChanged = $detectService->hasChanged($oldAppointments, $currentAppoiments); |
|
| 84 | 84 | $this->assertTrue($hasChanged); |
| 85 | 85 | } |
| 86 | 86 | |
| 87 | - public function testGetListChangings(){ |
|
| 87 | + public function testGetListChangings() { |
|
| 88 | 88 | $detectService = new DetectAppointmentsChangingsService($this->appointmentsCertain); |
| 89 | 89 | $oldAppointments = $this->certainAppointmentsList; |
| 90 | 90 | $currentAppoiments = $oldAppointments; |
@@ -94,14 +94,14 @@ discard block |
||
| 94 | 94 | unset($currentAppoiments[0]); |
| 95 | 95 | unset($currentAppoiments[1]); |
| 96 | 96 | unset($currentAppoiments[4]); |
| 97 | - $changings = $detectService->getListChangings($oldAppointments,$currentAppoiments); |
|
| 98 | - $this->assertEquals(3,count($changings)); |
|
| 99 | - $this->assertContains($delete1,$changings); |
|
| 100 | - $this->assertContains($delete2,$changings); |
|
| 101 | - $this->assertContains($delete3,$changings); |
|
| 97 | + $changings = $detectService->getListChangings($oldAppointments, $currentAppoiments); |
|
| 98 | + $this->assertEquals(3, count($changings)); |
|
| 99 | + $this->assertContains($delete1, $changings); |
|
| 100 | + $this->assertContains($delete2, $changings); |
|
| 101 | + $this->assertContains($delete3, $changings); |
|
| 102 | 102 | } |
| 103 | 103 | |
| 104 | - public function testDetectDeleteOrUpdated(){ |
|
| 104 | + public function testDetectDeleteOrUpdated() { |
|
| 105 | 105 | $detectService = new DetectAppointmentsChangingsService($this->appointmentsCertain); |
| 106 | 106 | $oldAppointments = $this->certainAppointmentsList; |
| 107 | 107 | $oldAppointments[10] = $this->personalAppointment(); |
@@ -113,19 +113,19 @@ discard block |
||
| 113 | 113 | $update1 = $currentAppoiments[10]; |
| 114 | 114 | $currentAppoiments[10]["startDate"] = "2015-17-07 12:00:00"; |
| 115 | 115 | $currentAppoiments[10]["endDate"] = "2015-17-07 12:30:00"; |
| 116 | - $changings = $detectService->getListChangings($oldAppointments,$currentAppoiments); |
|
| 117 | - $listDetected = $detectService->detectDeleteOrUpdated($currentAppoiments,$changings); |
|
| 118 | - $this->assertEquals(3,count($changings)); |
|
| 119 | - $this->assertArrayHasKey('deleted',$listDetected); |
|
| 120 | - $this->assertArrayHasKey('updated',$listDetected); |
|
| 121 | - $this->assertEquals(2,count($listDetected['deleted'])); |
|
| 122 | - $this->assertEquals(1,count($listDetected['updated'])); |
|
| 123 | - $this->assertContains($delete1,$listDetected['deleted']); |
|
| 124 | - $this->assertContains($delete2,$listDetected['deleted']); |
|
| 125 | - $this->assertContains($update1,$listDetected['updated']); |
|
| 116 | + $changings = $detectService->getListChangings($oldAppointments, $currentAppoiments); |
|
| 117 | + $listDetected = $detectService->detectDeleteOrUpdated($currentAppoiments, $changings); |
|
| 118 | + $this->assertEquals(3, count($changings)); |
|
| 119 | + $this->assertArrayHasKey('deleted', $listDetected); |
|
| 120 | + $this->assertArrayHasKey('updated', $listDetected); |
|
| 121 | + $this->assertEquals(2, count($listDetected['deleted'])); |
|
| 122 | + $this->assertEquals(1, count($listDetected['updated'])); |
|
| 123 | + $this->assertContains($delete1, $listDetected['deleted']); |
|
| 124 | + $this->assertContains($delete2, $listDetected['deleted']); |
|
| 125 | + $this->assertContains($update1, $listDetected['updated']); |
|
| 126 | 126 | } |
| 127 | 127 | |
| 128 | - public function testDetectAppointmentsChangings(){ |
|
| 128 | + public function testDetectAppointmentsChangings() { |
|
| 129 | 129 | $detectService = new DetectAppointmentsChangingsService($this->appointmentsCertain); |
| 130 | 130 | $oldAppointments = $this->certainAppointmentsList; |
| 131 | 131 | $oldAppointments[10] = $this->personalAppointment(); |
@@ -137,10 +137,10 @@ discard block |
||
| 137 | 137 | $update1 = $currentAppoiments[10]; |
| 138 | 138 | $currentAppoiments[10]["startDate"] = "2015-17-07 12:00:00"; |
| 139 | 139 | $currentAppoiments[10]["endDate"] = "2015-17-07 12:30:00"; |
| 140 | - $listDetected = $detectService->detectAppointmentsChangings($oldAppointments,$currentAppoiments); |
|
| 141 | - $this->assertContains($delete1,$listDetected['deleted']); |
|
| 142 | - $this->assertContains($delete2,$listDetected['deleted']); |
|
| 143 | - $this->assertContains($update1,$listDetected['updated']); |
|
| 140 | + $listDetected = $detectService->detectAppointmentsChangings($oldAppointments, $currentAppoiments); |
|
| 141 | + $this->assertContains($delete1, $listDetected['deleted']); |
|
| 142 | + $this->assertContains($delete2, $listDetected['deleted']); |
|
| 143 | + $this->assertContains($update1, $listDetected['updated']); |
|
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | } |
| 147 | 147 | \ No newline at end of file |