]> _ Git - fluidbook-toolbox.git/commitdiff
wip #5892 @0.25
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 27 Apr 2023 15:11:26 +0000 (17:11 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 27 Apr 2023 15:11:26 +0000 (17:11 +0200)
app/Models/FluidbookPublication.php

index 911ecf057232e7b1aced56762b179085a27fe03a..7b9faa99fb6fa79cd1627a92d436c83cee62ef95 100644 (file)
@@ -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;
     }