예제 #1
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());
 }
예제 #2
0
 /**
  * {@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);
 }