From: Vincent Vanwaelscappel Date: Wed, 22 Nov 2023 12:54:23 +0000 (+0100) Subject: wip #6501 @1 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=cba152842de935ad037c3756e28fef1e78b39785;p=fluidbook-toolbox.git wip #6501 @1 --- diff --git a/app/Console/Commands/FluidbookRegionMove.php b/app/Console/Commands/FluidbookRegionMove.php new file mode 100644 index 000000000..f205b734c --- /dev/null +++ b/app/Console/Commands/FluidbookRegionMove.php @@ -0,0 +1,28 @@ +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); + } +} diff --git a/app/Models/FluidbookDocument.php b/app/Models/FluidbookDocument.php index b0210df5e..3938a676d 100644 --- a/app/Models/FluidbookDocument.php +++ b/app/Models/FluidbookDocument.php @@ -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) diff --git a/app/Models/FluidbookPublication.php b/app/Models/FluidbookPublication.php index c820675ca..a69d6d0a9 100644 --- a/app/Models/FluidbookPublication.php +++ b/app/Models/FluidbookPublication.php @@ -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) diff --git a/app/helpers.php b/app/helpers.php index 0336658b2..23a24d64a 100644 --- a/app/helpers.php +++ b/app/helpers.php @@ -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); } }