]> _ Git - fluidbook-toolbox.git/commitdiff
wip #5996 @0.25
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 15 Jun 2023 07:58:30 +0000 (09:58 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 15 Jun 2023 07:58:30 +0000 (09:58 +0200)
.docker/dev/docker-compose.yml
.docker/dev/update.sh
app/Console/Commands/ToolboxPrecache.php
app/Models/FluidbookTranslate.php

index e159931584740e9223c2aef2ea4535d2c496b431..89381c72cea194060f9809602acc8fea38a0bf32 100644 (file)
@@ -69,6 +69,7 @@ services:
     networks:
       - fluidbook-toolbox-dev
       - fluidbook-processfarm
+    privileged: true
     restart: unless-stopped
 
   webserver:
index 724bf3917f2d68ae8dec881768d071c5d2c2c0b3..7c00c55e6fdce38eaba2c6cdefc034b79823ca1b 100644 (file)
@@ -1,10 +1,10 @@
 #!/bin/sh
 cd /docker/fluidbook-toolbox-dev
-/home/toolbox/dev/scripts/fixrights.sh
+/home/toolbox/www/scripts/fixrights.sh
 chown root:root /home/toolbox/dev/.docker/config/cron/host;ln -sf /home/toolbox/dev/.docker/config/cron/host /etc/cron.d/toolbox
 docker network create fluidbook-toolbox-dev
 docker compose down
 docker compose up -d
-/home/toolbox/dev/scripts/fixrights.sh
+/home/toolbox/www/scripts/fixrights.sh
 docker exec -it fluidbook-toolbox /application/scripts/update.sh
 
index 14016e88aa461382e3b9f3d57927d2125a4d2d47..6216840054dda8df6013da08bee319e93226f097 100644 (file)
@@ -3,6 +3,7 @@
 namespace App\Console\Commands;
 
 use App\Fluidbook\Farm;
+use App\Models\FluidbookTranslate;
 use Cubedesigners\UserDatabase\Permissions;
 use Cubist\Backpack\Console\Commands\CubistCommand;
 
@@ -15,5 +16,6 @@ class ToolboxPrecache extends CubistCommand
     {
         // Users tree
         Permissions::_getData(true);
+        FluidbookTranslate::getAllFluidbookTranslations(true);
     }
 }
index 05fc6d1340df45655f1c8898e6612efb865bd76c..0f1ed68f96c6ccbde9c16c3bb65fa44d06273b2d 100644 (file)
@@ -11,6 +11,7 @@ use App\Models\Traits\FluidbookPlayerBranches;
 use Cubist\Backpack\Facades\App;
 use Cubist\Backpack\Magic\Models\Translate;
 use Cubist\Util\PHP;
+use Illuminate\Support\Facades\Cache;
 
 // __('!!Traduction des fluidbooks')
 class FluidbookTranslate extends Translate
@@ -75,35 +76,40 @@ class FluidbookTranslate extends Translate
         return resource_path('lang/fluidbook.' . $locale . '.json');
     }
 
-    /**
-     * @throws \JsonException
-     */
-    public static function getAllFluidbookTranslations()
+    public static function getAllFluidbookTranslations($force = false)
     {
-        start_measure('Get all fluidbook translations');
         if (null === self::$_allTranslations) {
-            $t = FluidbookTranslate::find(1);
-            try {
-                $json = json_decode($t->getRawOriginal('content_translatable'), true, 512, JSON_THROW_ON_ERROR);
-            } catch (\Exception $e) {
-                $json = [];
+            $cacheKey = 'all_fluidbook_translations';
+            if ($force) {
+                Cache::forget($cacheKey);
             }
+            self::$_allTranslations = Cache::remember($cacheKey, 3600, function () {
+                start_measure('Get all fluidbook translations !');
+                $t = FluidbookTranslate::find(1);
+                try {
+                    $json = json_decode($t->getRawOriginal('content_translatable'), true, 512, JSON_THROW_ON_ERROR);
+                } catch (\Exception $e) {
+                    $json = [];
+                }
 
-            self::$_allTranslations = [];
+                $res = [];
 
-            foreach ($json as $code => $tr) {
-                $res[$code] = [];
-                foreach ($tr as $k => $v) {
-                    self::$_allTranslations[$code][$k] = ['str' => self::keyToStr($k), 'translation' => $v];
+                foreach ($json as $code => $tr) {
+                    $res[$code] = [];
+                    foreach ($tr as $k => $v) {
+                        $res[$code][$k] = ['str' => self::keyToStr($k), 'translation' => $v];
+                    }
                 }
-            }
 
-            $nsis = json_decode($t->getRawOriginal('nsis'), true, 512, JSON_THROW_ON_ERROR);
-            foreach ($nsis as $code => $v) {
-                self::$_allTranslations[$code]['nsis'] = $v;
-            }
+                $nsis = json_decode($t->getRawOriginal('nsis'), true, 512, JSON_THROW_ON_ERROR);
+                foreach ($nsis as $code => $v) {
+                    $res[$code]['nsis'] = $v;
+                }
+                stop_measure('Get all fluidbook translations !');
+                return $res;
+
+            });
         }
-        stop_measure('Get all fluidbook translations');
         return self::$_allTranslations;
     }