/** * Deletes all thumbnails from the given media object * * @param Media $media */ public function removeMediaThumbnails(Media $media) { $thumbnails = array_merge(array_values($media->getThumbnailFilePaths()), array_values($media->getThumbnailFilePaths(true))); foreach ($thumbnails as $thumbnail) { $thumbnailPath = $this->rootDir . '/' . $thumbnail; if ($this->mediaService->has($thumbnailPath)) { $this->mediaService->delete($thumbnailPath); } } }
/** * Migrate a single file * * @param string $path * @param MediaServiceInterface $fromFilesystem * @param MediaServiceInterface $toFileSystem * @param OutputInterface $output * @throws \Exception */ private function migrateFile($path, MediaServiceInterface $fromFilesystem, MediaServiceInterface $toFileSystem, OutputInterface $output) { // only do migration if it's on the local filesystem since could take a long time // to read and write all the files if ($fromFilesystem->getAdapterType() === 'local') { if (!$fromFilesystem->isEncoded($path)) { $this->counter['migrated']++; $output->writeln("Migrate: " . $path); $fromFilesystem->migrateFile($path); } } // file already exists if ($toFileSystem->has($path)) { $this->counter['skipped']++; $output->writeln("SKIP: " . $path); return; } // move file to new filesystem and remove the old one if ($fromFilesystem->has($path)) { $this->counter['moved']++; $output->writeln("Move: " . $path); $success = $this->writeStream($toFileSystem, $path, $fromFilesystem->readStream($path)); if ($success) { $fromFilesystem->delete($path); } return; } throw new \Exception("File not found: " . $path); }
/** * @param string $path */ private function _testDelete($path) { $this->assertTrue($this->mediaService->has($path)); $this->mediaService->delete($path); $this->assertFalse($this->mediaService->has($path)); }