--- /dev/null
+<?php
+
+namespace App\Console\Commands;
+
+use App\Models\FluidbookPublication;
+use Cubist\Backpack\Console\Commands\CubistCommand;
+use Illuminate\Support\Facades\DB;
+
+class FluidbookDocumentSetRegion extends CubistCommand
+{
+ protected $signature = 'fluidbook:document:setregion';
+ protected $description = 'Set right region to all documents';
+
+ /**
+ * @throws \Exception
+ */
+ public function handle()
+ {
+ $regions = [];
+ $default = 'UE';
+ foreach (FluidbookPublication::withoutGlobalScopes()->whereNot('region', $default)->get() as $fluidbook) {
+ /** @var $fluidbook FluidbookPublication */
+ $r = $fluidbook->region;
+
+ if (!isset($regions[$r])) {
+ $regions[$r] = [];
+ }
+ $regions[$r] += $fluidbook->getDocumentsId();
+
+ }
+
+ DB::table('fluidbook_document')->update(['region' => $default]);
+ foreach ($regions as $region => $documents) {
+ DB::table('fluidbook_document')->whereIn('id', $documents)->update(['region' => $region]);
+ }
+ }
+}
}
+ public function getDocumentsId()
+ {
+ $res = [];
+ if (null === $this->getComposition()) {
+ return [];
+ }
+ foreach ($this->getComposition() as $page) {
+ $res[$page[0]] = true;
+ }
+ return array_keys($res);
+ }
+
public function getDocumentSizes()
{
if (null === $this->_documentsSize) {
public function getComposition()
{
$res = $this->_getCompositionAttribute('composition');
+ if (null === $res) {
+ return [];
+ }
return $res;
}