Update video set reconciliation result output

This commit is contained in:
paranarimasu
2020-04-19 01:54:01 -05:00
parent b1e7abd09a
commit b79b5979e1
2 changed files with 55 additions and 26 deletions
+36 -7
View File
@@ -9,6 +9,13 @@ use Illuminate\Support\Facades\Storage;
class VideoReconcileCommand extends Command
{
// Result Counts
private $created = 0;
private $created_failed = 0;
private $deleted = 0;
private $deleted_failed = 0;
/**
* The name and signature of the console command.
*
@@ -60,18 +67,16 @@ class VideoReconcileCommand extends Command
// Existing videos as array
$db_videos = Video::all()->all();
// Flag for displaying no results message (no changes needed for reconciliation)
$no_results = true;
// Create videos that exist in storage but not in the database
$create_videos = array_udiff($fs_videos, $db_videos, [VideoReconcileCommand::class, 'compareVideos']);
foreach ($create_videos as $create_video) {
$create_result = $create_video->save();
$no_results = false;
if ($create_result) {
$this->created++;
Log::info("Video '{$create_video->basename}' created");
$this->info("Video '{$create_video->basename}' created");
} else {
$this->created_failed++;
Log::error("Video '{$create_video->basename}' was not created");
$this->error("Video '{$create_video->basename}' was not created");
}
@@ -81,18 +86,28 @@ class VideoReconcileCommand extends Command
$delete_videos = array_udiff($db_videos, $fs_videos, [VideoReconcileCommand::class, 'compareVideos']);
foreach ($delete_videos as $delete_video) {
$delete_result = $delete_video->delete();
$no_results = false;
if ($delete_result) {
$this->deleted++;
Log::info("Video '{$delete_video->basename}' deleted");
$this->info("Video '{$delete_video->basename}' deleted");
} else {
$this->deleted_failed++;
Log::error("Video '{$delete_video->basename}' was not deleted");
$this->error("Video '{$delete_video->basename}' was not deleted");
}
}
// Inform user that no changes were needed for this reconciliation
if ($no_results) {
// Output reconcilation results
if ($this->hasResults()) {
if ($this->hasChanges()) {
Log::info("{$this->created} Videos created, {$this->deleted} Videos deleted");
$this->info("{$this->created} Videos created, {$this->deleted} Videos deleted");
}
if ($this->hasFailures()) {
Log::error("Failed to create {$this->created_failed} Videos, delete {$this->deleted_failed} Videos");
$this->error("Failed to create {$this->created_failed} Videos, delete {$this->deleted_failed} Videos");
}
} else {
Log::info('No Videos created or deleted');
$this->info('No Videos created or deleted');
}
@@ -108,4 +123,18 @@ class VideoReconcileCommand extends Command
private static function reconciliationString($video) {
return "basename:{$video->basename},filename:{$video->filename},path:{$video->path}";
}
// Reconciliation Results
private function hasResults() {
return $this->hasChanges() || $this->hasFailures();
}
private function hasChanges() {
return $this->created > 0 || $this->deleted > 0;
}
private function hasFailures() {
return $this->created_failed > 0 || $this->deleted_failed > 0;
}
}
Generated
+19 -19
View File
@@ -836,23 +836,24 @@
},
{
"name": "guzzlehttp/guzzle",
"version": "6.5.2",
"version": "6.5.3",
"source": {
"type": "git",
"url": "https://github.com/guzzle/guzzle.git",
"reference": "43ece0e75098b7ecd8d13918293029e555a50f82"
"reference": "aab4ebd862aa7d04f01a4b51849d657db56d882e"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/guzzle/guzzle/zipball/43ece0e75098b7ecd8d13918293029e555a50f82",
"reference": "43ece0e75098b7ecd8d13918293029e555a50f82",
"url": "https://api.github.com/repos/guzzle/guzzle/zipball/aab4ebd862aa7d04f01a4b51849d657db56d882e",
"reference": "aab4ebd862aa7d04f01a4b51849d657db56d882e",
"shasum": ""
},
"require": {
"ext-json": "*",
"guzzlehttp/promises": "^1.0",
"guzzlehttp/psr7": "^1.6.1",
"php": ">=5.5"
"php": ">=5.5",
"symfony/polyfill-intl-idn": "^1.11"
},
"require-dev": {
"ext-curl": "*",
@@ -860,7 +861,6 @@
"psr/log": "^1.1"
},
"suggest": {
"ext-intl": "Required for Internationalized Domain Name (IDN) support",
"psr/log": "Required for using the Log middleware"
},
"type": "library",
@@ -899,7 +899,7 @@
"rest",
"web service"
],
"time": "2019-12-23T11:57:10+00:00"
"time": "2020-04-18T10:38:46+00:00"
},
{
"name": "guzzlehttp/promises",
@@ -1240,16 +1240,16 @@
},
{
"name": "league/commonmark",
"version": "1.3.4",
"version": "1.4.0",
"source": {
"type": "git",
"url": "https://github.com/thephpleague/commonmark.git",
"reference": "dd3261eb9a322e009fa5d96d19b9ae19708ce04b"
"reference": "517cbe1c6faf90afeb38a0e917c73acc6d3051ce"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/thephpleague/commonmark/zipball/dd3261eb9a322e009fa5d96d19b9ae19708ce04b",
"reference": "dd3261eb9a322e009fa5d96d19b9ae19708ce04b",
"url": "https://api.github.com/repos/thephpleague/commonmark/zipball/517cbe1c6faf90afeb38a0e917c73acc6d3051ce",
"reference": "517cbe1c6faf90afeb38a0e917c73acc6d3051ce",
"shasum": ""
},
"require": {
@@ -1267,7 +1267,7 @@
"github/gfm": "0.29.0",
"michelf/php-markdown": "~1.4",
"mikehaertl/php-shellcommand": "^1.4",
"phpstan/phpstan-shim": "^0.11.5",
"phpstan/phpstan": "^0.12",
"phpunit/phpunit": "^7.5",
"scrutinizer/ocular": "^1.5",
"symfony/finder": "^4.2"
@@ -1310,7 +1310,7 @@
"md",
"parser"
],
"time": "2020-04-13T20:52:18+00:00"
"time": "2020-04-18T20:46:13+00:00"
},
{
"name": "league/flysystem",
@@ -6093,16 +6093,16 @@
},
{
"name": "webmozart/assert",
"version": "1.7.0",
"version": "1.8.0",
"source": {
"type": "git",
"url": "https://github.com/webmozart/assert.git",
"reference": "aed98a490f9a8f78468232db345ab9cf606cf598"
"reference": "ab2cb0b3b559010b75981b1bdce728da3ee90ad6"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/webmozart/assert/zipball/aed98a490f9a8f78468232db345ab9cf606cf598",
"reference": "aed98a490f9a8f78468232db345ab9cf606cf598",
"url": "https://api.github.com/repos/webmozart/assert/zipball/ab2cb0b3b559010b75981b1bdce728da3ee90ad6",
"reference": "ab2cb0b3b559010b75981b1bdce728da3ee90ad6",
"shasum": ""
},
"require": {
@@ -6110,7 +6110,7 @@
"symfony/polyfill-ctype": "^1.8"
},
"conflict": {
"vimeo/psalm": "<3.6.0"
"vimeo/psalm": "<3.9.1"
},
"require-dev": {
"phpunit/phpunit": "^4.8.36 || ^7.5.13"
@@ -6137,7 +6137,7 @@
"check",
"validate"
],
"time": "2020-02-14T12:15:55+00:00"
"time": "2020-04-18T12:12:48+00:00"
}
],
"aliases": [],