|
@@ -3,16 +3,15 @@ declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace App\Service\Dolibarr\DolibarrSync;
|
|
namespace App\Service\Dolibarr\DolibarrSync;
|
|
|
|
|
|
|
|
-use App\Entity\Core\AddressPostal;
|
|
|
|
|
use App\Entity\Organization\Organization;
|
|
use App\Entity\Organization\Organization;
|
|
|
use App\Entity\Person\Person;
|
|
use App\Entity\Person\Person;
|
|
|
use App\Enum\Access\FunctionEnum;
|
|
use App\Enum\Access\FunctionEnum;
|
|
|
use App\Enum\Access\RoleEnum;
|
|
use App\Enum\Access\RoleEnum;
|
|
|
use App\Enum\Core\ContactPointTypeEnum;
|
|
use App\Enum\Core\ContactPointTypeEnum;
|
|
|
-use App\Enum\Network\NetworkEnum;
|
|
|
|
|
use App\Enum\Organization\AddressPostalOrganizationTypeEnum;
|
|
use App\Enum\Organization\AddressPostalOrganizationTypeEnum;
|
|
|
use App\Enum\Organization\OrganizationIdsEnum;
|
|
use App\Enum\Organization\OrganizationIdsEnum;
|
|
|
use App\Enum\Organization\SettingsProductEnum;
|
|
use App\Enum\Organization\SettingsProductEnum;
|
|
|
|
|
+use App\Enum\Person\GenderEnum;
|
|
|
use App\Repository\Access\AccessRepository;
|
|
use App\Repository\Access\AccessRepository;
|
|
|
use App\Repository\Access\FunctionTypeRepository;
|
|
use App\Repository\Access\FunctionTypeRepository;
|
|
|
use App\Repository\Core\ContactPointRepository;
|
|
use App\Repository\Core\ContactPointRepository;
|
|
@@ -27,6 +26,7 @@ use HttpException;
|
|
|
use libphonenumber\PhoneNumber;
|
|
use libphonenumber\PhoneNumber;
|
|
|
use libphonenumber\PhoneNumberFormat;
|
|
use libphonenumber\PhoneNumberFormat;
|
|
|
use libphonenumber\PhoneNumberUtil;
|
|
use libphonenumber\PhoneNumberUtil;
|
|
|
|
|
+use Psr\Log\LoggerInterface;
|
|
|
use Symfony\Contracts\Translation\TranslatorInterface;
|
|
use Symfony\Contracts\Translation\TranslatorInterface;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -43,7 +43,8 @@ class DolibarrSyncService
|
|
|
private ContactPointRepository $contactPointRepository,
|
|
private ContactPointRepository $contactPointRepository,
|
|
|
private FunctionTypeRepository $functionTypeRepository,
|
|
private FunctionTypeRepository $functionTypeRepository,
|
|
|
private DolibarrApiService $dolibarrApiService,
|
|
private DolibarrApiService $dolibarrApiService,
|
|
|
- private TranslatorInterface $translator
|
|
|
|
|
|
|
+ private TranslatorInterface $translator,
|
|
|
|
|
+ private LoggerInterface $logger
|
|
|
) {}
|
|
) {}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -55,157 +56,120 @@ class DolibarrSyncService
|
|
|
* Returns an array of DolibarrSyncOperations
|
|
* Returns an array of DolibarrSyncOperations
|
|
|
*
|
|
*
|
|
|
* @return array<DolibarrSyncOperation>
|
|
* @return array<DolibarrSyncOperation>
|
|
|
- * @throws HttpException
|
|
|
|
|
|
|
+ * @throws Exception
|
|
|
*/
|
|
*/
|
|
|
public function scan(): array {
|
|
public function scan(): array {
|
|
|
-
|
|
|
|
|
- var_dump($this->translator->trans('HOUR_PRESIDENT', ['gender' => 'F'] )); die;
|
|
|
|
|
|
|
+ $this->logger->info("Dolibarr sync started");
|
|
|
|
|
|
|
|
// Index the dolibarr clients by organization ids
|
|
// Index the dolibarr clients by organization ids
|
|
|
$dolibarrClientsIndex = $this->getDolibarrSocietiesIndex();
|
|
$dolibarrClientsIndex = $this->getDolibarrSocietiesIndex();
|
|
|
|
|
+ $this->logger->info(count($dolibarrClientsIndex) . " clients fetched from dolibarr");
|
|
|
|
|
|
|
|
// Get all active accesses
|
|
// Get all active accesses
|
|
|
$membersIndex = $this->getActiveMembersIndex();
|
|
$membersIndex = $this->getActiveMembersIndex();
|
|
|
|
|
|
|
|
// Get all the missions with an admin default role
|
|
// Get all the missions with an admin default role
|
|
|
$adminMissions = [];
|
|
$adminMissions = [];
|
|
|
- foreach ($this->functionTypeRepository->findBy(['roleByDefault' => RoleEnum::ROLE_ADMIN()]) as $functionType) {
|
|
|
|
|
|
|
+ foreach ($this->functionTypeRepository->findBy(['roleByDefault' => RoleEnum::ROLE_ADMIN()->getValue()]) as $functionType) {
|
|
|
$adminMissions[] = $functionType->getMission();
|
|
$adminMissions[] = $functionType->getMission();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ // Store networks ids id dolibarr
|
|
|
|
|
+ $cmfDolibarrId = (int)($this->dolibarrApiService->getSociety(OrganizationIdsEnum::CMF()->getValue())['id']);
|
|
|
|
|
+ $ffecDolibarrId = (int)($this->dolibarrApiService->getSociety(OrganizationIdsEnum::FFEC()->getValue())['id']);
|
|
|
|
|
+
|
|
|
// Loop over the Opentalent organizations, and fill up the operations list
|
|
// Loop over the Opentalent organizations, and fill up the operations list
|
|
|
$operations = [];
|
|
$operations = [];
|
|
|
- foreach ($this->organizationRepository->findAll() as $organization) {
|
|
|
|
|
- if (!array_key_exists($organization->getId(), $dolibarrClientsIndex)) {
|
|
|
|
|
- // this organization is not a client, probably a federation member
|
|
|
|
|
|
|
+ foreach ($dolibarrClientsIndex as $organizationId => $dolibarrSociety) {
|
|
|
|
|
+ $organization = $this->organizationRepository->find($organizationId);
|
|
|
|
|
+ if ($organization === null) {
|
|
|
|
|
+ $this->logger->error("Organization " . $organizationId . " not found in the Opentalent DB");
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- $dolibarrSociety = $dolibarrClientsIndex[$organization->getId()];
|
|
|
|
|
-
|
|
|
|
|
// Populate the expectedContacts array
|
|
// Populate the expectedContacts array
|
|
|
- if (array_key_exists($organization->getId(), $membersIndex)) {
|
|
|
|
|
- $organizationMembers = $membersIndex[$organization->getId()];
|
|
|
|
|
- } else {
|
|
|
|
|
- $organizationMembers = [];
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ $organizationMembers = $membersIndex[$organization->getId()] ?? [];
|
|
|
|
|
|
|
|
- $putSocietyData = [];
|
|
|
|
|
|
|
|
|
|
- // ** Sync name
|
|
|
|
|
- if ($organization->getName() !== $dolibarrSociety['name']) {
|
|
|
|
|
- $putSocietyData['name'] = $organization->getName();
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ // ===== Update Society =====
|
|
|
|
|
+ $newSocietyData = [];
|
|
|
|
|
|
|
|
- // ** Sync contact data of the client
|
|
|
|
|
- // Postal address
|
|
|
|
|
- /** @var AddressPostal | null */
|
|
|
|
|
- $mainAddress = $this->getOrganizationPostalAddress($organization);
|
|
|
|
|
|
|
+ // Sync name
|
|
|
|
|
+ $newSocietyData['name'] = $organization->getName();
|
|
|
|
|
|
|
|
|
|
+ // Sync contact data of the client
|
|
|
|
|
+ $mainAddress = $this->getOrganizationPostalAddress($organization);
|
|
|
if ($mainAddress !== null) {
|
|
if ($mainAddress !== null) {
|
|
|
- $streetAddress = AddressPostalUtils::getFullStreetAddress($mainAddress, '\n');
|
|
|
|
|
|
|
+ $streetAddress = AddressPostalUtils::getFullStreetAddress($mainAddress);
|
|
|
if (trim($mainAddress->getAddressOwner() ?? '') !== '') {
|
|
if (trim($mainAddress->getAddressOwner() ?? '') !== '') {
|
|
|
$streetAddress = $mainAddress->getAddressOwner() . '\n' . $streetAddress;
|
|
$streetAddress = $mainAddress->getAddressOwner() . '\n' . $streetAddress;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- if (
|
|
|
|
|
- preg_replace('/\s/', ' ', $streetAddress) !==
|
|
|
|
|
- preg_replace('/\s/', ' ', $dolibarrSociety['address'])
|
|
|
|
|
- ) {
|
|
|
|
|
- $putSocietyData['address'] = $streetAddress;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if ($mainAddress->getPostalCode() !== $dolibarrSociety['zip']) {
|
|
|
|
|
- $putSocietyData['zip'] = $mainAddress->getPostalCode();
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if ($mainAddress->getAddressCity() !== $dolibarrSociety['town']) {
|
|
|
|
|
- $putSocietyData['town'] = $mainAddress->getAddressCity();
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ $newSocietyData['address'] = $streetAddress;
|
|
|
|
|
+ $newSocietyData['zip'] = $mainAddress->getPostalCode();
|
|
|
|
|
+ $newSocietyData['town'] = $mainAddress->getAddressCity();
|
|
|
|
|
+ } else {
|
|
|
|
|
+ $newSocietyData['address'] = null;
|
|
|
|
|
+ $newSocietyData['zip'] = null;
|
|
|
|
|
+ $newSocietyData['town'] = null;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Sync contact
|
|
// Sync contact
|
|
|
- $email = $this->getOrganizationEmail($organization);
|
|
|
|
|
- if ($email !== $dolibarrSociety['email']) {
|
|
|
|
|
- $putSocietyData['email'] = $email;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- $phone = $this->getOrganizationPhone($organization);
|
|
|
|
|
- if ($phone !== $dolibarrSociety['phone']) {
|
|
|
|
|
- $putSocietyData['phone'] = $phone;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // ** Sync Network
|
|
|
|
|
- $network = $organization->getNetworkOrganizations()->first()->getNetwork();
|
|
|
|
|
- $parentOrganizationId = null;
|
|
|
|
|
|
|
+ $newSocietyData['email'] = $this->getOrganizationEmail($organization);
|
|
|
|
|
+ $newSocietyData['phone'] = $this->getOrganizationPhone($organization);
|
|
|
|
|
|
|
|
- if ($network->getId() === NetworkEnum::CMF()->getValue()) {
|
|
|
|
|
- $parentOrganizationId = OrganizationIdsEnum::CMF()->getValue();
|
|
|
|
|
- } else if ($network->getId() === NetworkEnum::FFEC()->getValue()) {
|
|
|
|
|
- $parentOrganizationId = OrganizationIdsEnum::FFEC()->getValue();
|
|
|
|
|
- } else {
|
|
|
|
|
- $parentOrganizationId = OrganizationIdsEnum::_2IOS()->getValue();
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- $parent = $this->dolibarrApiService->getSociety($parentOrganizationId);
|
|
|
|
|
- if ((int)$parent['id'] !== (int)$dolibarrSociety['parent']) {
|
|
|
|
|
- $putSocietyData['parent'] = (int)$parent['id'];
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ // Sync Network
|
|
|
|
|
+ $newSocietyData['parent'] = match (
|
|
|
|
|
+ $organization->getNetworkOrganizations()?->first()?->getNetwork()?->getId()
|
|
|
|
|
+ ) {
|
|
|
|
|
+ OrganizationIdsEnum::CMF()->getValue() => $cmfDolibarrId,
|
|
|
|
|
+ OrganizationIdsEnum::FFEC()->getValue() => $ffecDolibarrId,
|
|
|
|
|
+ default => null
|
|
|
|
|
+ };
|
|
|
|
|
|
|
|
// More infos
|
|
// More infos
|
|
|
- $infosArray = [];
|
|
|
|
|
-
|
|
|
|
|
|
|
+ $infos = [];
|
|
|
$product = $organization->getSettings()->getProduct();
|
|
$product = $organization->getSettings()->getProduct();
|
|
|
-
|
|
|
|
|
if (SettingsProductEnum::isSchool($product)) {
|
|
if (SettingsProductEnum::isSchool($product)) {
|
|
|
- $studentsCount = count(array_filter(
|
|
|
|
|
- $organizationMembers,
|
|
|
|
|
- function ($missions) { return in_array(FunctionEnum::STUDENT()->getValue(), $missions); }
|
|
|
|
|
- ));
|
|
|
|
|
- $infosArray[] = "Nombre d'élèves : " . $studentsCount;
|
|
|
|
|
|
|
+ $infos[] = $this->translator->trans('STUDENTS_COUNT') . " : " .
|
|
|
|
|
+ $this->countWithMission([FunctionEnum::STUDENT()->getValue()], $organizationMembers);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- if (
|
|
|
|
|
- SettingsProductEnum::isSchool($product) ||
|
|
|
|
|
- SettingsProductEnum::isArtist($product)
|
|
|
|
|
- ) {
|
|
|
|
|
- $membersCount = count(array_filter(
|
|
|
|
|
- $organizationMembers,
|
|
|
|
|
- function ($missions) { return in_array(FunctionEnum::ADHERENT()->getValue(), $missions); }
|
|
|
|
|
- ));
|
|
|
|
|
- $infosArray[] = "Nombre d'adhérents : " . $membersCount;
|
|
|
|
|
|
|
+ if (SettingsProductEnum::isSchool($product) || SettingsProductEnum::isArtist($product)) {
|
|
|
|
|
+ $infos[] = $this->translator->trans('ADHERENTS_COUNT') . " : " .
|
|
|
|
|
+ $this->countWithMission([FunctionEnum::ADHERENT()->getValue()], $organizationMembers);
|
|
|
}
|
|
}
|
|
|
|
|
+ $infos[] = $this->translator->trans('ADMIN_ACCESS_COUNT') . " : " .
|
|
|
|
|
+ $this->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...
|
|
|
|
|
+ $newSocietyData['array_options'] = $dolibarrSociety["array_options"];
|
|
|
|
|
+ $newSocietyData['array_options']['options_2iopeninfoopentalent'] = implode('\n', $infos);
|
|
|
|
|
+
|
|
|
|
|
+ // Only update the fields that are different
|
|
|
|
|
+ $newSocietyData = array_filter(
|
|
|
|
|
+ $newSocietyData,
|
|
|
|
|
+ function($v, $k) use ($dolibarrSociety) { return $v !== $dolibarrSociety[$k]; },
|
|
|
|
|
+ ARRAY_FILTER_USE_BOTH
|
|
|
|
|
+ );
|
|
|
|
|
|
|
|
- $adminsCount = count(array_filter(
|
|
|
|
|
- $organizationMembers,
|
|
|
|
|
- function ($missions) use ($adminMissions) { return !empty(array_intersect($adminMissions, $missions)); }
|
|
|
|
|
- ));
|
|
|
|
|
- $infosArray[] = "Nombre d'accès admin : " . $adminsCount;
|
|
|
|
|
-
|
|
|
|
|
- $infos = implode('\n', $infosArray);
|
|
|
|
|
- if ($infos !== $dolibarrSociety["array_options"]["options_2iopeninfoopentalent"]) {
|
|
|
|
|
- // /!\ On est forcé de passer la sub-array entière pour mettre à jour le champs modifié, sinon
|
|
|
|
|
- // tous les autres champs seront mis à null...
|
|
|
|
|
- $arrayOptions = $dolibarrSociety["array_options"];
|
|
|
|
|
- $arrayOptions['options_2iopeninfoopentalent'] = $infos;
|
|
|
|
|
- $putSocietyData['array_options'] = $arrayOptions;
|
|
|
|
|
|
|
+ // add an update operation if some data has to be updated
|
|
|
|
|
+ if (!empty($newSocietyData)) {
|
|
|
|
|
+ $operations[] = new DolibarrUpdateOperation(
|
|
|
|
|
+ 'Update society : ' . $organization->getName() . ' (' . $organization->getId() . ')',
|
|
|
|
|
+ 'thirdparties',
|
|
|
|
|
+ $dolibarrSociety,
|
|
|
|
|
+ $newSocietyData
|
|
|
|
|
+ );
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- $operations[] = new DolibarrUpdateOperation(
|
|
|
|
|
- 'Update society : ' . $organization->getName() . ' (' . $organization->getId() . ')',
|
|
|
|
|
- 'thirdparties',
|
|
|
|
|
- $dolibarrSociety,
|
|
|
|
|
- $putSocietyData
|
|
|
|
|
- );
|
|
|
|
|
|
|
|
|
|
- // ** Contacts
|
|
|
|
|
- $officeMissions = FunctionEnum::getOfficeMissions();
|
|
|
|
|
|
|
+ // ===== Update Contacts =====
|
|
|
$dolibarrContactsIndex = $this->getDolibarrContactsIndex((int)$dolibarrSociety['id']);
|
|
$dolibarrContactsIndex = $this->getDolibarrContactsIndex((int)$dolibarrSociety['id']);
|
|
|
$contactsProcessed = [];
|
|
$contactsProcessed = [];
|
|
|
|
|
|
|
|
foreach ($organizationMembers as $accessId => $missions) {
|
|
foreach ($organizationMembers as $accessId => $missions) {
|
|
|
foreach ($missions as $mission) {
|
|
foreach ($missions as $mission) {
|
|
|
- if (in_array($mission, $officeMissions)) {
|
|
|
|
|
|
|
+ if (in_array($mission, FunctionEnum::getOfficeMissions())) {
|
|
|
$access = $this->accessRepository->find($accessId);
|
|
$access = $this->accessRepository->find($accessId);
|
|
|
$person = $access->getPerson();
|
|
$person = $access->getPerson();
|
|
|
|
|
|
|
@@ -231,49 +195,38 @@ class DolibarrSyncService
|
|
|
|
|
|
|
|
$contact = $this->getPersonContact($person);
|
|
$contact = $this->getPersonContact($person);
|
|
|
|
|
|
|
|
- $newData = [
|
|
|
|
|
- 'civility_code' => ['MISS' => 'MME', 'MISTER' => 'MR'][$person->getGender()] ?? null,
|
|
|
|
|
|
|
+ $newContactData = [
|
|
|
|
|
+ 'civility_code' => $person->getGender() ? $this->translator->trans($person->getGender()) : null,
|
|
|
'lastname' => $person->getName(),
|
|
'lastname' => $person->getName(),
|
|
|
'firstname' => $person->getGivenName(),
|
|
'firstname' => $person->getGivenName(),
|
|
|
'email' => $contact?->getEmail(),
|
|
'email' => $contact?->getEmail(),
|
|
|
'phone_pro' => $contact?->getTelphone() ? $this->formatPhoneNumber($contact?->getTelphone()) : null,
|
|
'phone_pro' => $contact?->getTelphone() ? $this->formatPhoneNumber($contact?->getTelphone()) : null,
|
|
|
'phone_mobile' => $contact?->getMobilPhone() ? $this->formatPhoneNumber($contact?->getMobilPhone()): null,
|
|
'phone_mobile' => $contact?->getMobilPhone() ? $this->formatPhoneNumber($contact?->getMobilPhone()): null,
|
|
|
- 'poste' => implode(
|
|
|
|
|
- ', ',
|
|
|
|
|
- array_map(
|
|
|
|
|
- function($m) use ($person) {
|
|
|
|
|
- return $this->translator->trans($m, ['gender' => ['MISS' => 'F', 'MISTER' => 'M'][$person->getGender()] ?? '?'] );
|
|
|
|
|
- },
|
|
|
|
|
- array_filter(
|
|
|
|
|
- $missions,
|
|
|
|
|
- function ($m) { return $m !== FunctionEnum::ADHERENT()->getValue() && $m !== FunctionEnum::STUDENT()->getValue(); }
|
|
|
|
|
- )
|
|
|
|
|
- )
|
|
|
|
|
- )
|
|
|
|
|
|
|
+ 'poste' => $this->formatContactPosition($missions, $person->getGender())
|
|
|
];
|
|
];
|
|
|
|
|
|
|
|
if ($dolibarrContact === null) {
|
|
if ($dolibarrContact === null) {
|
|
|
$operations[] = new DolibarrCreateOperation(
|
|
$operations[] = new DolibarrCreateOperation(
|
|
|
'New contact: ' . $person->getName() . ' ' . $person->getGivenName() . ' (' . $person->getId() . ')',
|
|
'New contact: ' . $person->getName() . ' ' . $person->getGivenName() . ' (' . $person->getId() . ')',
|
|
|
'contacts',
|
|
'contacts',
|
|
|
- $newData
|
|
|
|
|
|
|
+ $newContactData
|
|
|
);
|
|
);
|
|
|
} else {
|
|
} else {
|
|
|
// Only update the fields that are different
|
|
// Only update the fields that are different
|
|
|
- $newData = array_filter(
|
|
|
|
|
- $newData,
|
|
|
|
|
|
|
+ $newContactData = array_filter(
|
|
|
|
|
+ $newContactData,
|
|
|
function($v, $k) use ($dolibarrContact) { return $v !== $dolibarrContact[$k]; },
|
|
function($v, $k) use ($dolibarrContact) { return $v !== $dolibarrContact[$k]; },
|
|
|
ARRAY_FILTER_USE_BOTH
|
|
ARRAY_FILTER_USE_BOTH
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
// add an update operation if some data has to be updated
|
|
// add an update operation if some data has to be updated
|
|
|
- if (!empty($newData)) {
|
|
|
|
|
|
|
+ if (!empty($newContactData)) {
|
|
|
$operations[] = new DolibarrUpdateOperation(
|
|
$operations[] = new DolibarrUpdateOperation(
|
|
|
'Update contact: ' . $person->getName() . ' ' . $person->getGivenName() . ' (' . $person->getId() . ')' .
|
|
'Update contact: ' . $person->getName() . ' ' . $person->getGivenName() . ' (' . $person->getId() . ')' .
|
|
|
' in ' . $organization->getName() . ' (' . $organization->getId() . ')',
|
|
' in ' . $organization->getName() . ' (' . $organization->getId() . ')',
|
|
|
'contacts',
|
|
'contacts',
|
|
|
$dolibarrContact,
|
|
$dolibarrContact,
|
|
|
- $newData,
|
|
|
|
|
|
|
+ $newContactData,
|
|
|
);
|
|
);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -285,7 +238,7 @@ class DolibarrSyncService
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
foreach ($dolibarrContactsIndex as $personId => $contactData) {
|
|
foreach ($dolibarrContactsIndex as $personId => $contactData) {
|
|
|
- if ($contactData['statut'] === 0) {
|
|
|
|
|
|
|
+ if ((int)$contactData['statut'] === 0) {
|
|
|
// contact is already disabled
|
|
// contact is already disabled
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
@@ -302,6 +255,14 @@ class DolibarrSyncService
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ $this->logger->info('Scan done, ' . count($operations) . ' required operations listed');
|
|
|
|
|
+ foreach ($operations as $operation) {
|
|
|
|
|
+ $this->logger->debug($operation->getLabel());
|
|
|
|
|
+ foreach ($operation->getChangeLog() as $message) {
|
|
|
|
|
+ $this->logger->debug($message);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
return $operations;
|
|
return $operations;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -316,14 +277,33 @@ class DolibarrSyncService
|
|
|
*/
|
|
*/
|
|
|
public function execute(array $operations): array
|
|
public function execute(array $operations): array
|
|
|
{
|
|
{
|
|
|
|
|
+ $this->logger->info('Execution started, ' . count($operations) . ' operations pending...');
|
|
|
|
|
+ $done = 0; $errors = 0; $unknown = 0;
|
|
|
|
|
+
|
|
|
foreach ($operations as $operation) {
|
|
foreach ($operations as $operation) {
|
|
|
if ($operation->getStatus() !== DolibarrSyncOperation::STATUS_READY) {
|
|
if ($operation->getStatus() !== DolibarrSyncOperation::STATUS_READY) {
|
|
|
// operation has already been treated
|
|
// operation has already been treated
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
|
$operation->execute();
|
|
$operation->execute();
|
|
|
|
|
+
|
|
|
|
|
+ if ($operation->getStatus() === DolibarrSyncOperation::STATUS_ERROR) {
|
|
|
|
|
+ $this->logger->error('Error while executing : ' . $operation);
|
|
|
|
|
+ $this->logger->error($operation->getErrorMessage());
|
|
|
|
|
+ $errors++;
|
|
|
|
|
+ } elseif ($operation->getStatus() === DolibarrSyncOperation::STATUS_DONE) {
|
|
|
|
|
+ $done++;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ $unknown++;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ $this->logger->info('Execution ended');
|
|
|
|
|
+ $this->logger->info('Done : ' . $done);
|
|
|
|
|
+ $this->logger->info('Errors : ' . $errors);
|
|
|
|
|
+ if ($unknown > 0)
|
|
|
|
|
+ $this->logger->warning('Unknown : ' . $unknown);
|
|
|
|
|
+
|
|
|
return $operations;
|
|
return $operations;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -343,32 +323,25 @@ class DolibarrSyncService
|
|
|
return $operations;
|
|
return $operations;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- /**
|
|
|
|
|
- * Log a new scanning error
|
|
|
|
|
- * @param $errorMsg
|
|
|
|
|
- */
|
|
|
|
|
- private function logScanError($errorMsg) {
|
|
|
|
|
- // TODO : implement
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
/**
|
|
/**
|
|
|
* Get the client societies dolibarr and index them by organization id
|
|
* Get the client societies dolibarr and index them by organization id
|
|
|
*
|
|
*
|
|
|
* @return array An index of the form [$organizationId => $dolibarrData]
|
|
* @return array An index of the form [$organizationId => $dolibarrData]
|
|
|
- * @throws HttpException
|
|
|
|
|
*/
|
|
*/
|
|
|
private function getDolibarrSocietiesIndex(): array
|
|
private function getDolibarrSocietiesIndex(): array
|
|
|
{
|
|
{
|
|
|
$index = [];
|
|
$index = [];
|
|
|
foreach ($this->dolibarrApiService->getAllClients() as $clientData) {
|
|
foreach ($this->dolibarrApiService->getAllClients() as $clientData) {
|
|
|
- if (!$clientData["array_options"]["options_2iopen_organization_id"] > 0) {
|
|
|
|
|
- $this->logScanError(
|
|
|
|
|
- "Missing organization id : " . $clientData["name"] . "(" . $clientData["code_client"] .")"
|
|
|
|
|
|
|
+ $organizationId = $clientData["array_options"]["options_2iopen_organization_id"] ?? null;
|
|
|
|
|
+ if (!$organizationId > 0) {
|
|
|
|
|
+ $this->logger->warning(
|
|
|
|
|
+ 'Dolibarr client has no organization id: ' .
|
|
|
|
|
+ $clientData['name'] . ' (' . $clientData['id'] . ')'
|
|
|
);
|
|
);
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- $index[$clientData["array_options"]["options_2iopen_organization_id"]] = $clientData;
|
|
|
|
|
|
|
+ $index[$organizationId] = $clientData;
|
|
|
}
|
|
}
|
|
|
return $index;
|
|
return $index;
|
|
|
}
|
|
}
|
|
@@ -422,11 +395,11 @@ class DolibarrSyncService
|
|
|
*/
|
|
*/
|
|
|
private function getOrganizationPostalAddress(Organization $organization) {
|
|
private function getOrganizationPostalAddress(Organization $organization) {
|
|
|
$addressPriorities = [
|
|
$addressPriorities = [
|
|
|
- AddressPostalOrganizationTypeEnum::ADDRESS_BILL()->getValue(),
|
|
|
|
|
- AddressPostalOrganizationTypeEnum::ADDRESS_CONTACT()->getValue(),
|
|
|
|
|
- AddressPostalOrganizationTypeEnum::ADDRESS_HEAD_OFFICE()->getValue(),
|
|
|
|
|
- AddressPostalOrganizationTypeEnum::ADDRESS_PRACTICE()->getValue(),
|
|
|
|
|
- AddressPostalOrganizationTypeEnum::ADDRESS_OTHER()->getValue()
|
|
|
|
|
|
|
+ AddressPostalOrganizationTypeEnum::ADDRESS_BILL(),
|
|
|
|
|
+ AddressPostalOrganizationTypeEnum::ADDRESS_CONTACT(),
|
|
|
|
|
+ AddressPostalOrganizationTypeEnum::ADDRESS_HEAD_OFFICE(),
|
|
|
|
|
+ AddressPostalOrganizationTypeEnum::ADDRESS_PRACTICE(),
|
|
|
|
|
+ AddressPostalOrganizationTypeEnum::ADDRESS_OTHER()
|
|
|
];
|
|
];
|
|
|
|
|
|
|
|
foreach ($addressPriorities as $addressType) {
|
|
foreach ($addressPriorities as $addressType) {
|
|
@@ -448,15 +421,15 @@ class DolibarrSyncService
|
|
|
private function getOrganizationPhone(Organization $organization): ?string
|
|
private function getOrganizationPhone(Organization $organization): ?string
|
|
|
{
|
|
{
|
|
|
$contactPriorities = [
|
|
$contactPriorities = [
|
|
|
- ContactPointTypeEnum::BILL()->getValue(),
|
|
|
|
|
- ContactPointTypeEnum::CONTACT()->getValue(),
|
|
|
|
|
- ContactPointTypeEnum::PRINCIPAL()->getValue(),
|
|
|
|
|
- ContactPointTypeEnum::OTHER()->getValue()
|
|
|
|
|
|
|
+ ContactPointTypeEnum::BILL(),
|
|
|
|
|
+ ContactPointTypeEnum::CONTACT(),
|
|
|
|
|
+ ContactPointTypeEnum::PRINCIPAL(),
|
|
|
|
|
+ ContactPointTypeEnum::OTHER()
|
|
|
];
|
|
];
|
|
|
|
|
|
|
|
foreach ($contactPriorities as $contactType) {
|
|
foreach ($contactPriorities as $contactType) {
|
|
|
foreach ($organization->getContactPoints() as $contactPoint) {
|
|
foreach ($organization->getContactPoints() as $contactPoint) {
|
|
|
- if ($contactPoint->getContactType() == $contactType) {
|
|
|
|
|
|
|
+ if ($contactPoint->getContactType() === $contactType) {
|
|
|
if ($contactPoint->getTelphone() !== null) {
|
|
if ($contactPoint->getTelphone() !== null) {
|
|
|
return $this->formatPhoneNumber($contactPoint->getTelphone());
|
|
return $this->formatPhoneNumber($contactPoint->getTelphone());
|
|
|
}
|
|
}
|
|
@@ -477,10 +450,10 @@ class DolibarrSyncService
|
|
|
*/
|
|
*/
|
|
|
private function getOrganizationEmail(Organization $organization) {
|
|
private function getOrganizationEmail(Organization $organization) {
|
|
|
$contactPriorities = [
|
|
$contactPriorities = [
|
|
|
- ContactPointTypeEnum::BILL()->getValue(),
|
|
|
|
|
- ContactPointTypeEnum::CONTACT()->getValue(),
|
|
|
|
|
- ContactPointTypeEnum::PRINCIPAL()->getValue(),
|
|
|
|
|
- ContactPointTypeEnum::OTHER()->getValue()
|
|
|
|
|
|
|
+ ContactPointTypeEnum::BILL(),
|
|
|
|
|
+ ContactPointTypeEnum::CONTACT(),
|
|
|
|
|
+ ContactPointTypeEnum::PRINCIPAL(),
|
|
|
|
|
+ ContactPointTypeEnum::OTHER()
|
|
|
];
|
|
];
|
|
|
|
|
|
|
|
foreach ($contactPriorities as $contactType) {
|
|
foreach ($contactPriorities as $contactType) {
|
|
@@ -493,15 +466,29 @@ class DolibarrSyncService
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Returns the number of accesses posseding at least one of the missions
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param array $missions A list of missions
|
|
|
|
|
+ * @param array $members An organization members as returned by getActiveMembersIndex: [$accessID => [$missions...]]
|
|
|
|
|
+ * @return int
|
|
|
|
|
+ */
|
|
|
|
|
+ private function countWithMission(array $missions, array $members): int {
|
|
|
|
|
+ return count(array_filter(
|
|
|
|
|
+ $members,
|
|
|
|
|
+ function ($actualMissions) use ($missions) { return !empty(array_intersect($actualMissions, $missions)); }
|
|
|
|
|
+ ));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
private function getPersonContact(Person $person) {
|
|
private function getPersonContact(Person $person) {
|
|
|
$contactPriorities = [
|
|
$contactPriorities = [
|
|
|
- ContactPointTypeEnum::PRINCIPAL()->getValue(),
|
|
|
|
|
- ContactPointTypeEnum::OTHER()->getValue()
|
|
|
|
|
|
|
+ ContactPointTypeEnum::PRINCIPAL(),
|
|
|
|
|
+ ContactPointTypeEnum::OTHER()
|
|
|
];
|
|
];
|
|
|
|
|
|
|
|
- foreach ($contactPriorities as $contactType) {
|
|
|
|
|
|
|
+ foreach ($contactPriorities as $contactTypeEnum) {
|
|
|
$result = $this->contactPointRepository->getByTypeAndPerson(
|
|
$result = $this->contactPointRepository->getByTypeAndPerson(
|
|
|
- ContactPointTypeEnum::PRINCIPAL()->getValue(), $person
|
|
|
|
|
|
|
+ $contactTypeEnum->getValue(), $person
|
|
|
);
|
|
);
|
|
|
if (!empty($result)) {
|
|
if (!empty($result)) {
|
|
|
return $result[0];
|
|
return $result[0];
|
|
@@ -510,6 +497,37 @@ class DolibarrSyncService
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Format the contact position from its gender and missions
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param array $missions
|
|
|
|
|
+ * @param string|null $gender
|
|
|
|
|
+ * @return string
|
|
|
|
|
+ */
|
|
|
|
|
+ private function formatContactPosition(array $missions, ?string $gender = 'X'): string {
|
|
|
|
|
+ $to_exclude = [FunctionEnum::ADHERENT(), FunctionEnum::STUDENT()];
|
|
|
|
|
+ return implode(
|
|
|
|
|
+ ', ',
|
|
|
|
|
+ array_map(
|
|
|
|
|
+ function($m) use ($gender) {
|
|
|
|
|
+ return $this->translator->trans(
|
|
|
|
|
+ $m,
|
|
|
|
|
+ ['gender' => [
|
|
|
|
|
+ GenderEnum::MISS()->getValue() => 'F',
|
|
|
|
|
+ GenderEnum::MISTER()->getValue() => 'M'
|
|
|
|
|
+ ][$gender] ?? 'X']
|
|
|
|
|
+ );
|
|
|
|
|
+ },
|
|
|
|
|
+ array_filter(
|
|
|
|
|
+ $missions,
|
|
|
|
|
+ function ($m) use ($to_exclude) {
|
|
|
|
|
+ return !in_array($m, $to_exclude);
|
|
|
|
|
+ }
|
|
|
|
|
+ )
|
|
|
|
|
+ )
|
|
|
|
|
+ );
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* Format a phone number into international format
|
|
* Format a phone number into international format
|
|
|
*
|
|
*
|