]> _ Git - fluidbook-toolbox.git/commitdiff
wait #7056 @2
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 28 Aug 2024 16:32:06 +0000 (18:32 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 28 Aug 2024 16:32:06 +0000 (18:32 +0200)
app/Http/Controllers/Admin/Operations/Tools/StaticSiteUploader.php
app/Jobs/WebflowPublish.php
app/Models/ToolWebflow.php

index 497ab47fbb1168ddb123bffb78a67e14e8762512..4d63e4f2aaccad2290a9539385cc650136f10f15 100644 (file)
@@ -59,13 +59,13 @@ trait StaticSiteUploader
         return redirect($site['url']);
     }
 
-    public static function rsync($from, $site)
+    public static function rsync($from, $site, $path = '')
     {
         if (is_string($site)) {
             $site = static::getSites()[$site];
         }
 
-        $dest = 'staticupload@' . $site['server'] . ':/home/staticupload/' . $site['id'];
+        $dest = 'staticupload@' . $site['server'] . ':/home/staticupload/' . $site['id'] . rtrim('/' . ltrim($path, '/'), '/');
         $rsync = new Rsync($from, $dest);
         $rsync->setMirror(true);
         $rsync->execute();
index f1f9505d1faff8193aedfa40737df5de179f3f41..b754472eaf37180496a4a3cb4d9d0adbf2a12c90 100644 (file)
@@ -33,6 +33,7 @@ class WebflowPublish extends Base
 
         $subject = __('Site :name publié', ['name' => $wf->name]);
         $notify = true;
+        $publishOn = 'dev';
         if ($this->mode === 'api') {
             $wf->getEditableData();
             $notify = false;
@@ -49,16 +50,20 @@ class WebflowPublish extends Base
             $text = __('Le site vient d\'être républié suite à une mise à jour de webflow');
         } else if ($this->mode === 'auto') {
             $text = __('Le site vient d\'être républié suite à une mise à jour des contenus');
+        } else if ($this->mode === 'production') {
+            $text = __('Le site vient d\'être républié en production');
+            $publishOn = 'production';
         } else {
             $text = __('Le site vient d\'être républié suite à une déclenchement manuel');
             $notify = false;
         }
 
-        $wf->compile();
+        $wf->compile($publishOn);
 
         $actions = [];
         foreach ($wf->getLocales() as $locale) {
-            $actions[__('Visiter [:locale]', ['locale' => $locale['locale']])] = 'https://' . $locale['url'];
+            $u = $publishOn === 'dev' ? $locale['url'] : $locale['prod'];
+            $actions[__('Visiter [:locale]', ['locale' => $locale['locale']])] = 'https://' . $u;
         }
         if ($notify && isset($text)) {
             if ($this->user === null) {
index 613ef425f8bdd4d54f42e50a9203d98ab409456c..33c0a5ef7188c55d6a750ef455801a5d9879c2a0 100644 (file)
@@ -57,7 +57,7 @@ class ToolWebflow extends ToolboxTranslatableModel
         $this->addField('publish_on_save', Checkbox::class, __('Publier le site lors de la modification de contenus'), ['default' => true, 'tab' => __('Paramètres')]);
         $this->addField('domains', Textarea::class, __('Domaines à télécharger'), ['translatable' => false, 'tab' => __('Paramètres')]);
         $this->addField('exclude_domains', Textarea::class, __('Domaines à exclure'), ['translatable' => false, 'tab' => __('Paramètres')]);
-        $this->addField('locales_domains', Table::class, __('Langues'), ['translatable' => false, 'columns' => ['locale' => __('Code langue'), 'url' => __('URL')], 'tab' => __('Paramètres')]);
+        $this->addField('locales_domains', Table::class, __('Langues'), ['translatable' => false, 'columns' => ['locale' => __('Code langue'), 'url' => __('URL de développement'), 'prod' => __('URL en production')], 'tab' => __('Paramètres')]);
         $this->addField('slack', Text::class, __('Notification slack'), ['translatable' => false, 'tab' => __('Paramètres')]);
         $s = StaticSiteUploader::getSites();
         $sites = [];
@@ -80,6 +80,15 @@ class ToolWebflow extends ToolboxTranslatableModel
 
     }
 
+    public function getLocaleData($code)
+    {
+        foreach ($this->getLocales() as $locale) {
+            if ($locale['locale'] === $code) {
+                return $locale;
+            }
+        }
+    }
+
     public function getLocales()
     {
         return Cache::get('webflow_' . $this->id . '_locales', []);
@@ -398,13 +407,13 @@ class ToolWebflow extends ToolboxTranslatableModel
         return $res;
     }
 
-    public function compile()
+    public function compile($env = "dev")
     {
         $this->_parsePages();
         foreach ($this->getLocales() as $locale) {
-            $this->compileLocale($locale['locale']);
+            $this->compileLocale($locale['locale'], $env);
         }
-        StaticSiteUploader::rsync(protected_path('webflow/final/' . $this->id), $this->upload);
+        StaticSiteUploader::rsync(protected_path('webflow/final/' . $this->id . '/' . $env), $this->upload, $env);
     }
 
     protected function getCustomCSS()
@@ -431,10 +440,10 @@ class ToolWebflow extends ToolboxTranslatableModel
         return Files::mkdir(protected_path('webflow/mirror/' . $this->id));
     }
 
-    protected function compileLocale($locale)
+    protected function compileLocale($locale, $env = 'dev')
     {
         $mirror = $this->getMirrorPath();
-        $path = Files::emptyDir(protected_path('webflow/final/' . $this->id . '/' . $locale));
+        $path = Files::emptyDir(protected_path('webflow/final/' . $this->id . '/' . $env . '/' . $locale));
         $rsync = new CommandLine\Rsync($mirror, $path, false);
         $rsync->addExclude('*.html');
         $rsync->execute();
@@ -455,13 +464,19 @@ class ToolWebflow extends ToolboxTranslatableModel
                 continue;
             }
             $relative = '/' . str_replace($mirror, '', $f->getPathname());
-            $this->compileHTMLFile($f, $relative, $path, $isMainLocale, $locale, $texts, $images, $seo, $urlmap);
+            $this->compileHTMLFile($f, $relative, $path, $isMainLocale, $locale, $texts, $images, $seo, $env);
         }
 
+        $domain = $this->getLocaleData($locale)[$env === 'dev' ? 'url' : 'prod'];
+
         // Redirections
         $htaccess = '<IfModule mod_rewrite.c>
     RewriteEngine On
     RewriteBase /
+
+    RewriteCond %{HTTP_HOST} !=' . $domain . '
+       RewriteRule ^(.*)$ https://' . $domain . '/$1 [R=301,L]
+
 ';
         foreach ($this->redirections as $redirection) {
             foreach ($seo as $s) {
@@ -481,7 +496,7 @@ class ToolWebflow extends ToolboxTranslatableModel
      * @param $locale string
      * @return void
      */
-    protected function compileHTMLFile($f, $relative, $dest, $isMainLocale, $locale, $texts, $images, $seo)
+    protected function compileHTMLFile($f, $relative, $dest, $isMainLocale, $locale, $texts, $images, $seo, $env = 'dev')
     {
 
         $urlmaps = $this->getURLMaps();
@@ -521,7 +536,8 @@ class ToolWebflow extends ToolboxTranslatableModel
                 continue;
             }
             $u = $urlmaps[$code][$origRelative] ?? $origRelative;
-            $localeURL .= 'var SWITCH_URL_' . $code . '="https://' . $l['url'] . $u . '";' . "\n";
+            $d = $l[$env === 'dev' ? 'url' : 'prod'];
+            $localeURL .= 'var SWITCH_URL_' . $code . '="https://' . $d . $u . '";' . "\n";
         }
         $localeURL .= "</script>";