From: Vincent Vanwaelscappel Date: Tue, 12 Mar 2024 07:40:08 +0000 (+0100) Subject: wip #6775 @0.75 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=06990b5f6975f7daeea72a1ea463f59582db6613;p=fluidbook-toolbox.git wip #6775 @0.75 --- diff --git a/app/Http/Controllers/Admin/Operations/Tools/WebflowOperation.php b/app/Http/Controllers/Admin/Operations/Tools/WebflowOperation.php index 5c7ea0391..13bd22263 100644 --- a/app/Http/Controllers/Admin/Operations/Tools/WebflowOperation.php +++ b/app/Http/Controllers/Admin/Operations/Tools/WebflowOperation.php @@ -4,9 +4,7 @@ namespace App\Http\Controllers\Admin\Operations\Tools; use App\Http\Middleware\CheckIfAdmin; use App\Http\Middleware\VerifyCsrfToken; -use App\Jobs\WebflowMirror; use App\Models\ToolWebflow; -use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Route; trait WebflowOperation @@ -14,7 +12,7 @@ trait WebflowOperation protected function setupWebflowRoutes($segment, $routeName, $controller) { Route::match(['get', 'post'], 'webhook/webflow/{id}', function ($id) { - ToolWebflow::withoutGlobalScopes()->find($id)->onPublish(); + ToolWebflow::withoutGlobalScopes()->find($id)->onPublish('webflow'); })->withoutMiddleware([VerifyCsrfToken::class, CheckIfAdmin::class]); } diff --git a/app/Jobs/WebflowPublish.php b/app/Jobs/WebflowPublish.php index ffd3f03ca..16e51156a 100644 --- a/app/Jobs/WebflowPublish.php +++ b/app/Jobs/WebflowPublish.php @@ -4,18 +4,52 @@ namespace App\Jobs; use App\Http\Controllers\Admin\Operations\Tools\StaticSiteUploader; use App\Models\ToolWebflow; +use App\Models\User; +use App\Notifications\ToolboxNotification; use App\Slack\Slack; class WebflowPublish extends Base { - public function __construct($id) + /** @var int */ + protected $id; + /** + * @var string + */ + protected $mode; + /** @var User */ + protected $user; + + public function __construct($id, $mode = 'manual', $user = null) { - /** @var ToolWebflow $wf */ - $wf = ToolWebflow::withoutGlobalScopes()->find($id); - $wf->mirror(false, true)->debug(); + $this->id = $id; + $this->mode = $mode; + $this->user = $user ?? backpack_user(); + } - StaticSiteUploader::rsync(protected_path('webflow/' . $id), $wf->upload); + public function handle() + { + /** @var ToolWebflow $wf */ + $wf = ToolWebflow::withoutGlobalScopes()->find($this->id); + $subject = __('Site :name publié', ['name' => $wf->name]); + if ($this->mode === 'webflow') { + $wf->mirror(false, true)->debug(); + $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 { + $text = __('Le site vient d\'être républié suite à une déclenchement manuel'); + } - Slack::send($wf->slack, __('Site publié'), __('Le site vient d\'être républié suite à une mise à jour de webflow ou manuellement'), ['Visiter' => $wf->getLocales()[0]['url']]); + StaticSiteUploader::rsync(protected_path('webflow/' . $this->id), $wf->upload); + $actions = []; + foreach ($wf->getLocales() as $locale) { + $actions[__('Visiter [:locale]', ['locale' => $locale['locale']])] = 'https://' . $locale['url']; + } + if ($this->user === null) { + Slack::send($wf->slack, $subject, $text, $actions, false); + } else { + $this->user->notify(new ToolboxNotification($subject, $text, $actions, true)); + } } + } diff --git a/app/Models/ToolWebflow.php b/app/Models/ToolWebflow.php index f9c1ef601..2b66c8c4a 100644 --- a/app/Models/ToolWebflow.php +++ b/app/Models/ToolWebflow.php @@ -55,9 +55,15 @@ class ToolWebflow extends ToolboxModel } - public function onPublish() + public function onPublish($mode = 'manual') { - WebflowPublish::dispatch($this->id); + WebflowPublish::dispatch($this->id, $mode); + } + + public function onSaved(): bool + { + $this->onPublish('auto'); + return parent::onSaved(); } /** @@ -117,6 +123,7 @@ class ToolWebflow extends ToolboxModel $locales = json_decode($locales, true); } Cache::put('webflow_' . $this->id . '_locales', $locales); + dddd($this->getLocales()); return parent::onRetrieved(); }