コード例 #1
0
 /**
  * @param string $identifier
  */
 public function deleteById($identifier)
 {
     $object = $this->findById($identifier);
     // todo: check if we want to throw an exception here
     if ($object !== NULL) {
         $this->persistenceManager->remove($object);
         $this->persistenceManager->persistAll();
     }
 }
コード例 #2
0
 /**
  * Removes an object from this repository.
  *
  * @param object $object The object to remove
  * @return void
  * @throws \TYPO3\Flow\Persistence\Exception\IllegalObjectTypeException
  * @api
  */
 public function remove($object)
 {
     if (!is_object($object) || !$object instanceof $this->entityClassName) {
         $type = is_object($object) ? get_class($object) : gettype($object);
         throw new \TYPO3\Flow\Persistence\Exception\IllegalObjectTypeException('The value given to remove() was ' . $type . ' , however the ' . get_class($this) . ' can only handle ' . $this->entityClassName . ' instances.', 1298403442);
     }
     $this->persistenceManager->remove($object);
 }
コード例 #3
0
 /**
  * Clean up resource registry
  *
  * This command checks the resource registry (that is the database tables) for orphaned resource objects which don't
  * seem to have any corresponding data anymore (for example: the file in Data/Persistent/Resources has been deleted
  * without removing the related Resource object).
  *
  * If the TYPO3.Media package is active, this command will also detect any assets referring to broken resources
  * and will remove the respective Asset object from the database when the broken resource is removed.
  *
  * This command will ask you interactively what to do before deleting anything.
  *
  * @return void
  */
 public function cleanCommand()
 {
     $this->outputLine('Checking if resource data exists for all known resource objects ...');
     $this->outputLine();
     $mediaPackagePresent = $this->packageManager->isPackageActive('TYPO3.Media');
     $resourcesCount = $this->resourceRepository->countAll();
     $this->output->progressStart($resourcesCount);
     $brokenResources = array();
     $relatedAssets = new \SplObjectStorage();
     foreach ($this->resourceRepository->findAll() as $resource) {
         $this->output->progressAdvance(1);
         /* @var \TYPO3\Flow\Resource\Resource $resource */
         $stream = $resource->getStream();
         if (!is_resource($stream)) {
             $brokenResources[] = $resource;
         }
     }
     $this->output->progressFinish();
     $this->outputLine();
     if ($mediaPackagePresent && count($brokenResources) > 0) {
         $assetRepository = $this->objectManager->get('TYPO3\\Media\\Domain\\Repository\\AssetRepository');
         /* @var \TYPO3\Media\Domain\Repository\AssetRepository $assetRepository */
         foreach ($brokenResources as $resource) {
             $assets = $assetRepository->findByResource($resource);
             if ($assets !== NULL) {
                 $relatedAssets[$resource] = $assets;
             }
         }
     }
     if (count($brokenResources) > 0) {
         $this->outputLine('<b>Found %s broken resource(s):</b>', array(count($brokenResources)));
         $this->outputLine();
         foreach ($brokenResources as $resource) {
             $this->outputLine('%s (%s) %s', array($resource->getFilename(), $resource->getSha1(), $resource->getCollectionName()));
             if (isset($relatedAssets[$resource])) {
                 foreach ($relatedAssets[$resource] as $asset) {
                     $this->outputLine(' -> %s (%s)', array(get_class($asset), $asset->getIdentifier()));
                 }
             }
         }
         $response = NULL;
         while (!in_array($response, array('y', 'n', 'c'))) {
             $response = $this->output->ask('<comment>Do you want to remove all broken resource objects and related assets from the database? (y/n/c) </comment>');
         }
         switch ($response) {
             case 'y':
                 foreach ($brokenResources as $resource) {
                     $resource->disableLifecycleEvents();
                     $this->persistenceManager->remove($resource);
                     if (isset($relatedAssets[$resource])) {
                         foreach ($relatedAssets[$resource] as $asset) {
                             $assetRepository->remove($asset);
                         }
                     }
                 }
                 $this->outputLine('Removed %s resource object(s) from the database.', array(count($brokenResources)));
                 break;
             case 'n':
                 $this->outputLine('Did not delete any resource objects.');
                 break;
             case 'c':
                 $this->outputLine('Stopping. Did not delete any resource objects.');
                 $this->quit(0);
                 break;
         }
     }
 }