]> _ Git - fluidbook-toolbox.git/commitdiff
wip #6433 @2
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 14 Dec 2023 10:02:39 +0000 (11:02 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 14 Dec 2023 10:02:39 +0000 (11:02 +0100)
.docker/config/php/fpm.conf
app/Jobs/UpdateWS2ThemeTable.php
app/Models/FluidbookTheme.php
scripts/fixrights.sh

index 710dfd9e8407e111a615e5e546c8ca5aef994f30..9cc8b92d48ee4547f9bc875ec26f166160e39b84 100644 (file)
@@ -31,7 +31,7 @@ group = 33
 
 pm = dynamic
 pm.max_children = 320
-pm.start_servers = 96
-pm.min_spare_servers = 80
-pm.max_spare_servers = 160
+pm.start_servers = 180
+pm.min_spare_servers = 160
+pm.max_spare_servers = 240
 pm.max_requests = 1000
index a38a97e7ae26037b2a1688596c03c66f54985a71..d6d48d15adeb4b00cd4a8f93ecbbc23112f898f7 100644 (file)
@@ -10,6 +10,8 @@ use Cubist\Backpack\Magic\Fields\Files;
 use Cubist\Util\CommandLine\Imagemagick;
 use Cubist\Util\Graphics\Image;
 use Fluidbook\Tools\SVG\SVGTools;
+use Illuminate\Database\UniqueConstraintViolationException;
+use Illuminate\Support\Facades\Cache;
 use Illuminate\Support\Facades\DB;
 use Mockery\Exception;
 use Spatie\MediaLibrary\MediaCollections\Models\Media;
@@ -45,39 +47,43 @@ class UpdateWS2ThemeTable extends Base
      */
     public function handle()
     {
-        $theme = new FluidbookTheme();
-
-        foreach ($theme->getFields() as $field) {
-            $name = $field->getAttribute('name');
-            $this->_allFields[] = $name;
-            if ($field instanceof Files) {
-                $this->_fileFields[] = $name;
-            } else if ($field instanceof Color) {
-                if ($field->getAttribute('allows_alpha')) {
-                    $this->_colorAlphaFields[] = $name;
-                } else {
-                    $this->_colorFields[] = $name;
+        $lock = Cache::lock('job_' . $this->uniqueId(), 10);
+        if ($lock->get()) {
+            $theme = new FluidbookTheme();
+
+            foreach ($theme->getFields() as $field) {
+                $name = $field->getAttribute('name');
+                $this->_allFields[] = $name;
+                if ($field instanceof Files) {
+                    $this->_fileFields[] = $name;
+                } else if ($field instanceof Color) {
+                    if ($field->getAttribute('allows_alpha')) {
+                        $this->_colorAlphaFields[] = $name;
+                    } else {
+                        $this->_colorFields[] = $name;
+                    }
                 }
             }
-        }
-        $this->_ignore = ['id', 'name', 'owner', 'created_at', 'deleted_at', 'updated_at', 'slug', 'signature'];
+            $this->_ignore = ['id', 'name', 'owner', 'created_at', 'deleted_at', 'updated_at', 'slug', 'signature'];
 
-        $data = [];
-        $t = DB::table('extranet_clean.ws3_themes');
-        if ($this->id === 'all') {
-            foreach (FluidbookTheme::where('created_ok', 1)->get() as $theme) {
+            $data = [];
+            $t = DB::table('extranet_clean.ws3_themes');
+            if ($this->id === 'all') {
+                foreach (FluidbookTheme::where('created_ok', 1)->get() as $theme) {
+                    $data[] = $this->_handleTheme($theme);
+                }
+                $t->truncate();
+            } else {
+                $theme = FluidbookTheme::find($this->id);
                 $data[] = $this->_handleTheme($theme);
+                $t->where('theme_id', '=', $this->id)->delete();
             }
-            $t->truncate();
-        } else {
-            $theme = FluidbookTheme::find($this->id);
-            $data[] = $this->_handleTheme($theme);
-            $t->where('theme_id', '=', $this->id)->delete();
-        }
-        try {
-            $t->insert($data);
-        } catch (Exception $e) {
+            try {
+                $t->insert($data);
+            } catch (Exception|UniqueConstraintViolationException $e) {
 
+            }
+            $lock->release();
         }
     }
 
index 9c9d7a97c393da4ae69e86f0b3b01f4f38e065fd..395201f2249a2fd811b4c9176fe447e269a879a6 100644 (file)
@@ -672,11 +672,12 @@ class FluidbookTheme extends ToolboxModel
         return self::$_colorToWS3Cache[$data];
     }
 
-    public function postSave()
+    public function onSaved(): bool
     {
-        parent::postSave();
+        $res = parent::onSaved();
         self::updateWS2Table($this->id);
         $this->_generateThemePreview();
+        return $res;
     }
 
     protected function _generateThemePreview($sync = false)
@@ -684,25 +685,19 @@ class FluidbookTheme extends ToolboxModel
         dispatch(new GenerateThemePreview($this))->onQueue('theme');
     }
 
-    public function postCreate()
-    {
-        parent::postCreate();
-        self::updateWS2Table($this->id);
-        $this->_generateThemePreview();
-    }
-
-    public function postDelete()
+    public function onDeleted(): bool
     {
-        parent::postDelete();
+        $res = parent::onDeleted();
         self::updateWS2Table();
+        return $res;
     }
 
     public static function updateWS2Table($id = null)
     {
+
         if (self::$updateWS2ViewOnChange) {
             if (null !== $id) {
-                $job = new UpdateWS2ThemeTable($id);
-                dispatch_sync($job);
+                dispatch_sync(new UpdateWS2ThemeTable($id));
             }
             dispatch(new UpdateWS2ThemeTable('all'))->onQueue('theme');
         }
index 33e1e5cea31486671947124be656bd8f31456840..4d1ecece7f1c0347616d6d5dcff306e4354fe982 100644 (file)
@@ -1,5 +1,6 @@
 #!/bin/sh
 chown root:root /home/toolbox/www/.docker/config/sudoers
+chown root:root /home/toolbox/www/.docker/config/cron/host
 chmod -R 755 /home/toolbox/www/scripts
 chmod -R 775 /home/toolbox/www/protected
 chmod -R 775 /home/toolbox/www/public