Skip to content

Commit

Permalink
Merge pull request #1 from muskie9/enhancement/cacheExisting
Browse files Browse the repository at this point in the history
ENHANCEMENT faster continue checking migrated files
  • Loading branch information
muskie9 committed May 19, 2018
2 parents aa5d82f + c97a814 commit 31c7953
Showing 1 changed file with 29 additions and 13 deletions.
42 changes: 29 additions & 13 deletions src/Tasks/FileMigrationTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,20 @@ public function run($request)
$migrateDirectoryStructure = $this->config()->get('migrate_directory_structure');
$publish = $this->config()->get('publish_on_migration');

$existing = File::get()->filter('LegacyPath:not', null)->column('LegacyPath');
$existing = array_combine($existing, $existing);

foreach ($this->traverseDirectory() as $file) {
$folder = null;
if ($migrateDirectoryStructure) {
$folder = $this->processDirectory($file);
}
if (!isset($existing[$file])) {
$folder = null;
if ($migrateDirectoryStructure) {
$folder = $this->processDirectory($file);
}

$destinationName = ($migrateDirectoryStructure) ? $this->getOriginalFilename($file) : null;
if ($this->migrateFile($file, $publish, $folder, $destinationName)) {
$count++;
$destinationName = ($migrateDirectoryStructure) ? $this->getOriginalFilename($file) : null;
if ($this->migrateFile($file, $publish, $folder, $destinationName)) {
$count++;
}
}
}
$time = microtime(true) - $_SERVER["REQUEST_TIME_FLOAT"];
Expand All @@ -90,20 +95,31 @@ protected function traverseDirectory($directory = null)

$objects = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($directory), \RecursiveIteratorIterator::SELF_FIRST);
$allowedExtensions = File::singleton()->config()->get('allowed_extensions');
unset($allowedExtensions[0]);

foreach ($objects as $name => $object) {
if (is_file($name)) {
$validFile = false;
foreach ($this->yieldExtensions($allowedExtensions) as $extension) {
if ($validFile == false && preg_match("/\.{$extension}/", $name)) {
$validFile = true;
yield $name;
}
if ($this->isValidFile($name, $allowedExtensions)) {
yield $name;
}
}
}
}

/**
* @param $fileName
* @param $allowedExtensions
*/
protected function isValidFile($fileName, $allowedExtensions)
{
foreach ($this->yieldExtensions($allowedExtensions) as $extension) {
if (preg_match("/\.{$extension}/", $fileName) == 1) {
return true;
}
}
return false;
}

/**
* @param $allowedExtensions
* @return \Generator
Expand Down

0 comments on commit 31c7953

Please sign in to comment.