diff --git a/src/FileMigrationHelper.php b/src/FileMigrationHelper.php index bfcd53b5..b2d767c0 100644 --- a/src/FileMigrationHelper.php +++ b/src/FileMigrationHelper.php @@ -9,7 +9,6 @@ use SilverStripe\Core\Config\Configurable; use SilverStripe\Core\Environment; use SilverStripe\Core\Injector\Injectable; -use SilverStripe\Core\Injector\Injector; use SilverStripe\ORM\DataList; use SilverStripe\ORM\DataObject; use SilverStripe\ORM\DataQuery; @@ -40,7 +39,7 @@ class FileMigrationHelper 'logger' => '%$' . LoggerInterface::class, ]; - /** @var LoggerInterface */ + /** @var LoggerInterface|null */ private $logger; /** @@ -89,7 +88,9 @@ public function run($base = null) $success = $this->migrateFile($base, $file, $filename); if ($processedCount % 100 === 0) { - $this->logger->info("Iterated $processedCount out of $total files. Migrated $migratedCount files."); + if ($this->logger) { + $this->logger->info("Iterated $processedCount out of $total files. Migrated $migratedCount files."); + } } $processedCount++; @@ -118,7 +119,9 @@ protected function migrateFile($base, File $file, $legacyFilename) // Make sure this legacy file actually exists $path = $base . '/' . $legacyFilename; if (!file_exists($path)) { - $this->logger->warning("$legacyFilename not migrated because the file does not exist ($path)"); + if ($this->logger) { + $this->logger->warning("$legacyFilename not migrated because the file does not exist ($path)"); + } return false; } @@ -129,7 +132,9 @@ protected function migrateFile($base, File $file, $legacyFilename) if ($this->config()->get('delete_invalid_files')) { $file->delete(); } - $this->logger->warning("$legacyFilename not migrated because the extension $extension is not a valid extension"); + if ($this->logger) { + $this->logger->warning("$legacyFilename not migrated because the extension $extension is not a valid extension"); + } return false; } @@ -179,7 +184,9 @@ protected function migrateFile($base, File $file, $legacyFilename) // removing the legacy file since it has been migrated now and not using legacy filenames $removed = unlink($path); if (!$removed) { - $this->logger->warning("$legacyFilename was migrated, but failed to remove the legacy file ($path)"); + if ($this->logger) { + $this->logger->warning("$legacyFilename was migrated, but failed to remove the legacy file ($path)"); + } } return $removed; }