]> _ Git - fluidbook-toolbox.git/commitdiff
wait #6023 @5
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 5 Sep 2023 17:14:37 +0000 (19:14 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 5 Sep 2023 17:14:37 +0000 (19:14 +0200)
app/Console/Commands/WorkshopMigration.php
resources/views/vendor/backpack/crud/buttons/fluidbook_publication/preview.blade.php

index 63471d6995787a757e5679352f64cd7937bae7bb..ea05a5789b7966ee00a7e227bfcbb997dadff90f 100644 (file)
@@ -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) {
index 2c25fb7f35f5ee7dc1139fca007e57ccc8c09108..f3521fb8e94d42b6db51d53b3d4d5d79e2f66ef2 100644 (file)
@@ -18,7 +18,7 @@
 
 @endphp
 
-@if($entry->allowsPreview())
+@if($entry->getPagesNumber()>0 && $entry->allowsPreview())
     <a class="btn btn-sm btn-link" target="{!! $actions['preview']['target'] !!}"
        href="{!! $actions['preview']['url'] !!}"
        @if(count($actions)>1)