You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

74 lines
1.9 KiB

<?php
namespace App\Console\Commands;
use App\ImageRecord;
use Illuminate\Console\Command;
use App\Services\DirService;
use Illuminate\Database\QueryException;
use Illuminate\Support\Facades\Log;
class RecordDir extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'record:dir {path}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Command description';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
//
$path = trim($this->argument("path"));
$service = new DirService();
$list = $service->recursiveScan($path);
// $i = 0;
foreach ($list["files"] as $file) {
if (strstr($file, ".DS_Store")) {
continue;
}
$fileInfo = pathinfo($file);
try {
$imageRecord = new ImageRecord();
$imageRecord->path = str_replace($path, "", $fileInfo["dirname"]);
$imageRecord->name = $fileInfo["basename"];
$imageRecord->type = 2;// dump($imageRecord->getAttributes());
// $i++;
// if ($i > 100) {
// exit;
// }
// continue;
$imageRecord->save();
} catch (QueryException $e) {
if (!str_contains($e->getMessage(), "Duplicate entry")) {
Log::error($e->getMessage());
}
}
unset($imageRecord);
}
}
}