]> _ Git - fluidbook-toolbox.git/commitdiff
wip #5835 @0.5
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 28 Mar 2023 18:54:14 +0000 (20:54 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 28 Mar 2023 18:54:14 +0000 (20:54 +0200)
app/Fluidbook/Packager/Download.php
app/Jobs/DownloadBase.php
app/Jobs/FluidbookCollectionDownload.php
app/Notifications/DownloadReady.php
app/Notifications/FluidbookslackChannel.php

index 02a7c71d49b5f6e64fbc1d384f8b44f11c524909..dd0cbca951c58fbda376e659c7e8d79867f17ab4 100644 (file)
@@ -5,6 +5,7 @@ namespace App\Fluidbook\Packager;
 use App\Jobs\DownloadBase;
 use App\Models\FluidbookExternalInstallServer;
 use App\Services\ScormCloud;
+use Cubist\Backpack\Facades\App;
 use Cubist\Util\CommandLine\Rsync;
 use Cubist\Util\Files\Files;
 use Cubist\Util\Text;
@@ -75,12 +76,14 @@ class Download extends DownloadBase
 
     public function handle()
     {
+        App::setLocale($this->user->preferredLocale());
         try {
             $url = $this->_compileandpackage();
             $translateVariables = ['title' => $this->_title(), 'nb' => $this->_id()];
 
             $subject = __($this->_subject, $translateVariables);
             $text = __($this->_text, $translateVariables);
+            $showTextIfNotEmail = false;
             $actions = [];
             if ($this->action === 'download' || $this->action === 'scormcloud') {
                 $actions = ['Télécharger' => $url];
@@ -124,10 +127,11 @@ class Download extends DownloadBase
             $subject = __('Erreur lors de la compilation du :type :nb', ['nb' => $this->_id(), 'type' => $this->type]);
             $text = __('Détails de l\'erreur :message', ['message' => $e->getMessage() . ' at line ' . $e->getLine() . ' of ' . $e->getFile()]);
             $actions = [];
+            $showTextIfNotEmail = true;
             Log::error($e);
         }
 
-        $this->sendNotification($subject, $text, $actions);
+        $this->sendNotification($subject, $text, $actions, $showTextIfNotEmail);
     }
 
     protected static function _cleanInstallDir($path)
index 51ba610383bd19597c43dbdc26a1364568d4f10f..28015d768c8c907150f7ab66a81c3246bdf0dc88 100644 (file)
@@ -54,19 +54,17 @@ class DownloadBase extends Base
 
     public function sendNotification($subject, $text, $actions = [])
     {
-        if ($this->getUser()->id == 5) {
-            $this->getUser()->notify(new DownloadReady($subject, $text, $actions));
-            return;
-        }
-
-        if ($this->getUser()->slack) {
-            if ($this->sendSlack($subject, $text, $actions)) {
-                return;
-            }
-        }
-
-        // Fallback email if
-        $this->sendEmail($subject, $text, $actions);
+        $this->getUser()->notify(new DownloadReady($subject, $text, $actions));
+//
+//
+//        if ($this->getUser()->slack) {
+//            if ($this->sendSlack($subject, $text, $actions)) {
+//                return;
+//            }
+//        }
+//
+//        // Fallback email if
+//        $this->sendEmail($subject, $text, $actions);
     }
 
     public function sendSlack($subject, $text, $actions = [])
@@ -131,6 +129,7 @@ class DownloadBase extends Base
             $subject = __($this->_subject, $translateVariables);
             $text = __($this->_text, $translateVariables);
             $actions = [__('Télécharger') => $url];
+            $showTextIfNotEmail = false;
             try {
                 if ($this->action === 'scormcloud') {
                     $scormURL = ScormCloud::send($url, 'toolbox_' . $this->type . '_' . $this->_id());
@@ -142,10 +141,11 @@ class DownloadBase extends Base
         } catch (\Exception $e) {
             $subject = __('Erreur lors de la compilation du :type :nb', ['nb' => $this->_id(), 'type' => $this->type]);
             $text = __('Détails de l\'erreur :message', ['message' => $e->getMessage() . ' at line ' . $e->getLine() . ' of ' . $e->getFile()]);
+            $showTextIfNotEmail = true;
             $actions = [];
         }
 
-        $this->sendNotification($subject, $text, $actions);
+        $this->sendNotification($subject, $text, $actions, $showTextIfNotEmail);
     }
 
     protected function _getTranslateVariables()
index 7bdb873d25314547eb109032b6dd8b0ff6eb5ac4..7713aada99312a79c7367376e1826846040c7819 100644 (file)
@@ -30,7 +30,7 @@ class FluidbookCollectionDownload extends DownloadBase
             $this->sendNotification(__('Collection ":title" (#:nb) installée sur le serveur hosting', $translateVariables), '', $url);
         } else if ($this->action === 'export' && in_array($this->entry->version, ['win_inss_html', 'win_ins_html'])) {
             $url = $this->downloadList($this->entry->getPageData());
-            $this->sendNotification(__($this->_subject, $translateVariables), __($this->_text,$translateVariables), $url);
+            $this->sendNotification(__($this->_subject, $translateVariables), __($this->_text, $translateVariables), $url);
         } else {
             parent::handle();
         }
index 34e8f4189172673552a572ceb42d08e4d0323dac..0ca9018c72f127c5d1739000db942b09d1b002f2 100644 (file)
@@ -15,18 +15,19 @@ class DownloadReady extends Notification
     protected $text;
     protected $actions = [];
     protected $error = false;
+    protected $showTextIfNotEmail = false;
 
     /**
      * Create a new notification instance.
      *
      * @return void
      */
-    public function __construct($subject = '', $text = '', $actions = [], $error = false)
+    public function __construct($subject = '', $text = '', $actions = [], $showTextIfNotEmail = false)
     {
         $this->subject = $subject;
         $this->text = $text;
         $this->actions = $actions;
-        $this->error = $error;
+        $this->showTextIfNotEmail = $showTextIfNotEmail;
     }
 
     /**
@@ -37,12 +38,13 @@ class DownloadReady extends Notification
      */
     public function via($notifiable)
     {
-        return ['database', 'mail'];
         if ($notifiable->slack) {
+            if ($notifiable->id == 5) {
+                return ['database', FluidbookslackChannel::class, 'mail'];
+            }
             return ['database', FluidbookslackChannel::class];
-        } else {
-            return ['database', 'mail'];
         }
+        return ['database', 'mail'];
     }
 
     /**
@@ -62,11 +64,6 @@ class DownloadReady extends Notification
             $m->line(new HtmlString($label . __(': ') . ' <a href="' . $url . '">' . $url . '</a>'));
         }
         $m->salutation(new HtmlString(__('Cordialement,') . "<br>" . __('L\'équipe Fluidbook')));
-        if ($this->error) {
-            $m->error();
-        } else {
-            $m->success();
-        }
         return $m;
 
     }
@@ -79,10 +76,25 @@ class DownloadReady extends Notification
      */
     public function toArray($notifiable)
     {
+
         return [
             'subject' => $this->subject,
             'text' => $this->text,
             'actions' => $this->actions,
         ];
     }
+
+    public function toSlack($notifiable)
+    {
+        return [
+            'subject' => $this->subject,
+            'text' => $this->showTextIfNotEmail ? $this->text : '',
+            'actions' => $this->actions,
+        ];
+    }
+
+    public function toDatabase($notifiable)
+    {
+        return $this->toSlack($notifiable);
+    }
 }
index 0fa714e06ab68f3f53a53e0fe820fcf40bd58b87..34b94a842f4751fa988a31c595887bb5f4269ce7 100644 (file)
@@ -4,6 +4,7 @@ namespace App\Notifications;
 
 use App\Slack\Slack;
 use Illuminate\Notifications\Notification;
+use Illuminate\Support\Facades\Log;
 
 class FluidbookslackChannel
 {
@@ -16,7 +17,7 @@ class FluidbookslackChannel
      */
     public function send($notifiable, Notification $notification)
     {
-        $message = $notification->toArray($notifiable);
+        $message = $notification->toSlack($notifiable);
         Slack::send($notifiable->slack, $message['subject'], $message['text'], $message['actions']);
     }
 }