]> _ Git - fluidbook-toolbox.git/commitdiff
wip #6501 @1
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 22 Nov 2023 12:54:23 +0000 (13:54 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 22 Nov 2023 12:54:23 +0000 (13:54 +0100)
app/Console/Commands/FluidbookRegionMove.php [new file with mode: 0644]
app/Models/FluidbookDocument.php
app/Models/FluidbookPublication.php
app/helpers.php

diff --git a/app/Console/Commands/FluidbookRegionMove.php b/app/Console/Commands/FluidbookRegionMove.php
new file mode 100644 (file)
index 0000000..f205b73
--- /dev/null
@@ -0,0 +1,28 @@
+<?php
+
+namespace App\Console\Commands;
+
+use App\Fluidbook\Region;
+use App\Models\FluidbookPublication;
+use Cubist\Backpack\Console\Commands\CubistCommand;
+
+class FluidbookRegionMove extends CubistCommand
+{
+    protected $signature = 'fluidbook:region:move {id} {region}';
+    protected $description = 'Move the fluidbook files to another region';
+
+    public function handle()
+    {
+        $region = $this->argument('region');
+        $id = $this->argument('id');
+        if (!in_array($region, Region::getAllRegionsCodes())) {
+            throw new \Exception('Invalid region ' . $region);
+        }
+        /** @var FluidbookPublication $fb */
+        $fb = FluidbookPublication::withoutGlobalScopes()->find($id);
+        if (null === $fb) {
+            throw new \Exception('Fluidbook ' . $id . ' not found');
+        }
+        $fb->moveRegion($region);
+    }
+}
index b0210df5e6390b384ecd25e63bb0bec6cc196be1..3938a676d611909072403d0467b59c35e8c855df 100644 (file)
@@ -205,7 +205,7 @@ class FluidbookDocument extends ToolboxModel
     /**
      * @return string
      */
-    public function path($path = ''): string
+    public function path($path = '', $forceRegion = null): string
     {
         $path = trim($path, DIRECTORY_SEPARATOR);
         $fname = false;
@@ -217,8 +217,10 @@ class FluidbookDocument extends ToolboxModel
             }
         }
 
+        $region = $forceRegion ?? $this->getRegion();
+
         $base = 'fluidbookpublication/docs/' . $this->id . '/' . $path;
-        $res = Files::mkdir($this->getRegion() == Region::EUROPE ? protected_path($base) : us_protected_path($base));
+        $res = Files::mkdir($region == Region::EUROPE ? protected_path($base) : us_protected_path($base));
 
         if ($fname) {
             $res .= $fname;
@@ -238,14 +240,14 @@ class FluidbookDocument extends ToolboxModel
             if ($region === $newRegion) {
                 continue;
             }
-            $from = $this->protected_path('fluidbookpublication/docs/' . $this->id, $region);
-            $to = $this->protected_path('fluidbookpublication/docs/' . $this->id, $newRegion);
+            $from = $this->path('', $region);
+            $to = $this->path('', $newRegion);
             $rsync = new Rsync($from, $to, false);
             $rsync->setMove(true);
             $rsync->execute();
         }
         $this->region = $newRegion;
-        $this->save();
+        $this->saveQuietly();
     }
 
     public function hasFile($page, $format = 'jpg', $resolution = 150, $quality = 85, $withText = true, $withGraphics = true, $version = 'html', $forceCheck = false)
index c820675ca0623e2509d3ee102e91a628bd4334f3..a69d6d0a9d396d1a74a15d3056c35c8519c91e51 100644 (file)
@@ -267,6 +267,9 @@ class FluidbookPublication extends ToolboxStatusModel
         return parent::setAttribute($key, $value);
     }
 
+    /**
+     * @throws \Exception
+     */
     public function onSaving(): bool
     {
         $this->setComposedAttributes();
@@ -817,6 +820,7 @@ class FluidbookPublication extends ToolboxStatusModel
     public function moveRegion($newRegion)
     {
         foreach (FluidbookDocument::withoutGlobalScopes()->whereIn('id', $this->getDocumentsId())->get() as $doc) {
+            /** @var $doc FluidbookDocument */
             $doc->moveRegion($newRegion);
         }
 
@@ -836,7 +840,7 @@ class FluidbookPublication extends ToolboxStatusModel
             }
         }
         $this->region = $newRegion;
-        $this->save();
+        $this->saveQuietly();
     }
 
     protected function _replicateMedia($newId)
index 0336658b2a01fb68ed46e82afbdff6e25153d657..23a24d64acc590900803b23cecafaac1c1d03e22 100644 (file)
@@ -15,13 +15,13 @@ if (!function_exists('dddd')) {
 if (!function_exists('us_path')) {
     function us_path($path = '')
     {
-        return base_path('/usstorage/' . $path);
+        return base_path('usstorage/' . $path);
     }
 }
 
 if (!function_exists('us_protected_path')) {
     function us_protected_path($path)
     {
-        return us_path('/protected/' . $path);
+        return us_path('protected/' . $path);
     }
 }