/** * @param string $class * @return bool */ protected function isClassApplicable($class) { if ($this->entityConnector->isWorkflowAware($class)) { return true; } $extendConfigProvider = $this->getExtendConfigProvider(); if (!$extendConfigProvider->hasConfig($class)) { return false; } $entityConfig = $extendConfigProvider->getConfig($class); return $entityConfig && $entityConfig->is('is_extend'); }
/** * Remove related workflow item * * @param LifecycleEventArgs $args */ public function preRemove(LifecycleEventArgs $args) { $entity = $args->getEntity(); if ($this->entityConnector->isWorkflowAware($entity)) { $workflowItem = $this->entityConnector->getWorkflowItem($entity); if ($workflowItem) { $args->getEntityManager()->remove($workflowItem); } } }
/** * @param string $entityClass * @throws WorkflowException */ public function generateWorkflowFields($entityClass) { if ($this->entityConnector->isWorkflowAware($entityClass)) { return; } $extendConfigProvider = $this->configManager->getProvider('extend'); $entityConfig = $extendConfigProvider->getConfig($entityClass); if (!$entityConfig || !$entityConfig->is('is_extend')) { throw new WorkflowException(sprintf('Class %s can not be extended', $entityClass)); } $workflowItemClass = 'Oro\\Bundle\\WorkflowBundle\\Entity\\WorkflowItem'; $workflowStepClass = 'Oro\\Bundle\\WorkflowBundle\\Entity\\WorkflowStep'; // add fields $hasWorkflowItemField = $this->configManager->hasConfig($entityClass, self::PROPERTY_WORKFLOW_ITEM); if (!$hasWorkflowItemField) { $this->addRelationField($entityClass, self::PROPERTY_WORKFLOW_ITEM, ConfigHelper::getTranslationKey('entity', 'label', $workflowItemClass, 'related_entity'), ConfigHelper::getTranslationKey('entity', 'description', $workflowItemClass, 'related_entity'), $workflowItemClass, 'id'); } $hasWorkflowStepField = $this->configManager->hasConfig($entityClass, self::PROPERTY_WORKFLOW_STEP); if (!$hasWorkflowStepField) { $this->addRelationField($entityClass, self::PROPERTY_WORKFLOW_STEP, ConfigHelper::getTranslationKey('entity', 'label', $workflowStepClass, 'related_entity'), ConfigHelper::getTranslationKey('entity', 'description', $workflowStepClass, 'related_entity'), $workflowStepClass, 'label'); } // update entity config $entityConfig->set('state', ExtendScope::STATE_UPDATE); $entityConfig->set('upgradeable', true); $this->configManager->persist($entityConfig); $this->configManager->flush(); // update database $this->entityProcessor->updateDatabase(); // make fields hidden // TODO: Fields can be hidden only after schema update due to a bug in DoctrineSubscriber // TODO: Should be fixed in scope of https://magecore.atlassian.net/browse/BAP-3621 // TODO: If make fields hidden then these fields will be created only for the first extended entity // TODO: Should be fixed in scope of https://magecore.atlassian.net/browse/BAP-3632 /* if (!$hasWorkflowItemField) { $this->hideRelationField($entityClass, self::PROPERTY_WORKFLOW_ITEM); } if (!$hasWorkflowStepField) { $this->hideRelationField($entityClass, self::PROPERTY_WORKFLOW_STEP); } $this->configManager->flush(); */ }
public function testIsWorkflowItemAware() { $this->assertTrue($this->entityConnector->isWorkflowAware(new EntityWithWorkflow())); $this->assertFalse($this->entityConnector->isWorkflowAware(new \DateTime())); }