|
|
@@ -83,7 +83,7 @@ class DolibarrSyncService
|
|
|
$operations = [];
|
|
|
$i = 0; $total = count($dolibarrClientsIndex);
|
|
|
foreach ($dolibarrClientsIndex as $organizationId => $dolibarrSociety) {
|
|
|
- $dolibarrSociety = $this->sanitizeDolibarrData($dolibarrSociety);
|
|
|
+ $dolibarrSociety = self::sanitizeDolibarrData($dolibarrSociety);
|
|
|
|
|
|
$organization = $this->organizationRepository->find($organizationId);
|
|
|
if ($organization === null) {
|
|
|
@@ -105,7 +105,7 @@ class DolibarrSyncService
|
|
|
if ($mainAddress !== null) {
|
|
|
$streetAddress = AddressPostalUtils::getFullStreetAddress($mainAddress);
|
|
|
if (trim($mainAddress->getAddressOwner() ?? '') !== '') {
|
|
|
- $streetAddress = $mainAddress->getAddressOwner() . '\n' . $streetAddress;
|
|
|
+ $streetAddress = $mainAddress->getAddressOwner() . "\n" . $streetAddress;
|
|
|
}
|
|
|
$newSocietyData['address'] = $streetAddress;
|
|
|
$newSocietyData['zip'] = $mainAddress->getPostalCode();
|
|
|
@@ -134,14 +134,14 @@ class DolibarrSyncService
|
|
|
$product = $organization->getSettings()->getProduct();
|
|
|
if (SettingsProductEnum::isSchool($product)) {
|
|
|
$infos[] = $this->translator->trans('STUDENTS_COUNT') . " : " .
|
|
|
- $this->countWithMission([FunctionEnum::STUDENT()->getValue()], $organizationMembers);
|
|
|
+ self::countWithMission([FunctionEnum::STUDENT()->getValue()], $organizationMembers);
|
|
|
}
|
|
|
if (SettingsProductEnum::isSchool($product) || SettingsProductEnum::isArtist($product)) {
|
|
|
$infos[] = $this->translator->trans('ADHERENTS_COUNT') . " : " .
|
|
|
- $this->countWithMission([FunctionEnum::ADHERENT()->getValue()], $organizationMembers);
|
|
|
+ self::countWithMission([FunctionEnum::ADHERENT()->getValue()], $organizationMembers);
|
|
|
}
|
|
|
$infos[] = $this->translator->trans('ADMIN_ACCESS_COUNT') . " : " .
|
|
|
- $this->countWithMission($adminMissions, $organizationMembers);
|
|
|
+ self::countWithMission($adminMissions, $organizationMembers);
|
|
|
|
|
|
// /!\ On est forcé de passer la sub-array entière pour mettre à jour le champ modifié, sinon
|
|
|
// tous les autres champs seront passés à null...
|
|
|
@@ -149,7 +149,7 @@ class DolibarrSyncService
|
|
|
$newSocietyData['array_options']['options_2iopeninfoopentalent'] = implode("\n", $infos);
|
|
|
|
|
|
// Only update the fields that are different
|
|
|
- $newSocietyData = $this->filterDiff($dolibarrSociety, $newSocietyData);
|
|
|
+ $newSocietyData = self::filterDiff($dolibarrSociety, $newSocietyData);
|
|
|
|
|
|
// Add an update operation if some data has to be updated
|
|
|
if (!empty($newSocietyData)) {
|
|
|
@@ -167,12 +167,19 @@ class DolibarrSyncService
|
|
|
|
|
|
foreach ($organizationMembers as $accessId => $missions) {
|
|
|
foreach ($missions as $mission) {
|
|
|
- if (in_array($mission, FunctionEnum::getOfficeMissions())) {
|
|
|
+ if (in_array($mission, FunctionEnum::getOfficeMissions(), true)) {
|
|
|
$access = $this->accessRepository->find($accessId);
|
|
|
+ if ($access === null) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
$person = $access->getPerson();
|
|
|
+ if ($person === null) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
|
|
|
// Keep track of the contacts seen
|
|
|
- if (in_array($person->getId(), $contactsProcessed)) {
|
|
|
+ if (in_array($person->getId(), $contactsProcessed, true)) {
|
|
|
// already updated from another mission
|
|
|
continue;
|
|
|
}
|
|
|
@@ -185,7 +192,7 @@ class DolibarrSyncService
|
|
|
|
|
|
// Build parameters for the query (if a query is needed
|
|
|
$dolibarrContact = $dolibarrContactsIndex[$person->getId()] ?? null;
|
|
|
- $dolibarrContact = $this->sanitizeDolibarrData($dolibarrContact);
|
|
|
+ $dolibarrContact = self::sanitizeDolibarrData($dolibarrContact);
|
|
|
|
|
|
$contact = $this->getPersonContact($person);
|
|
|
|
|
|
@@ -194,8 +201,8 @@ class DolibarrSyncService
|
|
|
'lastname' => trim($person->getName()),
|
|
|
'firstname' => trim($person->getGivenName()),
|
|
|
'email' => $contact?->getEmail(),
|
|
|
- 'phone_pro' => $contact?->getTelphone() ? $this->formatPhoneNumber($contact?->getTelphone()) : null,
|
|
|
- 'phone_mobile' => $contact?->getMobilPhone() ? $this->formatPhoneNumber($contact?->getMobilPhone()): null,
|
|
|
+ 'phone_pro' => $contact?->getTelphone() ? self::formatPhoneNumber($contact?->getTelphone()) : null,
|
|
|
+ 'phone_mobile' => $contact?->getMobilPhone() ? self::formatPhoneNumber($contact?->getMobilPhone()): null,
|
|
|
'poste' => $this->formatContactPosition($missions, $person->getGender())
|
|
|
];
|
|
|
|
|
|
@@ -213,7 +220,7 @@ class DolibarrSyncService
|
|
|
);
|
|
|
} else {
|
|
|
// Only update the fields that are different
|
|
|
- $newContactData = $this->filterDiff($dolibarrContact, $newContactData);
|
|
|
+ $newContactData = self::filterDiff($dolibarrContact, $newContactData);
|
|
|
|
|
|
// add an update operation if some data has to be updated
|
|
|
if (!empty($newContactData)) {
|
|
|
@@ -238,7 +245,7 @@ class DolibarrSyncService
|
|
|
// contact is already disabled
|
|
|
continue;
|
|
|
}
|
|
|
- if (!in_array($personId, $contactsProcessed)) {
|
|
|
+ if (!in_array($personId, $contactsProcessed, true)) {
|
|
|
// Ce personId n'existe plus dans les membres Opentalent de cette société, on delete
|
|
|
$operations[] = new UpdateOperation(
|
|
|
'Disable contact: ' . $contactData['lastname'] . ' ' . $contactData['firstname'] . ' (' . $personId . ')' .
|
|
|
@@ -316,8 +323,9 @@ class DolibarrSyncService
|
|
|
$this->logger->info('Execution ended');
|
|
|
$this->logger->info('Done : ' . $done);
|
|
|
$this->logger->info('Errors : ' . $errors);
|
|
|
- if ($unknown > 0)
|
|
|
+ if ($unknown > 0) {
|
|
|
$this->logger->warning('Unknown : ' . $unknown);
|
|
|
+ }
|
|
|
|
|
|
return $operations;
|
|
|
}
|
|
|
@@ -348,7 +356,7 @@ class DolibarrSyncService
|
|
|
$index = [];
|
|
|
foreach ($this->dolibarrApiService->getAllClients() as $clientData) {
|
|
|
$organizationId = $clientData["array_options"]["options_2iopen_organization_id"] ?? null;
|
|
|
- if (!$organizationId > 0) {
|
|
|
+ if (!($organizationId > 0)) {
|
|
|
$this->logger->warning(
|
|
|
'Dolibarr client has no organization id: ' .
|
|
|
$clientData['name'] . ' (' . $clientData['id'] . ')'
|
|
|
@@ -370,7 +378,7 @@ class DolibarrSyncService
|
|
|
$index = [];
|
|
|
$contacts = $this->dolibarrApiService->getOpentalentContacts($socId);
|
|
|
foreach ($contacts as $contactData) {
|
|
|
- $personId = intval($contactData["array_options"]["options_2iopen_person_id"]);
|
|
|
+ $personId = (int)$contactData["array_options"]["options_2iopen_person_id"];
|
|
|
$index[$personId] = $contactData;
|
|
|
}
|
|
|
return $index;
|
|
|
@@ -413,16 +421,15 @@ class DolibarrSyncService
|
|
|
* @return array|null
|
|
|
*/
|
|
|
protected static function sanitizeDolibarrData(?array $data): ?array {
|
|
|
- if ($data === null)
|
|
|
+ if ($data === null) {
|
|
|
return null;
|
|
|
+ }
|
|
|
|
|
|
foreach ($data as $field => $value) {
|
|
|
if (is_array($value)) {
|
|
|
$data[$field] = self::sanitizeDolibarrData($value);
|
|
|
- } else {
|
|
|
- if ($value === '') {
|
|
|
- $data[$field] = null;
|
|
|
- }
|
|
|
+ } else if ($value === '') {
|
|
|
+ $data[$field] = null;
|
|
|
}
|
|
|
}
|
|
|
return $data;
|
|
|
@@ -447,7 +454,7 @@ class DolibarrSyncService
|
|
|
|
|
|
foreach ($addressPriorities as $addressType) {
|
|
|
foreach ($organizationAddressPostal as $postalAddress) {
|
|
|
- if ($postalAddress->getType() == $addressType) {
|
|
|
+ if ($postalAddress->getType() === $addressType) {
|
|
|
return $postalAddress->getAddressPostal();
|
|
|
}
|
|
|
}
|
|
|
@@ -477,10 +484,10 @@ class DolibarrSyncService
|
|
|
if ($contactPoint->getContactType() === $contactType) {
|
|
|
if ($contactPoint->getTelphone() !== null) {
|
|
|
|
|
|
- return $this->formatPhoneNumber($contactPoint->getTelphone());
|
|
|
+ return self::formatPhoneNumber($contactPoint->getTelphone());
|
|
|
}
|
|
|
if ($contactPoint->getMobilPhone() !== null) {
|
|
|
- return $this->formatPhoneNumber($contactPoint->getMobilPhone());
|
|
|
+ return self::formatPhoneNumber($contactPoint->getMobilPhone());
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -506,7 +513,7 @@ class DolibarrSyncService
|
|
|
|
|
|
foreach ($contactPriorities as $contactType) {
|
|
|
foreach ($contactPoints as $contactPoint) {
|
|
|
- if ($contactPoint->getContactType() == $contactType && $contactPoint->getEmail() !== null) {
|
|
|
+ if ($contactPoint->getContactType() === $contactType && $contactPoint->getEmail() !== null) {
|
|
|
return $contactPoint->getEmail();
|
|
|
}
|
|
|
}
|
|
|
@@ -524,7 +531,7 @@ class DolibarrSyncService
|
|
|
protected static function countWithMission(array $missions, array $members): int {
|
|
|
return count(array_filter(
|
|
|
$members,
|
|
|
- function ($actualMissions) use ($missions) { return !empty(array_intersect($actualMissions, $missions)); }
|
|
|
+ static function ($actualMissions) use ($missions) { return !empty(array_intersect($actualMissions, $missions)); }
|
|
|
));
|
|
|
}
|
|
|
|
|
|
@@ -580,8 +587,8 @@ class DolibarrSyncService
|
|
|
},
|
|
|
array_filter(
|
|
|
$missions,
|
|
|
- function ($m) use ($to_exclude) {
|
|
|
- return !in_array($m, $to_exclude);
|
|
|
+ static function ($m) use ($to_exclude) {
|
|
|
+ return !in_array($m, $to_exclude, true);
|
|
|
}
|
|
|
)
|
|
|
)
|