Ejemplo n.º 1
0
 /**
  * Gets a table name for many-to-many relation
  *
  * @param string $activityTableName Activity entity table name. It is owning side of the association.
  * @param string $targetTableName   Target entity table name.
  *
  * @return string
  */
 public function getAssociationTableName($activityTableName, $targetTableName)
 {
     $sourceClassName = $this->extendExtension->getEntityClassByTableName($activityTableName);
     $targetClassName = $this->extendExtension->getEntityClassByTableName($targetTableName);
     $associationName = ExtendHelper::buildAssociationName($targetClassName, ActivityScope::ASSOCIATION_KIND);
     return $this->nameGenerator->generateManyToManyJoinTableName($sourceClassName, $associationName, $targetClassName);
 }
Ejemplo n.º 2
0
 /**
  * Add inheritance tables to target to show inherited activities
  *
  * @param Schema $schema
  * @param string $targetTableName Target entity table name
  * @param string $inheritanceTableName Inheritance entity table name
  * @param string[] $path Path of relations to target entity
  */
 public function addInheritanceTargets(Schema $schema, $targetTableName, $inheritanceTableName, $path)
 {
     $targetTable = $schema->getTable($targetTableName);
     $options = new OroOptions();
     $inheritance['target'] = $this->extendExtension->getEntityClassByTableName($inheritanceTableName);
     $inheritance['path'] = $path;
     $inheritances[] = $inheritance;
     $options->append('activity', 'inheritance_targets', $inheritances);
     $targetTable->addOption(OroOptions::KEY, $options);
 }
Ejemplo n.º 3
0
 /**
  * Adds the association between the target table and the visit table
  *
  * @param Schema $schema
  * @param string $targetTableName  Target entity table name
  * @param string $targetColumnName A column name is used to show related entity
  */
 public function addIdentifierAssociation(Schema $schema, $targetTableName, $targetColumnName = null)
 {
     $visitTable = $schema->getTable(self::VISIT_TABLE_NAME);
     $targetTable = $schema->getTable($targetTableName);
     if (empty($targetColumnName)) {
         $primaryKeyColumns = $targetTable->getPrimaryKeyColumns();
         $targetColumnName = array_shift($primaryKeyColumns);
     }
     $associationName = ExtendHelper::buildAssociationName($this->extendExtension->getEntityClassByTableName($targetTableName), self::ASSOCIATION_KIND);
     $this->extendExtension->addManyToOneRelation($schema, $visitTable, $associationName, $targetTable, $targetColumnName);
 }
Ejemplo n.º 4
0
 /**
  * Adds the association between the given table and the activity list table
  *
  * @param Schema $schema
  * @param string $targetTableName Target entity table name
  */
 public function addActivityListAssociation(Schema $schema, $targetTableName)
 {
     $targetTable = $schema->getTable($targetTableName);
     // Column names are used to show a title of target entity
     $targetTitleColumnNames = $targetTable->getPrimaryKeyColumns();
     // Column names are used to show detailed info about target entity
     $targetDetailedColumnNames = $targetTable->getPrimaryKeyColumns();
     // Column names are used to show target entity in a grid
     $targetGridColumnNames = $targetTable->getPrimaryKeyColumns();
     $associationName = ExtendHelper::buildAssociationName($this->extendExtension->getEntityClassByTableName($targetTableName), ActivityListEntityConfigDumperExtension::ASSOCIATION_KIND);
     $this->extendExtension->addManyToManyRelation($schema, $schema->getTable('oro_activity_list'), $associationName, $targetTable, $targetTitleColumnNames, $targetDetailedColumnNames, $targetGridColumnNames, ['extend' => ['without_default' => true]]);
 }
Ejemplo n.º 5
0
 /**
  * Adds the association between the target table and the note table
  *
  * @param Schema $schema
  * @param string $targetTableName  Target entity table name
  * @param string $targetColumnName A column name is used to show related entity
  */
 public function addNoteAssociation(Schema $schema, $targetTableName, $targetColumnName = null)
 {
     $noteTable = $schema->getTable(self::NOTE_TABLE_NAME);
     $targetTable = $schema->getTable($targetTableName);
     if (empty($targetColumnName)) {
         $primaryKeyColumns = $targetTable->getPrimaryKeyColumns();
         $targetColumnName = array_shift($primaryKeyColumns);
     }
     $options = new OroOptions();
     $options->set('note', 'enabled', true);
     $targetTable->addOption(OroOptions::KEY, $options);
     $associationName = ExtendHelper::buildAssociationName($this->extendExtension->getEntityClassByTableName($targetTableName));
     $this->extendExtension->addManyToOneRelation($schema, $noteTable, $associationName, $targetTable, $targetColumnName);
 }
Ejemplo n.º 6
0
 /**
  * Adds the association between the target table and the attachment table
  *
  * @param Schema   $schema
  * @param string   $targetTableName  Target entity table name
  * @param string[] $allowedMimeTypes The list of allowed MIME types
  * @param int      $maxFileSize      Max allowed file size in megabytes
  */
 public function addAttachmentAssociation(Schema $schema, $targetTableName, array $allowedMimeTypes = [], $maxFileSize = 1)
 {
     $noteTable = $schema->getTable(self::ATTACHMENT_ASSOCIATION_TABLE_NAME);
     $targetTable = $schema->getTable($targetTableName);
     $primaryKeyColumns = $targetTable->getPrimaryKeyColumns();
     $targetColumnName = array_shift($primaryKeyColumns);
     $options = new OroOptions();
     $options->set('attachment', 'enabled', true);
     $options->set('attachment', 'maxsize', $maxFileSize);
     $options->set('attachment', 'mimetypes', implode("\n", $allowedMimeTypes));
     $targetTable->addOption(OroOptions::KEY, $options);
     $associationName = ExtendHelper::buildAssociationName($this->extendExtension->getEntityClassByTableName($targetTableName));
     $this->extendExtension->addManyToOneRelation($schema, $noteTable, $associationName, $targetTable, $targetColumnName);
 }
Ejemplo n.º 7
0
 /**
  * Adds the association between the given table and the table contains activity records
  *
  * The activity entity must be included in 'activity' group ('groups' attribute of 'grouping' scope)
  *
  * @param Schema $schema
  * @param string $activityTableName Activity entity table name. It is owning side of the association
  * @param string $targetTableName   Target entity table name
  * @param bool   $immutable         Set TRUE to prohibit disabling the activity association from UI
  */
 public function addActivityAssociation(Schema $schema, $activityTableName, $targetTableName, $immutable = false)
 {
     $targetTable = $schema->getTable($targetTableName);
     // Column names are used to show a title of target entity
     $targetTitleColumnNames = $targetTable->getPrimaryKeyColumns();
     // Column names are used to show detailed info about target entity
     $targetDetailedColumnNames = $targetTable->getPrimaryKeyColumns();
     // Column names are used to show target entity in a grid
     $targetGridColumnNames = $targetTable->getPrimaryKeyColumns();
     $activityClassName = $this->extendExtension->getEntityClassByTableName($activityTableName);
     $options = new OroOptions();
     $options->append('activity', 'activities', $activityClassName);
     if ($immutable) {
         $options->append('activity', 'immutable', $activityClassName);
     }
     $targetTable->addOption(OroOptions::KEY, $options);
     $associationName = ExtendHelper::buildAssociationName($this->extendExtension->getEntityClassByTableName($targetTableName), ActivityScope::ASSOCIATION_KIND);
     $this->extendExtension->addManyToManyRelation($schema, $activityTableName, $associationName, $targetTable, $targetTitleColumnNames, $targetDetailedColumnNames, $targetGridColumnNames, ['extend' => ['without_default' => true]]);
 }
Ejemplo n.º 8
0
 /**
  * @param string $fieldName
  *
  * @return ParametrizedSqlMigrationQuery
  */
 protected function getDropEntityConfigManyToOneRelationQuery($fieldName)
 {
     $dropFieldIndexSql = 'DELETE FROM oro_entity_config_index_value' . ' WHERE entity_id IS NULL AND field_id IN (' . ' SELECT oecf.id FROM oro_entity_config_field AS oecf' . ' WHERE oecf.field_name = :field' . ' AND oecf.entity_id IN (' . ' SELECT oec.id' . ' FROM oro_entity_config AS oec' . ' WHERE oec.class_name = :class' . ' ))';
     $dropFieldSql = 'DELETE FROM oro_entity_config_field' . ' WHERE field_name = :field' . ' AND entity_id IN (' . ' SELECT id' . ' FROM oro_entity_config' . ' WHERE class_name = :class' . ' )';
     $taskClassName = $this->extendExtension->getEntityClassByTableName('orocrm_task');
     $query = new ParametrizedSqlMigrationQuery();
     $query->addSql($dropFieldIndexSql, ['field' => $fieldName, 'class' => $taskClassName], ['field' => 'string', 'class' => 'string']);
     $query->addSql($dropFieldSql, ['field' => $fieldName, 'class' => $taskClassName], ['field' => 'string', 'class' => 'string']);
     return $query;
 }
Ejemplo n.º 9
0
 /**
  * @param string   $sourceTableName
  * @param string   $targetTableName
  * @param string   $ownerColumnName
  * @param QueryBag $queries
  */
 public function assignActivities($sourceTableName, $targetTableName, $ownerColumnName, QueryBag $queries)
 {
     // prepare select email_id:contact_id sql
     $fromAndRecipients = '
         SELECT DISTINCT email_id, owner_id FROM (
             SELECT e.id as email_id, ea.{owner} as owner_id
             FROM oro_email_address ea
                 INNER JOIN oro_email e ON e.from_email_address_id = ea.id
             WHERE ea.{owner} IS NOT NULL
             UNION
             SELECT er.email_id as email_id, ea.{owner} as owner_id
             FROM oro_email_address ea
                 INNER JOIN oro_email_recipient er ON er.email_address_id = ea.id
             WHERE ea.{owner} IS NOT NULL
         ) as subq';
     $sourceClassName = $this->extendExtension->getEntityClassByTableName($sourceTableName);
     $targetClassName = $this->extendExtension->getEntityClassByTableName($targetTableName);
     $fromAndRecipients = str_replace('{owner}', $ownerColumnName, $fromAndRecipients);
     $associationName = ExtendHelper::buildAssociationName($targetClassName, ActivityScope::ASSOCIATION_KIND);
     $tableName = $this->nameGenerator->generateManyToManyJoinTableName($sourceClassName, $associationName, $targetClassName);
     $queries->addQuery(sprintf("INSERT INTO %s %s", $tableName, $fromAndRecipients));
 }
Ejemplo n.º 10
0
 /**
  * Gets an activity list table name for many-to-many relation
  *
  * @param string $targetTableName Target entity table name.
  *
  * @return string
  */
 protected function getAssociationActivityListTableName($targetTableName)
 {
     $targetClassName = $this->extendExtension->getEntityClassByTableName($targetTableName);
     $associationName = ExtendHelper::buildAssociationName($targetClassName, ActivityListEntityConfigDumperExtension::ASSOCIATION_KIND);
     return $this->nameGenerator->generateManyToManyJoinTableName(ActivityListEntityConfigDumperExtension::ENTITY_CLASS, $associationName, $targetClassName);
 }
Ejemplo n.º 11
0
 /**
  * Gets an association column name for note relation
  *
  * @param string $targetTableName Target entity table name.
  *
  * @return string
  */
 public function getAssociationColumnName($targetTableName)
 {
     $associationName = ExtendHelper::buildAssociationName($this->extendExtension->getEntityClassByTableName($targetTableName));
     return $this->nameGenerator->generateManyToOneRelationColumnName($associationName);
 }