--- /dev/null
+<?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);
+ }
+}
/**
* @return string
*/
- public function path($path = ''): string
+ public function path($path = '', $forceRegion = null): string
{
$path = trim($path, DIRECTORY_SEPARATOR);
$fname = false;
}
}
+ $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;
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)
return parent::setAttribute($key, $value);
}
+ /**
+ * @throws \Exception
+ */
public function onSaving(): bool
{
$this->setComposedAttributes();
public function moveRegion($newRegion)
{
foreach (FluidbookDocument::withoutGlobalScopes()->whereIn('id', $this->getDocumentsId())->get() as $doc) {
+ /** @var $doc FluidbookDocument */
$doc->moveRegion($newRegion);
}
}
}
$this->region = $newRegion;
- $this->save();
+ $this->saveQuietly();
}
protected function _replicateMedia($newId)
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);
}
}