From 7f427a90ccc46b39e92a0f2b47d8be95c638c5ee Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Tue, 5 Sep 2023 19:14:37 +0200 Subject: [PATCH] wait #6023 @5 --- app/Console/Commands/WorkshopMigration.php | 39 +++++++++++++++++-- .../fluidbook_publication/preview.blade.php | 2 +- 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/app/Console/Commands/WorkshopMigration.php b/app/Console/Commands/WorkshopMigration.php index 63471d699..ea05a5789 100644 --- a/app/Console/Commands/WorkshopMigration.php +++ b/app/Console/Commands/WorkshopMigration.php @@ -6,10 +6,12 @@ namespace App\Console\Commands; use App\Models\FluidbookDocument; use App\Models\FluidbookPublication; use App\Models\FluidbookTheme; +use App\Models\FluidbookTranslate; use Cubist\Backpack\Console\Commands\CubistCommand; use Cubist\Backpack\Magic\Fields\Color; use Cubist\Backpack\Magic\Fields\Datetime; use Cubist\Util\ArrayUtil; +use Cubist\Util\Json; use Cubist\Util\ObjectUtil; use Cubist\Util\PHP; use Illuminate\Contracts\Cache\Lock; @@ -19,7 +21,7 @@ use Illuminate\Support\Facades\DB; class WorkshopMigration extends CubistCommand { - protected $signature = 'ws:migrate {--publications=v2} {--documents=missing} {--quick}'; + protected $signature = 'ws:migrate {--publications=v2} {--documents=missing} {--quick} {--force}'; protected $description = 'Migrate data from Workshop V2'; protected $_wsRanks = []; const OLD_DB = 'extranet_clean'; @@ -35,7 +37,9 @@ class WorkshopMigration extends CubistCommand public function handle() { $this->_lock = Cache::lock('ws2_migrate', 3600); - if (!$this->_lock->get()) { + + if (!$this->option('force') && !$this->_lock->get()) { + $this->line('Migration is locked. Use --force to remove lock'); return; } @@ -103,7 +107,7 @@ class WorkshopMigration extends CubistCommand DB::update('DELETE FROM fluidbook_document WHERE id<' . self::WS3_DOC_ID); } else { $range = ArrayUtil::parseRange($this->option('documents')); - FluidbookDocument::withoutGlobalScopes()->whereIn('id', $range)->delete(); + FluidbookDocument::withoutGlobalScopes()->whereIn('id', $range)->forceDelete(); $q->whereIn('document_id', $range); } @@ -215,7 +219,7 @@ class WorkshopMigration extends CubistCommand $q->where('book_id', '>', $f->id); } else { $range = ArrayUtil::parseRange($this->option('publications')); - FluidbookPublication::withoutGlobalScopes()->where('version', '<=', 2)->whereIn('id', $range)->delete(); + FluidbookPublication::withoutGlobalScopes()->where('version', '<=', 2)->whereIn('id', $range)->forceDelete(); $q->whereIn('book_id', $range); } @@ -246,6 +250,10 @@ class WorkshopMigration extends CubistCommand $v = $date; } else if ($k == 'chapters') { $v = $this->_normalizeChapters($v); + } else if ($new == 'translations') { + $v = $this->_normalizeTranslations($v, $e->lang); + } else if (Json::isJson($v)) { + $v = json_decode($v, true); } $c->setAttribute($new, $v); } @@ -270,6 +278,8 @@ class WorkshopMigration extends CubistCommand $date = new \DateTime(); $date->setTimestamp($data); $data = $date; + } else if (Json::isJson($data)) { + $data = json_decode($data, true); } if (isset($mapValues[$data])) { $data = $mapValues[$data]; @@ -297,6 +307,27 @@ class WorkshopMigration extends CubistCommand } } + protected function _normalizeTranslations($value, $lang) + { + if (!is_string($value) || !Json::isJson($value)) { + return []; + } + $translations = json_decode($value); + $res = []; + + $l10n = FluidbookTranslate::getCompiledTranslations()[$lang]; + + foreach ($translations as $base => $trans) { + if (!isset($l10n[$base]) || !$trans || $l10n[$base] === $trans) { + + } else { + $res[$base] = $trans; + } + } + + return $res; + } + public function _normalizeChapters($value) { if (!$value) { diff --git a/resources/views/vendor/backpack/crud/buttons/fluidbook_publication/preview.blade.php b/resources/views/vendor/backpack/crud/buttons/fluidbook_publication/preview.blade.php index 2c25fb7f3..f3521fb8e 100644 --- a/resources/views/vendor/backpack/crud/buttons/fluidbook_publication/preview.blade.php +++ b/resources/views/vendor/backpack/crud/buttons/fluidbook_publication/preview.blade.php @@ -18,7 +18,7 @@ @endphp -@if($entry->allowsPreview()) +@if($entry->getPagesNumber()>0 && $entry->allowsPreview()) 1) -- 2.39.5