From 248550ed6ffea878c01809af23130bade97d6ae0 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Wed, 28 Aug 2024 18:32:06 +0200 Subject: [PATCH] wait #7056 @2 --- .../Operations/Tools/StaticSiteUploader.php | 4 +-- app/Jobs/WebflowPublish.php | 9 +++-- app/Models/ToolWebflow.php | 34 ++++++++++++++----- 3 files changed, 34 insertions(+), 13 deletions(-) diff --git a/app/Http/Controllers/Admin/Operations/Tools/StaticSiteUploader.php b/app/Http/Controllers/Admin/Operations/Tools/StaticSiteUploader.php index 497ab47fb..4d63e4f2a 100644 --- a/app/Http/Controllers/Admin/Operations/Tools/StaticSiteUploader.php +++ b/app/Http/Controllers/Admin/Operations/Tools/StaticSiteUploader.php @@ -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(); diff --git a/app/Jobs/WebflowPublish.php b/app/Jobs/WebflowPublish.php index f1f9505d1..b754472ea 100644 --- a/app/Jobs/WebflowPublish.php +++ b/app/Jobs/WebflowPublish.php @@ -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) { diff --git a/app/Models/ToolWebflow.php b/app/Models/ToolWebflow.php index 613ef425f..33c0a5ef7 100644 --- a/app/Models/ToolWebflow.php +++ b/app/Models/ToolWebflow.php @@ -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 = ' 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 .= ""; -- 2.39.5