Beispiel #1
0
 /**
  * @param string $entityClassName
  * @param string $relationType
  *
  * @return array
  */
 protected function getEntityChoiceList($entityClassName, $relationType)
 {
     /** @var EntityConfigId[] $entityIds */
     $entityIds = $this->targetEntityClass ? [$this->configManager->getId('extend', $this->targetEntityClass)] : $this->configManager->getIds('extend');
     if (in_array($relationType, [RelationTypeBase::ONE_TO_MANY, RelationTypeBase::MANY_TO_MANY], true)) {
         $entityIds = array_filter($entityIds, function (EntityConfigId $configId) {
             $config = $this->configManager->getConfig($configId);
             return $config->is('is_extend');
         });
     }
     $entityIds = array_filter($entityIds, function (EntityConfigId $configId) {
         $config = $this->configManager->getConfig($configId);
         return !$config->is('state', ExtendScope::STATE_NEW) && ($this->targetEntityClass || !$config->is('is_deleted'));
     });
     $choices = [];
     foreach ($entityIds as $entityId) {
         $className = $entityId->getClassName();
         if (!$this->configManager->hasConfig($className, 'id') && !ExtendHelper::isCustomEntity($className)) {
             // @todo: temporary ignore entities that don't have PK with name 'id'
             // remove this in https://magecore.atlassian.net/browse/BAP-9713
             continue;
         }
         if ($className !== $entityClassName) {
             $entityConfig = $this->configManager->getProvider('entity')->getConfig($className);
             $choices[$className] = $entityConfig->get('label');
         }
     }
     return $choices;
 }
 /**
  * Gets a list of ids for all classes (if $className is not specified) or all fields of
  * the given $className, which can be managed by this provider.
  *
  * @param string|null $className
  * @return array|ConfigIdInterface[]
  */
 public function getIds($className = null)
 {
     if ($className) {
         $className = $this->getClassName($className);
     }
     return $this->configManager->getIds($this->getScope(), $className);
 }
 /**
  * Get array with all target classes (entities where activity can be assigned to)
  *
  * @param bool $regenerateCaches
  * @return array
  */
 public function getTargetEntityClasses($regenerateCaches = false)
 {
     if (empty($this->targetClasses)) {
         /** @var ConfigIdInterface[] $configIds */
         $configIds = $this->configManager->getIds('entity', null, false, $regenerateCaches);
         foreach ($configIds as $configId) {
             foreach ($this->providers as $provider) {
                 if ($provider->isApplicableTarget($configId, $this->configManager) && !in_array($configId->getClassName(), $this->targetClasses)) {
                     $this->targetClasses[] = $configId->getClassName();
                     continue;
                 }
             }
         }
     }
     return $this->targetClasses;
 }
Beispiel #4
0
 /**
  * Gets a list of ids for all configurable entities (if $className is not specified)
  * or all configurable fields of the given $className, which can be managed by this provider.
  *
  * @param string|null $className
  * @param bool        $withHidden Set true if you need ids of all configurable entities,
  *                                including entities marked as mode="hidden"
  *
  * @return array|ConfigIdInterface[]
  */
 public function getIds($className = null, $withHidden = false)
 {
     if ($className) {
         $className = $this->getClassName($className);
     }
     return $this->configManager->getIds($this->getScope(), $className, $withHidden);
 }
Beispiel #5
0
 /**
  * @dataProvider getIdsProvider
  */
 public function testGetIds($scope, $className, $withHidden, $expectedIds)
 {
     $models = [$this->createEntityConfigModel('EntityClass1'), $this->createEntityConfigModel('EntityClass2'), $this->createEntityConfigModel('HiddenEntity', ConfigModel::MODE_HIDDEN)];
     $entityModel = $this->createEntityConfigModel('EntityClass1');
     $fieldModels = [$this->createFieldConfigModel($entityModel, 'f1', 'int'), $this->createFieldConfigModel($entityModel, 'f2', 'int'), $this->createFieldConfigModel($entityModel, 'hiddenField', 'int', ConfigModel::MODE_HIDDEN)];
     $this->modelManager->expects($this->any())->method('checkDatabase')->willReturn(true);
     $this->modelManager->expects($this->once())->method('getModels')->with($className)->willReturn($className ? $fieldModels : $models);
     $result = $this->configManager->getIds($scope, $className, $withHidden);
     $this->assertEquals($expectedIds, array_values($result));
 }
 /**
  * @param string $targetClassName
  * @param string $activityClassName
  *
  * @return bool
  */
 public function isApplicableTarget($targetClassName, $activityClassName)
 {
     /** @var ConfigIdInterface[] $configIds */
     $configIds = $this->configManager->getIds('entity', null, false);
     foreach ($configIds as $configId) {
         if (array_key_exists($activityClassName, $this->providers)) {
             $provider = $this->getProviderByClass($activityClassName);
             if ($provider->isApplicableTarget($configId, $this->configManager) && $configId->getClassName() === $targetClassName) {
                 return true;
             }
         }
     }
     return false;
 }
 /**
  * Get array with all target classes (entities where activity can be assigned to)
  *
  * @param bool $accessible Whether only targets are ready to be used in a business logic should be returned.
  *                         It means that an association with the target entity should exist
  *                         and should not be marked as deleted.
  *
  * @return string[]
  */
 public function getTargetEntityClasses($accessible = true)
 {
     if (null === $this->targetClasses || !isset($this->targetClasses[$accessible])) {
         $targetClasses = [];
         /** @var ConfigIdInterface[] $configIds */
         $configIds = $this->configManager->getIds('entity');
         foreach ($configIds as $configId) {
             $entityClass = $configId->getClassName();
             foreach ($this->providers as $provider) {
                 if ($provider->isApplicableTarget($entityClass, $accessible)) {
                     $targetClasses[] = $entityClass;
                     break;
                 }
             }
         }
         $this->targetClasses[$accessible] = $targetClasses;
     }
     return $this->targetClasses[$accessible];
 }
 protected function renameExtendColumns(Schema $schema, QueryBag $queries, ConfigManager $configManager)
 {
     /** @var EntityMetadataHelper $entityMetadataHelper */
     $entityMetadataHelper = $this->container->get('oro_entity_extend.migration.entity_metadata_helper');
     $configManager->clearConfigurableCache();
     /** @var EntityConfigId[] $entityConfigIds */
     $entityConfigIds = $configManager->getIds('extend');
     foreach ($entityConfigIds as $entityConfigId) {
         if ($configManager->getConfig($entityConfigId)->is('is_extend')) {
             $tableName = $entityMetadataHelper->getTableNameByEntityClass($entityConfigId->getClassName());
             if ($tableName && $schema->hasTable($tableName)) {
                 $table = $schema->getTable($tableName);
                 /** @var FieldConfigId[] $fieldConfigIds */
                 $fieldConfigIds = $configManager->getIds('extend', $entityConfigId->getClassName());
                 foreach ($fieldConfigIds as $fieldConfigId) {
                     if ($configManager->getConfig($fieldConfigId)->is('extend')) {
                         $this->renameExtendField($schema, $queries, $table, $fieldConfigId, $configManager, $entityMetadataHelper);
                     }
                 }
             }
         }
     }
 }