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;
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];
$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)
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 = [])
$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());
} 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()
$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();
}
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;
}
/**
*/
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'];
}
/**
$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;
}
*/
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);
+ }
}
use App\Slack\Slack;
use Illuminate\Notifications\Notification;
+use Illuminate\Support\Facades\Log;
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']);
}
}