<?php
declare(strict_types=1);
namespace CrmBundleMigrations;
use App\Services\ObjectSerialize;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
use Symfony\Component\Uid\UuidV6;
final class Version20221207101107 extends AbstractMigration
{
private ObjectSerialize $objectSerialize;
public function setObjectSerialize(ObjectSerialize $objectSerialize)
{
$this->objectSerialize = $objectSerialize;
}
public function up(Schema $schema): void
{
$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');
$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');
$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');
$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');
$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');
$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');
$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');
$this->addSql('ALTER TABLE crm_bundle__opportunity ADD CONSTRAINT FK_CEF0F8C76B00C1CF FOREIGN KEY (context_id) REFERENCES context (id)');
$this->addSql('ALTER TABLE crm_bundle__opportunity ADD CONSTRAINT FK_CEF0F8C79395C3F3 FOREIGN KEY (customer_id) REFERENCES customers_bundle__customer (id)');
$this->addSql('ALTER TABLE crm_bundle__opportunity ADD CONSTRAINT FK_CEF0F8C77854071C FOREIGN KEY (commercial_id) REFERENCES user (id)');
$this->addSql('ALTER TABLE crm_bundle__opportunity ADD CONSTRAINT FK_CEF0F8C75D83CC1 FOREIGN KEY (state_id) REFERENCES crm_bundle__opportunity_state (id)');
$this->addSql('ALTER TABLE crm_bundle__opportunity ADD CONSTRAINT FK_CEF0F8C7982F853F FOREIGN KEY (recommendation_type_id) REFERENCES crm_bundle__recommendation_type (id)');
$this->addSql('ALTER TABLE crm_bundle__opportunity ADD CONSTRAINT FK_CEF0F8C7C0F34BEC FOREIGN KEY (recommendation_customer_id) REFERENCES customers_bundle__customer (id)');
$this->addSql('ALTER TABLE crm_bundle__opportunity ADD CONSTRAINT FK_CEF0F8C7B03A8386 FOREIGN KEY (created_by_id) REFERENCES user (id)');
$this->addSql('ALTER TABLE crm_bundle__opportunity ADD CONSTRAINT FK_CEF0F8C7896DBBDE FOREIGN KEY (updated_by_id) REFERENCES user (id)');
$this->addSql('ALTER TABLE crm_bundle__opportunity ADD CONSTRAINT FK_CEF0F8C7C76F1F52 FOREIGN KEY (deleted_by_id) REFERENCES user (id)');
$this->addSql('ALTER TABLE crm_bundle__opportunity_activity ADD CONSTRAINT FK_3D0068599A34590F FOREIGN KEY (opportunity_id) REFERENCES crm_bundle__opportunity (id)');
$this->addSql('ALTER TABLE crm_bundle__opportunity_activity ADD CONSTRAINT FK_3D006859C825429A FOREIGN KEY (opportunity_document_id) REFERENCES crm_bundle__opportunity_document (id)');
$this->addSql('ALTER TABLE crm_bundle__opportunity_activity ADD CONSTRAINT FK_3D0068592AFDDCD2 FOREIGN KEY (opportunity_state_id) REFERENCES crm_bundle__opportunity_state (id)');
$this->addSql('ALTER TABLE crm_bundle__opportunity_activity ADD CONSTRAINT FK_3D006859B03A8386 FOREIGN KEY (created_by_id) REFERENCES user (id)');
$this->addSql('ALTER TABLE crm_bundle__opportunity_activity ADD CONSTRAINT FK_3D006859896DBBDE FOREIGN KEY (updated_by_id) REFERENCES user (id)');
$this->addSql('ALTER TABLE crm_bundle__opportunity_activity ADD CONSTRAINT FK_3D006859C76F1F52 FOREIGN KEY (deleted_by_id) REFERENCES user (id)');
$this->addSql('ALTER TABLE crm_bundle__opportunity_document ADD CONSTRAINT FK_491DEB759A34590F FOREIGN KEY (opportunity_id) REFERENCES crm_bundle__opportunity (id)');
$this->addSql('ALTER TABLE crm_bundle__opportunity_document ADD CONSTRAINT FK_491DEB75B4EA4E60 FOREIGN KEY (quotation_id) REFERENCES sales_bundle__quotation (id)');
$this->addSql('ALTER TABLE crm_bundle__opportunity_document ADD CONSTRAINT FK_491DEB758D9F6D38 FOREIGN KEY (order_id) REFERENCES sales_bundle__order (id)');
$this->addSql('ALTER TABLE crm_bundle__opportunity_document ADD CONSTRAINT FK_491DEB752989F1FD FOREIGN KEY (invoice_id) REFERENCES sales_bundle__invoice (id)');
$this->addSql('ALTER TABLE crm_bundle__opportunity_document ADD CONSTRAINT FK_491DEB751C696F7A FOREIGN KEY (credit_note_id) REFERENCES sales_bundle__credit_note (id)');
$this->addSql('ALTER TABLE crm_bundle__opportunity_document ADD CONSTRAINT FK_491DEB75B03A8386 FOREIGN KEY (created_by_id) REFERENCES user (id)');
$this->addSql('ALTER TABLE crm_bundle__opportunity_document ADD CONSTRAINT FK_491DEB75896DBBDE FOREIGN KEY (updated_by_id) REFERENCES user (id)');
$this->addSql('ALTER TABLE crm_bundle__opportunity_document ADD CONSTRAINT FK_491DEB75C76F1F52 FOREIGN KEY (deleted_by_id) REFERENCES user (id)');
$this->addSql('ALTER TABLE crm_bundle__opportunity_state ADD CONSTRAINT FK_4055A61AB03A8386 FOREIGN KEY (created_by_id) REFERENCES user (id)');
$this->addSql('ALTER TABLE crm_bundle__opportunity_state ADD CONSTRAINT FK_4055A61A896DBBDE FOREIGN KEY (updated_by_id) REFERENCES user (id)');
$this->addSql('ALTER TABLE crm_bundle__opportunity_state ADD CONSTRAINT FK_4055A61AC76F1F52 FOREIGN KEY (deleted_by_id) REFERENCES user (id)');
$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');
$this->addSql('ALTER TABLE crm_bundle__recommendation_type ADD CONSTRAINT FK_ABB41E28B03A8386 FOREIGN KEY (created_by_id) REFERENCES user (id)');
$this->addSql('ALTER TABLE crm_bundle__recommendation_type ADD CONSTRAINT FK_ABB41E28896DBBDE FOREIGN KEY (updated_by_id) REFERENCES user (id)');
$this->addSql('ALTER TABLE crm_bundle__recommendation_type ADD CONSTRAINT FK_ABB41E28C76F1F52 FOREIGN KEY (deleted_by_id) REFERENCES user (id)');
$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');
}
public function down(Schema $schema): void
{
$this->addSql('ALTER TABLE crm_bundle__opportunity DROP FOREIGN KEY FK_CEF0F8C76B00C1CF');
$this->addSql('ALTER TABLE crm_bundle__opportunity DROP FOREIGN KEY FK_CEF0F8C79395C3F3');
$this->addSql('ALTER TABLE crm_bundle__opportunity DROP FOREIGN KEY FK_CEF0F8C77854071C');
$this->addSql('ALTER TABLE crm_bundle__opportunity DROP FOREIGN KEY FK_CEF0F8C75D83CC1');
$this->addSql('ALTER TABLE crm_bundle__opportunity DROP FOREIGN KEY FK_CEF0F8C7982F853F');
$this->addSql('ALTER TABLE crm_bundle__opportunity DROP FOREIGN KEY FK_CEF0F8C7C0F34BEC');
$this->addSql('ALTER TABLE crm_bundle__opportunity DROP FOREIGN KEY FK_CEF0F8C7B03A8386');
$this->addSql('ALTER TABLE crm_bundle__opportunity DROP FOREIGN KEY FK_CEF0F8C7896DBBDE');
$this->addSql('ALTER TABLE crm_bundle__opportunity DROP FOREIGN KEY FK_CEF0F8C7C76F1F52');
$this->addSql('ALTER TABLE crm_bundle__opportunity_activity DROP FOREIGN KEY FK_3D0068599A34590F');
$this->addSql('ALTER TABLE crm_bundle__opportunity_activity DROP FOREIGN KEY FK_3D006859C825429A');
$this->addSql('ALTER TABLE crm_bundle__opportunity_activity DROP FOREIGN KEY FK_3D0068592AFDDCD2');
$this->addSql('ALTER TABLE crm_bundle__opportunity_activity DROP FOREIGN KEY FK_3D006859B03A8386');
$this->addSql('ALTER TABLE crm_bundle__opportunity_activity DROP FOREIGN KEY FK_3D006859896DBBDE');
$this->addSql('ALTER TABLE crm_bundle__opportunity_activity DROP FOREIGN KEY FK_3D006859C76F1F52');
$this->addSql('ALTER TABLE crm_bundle__opportunity_document DROP FOREIGN KEY FK_491DEB759A34590F');
$this->addSql('ALTER TABLE crm_bundle__opportunity_document DROP FOREIGN KEY FK_491DEB75B4EA4E60');
$this->addSql('ALTER TABLE crm_bundle__opportunity_document DROP FOREIGN KEY FK_491DEB758D9F6D38');
$this->addSql('ALTER TABLE crm_bundle__opportunity_document DROP FOREIGN KEY FK_491DEB752989F1FD');
$this->addSql('ALTER TABLE crm_bundle__opportunity_document DROP FOREIGN KEY FK_491DEB751C696F7A');
$this->addSql('ALTER TABLE crm_bundle__opportunity_document DROP FOREIGN KEY FK_491DEB75B03A8386');
$this->addSql('ALTER TABLE crm_bundle__opportunity_document DROP FOREIGN KEY FK_491DEB75896DBBDE');
$this->addSql('ALTER TABLE crm_bundle__opportunity_document DROP FOREIGN KEY FK_491DEB75C76F1F52');
$this->addSql('ALTER TABLE crm_bundle__opportunity_state DROP FOREIGN KEY FK_4055A61AB03A8386');
$this->addSql('ALTER TABLE crm_bundle__opportunity_state DROP FOREIGN KEY FK_4055A61A896DBBDE');
$this->addSql('ALTER TABLE crm_bundle__opportunity_state DROP FOREIGN KEY FK_4055A61AC76F1F52');
$this->addSql('ALTER TABLE crm_bundle__opportunity_state_translations DROP FOREIGN KEY FK_122C1FEC232D562B');
$this->addSql('ALTER TABLE crm_bundle__recommendation_type DROP FOREIGN KEY FK_ABB41E28B03A8386');
$this->addSql('ALTER TABLE crm_bundle__recommendation_type DROP FOREIGN KEY FK_ABB41E28896DBBDE');
$this->addSql('ALTER TABLE crm_bundle__recommendation_type DROP FOREIGN KEY FK_ABB41E28C76F1F52');
$this->addSql('ALTER TABLE crm_bundle__recommendation_type_translations DROP FOREIGN KEY FK_2E52E273232D562B');
$this->addSql('DROP TABLE crm_bundle__opportunity');
$this->addSql('DROP TABLE crm_bundle__opportunity_activity');
$this->addSql('DROP TABLE crm_bundle__opportunity_document');
$this->addSql('DROP TABLE crm_bundle__opportunity_state');
$this->addSql('DROP TABLE crm_bundle__opportunity_state_translations');
$this->addSql('DROP TABLE crm_bundle__recommendation_type');
$this->addSql('DROP TABLE crm_bundle__recommendation_type_translations');
}
public function postUp(Schema $schema): void
{
parent::postUp($schema);
$now = (new \DateTime())->format('Y-m-d H:i:s');
$configurations = [
'crm_bundle__notify_creation_opportunity' => true
];
foreach ($configurations as $configuration => $value) {
$this->connection->insert('configuration', [
'id' => (new UuidV6())->toBinary(),
'name' => $configuration,
'context_id' => null,
'value' => $this->objectSerialize->add((object) ['value' => $value]),
'created_at' => $now,
'updated_at' => $now
]);
}
$languages = $this->connection->executeQuery('SELECT * FROM language WHERE deleted_at IS NULL')
->fetchAllAssociative();
$rootLocale = 'en';
$defaultLocale = $this->connection
->executeQuery('SELECT locale FROM language WHERE deleted_at IS NULL AND is_default = 1')
->fetchOne() ?: 'en';
$opportunityStates = [
[
'names' => ['fr' => 'Ouverte', 'en' => 'Opened'],
'color' => '#2F99DA',
'text_color' => '#FFFFFF',
'is_default' => true
],
[
'names' => ['fr' => 'Gagnée', 'en' => 'Won'],
'color' => '#21C033',
'text_color' => '#FFFFFF',
'is_default' => false
],
[
'names' => ['fr' => 'Perdue', 'en' => 'Lost'],
'color' => '#DC143D',
'text_color' => '#FFFFFF',
'is_default' => false
]
];
foreach ($opportunityStates as $opportunityState) {
$opportunityStateId = (new UuidV6())->toBinary();
$this->connection->insert('crm_bundle__opportunity_state', [
'id' => $opportunityStateId,
'name' => !empty($opportunityState['names'][$defaultLocale]) ?
$opportunityState['names'][$defaultLocale] : $opportunityState['names'][$rootLocale],
'color' => $opportunityState['color'],
'text_color' => $opportunityState['text_color'],
'is_default' => (int) $opportunityState['is_default'],
'is_active' => 1,
'created_at' => $now,
'updated_at' => $now
]);
foreach ($languages as $language) {
$localeTo = $rootLocale;
if (!empty($opportunityState['names'][$language['locale']])) {
$localeTo = $language['locale'];
} elseif (!empty($opportunityState['names'][$defaultLocale])) {
$localeTo = $defaultLocale;
}
$this->connection->insert('crm_bundle__opportunity_state_translations', [
'object_id' => $opportunityStateId,
'locale' => $language['locale'],
'field' => 'name',
'content' => $opportunityState['names'][$localeTo]
]);
}
}
$recommendationTypes = [
[
'names' => ['fr' => 'Publicité', 'en' => 'Advertising'],
'hasCustomer' => false
],
[
'names' => ['fr' => 'Réseaux sociaux', 'en' => 'Social networks'],
'hasCustomer' => false
],
[
'names' => ['fr' => 'Client', 'en' => 'Customer'],
'hasCustomer' => true
],
[
'names' => ['fr' => 'Auto recommandation', 'en' => 'Self-recommendation'],
'hasCustomer' => false
]
];
foreach ($recommendationTypes as $recommendationType) {
$recommendationTypeId = (new UuidV6())->toBinary();
$this->connection->insert('crm_bundle__recommendation_type', [
'id' => $recommendationTypeId,
'name' => !empty($recommendationType['names'][$defaultLocale]) ?
$recommendationType['names'][$defaultLocale] : $recommendationType['names'][$rootLocale],
'has_customer' => (int) $recommendationType['hasCustomer'],
'is_active' => 1,
'created_at' => $now,
'updated_at' => $now
]);
foreach ($languages as $language) {
$localeTo = $rootLocale;
if (!empty($recommendationType['names'][$language['locale']])) {
$localeTo = $language['locale'];
} elseif (!empty($recommendationType['names'][$defaultLocale])) {
$localeTo = $defaultLocale;
}
$this->connection->insert('crm_bundle__recommendation_type_translations', [
'object_id' => $recommendationTypeId,
'locale' => $language['locale'],
'field' => 'name',
'content' => $recommendationType['names'][$localeTo]
]);
}
}
}
}