/** * 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); }