protected function getResponse(MassActionHandlerArgs $args, $count = 0)
 {
     $massAction = $args->getMassAction();
     $responseMessage = $massAction->getOptions()->offsetGetByPath('[messages][success]', $this->responseMessage);
     $successful = $count > 0;
     $options = ['count' => $count];
     return new MassActionResponse($successful, $this->translator->transChoice($responseMessage, $count, ['%count%' => $count]), $options);
 }
예제 #2
0
 /**
  * @param MassActionHandlerArgs $args
  *
  * @return MassDeleteLimitResult
  */
 public function getLimitResult(MassActionHandlerArgs $args)
 {
     $query = $args->getResults()->getSource();
     $resultsForSelected = new DeletionIterableResult($query);
     $deletableQuery = $this->cloneQuery($query);
     $accessLimitedQuery = $this->aclHelper->apply($deletableQuery, 'DELETE');
     $resultsForDelete = new DeletionIterableResult($accessLimitedQuery);
     return new MassDeleteLimitResult($resultsForSelected->count(), $resultsForDelete->count());
 }
 /**
  * {@inheritdoc}
  */
 public function handle(MassActionHandlerArgs $args)
 {
     $massAction = $args->getMassAction();
     $entityName = $this->actionRepository->getEntityName($args->getDatagrid());
     if (!$this->isMassActionEnabled($entityName)) {
         return $this->getResponse($massAction, 0, 'Action not configured or not allowed');
     }
     $massAction->getOptions()->offsetSet('entityName', $entityName);
     $entitiesCount = $this->actionRepository->batchUpdate($massAction, $args->getResults(), $args->getData());
     return $this->getResponse($massAction, $entitiesCount);
 }
예제 #4
0
 /**
  * {@inheritdoc}
  */
 public function handle(MassActionHandlerArgs $args)
 {
     $massAction = $args->getMassAction();
     $options = $massAction->getOptions()->toArray();
     if (empty($options['entity_name'])) {
         throw new InvalidArgumentException('Entity name is missing.');
     }
     $entityIdentifier = $this->doctrineHelper->getSingleIdentifierFieldName($options['entity_name']);
     $entityIds = $this->getIdsFromResult($args->getResults(), $entityIdentifier);
     $entities = $this->doctrineHelper->getEntitiesByIds($options['entity_name'], $entityIds);
     return new MassActionResponse(true, null, array('entities' => $entities, 'entity_name' => $options['entity_name'], 'options' => $options));
 }
예제 #5
0
 /**
  * @param MassActionHandlerArgs $args
  *
  * @return MassActionResponse
  * @throws \Exception
  */
 protected function doDelete(MassActionHandlerArgs $args)
 {
     $iteration = 0;
     $entityName = null;
     $entityIdentifiedField = null;
     $queryBuilder = $args->getResults()->getSource();
     $results = new DeletionIterableResult($queryBuilder);
     $results->setBufferSize(self::FLUSH_BATCH_SIZE);
     // batch remove should be processed in transaction
     $this->entityManager->beginTransaction();
     try {
         // if huge amount data must be deleted
         set_time_limit(0);
         foreach ($results as $result) {
             /** @var $result ResultRecordInterface */
             $entity = $result->getRootEntity();
             if (!$entity) {
                 // no entity in result record, it should be extracted from DB
                 if (!$entityName) {
                     $entityName = $this->getEntityName($args);
                 }
                 if (!$entityIdentifiedField) {
                     $entityIdentifiedField = $this->getEntityIdentifierField($args);
                 }
                 $entity = $this->getEntity($entityName, $result->getValue($entityIdentifiedField));
             }
             if ($entity) {
                 $this->entityManager->remove($entity);
                 $iteration++;
                 if ($iteration % self::FLUSH_BATCH_SIZE == 0) {
                     $this->finishBatch();
                 }
             }
         }
         if ($iteration % self::FLUSH_BATCH_SIZE > 0) {
             $this->finishBatch();
         }
         $this->entityManager->commit();
     } catch (\Exception $e) {
         $this->entityManager->rollback();
         throw $e;
     }
     return $this->getDeleteResponse($args, $iteration);
 }
 /**
  * @param MassActionHandlerArgs $args
  * @param int $entitiesCount
  * @param int|null $shoppingListId
  *
  * @return MassActionResponse
  */
 protected function generateResponse(MassActionHandlerArgs $args, $entitiesCount = 0, $shoppingListId = null)
 {
     $transChoiceKey = $args->getMassAction()->getOptions()->offsetGetByPath('[messages][success]', 'orob2b.shoppinglist.actions.add_success_message');
     return new MassActionResponse($entitiesCount > 0, $this->messageGenerator->getSuccessMessage($shoppingListId, $entitiesCount, $transChoiceKey), ['count' => $entitiesCount]);
 }
예제 #7
0
 /**
  * @param MassActionHandlerArgs $args
  *
  * @throws LogicException
  * @return string
  */
 protected function getEntityIdentifierField(MassActionHandlerArgs $args)
 {
     $massAction = $args->getMassAction();
     $identifier = $massAction->getOptions()->offsetGet('data_identifier');
     if (!$identifier) {
         throw new LogicException(sprintf('Mass action "%s" must define identifier name', $massAction->getName()));
     }
     // if we ask identifier that's means that we have plain data in array
     // so we will just use column name without entity alias
     if (strpos('.', $identifier) !== -1) {
         $parts = explode('.', $identifier);
         $identifier = end($parts);
     }
     return $identifier;
 }
 /**
  * @param MassActionHandlerArgs $args
  */
 public function __construct(MassActionHandlerArgs $args)
 {
     $this->args = $args->getData();
 }