Skip to content

Commit

Permalink
Fix travis test. Logger is not always defined
Browse files Browse the repository at this point in the history
  • Loading branch information
bergice committed Apr 10, 2019
1 parent f234a8d commit 0c4f874
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/FileMigrationHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -40,7 +39,7 @@ class FileMigrationHelper
'logger' => '%$' . LoggerInterface::class,
];

/** @var LoggerInterface */
/** @var LoggerInterface|null */
private $logger;

/**
Expand Down Expand Up @@ -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++;
Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 0c4f874

Please sign in to comment.