diff --git a/app/Jobs/CatalogVerify.php b/app/Jobs/CatalogVerify.php index efee0c1..a52ec82 100644 --- a/app/Jobs/CatalogVerify.php +++ b/app/Jobs/CatalogVerify.php @@ -9,11 +9,12 @@ use Illuminate\Queue\SerializesModels; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Support\Facades\Log; +use App\Traits\Files; use App\Traits\Type; class CatalogVerify extends Job implements ShouldQueue { - use Dispatchable, Queueable, InteractsWithQueue, SerializesModels, Type; + use Dispatchable, Queueable, InteractsWithQueue, SerializesModels, Type, Files; // What we should verify private $type = NULL; @@ -57,8 +58,44 @@ class CatalogVerify extends Job implements ShouldQueue $good++; }); - Log::info('DB Media Verify Complete: [%s] Good: [%d], Missing: [%d], Changed: [%d]',$this->type,$good,$bad,$ugly); + Log::info(sprintf('DB Media Verify Complete: [%s] Good: [%d], Missing: [%d], Changed: [%d]',$this->type,$good,$bad,$ugly)); // Go through filesystem and see that a record exists in the DB, if not add it. + $parentdir = config($this->type.'.dir'); + $parentdir = 'app'; + + $good = $bad = 0; + + foreach ($this->dirlist($parentdir) as $dir) { + foreach ($this->getFiles(['dir'=>$dir,'file'=>NULL],$this->type) as $file) { + if (! $class::where('filename',$file)->count()) { + $bad++; + Log::error(sprintf('File not in DB: [%s] (%s)',$this->type,$file)); + } else { + $good++; + } + } + } + + Log::info(sprintf('File Media Verify Complete: [%s] Good: [%d], Not In DB: [%d]',$this->type,$good,$bad)); + } + + /** + * Recursively get a list of dirs + * @param $path + * @return \Illuminate\Support\Collection + */ + private function dirlist($path) + { + $list = collect(); + + $list->push($path); + + foreach (glob($path.'/*',GLOB_ONLYDIR) as $dir) { + foreach ($this->dirlist($dir) as $subdir) + $list->push($subdir); + } + + return $list; } } \ No newline at end of file diff --git a/app/Traits/Files.php b/app/Traits/Files.php index ad00b7a..fa20987 100644 --- a/app/Traits/Files.php +++ b/app/Traits/Files.php @@ -16,7 +16,7 @@ trait Files if (is_null($option['file']) AND is_null($option['dir'])) abort(500,'Missing filename, please use --file= OR --dir='); - Log::info(sprintf('%s: Processing: %s',__METHOD__,($option['file'] ? $option['file'] : $option['dir']))); + Log::debug(sprintf('%s: Processing: %s',__METHOD__,($option['file'] ? $option['file'] : $option['dir']))); $files = collect(); $dir = ''; @@ -26,7 +26,7 @@ trait Files $dir = preg_replace('/\/$/','',$option['dir']); // Exclude . & .. from the path. - $files = $files->merge(array_diff(scandir($dir),array('.','..'))); + $files = $files->merge(array_filter(array_diff(scandir($dir),array('.','..')),function($item) use ($dir) { return is_file($dir.'/'.$item); })); } elseif ($option['file'] AND ! is_dir($option['file']) AND file_exists($option['file'])) { $dir = dirname($option['file']); @@ -43,7 +43,7 @@ trait Files return sprintf('%s/%s',$dir,$value); }); - Log::info(sprintf('%s: Processing: %s (%s)',__METHOD__,($option['file'] ? $option['file'] : $option['dir']),count($files))); + Log::debug(sprintf('%s: Processing: %s (%s)',__METHOD__,($option['file'] ? $option['file'] : $option['dir']),count($files))); return $files; }