vendor/bluue/crm-bundle/migrations/Version20221207101107.php line 1

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace CrmBundleMigrations;
  4. use App\Services\ObjectSerialize;
  5. use Doctrine\DBAL\Schema\Schema;
  6. use Doctrine\Migrations\AbstractMigration;
  7. use Symfony\Component\Uid\UuidV6;
  8. final class Version20221207101107 extends AbstractMigration
  9. {
  10.     private ObjectSerialize $objectSerialize;
  11.     public function setObjectSerialize(ObjectSerialize $objectSerialize)
  12.     {
  13.         $this->objectSerialize $objectSerialize;
  14.     }
  15.     public function up(Schema $schema): void
  16.     {
  17.         $this->addSql('CREATE TABLE crm_bundle__opportunity (id BINARY(16) NOT NULL COMMENT \'(DC2Type:uuid)\', context_id BINARY(16) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', customer_id BINARY(16) NOT NULL COMMENT \'(DC2Type:uuid)\', commercial_id BINARY(16) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', state_id BINARY(16) NOT NULL COMMENT \'(DC2Type:uuid)\', recommendation_type_id BINARY(16) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', recommendation_customer_id BINARY(16) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', created_by_id BINARY(16) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', updated_by_id BINARY(16) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', deleted_by_id BINARY(16) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', name VARCHAR(255) DEFAULT NULL, description LONGTEXT DEFAULT NULL, document_link LONGTEXT DEFAULT NULL, deadline DATE DEFAULT NULL, presentation_date DATE DEFAULT NULL, installation_date DATE DEFAULT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, deleted_at DATETIME DEFAULT NULL, INDEX IDX_CEF0F8C76B00C1CF (context_id), INDEX IDX_CEF0F8C79395C3F3 (customer_id), INDEX IDX_CEF0F8C77854071C (commercial_id), INDEX IDX_CEF0F8C75D83CC1 (state_id), INDEX IDX_CEF0F8C7982F853F (recommendation_type_id), INDEX IDX_CEF0F8C7C0F34BEC (recommendation_customer_id), INDEX IDX_CEF0F8C7B03A8386 (created_by_id), INDEX IDX_CEF0F8C7896DBBDE (updated_by_id), INDEX IDX_CEF0F8C7C76F1F52 (deleted_by_id), INDEX name (name), INDEX created_at (created_at), INDEX deleted_at (deleted_at), INDEX updated_at (updated_at), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
  18.         $this->addSql('CREATE TABLE crm_bundle__opportunity_activity (id BINARY(16) NOT NULL COMMENT \'(DC2Type:uuid)\', opportunity_id BINARY(16) NOT NULL COMMENT \'(DC2Type:uuid)\', opportunity_document_id BINARY(16) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', opportunity_state_id BINARY(16) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', created_by_id BINARY(16) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', updated_by_id BINARY(16) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', deleted_by_id BINARY(16) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', comment LONGTEXT DEFAULT NULL, meeting_date DATETIME DEFAULT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, deleted_at DATETIME DEFAULT NULL, INDEX IDX_3D0068599A34590F (opportunity_id), INDEX IDX_3D006859C825429A (opportunity_document_id), INDEX IDX_3D0068592AFDDCD2 (opportunity_state_id), INDEX IDX_3D006859B03A8386 (created_by_id), INDEX IDX_3D006859896DBBDE (updated_by_id), INDEX IDX_3D006859C76F1F52 (deleted_by_id), INDEX deleted_at (deleted_at), INDEX created_at (created_at), INDEX updated_at (updated_at), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
  19.         $this->addSql('CREATE TABLE crm_bundle__opportunity_document (id BINARY(16) NOT NULL COMMENT \'(DC2Type:uuid)\', opportunity_id BINARY(16) NOT NULL COMMENT \'(DC2Type:uuid)\', quotation_id BINARY(16) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', order_id BINARY(16) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', invoice_id BINARY(16) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', credit_note_id BINARY(16) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', created_by_id BINARY(16) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', updated_by_id BINARY(16) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', deleted_by_id BINARY(16) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, deleted_at DATETIME DEFAULT NULL, INDEX IDX_491DEB759A34590F (opportunity_id), INDEX IDX_491DEB75B4EA4E60 (quotation_id), INDEX IDX_491DEB758D9F6D38 (order_id), INDEX IDX_491DEB752989F1FD (invoice_id), INDEX IDX_491DEB751C696F7A (credit_note_id), INDEX IDX_491DEB75B03A8386 (created_by_id), INDEX IDX_491DEB75896DBBDE (updated_by_id), INDEX IDX_491DEB75C76F1F52 (deleted_by_id), INDEX deleted_at (deleted_at), INDEX created_at (created_at), INDEX updated_at (updated_at), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
  20.         $this->addSql('CREATE TABLE crm_bundle__opportunity_state (id BINARY(16) NOT NULL COMMENT \'(DC2Type:uuid)\', created_by_id BINARY(16) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', updated_by_id BINARY(16) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', deleted_by_id BINARY(16) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', name VARCHAR(128) NOT NULL, color VARCHAR(7) NOT NULL, text_color VARCHAR(7) NOT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, deleted_at DATETIME DEFAULT NULL, is_active TINYINT(1) DEFAULT 1 NOT NULL, is_default TINYINT(1) NOT NULL, INDEX IDX_4055A61AB03A8386 (created_by_id), INDEX IDX_4055A61A896DBBDE (updated_by_id), INDEX IDX_4055A61AC76F1F52 (deleted_by_id), INDEX name (name), INDEX color (color), INDEX text_color (text_color), INDEX is_active (is_active), INDEX is_default (is_default), INDEX deleted_at (deleted_at), INDEX created_at (created_at), INDEX updated_at (updated_at), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
  21.         $this->addSql('CREATE TABLE crm_bundle__opportunity_state_translations (id INT AUTO_INCREMENT NOT NULL, object_id BINARY(16) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', locale VARCHAR(8) NOT NULL, field VARCHAR(32) NOT NULL, content LONGTEXT DEFAULT NULL, INDEX IDX_122C1FEC232D562B (object_id), FULLTEXT INDEX content (content), UNIQUE INDEX lookup_unique_idx (locale, object_id, field), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
  22.         $this->addSql('CREATE TABLE crm_bundle__recommendation_type (id BINARY(16) NOT NULL COMMENT \'(DC2Type:uuid)\', created_by_id BINARY(16) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', updated_by_id BINARY(16) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', deleted_by_id BINARY(16) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', name VARCHAR(128) NOT NULL, has_customer TINYINT(1) NOT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, deleted_at DATETIME DEFAULT NULL, is_active TINYINT(1) DEFAULT 1 NOT NULL, INDEX IDX_ABB41E28B03A8386 (created_by_id), INDEX IDX_ABB41E28896DBBDE (updated_by_id), INDEX IDX_ABB41E28C76F1F52 (deleted_by_id), INDEX name (name), INDEX has_customer (has_customer), INDEX is_active (is_active), INDEX deleted_at (deleted_at), INDEX created_at (created_at), INDEX updated_at (updated_at), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
  23.         $this->addSql('CREATE TABLE crm_bundle__recommendation_type_translations (id INT AUTO_INCREMENT NOT NULL, object_id BINARY(16) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', locale VARCHAR(8) NOT NULL, field VARCHAR(32) NOT NULL, content LONGTEXT DEFAULT NULL, INDEX IDX_2E52E273232D562B (object_id), FULLTEXT INDEX content (content), UNIQUE INDEX lookup_unique_idx (locale, object_id, field), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
  24.         $this->addSql('ALTER TABLE crm_bundle__opportunity ADD CONSTRAINT FK_CEF0F8C76B00C1CF FOREIGN KEY (context_id) REFERENCES context (id)');
  25.         $this->addSql('ALTER TABLE crm_bundle__opportunity ADD CONSTRAINT FK_CEF0F8C79395C3F3 FOREIGN KEY (customer_id) REFERENCES customers_bundle__customer (id)');
  26.         $this->addSql('ALTER TABLE crm_bundle__opportunity ADD CONSTRAINT FK_CEF0F8C77854071C FOREIGN KEY (commercial_id) REFERENCES user (id)');
  27.         $this->addSql('ALTER TABLE crm_bundle__opportunity ADD CONSTRAINT FK_CEF0F8C75D83CC1 FOREIGN KEY (state_id) REFERENCES crm_bundle__opportunity_state (id)');
  28.         $this->addSql('ALTER TABLE crm_bundle__opportunity ADD CONSTRAINT FK_CEF0F8C7982F853F FOREIGN KEY (recommendation_type_id) REFERENCES crm_bundle__recommendation_type (id)');
  29.         $this->addSql('ALTER TABLE crm_bundle__opportunity ADD CONSTRAINT FK_CEF0F8C7C0F34BEC FOREIGN KEY (recommendation_customer_id) REFERENCES customers_bundle__customer (id)');
  30.         $this->addSql('ALTER TABLE crm_bundle__opportunity ADD CONSTRAINT FK_CEF0F8C7B03A8386 FOREIGN KEY (created_by_id) REFERENCES user (id)');
  31.         $this->addSql('ALTER TABLE crm_bundle__opportunity ADD CONSTRAINT FK_CEF0F8C7896DBBDE FOREIGN KEY (updated_by_id) REFERENCES user (id)');
  32.         $this->addSql('ALTER TABLE crm_bundle__opportunity ADD CONSTRAINT FK_CEF0F8C7C76F1F52 FOREIGN KEY (deleted_by_id) REFERENCES user (id)');
  33.         $this->addSql('ALTER TABLE crm_bundle__opportunity_activity ADD CONSTRAINT FK_3D0068599A34590F FOREIGN KEY (opportunity_id) REFERENCES crm_bundle__opportunity (id)');
  34.         $this->addSql('ALTER TABLE crm_bundle__opportunity_activity ADD CONSTRAINT FK_3D006859C825429A FOREIGN KEY (opportunity_document_id) REFERENCES crm_bundle__opportunity_document (id)');
  35.         $this->addSql('ALTER TABLE crm_bundle__opportunity_activity ADD CONSTRAINT FK_3D0068592AFDDCD2 FOREIGN KEY (opportunity_state_id) REFERENCES crm_bundle__opportunity_state (id)');
  36.         $this->addSql('ALTER TABLE crm_bundle__opportunity_activity ADD CONSTRAINT FK_3D006859B03A8386 FOREIGN KEY (created_by_id) REFERENCES user (id)');
  37.         $this->addSql('ALTER TABLE crm_bundle__opportunity_activity ADD CONSTRAINT FK_3D006859896DBBDE FOREIGN KEY (updated_by_id) REFERENCES user (id)');
  38.         $this->addSql('ALTER TABLE crm_bundle__opportunity_activity ADD CONSTRAINT FK_3D006859C76F1F52 FOREIGN KEY (deleted_by_id) REFERENCES user (id)');
  39.         $this->addSql('ALTER TABLE crm_bundle__opportunity_document ADD CONSTRAINT FK_491DEB759A34590F FOREIGN KEY (opportunity_id) REFERENCES crm_bundle__opportunity (id)');
  40.         $this->addSql('ALTER TABLE crm_bundle__opportunity_document ADD CONSTRAINT FK_491DEB75B4EA4E60 FOREIGN KEY (quotation_id) REFERENCES sales_bundle__quotation (id)');
  41.         $this->addSql('ALTER TABLE crm_bundle__opportunity_document ADD CONSTRAINT FK_491DEB758D9F6D38 FOREIGN KEY (order_id) REFERENCES sales_bundle__order (id)');
  42.         $this->addSql('ALTER TABLE crm_bundle__opportunity_document ADD CONSTRAINT FK_491DEB752989F1FD FOREIGN KEY (invoice_id) REFERENCES sales_bundle__invoice (id)');
  43.         $this->addSql('ALTER TABLE crm_bundle__opportunity_document ADD CONSTRAINT FK_491DEB751C696F7A FOREIGN KEY (credit_note_id) REFERENCES sales_bundle__credit_note (id)');
  44.         $this->addSql('ALTER TABLE crm_bundle__opportunity_document ADD CONSTRAINT FK_491DEB75B03A8386 FOREIGN KEY (created_by_id) REFERENCES user (id)');
  45.         $this->addSql('ALTER TABLE crm_bundle__opportunity_document ADD CONSTRAINT FK_491DEB75896DBBDE FOREIGN KEY (updated_by_id) REFERENCES user (id)');
  46.         $this->addSql('ALTER TABLE crm_bundle__opportunity_document ADD CONSTRAINT FK_491DEB75C76F1F52 FOREIGN KEY (deleted_by_id) REFERENCES user (id)');
  47.         $this->addSql('ALTER TABLE crm_bundle__opportunity_state ADD CONSTRAINT FK_4055A61AB03A8386 FOREIGN KEY (created_by_id) REFERENCES user (id)');
  48.         $this->addSql('ALTER TABLE crm_bundle__opportunity_state ADD CONSTRAINT FK_4055A61A896DBBDE FOREIGN KEY (updated_by_id) REFERENCES user (id)');
  49.         $this->addSql('ALTER TABLE crm_bundle__opportunity_state ADD CONSTRAINT FK_4055A61AC76F1F52 FOREIGN KEY (deleted_by_id) REFERENCES user (id)');
  50.         $this->addSql('ALTER TABLE crm_bundle__opportunity_state_translations ADD CONSTRAINT FK_122C1FEC232D562B FOREIGN KEY (object_id) REFERENCES crm_bundle__opportunity_state (id) ON DELETE CASCADE');
  51.         $this->addSql('ALTER TABLE crm_bundle__recommendation_type ADD CONSTRAINT FK_ABB41E28B03A8386 FOREIGN KEY (created_by_id) REFERENCES user (id)');
  52.         $this->addSql('ALTER TABLE crm_bundle__recommendation_type ADD CONSTRAINT FK_ABB41E28896DBBDE FOREIGN KEY (updated_by_id) REFERENCES user (id)');
  53.         $this->addSql('ALTER TABLE crm_bundle__recommendation_type ADD CONSTRAINT FK_ABB41E28C76F1F52 FOREIGN KEY (deleted_by_id) REFERENCES user (id)');
  54.         $this->addSql('ALTER TABLE crm_bundle__recommendation_type_translations ADD CONSTRAINT FK_2E52E273232D562B FOREIGN KEY (object_id) REFERENCES crm_bundle__recommendation_type (id) ON DELETE CASCADE');
  55.     }
  56.     public function down(Schema $schema): void
  57.     {
  58.         $this->addSql('ALTER TABLE crm_bundle__opportunity DROP FOREIGN KEY FK_CEF0F8C76B00C1CF');
  59.         $this->addSql('ALTER TABLE crm_bundle__opportunity DROP FOREIGN KEY FK_CEF0F8C79395C3F3');
  60.         $this->addSql('ALTER TABLE crm_bundle__opportunity DROP FOREIGN KEY FK_CEF0F8C77854071C');
  61.         $this->addSql('ALTER TABLE crm_bundle__opportunity DROP FOREIGN KEY FK_CEF0F8C75D83CC1');
  62.         $this->addSql('ALTER TABLE crm_bundle__opportunity DROP FOREIGN KEY FK_CEF0F8C7982F853F');
  63.         $this->addSql('ALTER TABLE crm_bundle__opportunity DROP FOREIGN KEY FK_CEF0F8C7C0F34BEC');
  64.         $this->addSql('ALTER TABLE crm_bundle__opportunity DROP FOREIGN KEY FK_CEF0F8C7B03A8386');
  65.         $this->addSql('ALTER TABLE crm_bundle__opportunity DROP FOREIGN KEY FK_CEF0F8C7896DBBDE');
  66.         $this->addSql('ALTER TABLE crm_bundle__opportunity DROP FOREIGN KEY FK_CEF0F8C7C76F1F52');
  67.         $this->addSql('ALTER TABLE crm_bundle__opportunity_activity DROP FOREIGN KEY FK_3D0068599A34590F');
  68.         $this->addSql('ALTER TABLE crm_bundle__opportunity_activity DROP FOREIGN KEY FK_3D006859C825429A');
  69.         $this->addSql('ALTER TABLE crm_bundle__opportunity_activity DROP FOREIGN KEY FK_3D0068592AFDDCD2');
  70.         $this->addSql('ALTER TABLE crm_bundle__opportunity_activity DROP FOREIGN KEY FK_3D006859B03A8386');
  71.         $this->addSql('ALTER TABLE crm_bundle__opportunity_activity DROP FOREIGN KEY FK_3D006859896DBBDE');
  72.         $this->addSql('ALTER TABLE crm_bundle__opportunity_activity DROP FOREIGN KEY FK_3D006859C76F1F52');
  73.         $this->addSql('ALTER TABLE crm_bundle__opportunity_document DROP FOREIGN KEY FK_491DEB759A34590F');
  74.         $this->addSql('ALTER TABLE crm_bundle__opportunity_document DROP FOREIGN KEY FK_491DEB75B4EA4E60');
  75.         $this->addSql('ALTER TABLE crm_bundle__opportunity_document DROP FOREIGN KEY FK_491DEB758D9F6D38');
  76.         $this->addSql('ALTER TABLE crm_bundle__opportunity_document DROP FOREIGN KEY FK_491DEB752989F1FD');
  77.         $this->addSql('ALTER TABLE crm_bundle__opportunity_document DROP FOREIGN KEY FK_491DEB751C696F7A');
  78.         $this->addSql('ALTER TABLE crm_bundle__opportunity_document DROP FOREIGN KEY FK_491DEB75B03A8386');
  79.         $this->addSql('ALTER TABLE crm_bundle__opportunity_document DROP FOREIGN KEY FK_491DEB75896DBBDE');
  80.         $this->addSql('ALTER TABLE crm_bundle__opportunity_document DROP FOREIGN KEY FK_491DEB75C76F1F52');
  81.         $this->addSql('ALTER TABLE crm_bundle__opportunity_state DROP FOREIGN KEY FK_4055A61AB03A8386');
  82.         $this->addSql('ALTER TABLE crm_bundle__opportunity_state DROP FOREIGN KEY FK_4055A61A896DBBDE');
  83.         $this->addSql('ALTER TABLE crm_bundle__opportunity_state DROP FOREIGN KEY FK_4055A61AC76F1F52');
  84.         $this->addSql('ALTER TABLE crm_bundle__opportunity_state_translations DROP FOREIGN KEY FK_122C1FEC232D562B');
  85.         $this->addSql('ALTER TABLE crm_bundle__recommendation_type DROP FOREIGN KEY FK_ABB41E28B03A8386');
  86.         $this->addSql('ALTER TABLE crm_bundle__recommendation_type DROP FOREIGN KEY FK_ABB41E28896DBBDE');
  87.         $this->addSql('ALTER TABLE crm_bundle__recommendation_type DROP FOREIGN KEY FK_ABB41E28C76F1F52');
  88.         $this->addSql('ALTER TABLE crm_bundle__recommendation_type_translations DROP FOREIGN KEY FK_2E52E273232D562B');
  89.         $this->addSql('DROP TABLE crm_bundle__opportunity');
  90.         $this->addSql('DROP TABLE crm_bundle__opportunity_activity');
  91.         $this->addSql('DROP TABLE crm_bundle__opportunity_document');
  92.         $this->addSql('DROP TABLE crm_bundle__opportunity_state');
  93.         $this->addSql('DROP TABLE crm_bundle__opportunity_state_translations');
  94.         $this->addSql('DROP TABLE crm_bundle__recommendation_type');
  95.         $this->addSql('DROP TABLE crm_bundle__recommendation_type_translations');
  96.     }
  97.     public function postUp(Schema $schema): void
  98.     {
  99.         parent::postUp($schema);
  100.         $now = (new \DateTime())->format('Y-m-d H:i:s');
  101.         $configurations = [
  102.             'crm_bundle__notify_creation_opportunity' => true
  103.         ];
  104.         foreach ($configurations as $configuration => $value) {
  105.             $this->connection->insert('configuration', [
  106.                 'id' => (new UuidV6())->toBinary(),
  107.                 'name' => $configuration,
  108.                 'context_id' => null,
  109.                 'value' => $this->objectSerialize->add((object) ['value' => $value]),
  110.                 'created_at' => $now,
  111.                 'updated_at' => $now
  112.             ]);
  113.         }
  114.         $languages $this->connection->executeQuery('SELECT * FROM language WHERE deleted_at IS NULL')
  115.             ->fetchAllAssociative();
  116.         $rootLocale 'en';
  117.         $defaultLocale $this->connection
  118.             ->executeQuery('SELECT locale FROM language WHERE deleted_at IS NULL AND is_default = 1')
  119.             ->fetchOne() ?: 'en';
  120.         $opportunityStates = [
  121.             [
  122.                 'names' => ['fr' => 'Ouverte''en' => 'Opened'],
  123.                 'color' => '#2F99DA',
  124.                 'text_color' => '#FFFFFF',
  125.                 'is_default' => true
  126.             ],
  127.             [
  128.                 'names' => ['fr' => 'Gagnée''en' => 'Won'],
  129.                 'color' => '#21C033',
  130.                 'text_color' => '#FFFFFF',
  131.                 'is_default' => false
  132.             ],
  133.             [
  134.                 'names' => ['fr' => 'Perdue''en' => 'Lost'],
  135.                 'color' => '#DC143D',
  136.                 'text_color' => '#FFFFFF',
  137.                 'is_default' => false
  138.             ]
  139.         ];
  140.         foreach ($opportunityStates as $opportunityState) {
  141.             $opportunityStateId = (new UuidV6())->toBinary();
  142.             $this->connection->insert('crm_bundle__opportunity_state', [
  143.                 'id' => $opportunityStateId,
  144.                 'name' => !empty($opportunityState['names'][$defaultLocale]) ?
  145.                     $opportunityState['names'][$defaultLocale] : $opportunityState['names'][$rootLocale],
  146.                 'color' => $opportunityState['color'],
  147.                 'text_color' => $opportunityState['text_color'],
  148.                 'is_default' => (int) $opportunityState['is_default'],
  149.                 'is_active' => 1,
  150.                 'created_at' => $now,
  151.                 'updated_at' => $now
  152.             ]);
  153.             foreach ($languages as $language) {
  154.                 $localeTo $rootLocale;
  155.                 if (!empty($opportunityState['names'][$language['locale']])) {
  156.                     $localeTo $language['locale'];
  157.                 } elseif (!empty($opportunityState['names'][$defaultLocale])) {
  158.                     $localeTo $defaultLocale;
  159.                 }
  160.                 $this->connection->insert('crm_bundle__opportunity_state_translations', [
  161.                     'object_id' => $opportunityStateId,
  162.                     'locale' => $language['locale'],
  163.                     'field' => 'name',
  164.                     'content' => $opportunityState['names'][$localeTo]
  165.                 ]);
  166.             }
  167.         }
  168.         $recommendationTypes = [
  169.             [
  170.                 'names' => ['fr' => 'Publicité''en' => 'Advertising'],
  171.                 'hasCustomer' => false
  172.             ],
  173.             [
  174.                 'names' => ['fr' => 'Réseaux sociaux''en' => 'Social networks'],
  175.                 'hasCustomer' => false
  176.             ],
  177.             [
  178.                 'names' => ['fr' => 'Client''en' => 'Customer'],
  179.                 'hasCustomer' => true
  180.             ],
  181.             [
  182.                 'names' => ['fr' => 'Auto recommandation''en' => 'Self-recommendation'],
  183.                 'hasCustomer' => false
  184.             ]
  185.         ];
  186.         foreach ($recommendationTypes as $recommendationType) {
  187.             $recommendationTypeId = (new UuidV6())->toBinary();
  188.             $this->connection->insert('crm_bundle__recommendation_type', [
  189.                 'id' => $recommendationTypeId,
  190.                 'name' => !empty($recommendationType['names'][$defaultLocale]) ?
  191.                     $recommendationType['names'][$defaultLocale] : $recommendationType['names'][$rootLocale],
  192.                 'has_customer' => (int) $recommendationType['hasCustomer'],
  193.                 'is_active' => 1,
  194.                 'created_at' => $now,
  195.                 'updated_at' => $now
  196.             ]);
  197.             foreach ($languages as $language) {
  198.                 $localeTo $rootLocale;
  199.                 if (!empty($recommendationType['names'][$language['locale']])) {
  200.                     $localeTo $language['locale'];
  201.                 } elseif (!empty($recommendationType['names'][$defaultLocale])) {
  202.                     $localeTo $defaultLocale;
  203.                 }
  204.                 $this->connection->insert('crm_bundle__recommendation_type_translations', [
  205.                     'object_id' => $recommendationTypeId,
  206.                     'locale' => $language['locale'],
  207.                     'field' => 'name',
  208.                     'content' => $recommendationType['names'][$localeTo]
  209.                 ]);
  210.             }
  211.         }
  212.     }
  213. }