From 12c8102642e9e412e28390fb82faa99c83b29933 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Thu, 27 Apr 2023 17:11:26 +0200 Subject: [PATCH] wip #5892 @0.25 --- app/Models/FluidbookPublication.php | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/app/Models/FluidbookPublication.php b/app/Models/FluidbookPublication.php index 911ecf057..7b9faa99f 100644 --- a/app/Models/FluidbookPublication.php +++ b/app/Models/FluidbookPublication.php @@ -37,6 +37,7 @@ use Cubist\Util\ArrayUtil; use Cubist\Util\Files\Files; use Cubist\Util\Graphics\Image; use Cubist\Util\Json; +use Cubist\Util\Str; use Datetime; use Illuminate\Support\Facades\Artisan; @@ -203,6 +204,7 @@ class FluidbookPublication extends ToolboxSettingsModel { $this->setComposedAttributes(); $this->checkHash(); + $this->checkCID(); $this->checkExternalServers(); if ($this->_compositionUpdated) { $this->setAttribute('composition_updated_at', new Datetime()); @@ -210,6 +212,18 @@ class FluidbookPublication extends ToolboxSettingsModel return parent::onSaving(); } + protected function checkCID() + { + if (!$this->cid) { + while (true) { + $this->cid = Str::random(8); + if (static::withoutGlobalScopes()->where('cid', $this->cid)->get()->count() === 0) { + break; + } + } + } + } + protected function checkExternalServers() { $o = ArrayUtil::asArray($this->install_online); @@ -514,11 +528,11 @@ class FluidbookPublication extends ToolboxSettingsModel $res = $l10n[$defaultLocale]; if ($this->translations) { - if(is_string($this->translations)) { + if (is_string($this->translations)) { if (Json::isJson($this->translations)) { $this->translations = json_decode($this->translations); - }else{ - $this->translations=[]; + } else { + $this->translations = []; } } foreach ($this->translations as $k => $v) { @@ -610,12 +624,11 @@ class FluidbookPublication extends ToolboxSettingsModel $current = static::find($this->id); } $new = $current->replicate($except); - if (backpack_user()) { - $new->owner = backpack_user()->id; - } $new->status = 0; $new->title = __('Copie de :title', ['title' => $new->title]); $new->visits_counter = 0; + $new->hash = ''; + $new->cid = ''; return $new; } -- 2.39.5