Exemplo n.º 1
0
 /**
  * @test
  * @group library
  */
 public function deleteByNameShouldDeleteExpectedMediaCacheFiles()
 {
     $config = Registry::getConfig();
     $testMediaCacheFilesDirectory = $config->media->cache->directory;
     $websiteId = 'SITE-mcde007d-12a5-46cd-a651-fc42dc78fe5f-SITE';
     $mediaCacheFiles = array('rs7dad6afc94668485dbd2d1a27dc3f1.gif', 'rs7dad6afc94668485dbd2d1a27dc3f1_70x70.gif', 'rs7dad6afc94668485dbd2d1a27dc3f1_180x180.gif', 'rs7dad6afc94668485dbd2d1a27dc3f1_100x100.gif');
     $this->assertTrue($this->createTestMediaCaches($websiteId, $mediaCacheFiles));
     foreach ($mediaCacheFiles as $mediaCacheFile) {
         $deletableMediaCacheFile = $testMediaCacheFilesDirectory . DIRECTORY_SEPARATOR . $websiteId . DIRECTORY_SEPARATOR . $mediaCacheFile;
         $this->assertFileExists($deletableMediaCacheFile);
     }
     $this->service = new CacheService($testMediaCacheFilesDirectory);
     $this->assertTrue($this->service->delete($websiteId, 'rs7dad6afc94668485dbd2d1a27dc3f1.gif'));
     foreach ($mediaCacheFiles as $mediaCacheFile) {
         $deletableMediaCacheFile = $testMediaCacheFilesDirectory . DIRECTORY_SEPARATOR . $websiteId . DIRECTORY_SEPARATOR . $mediaCacheFile;
         $this->assertFileNotExists($deletableMediaCacheFile);
     }
 }
Exemplo n.º 2
0
 /**
  * Loescht Media-Items
  *
  * IDs der Media items, welche nicht geloescht werden konnten, werden
  * zurueckgegeben
  *
  * @param  array  $mediaIds
  * @param  string $websiteId
  * @return array
  */
 public function delete(array $mediaIds, $websiteId, $checkNonDeletables = true)
 {
     $notDeletableIds = array();
     if (count($mediaIds) == 0) {
         return $notDeletableIds;
     }
     if ($checkNonDeletables === true) {
         foreach ($mediaIds as $index => $mediaId) {
             $notDeletableInfos = array('modules' => array(), 'templates' => array(), 'pages' => array());
             $deleteMediaSuccess = true;
             $mediaRelations = $this->getMediaRelations($mediaId, $websiteId);
             if (count($mediaRelations) > 0) {
                 foreach ($notDeletableInfos as $relationKey => $relationValues) {
                     if (isset($mediaRelations[$relationKey])) {
                         $notDeletableInfos[$relationKey] = $mediaRelations[$relationKey];
                         $deleteMediaSuccess = false;
                     }
                 }
                 unset($mediaIds[$index]);
             }
             if ($deleteMediaSuccess == false) {
                 try {
                     $mediaName = $this->getService()->getById($mediaId, $websiteId)->getName();
                 } catch (\Exception $e) {
                     $mediaName = 'unknown';
                 }
                 \Cms\ExceptionStack::addException(new \Cms\Exception(236, __METHOD__, __LINE__, array('id' => $mediaId, 'name' => $mediaName, 'infos' => $notDeletableInfos)));
                 $notDeletableIds[] = $mediaId;
             }
         }
     }
     $config = Registry::getConfig();
     $mediaDirectory = $config->media->files->directory;
     $mediaFileService = new MediaFileService($mediaDirectory);
     $mediaCacheDirectory = $config->media->cache->directory;
     $cacheFileService = new MediaCacheService($mediaCacheDirectory);
     foreach ($mediaIds as $index => $id) {
         $media = $this->getService()->getById($id, $websiteId);
         if ($media !== null) {
             $mediaFileService->delete($websiteId, $media->getFile());
             $cacheFileService->delete($websiteId, $media->getFile());
         }
     }
     $this->getService()->delete($mediaIds, $websiteId);
     return $notDeletableIds;
 }