/**
  * @param LoggerInterface $logger
  * @param bool            $dryRun
  */
 protected function runActivityLists(LoggerInterface $logger, $dryRun = false)
 {
     // @todo: this workaround should be removed in BAP-9156
     $this->configManager->clear();
     $targetEntities = $this->provider->getTargetEntityClasses(false);
     $toSchema = clone $this->schema;
     $hasSchemaChanges = false;
     foreach ($targetEntities as $targetEntity) {
         $associationName = ExtendHelper::buildAssociationName($targetEntity, ActivityListEntityConfigDumperExtension::ASSOCIATION_KIND);
         $relationTableName = $this->nameGenerator->generateManyToManyJoinTableName(ActivityListEntityConfigDumperExtension::ENTITY_CLASS, $associationName, $targetEntity);
         if (!$toSchema->hasTable($relationTableName)) {
             $hasSchemaChanges = true;
             $this->activityListExtension->addActivityListAssociation($toSchema, $this->metadataHelper->getTableNameByEntityClass($targetEntity));
         }
     }
     if ($hasSchemaChanges) {
         $comparator = new Comparator();
         $platform = $this->connection->getDatabasePlatform();
         $schemaDiff = $comparator->compare($this->schema, $toSchema);
         $queries = $schemaDiff->toSql($platform);
         foreach ($queries as $query) {
             $this->logQuery($logger, $query);
             if (!$dryRun) {
                 $this->connection->executeQuery($query);
             }
         }
     }
 }
 public function testRunActivityLists()
 {
     $connection = $this->getMockBuilder('Doctrine\\DBAL\\Connection')->disableOriginalConstructor()->getMock();
     $connection->expects($this->any())->method('getDatabasePlatform')->will($this->returnValue(new MySqlPlatform()));
     $this->migrationQuery->setConnection($connection);
     $table = $this->schema->createTable('acme_test');
     $table->addColumn('id', 'integer', ['autoincrement' => true]);
     $table->setPrimaryKey(['id']);
     $table = $this->schema->createTable('oro_activity_list');
     $table->addColumn('id', 'integer', ['autoincrement' => true]);
     $table->setPrimaryKey(['id']);
     $extendOptionsManager = new ExtendOptionsManager();
     $entityMetadataHelper = $this->getMockBuilder('Oro\\Bundle\\EntityExtendBundle\\Migration\\EntityMetadataHelper')->disableOriginalConstructor()->getMock();
     $extendExtension = new ExtendExtension($extendOptionsManager, $entityMetadataHelper);
     $extendExtension->setNameGenerator($this->nameGenerator);
     $this->activityListExtension->setExtendExtension($extendExtension);
     $this->provider->expects($this->once())->method('getTargetEntityClasses')->willReturn(['Acme\\TestBundle\\Entity\\Test']);
     $this->metadataHelper->expects($this->once())->method('getTableNameByEntityClass')->with('Acme\\TestBundle\\Entity\\Test')->willReturn('acme_test');
     $entityMetadataHelper->expects($this->any())->method('getEntityClassByTableName')->willReturnCallback(function ($tableName) {
         if ($tableName === 'acme_test') {
             return 'Acme\\TestBundle\\Entity\\Test';
         }
         return 'Oro\\Bundle\\ActivityListBundle\\Entity\\ActivityList';
     });
     $log = $this->migrationQuery->getDescription();
     $this->assertEquals('CREATE TABLE oro_rel_c3990ba6784dd132527c89 (activitylist_id INT NOT NULL, test_id INT NOT NULL, ' . 'INDEX IDX_53682E3596EB1108 (activitylist_id), INDEX IDX_53682E351E5D0459 (test_id), ' . 'PRIMARY KEY(activitylist_id, test_id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ' . 'ENGINE = InnoDB', $log[0]);
     $this->assertEquals('ALTER TABLE oro_rel_c3990ba6784dd132527c89 ADD CONSTRAINT FK_53682E3596EB1108 ' . 'FOREIGN KEY (activitylist_id) REFERENCES oro_activity_list (id) ON DELETE CASCADE', $log[1]);
     $this->assertEquals('ALTER TABLE oro_rel_c3990ba6784dd132527c89 ADD CONSTRAINT FK_53682E351E5D0459 FOREIGN KEY (test_id) ' . 'REFERENCES acme_test (id) ON DELETE CASCADE', $log[2]);
 }
Exemplo n.º 3
0
 /**
  * @param Schema $schema
  * @param ActivityListExtension $activityListExtension
  */
 public static function addInheritanceTargets(Schema $schema, ActivityListExtension $activityListExtension)
 {
     $activityListExtension->addInheritanceTargets($schema, 'orocrm_account', 'orocrm_contact', ['accounts']);
 }
Exemplo n.º 4
0
 /**
  * @return string
  */
 protected function getFillOrderCallActivityListQuery()
 {
     $sql = 'INSERT INTO %s (activitylist_id, order_id)' . ' SELECT al.id, rel.order_id' . ' FROM oro_activity_list al' . ' JOIN %s rel ON rel.call_id = al.related_activity_id' . ' AND al.related_activity_class = :class';
     return sprintf($sql, $this->activityListExtension->getAssociationTableName('orocrm_magento_order'), $this->activityExtension->getAssociationTableName('orocrm_call', 'orocrm_magento_order'));
 }
Exemplo n.º 5
0
 /**
  * Manually create activitylist association tables for further filling.
  *
  * @param Schema                $schema
  * @param ActivityListExtension $activityListExtension
  */
 public static function addActivityListAssociationTables(Schema $schema, ActivityListExtension $activityListExtension)
 {
     $activityListExtension->addActivityListAssociation($schema, 'orocrm_magento_cart');
     $activityListExtension->addActivityListAssociation($schema, 'orocrm_magento_order');
 }
Exemplo n.º 6
0
 /**
  * Manually create activitylist association table for further filling.
  *
  * @param Schema                $schema
  * @param ActivityListExtension $activityListExtension
  */
 public static function addActivityListAssociationTable(Schema $schema, ActivityListExtension $activityListExtension)
 {
     $activityListExtension->addActivityListAssociation($schema, 'orocrm_contactus_request');
 }
Exemplo n.º 7
0
 /**
  * @param Schema $schema
  * @param ActivityListExtension $activityListExtension
  */
 public static function addInheritanceTargets(Schema $schema, ActivityListExtension $activityListExtension)
 {
     $activityListExtension->addInheritanceTargets($schema, 'orocrm_account', 'orocrm_sales_lead', ['contact', 'accounts']);
     $activityListExtension->addInheritanceTargets($schema, 'orocrm_account', 'orocrm_sales_opportunity', ['customer', 'account']);
     $activityListExtension->addInheritanceTargets($schema, 'orocrm_account', 'orocrm_sales_b2bcustomer', ['account']);
 }
Exemplo n.º 8
0
 /**
  * @param Schema $schema
  * @param ActivityListExtension $activityListExtension
  */
 public static function addInheritanceTargets(Schema $schema, ActivityListExtension $activityListExtension)
 {
     $activityListExtension->addInheritanceTargets($schema, 'orocrm_account', 'orocrm_magento_customer', ['account']);
     $activityListExtension->addInheritanceTargets($schema, 'orocrm_account', 'orocrm_magento_order', ['customer', 'account']);
     $activityListExtension->addInheritanceTargets($schema, 'orocrm_account', 'orocrm_magento_cart', ['customer', 'account']);
 }