64 lines
1.6 KiB
PHP
64 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Jobs;
|
|
|
|
use Illuminate\Bus\Queueable;
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
use Illuminate\Foundation\Bus\Dispatchable;
|
|
use Illuminate\Queue\SerializesModels;
|
|
use Illuminate\Queue\InteractsWithQueue;
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
use App\Traits\Type;
|
|
|
|
class CatalogVerify extends Job implements ShouldQueue
|
|
{
|
|
use Dispatchable, Queueable, InteractsWithQueue, SerializesModels, Type;
|
|
|
|
// What we should verify
|
|
private $type = NULL;
|
|
|
|
/**
|
|
* Create a new job instance.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function __construct(string $type) {
|
|
$this->type = $type;
|
|
}
|
|
|
|
/**
|
|
* Execute the job.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function handle()
|
|
{
|
|
Log::info(sprintf('%s: Scanning [%s]',__METHOD__,$this->type));
|
|
|
|
// Go through DB and verify files exist
|
|
$class = $this->getModelType($this->type);
|
|
|
|
$good = $bad = $ugly = 0;
|
|
|
|
$class::select('*')->each(function($o) use ($good,$bad,$ugly) {
|
|
if (! file_exists($o->file_name_current(FALSE))) {
|
|
Log::error(sprintf('Media doesnt exist: [%s] (%d:%s)',$this->type,$o->id,$o->file_name_current(FALSE)));
|
|
$bad++;
|
|
return;
|
|
}
|
|
|
|
if (($x=md5_file($o->file_name_current(FALSE))) !== $o->file_signature) {
|
|
Log::error(sprintf('Media MD5 doesnt match DB: [%s] (%d:%s) [%s:%s]',$this->type,$o->id,$o->file_name_current(FALSE),$x,$o->file_signature));
|
|
$ugly++;
|
|
return;
|
|
}
|
|
|
|
$good++;
|
|
});
|
|
|
|
Log::info('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.
|
|
}
|
|
} |