From d21df1c5754f2485f6c32511eee710dc5065e991 Mon Sep 17 00:00:00 2001 From: Deon George Date: Thu, 16 Jul 2020 11:41:17 +1000 Subject: [PATCH] Start of CatalogVerify --- .env.example | 9 ++-- app/Console/Commands/CatalogVerify.php | 52 +++++++++++++++++++++ app/Jobs/CatalogVerify.php | 62 ++++++++++++++++++++++++++ app/Models/Abstracted/Catalog.php | 2 +- 4 files changed, 120 insertions(+), 5 deletions(-) create mode 100644 app/Console/Commands/CatalogVerify.php create mode 100644 app/Jobs/CatalogVerify.php diff --git a/.env.example b/.env.example index 604b401..324d5ce 100644 --- a/.env.example +++ b/.env.example @@ -1,4 +1,5 @@ APP_NAME=Laravel +APP_NAME_HTML_LONG="LaravelApplication" APP_ENV=local APP_KEY= APP_DEBUG=true @@ -7,15 +8,15 @@ APP_URL=http://localhost LOG_CHANNEL=stack DB_CONNECTION=mysql -DB_HOST=127.0.0.1 +DB_HOST=database DB_PORT=3306 -DB_DATABASE=laravel -DB_USERNAME=root +DB_DATABASE=database +DB_USERNAME=web DB_PASSWORD= BROADCAST_DRIVER=log CACHE_DRIVER=file -QUEUE_CONNECTION=sync +QUEUE_CONNECTION=database SESSION_DRIVER=file SESSION_LIFETIME=120 diff --git a/app/Console/Commands/CatalogVerify.php b/app/Console/Commands/CatalogVerify.php new file mode 100644 index 0000000..ca25f87 --- /dev/null +++ b/app/Console/Commands/CatalogVerify.php @@ -0,0 +1,52 @@ +argument('type')) { + $this->dispatch(new Job($this->argument('type')))->onQueue('scan'); + + } else { + } + } +} \ No newline at end of file diff --git a/app/Jobs/CatalogVerify.php b/app/Jobs/CatalogVerify.php new file mode 100644 index 0000000..ad9cc57 --- /dev/null +++ b/app/Jobs/CatalogVerify.php @@ -0,0 +1,62 @@ +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; + + $result = $class::select('*')->each(function($o) use ($good,$bad,$ugly) { + if (! file_exists($o->file_name(FALSE))) { + Log::error(sprintf('Media doesnt exist: [%s] (%d:%s)',$this->type,$o->id,$o->file_name(FALSE))); + $bad++; + return; + } + + if (($x=md5_file($o->file_name(FALSE))) !== $o->file_signature) { + Log::error(sprintf('Media MD5 doesnt match DB: [%s] (%d:%s) [%s:%s]',$this->type,$o->id,$o->file_name(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. + } +} \ No newline at end of file diff --git a/app/Models/Abstracted/Catalog.php b/app/Models/Abstracted/Catalog.php index d8cb82e..b5e6632 100644 --- a/app/Models/Abstracted/Catalog.php +++ b/app/Models/Abstracted/Catalog.php @@ -253,7 +253,7 @@ abstract class Catalog extends Model /** * Determine the new name for the image - * @deprecated + * @deprecated use $this->file_name() */ public function file_path($short=FALSE,$new=FALSE) {