diff --git a/bin/external/localeo/LocaleoScript.php b/bin/external/localeo/LocaleoScript.php index 04281f3249853ee76d7a82c92b89c58d4c474cf9..03a19cbf78d8c23871ca01ffc12f5ca3b1379fe9 100644 --- a/bin/external/localeo/LocaleoScript.php +++ b/bin/external/localeo/LocaleoScript.php @@ -143,6 +143,13 @@ class LocaleoScript return; } + if (!file_exists('bin/external/localeo/updateContact.timestamp')) { + $file = fopen('bin/external/localeo/updateContact.timestamp', 'w'); + fwrite($file, time()); + fclose($file); + return; + } + $dataToMerge = []; if (!empty($configuration->updateContact->data)) { foreach ($configuration->updateContact->data as $value) { @@ -153,24 +160,18 @@ class LocaleoScript \SrcCore\models\DatabasePDO::reset(); new \SrcCore\models\DatabasePDO(['customId' => $customId]); - $where = ['enabled = ?', "external_id->>'localeoId' is not null"]; - $data = [true]; - if (file_exists('bin/external/localeo/updateContact.timestamp')) { - $time = file_get_contents('bin/external/localeo/updateContact.timestamp'); - $where[] = 'modification_date > ?'; - $data[] = date('Y-m-d H:i:s', $time); - - } - $file = fopen('bin/external/localeo/updateContact.timestamp', 'w'); - fwrite($file, time()); - fclose($file); + $time = file_get_contents('bin/external/localeo/updateContact.timestamp'); $contacts = \Contact\models\ContactModel::get([ 'select' => ['*'], - 'where' => $where, - 'data' => $data + 'where' => ['enabled = ?', "external_id->>'localeoId' is not null", 'modification_date > ?'], + 'data' => [true, date('Y-m-d H:i:s', $time)] ]); + $file = fopen('bin/external/localeo/updateContact.timestamp', 'w'); + fwrite($file, time()); + fclose($file); + foreach ($contacts as $contact) { $externalId = json_decode($contact['external_id'], true); @@ -458,6 +459,13 @@ class LocaleoScript return; } + if (!file_exists('bin/external/localeo/closeResource.timestamp')) { + $file = fopen('bin/external/localeo/closeResource.timestamp', 'w'); + fwrite($file, time()); + fclose($file); + return; + } + $dataToMerge = []; if (!empty($configuration->closeResource->data)) { foreach ($configuration->closeResource->data as $value) { @@ -468,24 +476,18 @@ class LocaleoScript \SrcCore\models\DatabasePDO::reset(); new \SrcCore\models\DatabasePDO(['customId' => $customId]); - $where = ["external_id->>'localeoId' is not null", 'status = ?', 'closing_date is not null']; - $data = [$status]; - if (file_exists('bin/external/localeo/closeResource.timestamp')) { - $time = file_get_contents('bin/external/localeo/closeResource.timestamp'); - $where[] = 'closing_date > ?'; - $data[] = date('Y-m-d H:i:s', $time); - } - - $file = fopen('bin/external/localeo/closeResource.timestamp', 'w'); - fwrite($file, time()); - fclose($file); + $time = file_get_contents('bin/external/localeo/closeResource.timestamp'); $resources = \Resource\models\ResModel::get([ 'select' => ['res_id', "external_id->>'localeoId' as \"localeoId\""], - 'where' => $where, - 'data' => $data + 'where' => ["external_id->>'localeoId' is not null", 'status = ?', 'closing_date is not null', 'closing_date > ?'], + 'data' => [$status, date('Y-m-d H:i:s', $time)] ]); + $file = fopen('bin/external/localeo/closeResource.timestamp', 'w'); + fwrite($file, time()); + fclose($file); + foreach ($resources as $resource) { $body = [];