/** * @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); }
/** * {@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)); }
public function handle(MassActionHandlerArgs $args) { $iterations = 0; try { /** @var ResultRecord $result */ foreach ($args->getResults() as $result) { $this->userService->resetPassword(new User($result->getValue('id'), User::TYPE_DIAMANTE)); ++$iterations; } } catch (\Exception $e) { throw $e; } return $this->getResponse($args, $iterations); }
/** * {@inheritDoc} */ public function handle(MassActionHandlerArgs $args) { $iteration = 0; $entityName = null; $entityIdentifiedField = null; $results = new DeletionIterableResult($args->getResults()->getSource()); $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) { if ($this->securityFacade->isGranted('DELETE', $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->getResponse($args, $iteration); }