Ejemplo n.º 1
0
 /**
  * @param string $sourceWebsiteId
  * @param string $newWebsiteId
  */
 public function copyMediaToNewWebsite($sourceWebsiteId, $newWebsiteId)
 {
     $config = Registry::getConfig();
     $mediaDirectory = $config->media->files->directory;
     $mediaFileService = new MediaFileService($mediaDirectory);
     $sourceMediaDirectory = $mediaDirectory . DIRECTORY_SEPARATOR . $sourceWebsiteId;
     if (is_dir($sourceMediaDirectory)) {
         $mediaFileService->copyMediaFileToNewWebsite($sourceWebsiteId, $newWebsiteId);
     }
     return $this->execute('copyMediaToNewWebsite', array($sourceWebsiteId, $newWebsiteId));
 }
 /**
  * @test
  * @group library
  */
 public function copyShouldCopyAsExpected()
 {
     $sourceWebsiteId = 'SITE-mf12copy-20da-4ea8-a477-4ee793source-SITE';
     $destinationWebsiteId = 'SITE-mf12copy-20da-4ea8-a477-4ee7j3f5dest-SITE';
     $this->service->copyMediaFileToNewWebsite($sourceWebsiteId, $destinationWebsiteId);
     $expectedDestinationDirectory = $this->testMediaFilesDirectory . DIRECTORY_SEPARATOR . $destinationWebsiteId;
     $assertionMessage = sprintf("Destination directory '%s' has not been created", $expectedDestinationDirectory);
     $this->assertTrue(is_dir($expectedDestinationDirectory), $assertionMessage);
     $testFilesDirectory = $this->config->test->files->directory;
     $expectedCopyTreeFile = $testFilesDirectory . DIRECTORY_SEPARATOR . 'expected_media_copy.tree';
     $expectedCopyTree = file_get_contents($expectedCopyTreeFile);
     $this->assertSame($expectedCopyTree, DirectoryHelper::getRecursiveAsJson($expectedDestinationDirectory, true), "Tree mismatch between copied directory tree and expected directory tree");
     DirectoryHelper::removeRecursiv($expectedDestinationDirectory, $this->testMediaFilesDirectory);
 }
Ejemplo n.º 3
0
 /**
  * @test
  * @group library
  */
 public function deleteByNameShouldDeleteExpectedMediaFiles()
 {
     $config = Registry::getConfig();
     $testMediaFilesDirectory = $config->media->files->directory;
     $websiteId = 'SITE-mede000d-11a5-46cd-a651-fc42dc78fe5f-SITE';
     $mediaFiles = array('rs7fad6afc94668485dbd2d1a27dc3f0.png', 'rs7dad6afc94668485dbd2d1a27dc3f1.gif', 'rs7had6afc94668485dbd2d1a27dc3f2.jpg');
     $this->assertTrue($this->createTestMedias($websiteId, $mediaFiles));
     foreach ($mediaFiles as $mediaFile) {
         $deletableMediaFile = $testMediaFilesDirectory . DIRECTORY_SEPARATOR . $websiteId . DIRECTORY_SEPARATOR . $mediaFile;
         $this->assertFileExists($deletableMediaFile);
     }
     $this->service = new FileService($testMediaFilesDirectory);
     foreach ($mediaFiles as $mediaFile) {
         $this->assertTrue($this->service->delete($websiteId, $mediaFile));
     }
     foreach ($mediaFiles as $mediaFile) {
         $deletableMediaFile = $testMediaFilesDirectory . DIRECTORY_SEPARATOR . $websiteId . DIRECTORY_SEPARATOR . $mediaFile;
         $this->assertFileNotExists($deletableMediaFile);
     }
 }
Ejemplo n.º 4
0
 protected function setUploadedFileToMediaItem($upload, $media, $uploadFileName)
 {
     $mediaFileService = new MediaFileService(Registry::getConfig()->media->files->directory);
     $destinationDirectory = $mediaFileService->makeMediaWebsiteDirectory($media->getWebsiteid());
     $upload->setDestination($destinationDirectory);
     $upload->receive();
     $md5HashedFile = $mediaFileService->hashFilename(FS::joinPath($destinationDirectory, $uploadFileName), $media->getId());
     $md5HashedFilename = basename($md5HashedFile);
     if ($md5HashedFilename !== null) {
         $this->getBusiness()->edit($media->getId(), $media->getWebsiteid(), array('file' => $md5HashedFilename, 'dateuploaded' => time()));
     }
 }
Ejemplo n.º 5
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;
 }