|
|
@@ -12,6 +12,7 @@ use App\Enum\Access\RoleEnum;
|
|
|
use App\Enum\Core\ContactPointTypeEnum;
|
|
|
use App\Enum\Network\NetworkEnum;
|
|
|
use App\Enum\Organization\AddressPostalOrganizationTypeEnum;
|
|
|
+use App\Enum\Organization\LegalEnum;
|
|
|
use App\Enum\Organization\OrganizationIdsEnum;
|
|
|
use App\Enum\Organization\SettingsProductEnum;
|
|
|
use App\Enum\Person\GenderEnum;
|
|
|
@@ -21,6 +22,7 @@ use App\Repository\Organization\OrganizationRepository;
|
|
|
use App\Service\Core\AddressPostalUtils;
|
|
|
use App\Service\Rest\Operation\BaseRestOperation;
|
|
|
use App\Service\Rest\Operation\CreateOperation;
|
|
|
+use App\Service\Rest\Operation\DeleteOperation;
|
|
|
use App\Service\Rest\Operation\UpdateOperation;
|
|
|
use App\Service\Utils\ArrayUtils;
|
|
|
use Exception;
|
|
|
@@ -47,6 +49,22 @@ use Symfony\Contracts\Translation\TranslatorInterface;
|
|
|
*/
|
|
|
class DolibarrSyncService
|
|
|
{
|
|
|
+ private const ASSOCIATION_SCHOOL_TAG_ID = 67;
|
|
|
+ private const ASSOCIATION_PREMIUM_TAG_ID = 69;
|
|
|
+ private const LOCAL_AUTH_SCHOOL_TAG_ID = 68;
|
|
|
+ private const LOCAL_AUTH_PREMIUM_TAG_ID = 70;
|
|
|
+
|
|
|
+ private const SYNCHRONIZED_TAGS = [
|
|
|
+ self::ASSOCIATION_SCHOOL_TAG_ID => 'Association School',
|
|
|
+ self::ASSOCIATION_PREMIUM_TAG_ID => 'Association School Premium',
|
|
|
+ self::LOCAL_AUTH_SCHOOL_TAG_ID => 'CT School',
|
|
|
+ self::LOCAL_AUTH_PREMIUM_TAG_ID => 'CT School Premium'
|
|
|
+ ];
|
|
|
+
|
|
|
+ private const ASSO1901_JURIDIC_FORM_ID = 92;
|
|
|
+ private const ASSO_JURIDIC_FORM_ID = 608;
|
|
|
+ private const LOCAL_AUTH_JURIDIC_FORM_ID = 72;
|
|
|
+
|
|
|
private LoggerInterface $logger;
|
|
|
|
|
|
public function __construct(
|
|
|
@@ -104,6 +122,7 @@ class DolibarrSyncService
|
|
|
$i = 0; $total = count($dolibarrClientsIndex);
|
|
|
foreach ($dolibarrClientsIndex as $organizationId => $dolibarrSociety) {
|
|
|
$dolibarrSociety = $this->sanitizeDolibarrData($dolibarrSociety);
|
|
|
+ $dolibarrSocietyId = (int)$dolibarrSociety['id'];
|
|
|
|
|
|
$organization = $this->organizationRepository->find($organizationId);
|
|
|
if ($organization === null) {
|
|
|
@@ -193,14 +212,14 @@ class DolibarrSyncService
|
|
|
$operations[] = new UpdateOperation(
|
|
|
'Update society : ' . $organization->getName() . ' (' . $organization->getId() . ')',
|
|
|
'thirdparties',
|
|
|
- (int)$dolibarrSociety['id'],
|
|
|
+ $dolibarrSocietyId,
|
|
|
$newSocietyData,
|
|
|
$dolibarrSociety
|
|
|
);
|
|
|
}
|
|
|
|
|
|
// ===== Update Contacts =====
|
|
|
- $dolibarrSocietyContacts = $this->dolibarrApiService->getContacts((int)$dolibarrSociety['id']);
|
|
|
+ $dolibarrSocietyContacts = $this->dolibarrApiService->getContacts($dolibarrSocietyId);
|
|
|
$contactsProcessed = [];
|
|
|
|
|
|
foreach ($organizationMembers as $accessId => $missions) {
|
|
|
@@ -249,7 +268,7 @@ class DolibarrSyncService
|
|
|
|
|
|
if ($dolibarrContact === null) {
|
|
|
// New contact
|
|
|
- $newContactData['socid'] = (int)$dolibarrSociety['id'];
|
|
|
+ $newContactData['socid'] = $dolibarrSocietyId;
|
|
|
|
|
|
$operations[] = new CreateOperation(
|
|
|
'New contact: ' . $person->getName() . ' ' . $person->getGivenName() . ' (' . $person->getId() . ')',
|
|
|
@@ -271,7 +290,7 @@ class DolibarrSyncService
|
|
|
'Update contact: ' . $person->getName() . ' ' . $person->getGivenName() . ' (' . $person->getId() . ')' .
|
|
|
' in ' . $organization->getName() . ' (' . $organization->getId() . ')',
|
|
|
'contacts',
|
|
|
- (int)$dolibarrContact['id'],
|
|
|
+ $dolibarrSocietyId,
|
|
|
$newContactData,
|
|
|
$dolibarrContact
|
|
|
);
|
|
|
@@ -294,13 +313,63 @@ class DolibarrSyncService
|
|
|
'Disable contact: ' . $contactData['lastname'] . ' ' . $contactData['firstname'] . ' (' . $personId . ')' .
|
|
|
' from ' . $organization->getName() . ' (' . $organization->getId() . ')',
|
|
|
'contacts',
|
|
|
- (int)$contactData['id'],
|
|
|
+ $dolibarrSocietyId,
|
|
|
['statut' => '0'],
|
|
|
$contactData
|
|
|
);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ // ===== Update Tags =====
|
|
|
+ $currentTags = $this->dolibarrApiService->getSocietyTagsIds($dolibarrSocietyId);
|
|
|
+ $expectedTags = [];
|
|
|
+
|
|
|
+ // Association and local auth, with school or school premium products
|
|
|
+ if ($organization->getLegalStatus() === LegalEnum::ASSOCIATION_LAW_1901()->getValue()) {
|
|
|
+ if ($product === SettingsProductEnum::SCHOOL()->getValue()) {
|
|
|
+ $expectedTags[] = self::ASSOCIATION_SCHOOL_TAG_ID;
|
|
|
+ }
|
|
|
+ if ($product === SettingsProductEnum::SCHOOL_PREMIUM()->getValue()) {
|
|
|
+ $expectedTags[] = self::ASSOCIATION_PREMIUM_TAG_ID;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if ($organization->getLegalStatus() === LegalEnum::LOCAL_AUTHORITY()->getValue()) {
|
|
|
+ if ($product === SettingsProductEnum::SCHOOL()->getValue()) {
|
|
|
+ $expectedTags[] = self::LOCAL_AUTH_SCHOOL_TAG_ID;
|
|
|
+ }
|
|
|
+ if ($product === SettingsProductEnum::SCHOOL_PREMIUM()->getValue()) {
|
|
|
+ $expectedTags[] = self::LOCAL_AUTH_PREMIUM_TAG_ID;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // Remove unexpected tags
|
|
|
+ foreach ($currentTags as $tagId) {
|
|
|
+ if (!array_key_exists($tagId, self::SYNCHRONIZED_TAGS)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!in_array($tagId, $expectedTags)) {
|
|
|
+ $operations[] = new DeleteOperation(
|
|
|
+ "Delete tag: `" . self::SYNCHRONIZED_TAGS[$tagId] .
|
|
|
+ '` from ' . $organization->getName() . ' (' . $organization->getId() . ')',
|
|
|
+ "/thirdparties/$dolibarrSocietyId/categories",
|
|
|
+ $tagId
|
|
|
+ );
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // Add missing tags
|
|
|
+ foreach ($expectedTags as $tagId) {
|
|
|
+ if (!in_array($tagId, $currentTags)) {
|
|
|
+ $operations[] = new CreateOperation(
|
|
|
+ "Add tag: `" . self::SYNCHRONIZED_TAGS[$tagId] .
|
|
|
+ '` to ' . $organization->getName() . ' (' . $organization->getId() . ')',
|
|
|
+ "/thirdparties/$dolibarrSocietyId/categories/$tagId",
|
|
|
+ []
|
|
|
+ );
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
// Next society
|
|
|
$i++;
|
|
|
if ($progressionCallback !== null) {
|
|
|
@@ -380,6 +449,10 @@ class DolibarrSyncService
|
|
|
}
|
|
|
|
|
|
$this->logger->info('Execution ended');
|
|
|
+
|
|
|
+// $this->logger->info('Post-script updates');
|
|
|
+// $this->postscript();
|
|
|
+
|
|
|
$this->logger->info('Done : ' . $done);
|
|
|
$this->logger->info('Errors : ' . $errors);
|
|
|
if ($unknown > 0) {
|
|
|
@@ -763,4 +836,50 @@ class DolibarrSyncService
|
|
|
);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+// protected function postscript(): void
|
|
|
+// {
|
|
|
+// $this->updateTags();
|
|
|
+// }
|
|
|
+//
|
|
|
+// protected function updateTags(): void
|
|
|
+// {
|
|
|
+// $ASSOCIATION_SCHOOL_TAG_ID = 67;
|
|
|
+// $ASSOCIATION_PREMIUM_TAG_ID = 69;
|
|
|
+// $LOCAL_AUTH_SCHOOL_TAG_ID = 68;
|
|
|
+// $LOCAL_AUTH_PREMIUM_TAG_ID = 70;
|
|
|
+//
|
|
|
+//
|
|
|
+//
|
|
|
+// $sql = "delete from llx_categorie_societe where fk_categorie=$ASSOCIATION_SCHOOL_TAG_ID;";
|
|
|
+// $sql = "delete from llx_categorie_societe where fk_categorie=$LOCAL_AUTH_SCHOOL_TAG_ID;";
|
|
|
+// $sql = "delete from llx_categorie_societe where fk_categorie=$ASSOCIATION_PREMIUM_TAG_ID;";
|
|
|
+// $sql = "delete from llx_categorie_societe where fk_categorie=$LOCAL_AUTH_PREMIUM_TAG_ID;";
|
|
|
+//
|
|
|
+// $sql = "insert into llx_categorie_societe (fk_categorie, fk_soc)
|
|
|
+// select $ASSOCIATION_SCHOOL_TAG_ID, s.rowid
|
|
|
+// from doliprod.llx_societe s
|
|
|
+// left join llx_societe_extrafields e on s.rowid = e.fk_object
|
|
|
+// where s.fk_forme_juridique in (92, 608) and s.client=1 and e.`2iopen_software_opentalent` = 'Opentalent School';";
|
|
|
+//
|
|
|
+// $sql = "insert into llx_categorie_societe (fk_categorie, fk_soc)
|
|
|
+// select $ASSOCIATION_PREMIUM_TAG_ID, s.rowid
|
|
|
+// from doliprod.llx_societe s
|
|
|
+// left join llx_societe_extrafields e on s.rowid = e.fk_object
|
|
|
+// where s.fk_forme_juridique in (92, 608) and s.client=1 and e.`2iopen_software_opentalent` = 'Opentalent School Premium';";
|
|
|
+//
|
|
|
+// $sql = "insert into llx_categorie_societe (fk_categorie, fk_soc)
|
|
|
+// select $LOCAL_AUTH_SCHOOL_TAG_ID, s.rowid
|
|
|
+// from doliprod.llx_societe s
|
|
|
+// left join llx_societe_extrafields e on s.rowid = e.fk_object
|
|
|
+// where s.fk_forme_juridique = 72 and s.client=1 and e.`2iopen_software_opentalent` = 'Opentalent School';";
|
|
|
+//
|
|
|
+// $sql = "insert into llx_categorie_societe (fk_categorie, fk_soc)
|
|
|
+// select $LOCAL_AUTH_PREMIUM_TAG_ID, s.rowid
|
|
|
+// from doliprod.llx_societe s
|
|
|
+// left join llx_societe_extrafields e on s.rowid = e.fk_object
|
|
|
+// where s.fk_forme_juridique = 72 and s.client=1 and e.`2iopen_software_opentalent` = 'Opentalent School Premium';";
|
|
|
+//
|
|
|
+// }
|
|
|
+
|
|
|
}
|