From 3ee30cb1d961bfd9efd7b59443926947faee5cbd Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Tue, 1 Oct 2024 19:04:53 +0200 Subject: [PATCH] wip #7112 @0.5 --- app/Fluidbook/Compiler/Compiler.php | 3 + app/Fluidbook/Packager/Download.php | 115 +++++++++--------- .../DownloadOperation.php | 1 - app/Models/Traits/PublicationSettings.php | 1 + 4 files changed, 63 insertions(+), 57 deletions(-) diff --git a/app/Fluidbook/Compiler/Compiler.php b/app/Fluidbook/Compiler/Compiler.php index aef9062f6..5ff82878d 100644 --- a/app/Fluidbook/Compiler/Compiler.php +++ b/app/Fluidbook/Compiler/Compiler.php @@ -1503,6 +1503,9 @@ class Compiler extends Base implements CompilerInterface, IVirtualDirectoryError } } + // Loadbalancer + $this->config->hosting_loadbalancer_ignore = Text::explodeNewLines($this->config->hosting_loadbalancer_ignore); + $this->config->content_lock = $this->content_lock; } diff --git a/app/Fluidbook/Packager/Download.php b/app/Fluidbook/Packager/Download.php index 914ea6549..cc92348a9 100644 --- a/app/Fluidbook/Packager/Download.php +++ b/app/Fluidbook/Packager/Download.php @@ -91,66 +91,69 @@ class Download extends DownloadBase { App::setLocale($this->user->preferredLocale()); $res = []; - // 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]; - $res[] = $url; - - if ($this->action === 'scormcloud') { - try { - $scormURL = ScormCloud::send($url, env('SCORM_CLOUD_PREFIX', 'toolbox_') . $this->type . '_' . $this->_id()); - $actions[__('Tester sur SCORM Cloud')] = $scormURL; - $res[] = $url; - } catch (\Exception $e) { - Log::error($e); - $text .= "\n\n" . __('Une erreur s\'est produite lors de l\'envoi sur SCORM Cloud (App ID :appid) : :error', ['error' => $e->getMessage(), 'appid' => env('SCORM_CLOUD_APP_ID')]); - $showTextIfNotEmail = true; - } - } - } else if ($this->action === 'install') { - $s = $this->entry->install_online; - $dest = Driver::cleanInstallDir($s['path']); - /** @var FluidbookExternalInstallServer $server */ - $server = FluidbookExternalInstallServer::find($s['server']); - if (!$server) { - throw new \Exception('No valid server defined for external installation'); - } - if (!$dest && !$server->allows_root) { - throw new \Exception('No path defined for external server installation : this server does not allow installing on root'); + // 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]; + $res[] = $url; + + if ($this->action === 'scormcloud') { + try { + $scormURL = ScormCloud::send($url, env('SCORM_CLOUD_PREFIX', 'toolbox_') . $this->type . '_' . $this->_id()); + $actions[__('Tester sur SCORM Cloud')] = $scormURL; + $res[] = $url; + } catch (\Exception $e) { + Log::error($e); + $text .= "\n\n" . __('Une erreur s\'est produite lors de l\'envoi sur SCORM Cloud (App ID :appid) : :error', ['error' => $e->getMessage(), 'appid' => env('SCORM_CLOUD_APP_ID')]); + $showTextIfNotEmail = true; } + } + } else if ($this->action === 'install') { + $s = $this->entry->install_online; + $dest = Driver::cleanInstallDir($s['path']); + /** @var FluidbookExternalInstallServer $server */ + $server = FluidbookExternalInstallServer::find($s['server']); + if (!$server) { + throw new \Exception('No valid server defined for external installation'); + } + if (!$dest && !$server->allows_root) { + throw new \Exception('No path defined for external server installation : this server does not allow installing on root'); + } - $translateVariables['server'] = $server->name; - $subject = __($this->_installSubject, $translateVariables); - $text = __($this->_installText, $translateVariables); - $path = $this->_compileandpackage(false); + $translateVariables['server'] = $server->name; + $subject = __($this->_installSubject, $translateVariables); + $text = __($this->_installText, $translateVariables); + $path = $this->_compileandpackage(false); - /** @var Local $driver */ - $driver = $server->getTransferDriver(); - $driver->copy($path, $dest, false, false); + /** @var Local $driver */ + $driver = $server->getTransferDriver(); + $driver->copy($path, $dest, false, false); - $url = $server->makeURL($dest); - if (null !== $url) { - $actions = [__('Voir sur :server', ['server' => $server->name]) => $url]; - } - $res[] = $url; - } else if ($this->action === 'loadbalancer') { - $path = $this->_compileandpackage(false); - $dest = $this->entry->protected_path('fluidbookpublication/loadbalancer/' . $this->entry->id . '_' . $this->entry->hash . '/'); + $url = $server->makeURL($dest); + if (null !== $url) { + $actions = [__('Voir sur :server', ['server' => $server->name]) => $url]; + } + $res[] = $url; + if ($this->entry->hosting_loadbalancer) { + Download::dispatch($this->entry, $this->version, 'loadbalancer', $this->user, $this->_params); + } + } else if ($this->action === 'loadbalancer') { + $path = $this->_compileandpackage(false); + $dest = $this->entry->protected_path('fluidbookpublication/loadbalancer/' . $this->entry->id . '_' . $this->entry->hash . '/'); - $rsync = new Rsync($path, $dest, true); - $rsync->execute(); - $rsync->debug(); + $rsync = new Rsync($path, $dest, true); + $rsync->execute(); + $rsync->debug(); - $subject = __($this->_loadbalancerSubject, $translateVariables); - $text = __($this->_loadbalancerText, $translateVariables); - } + $subject = __($this->_loadbalancerSubject, $translateVariables); + $text = __($this->_loadbalancerText, $translateVariables); + } // } 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()]); @@ -167,8 +170,8 @@ class Download extends DownloadBase protected function _compileandpackage($zip = true) { - // if ($this->entry->version == 3) { - $packager = Packager::package($this->entry->id, $this->version, $zip, true, $this->_params); + // if ($this->entry->version == 3) { + $packager = Packager::package($this->entry->id, $this->version, $zip, true, $this->_params); // } else { // $packager = new WorkshopPackager($this->entry->id, $this->version, null, $this->_params); // $packager->zipPackage = $zip; diff --git a/app/Http/Controllers/Admin/Operations/FluidbookPublication/DownloadOperation.php b/app/Http/Controllers/Admin/Operations/FluidbookPublication/DownloadOperation.php index 38b61ead3..64e1079ab 100644 --- a/app/Http/Controllers/Admin/Operations/FluidbookPublication/DownloadOperation.php +++ b/app/Http/Controllers/Admin/Operations/FluidbookPublication/DownloadOperation.php @@ -4,7 +4,6 @@ namespace App\Http\Controllers\Admin\Operations\FluidbookPublication; use App\Fluidbook\Packager\Download; use App\Http\Middleware\CheckIfAdmin; -use App\Jobs\FluidbookSettingsExport; use App\Jobs\GenerateDeliveryThumbnailsPreview; use App\Models\FluidbookPublication; use Cubist\Backpack\Http\Controllers\Base\XSendFileController; diff --git a/app/Models/Traits/PublicationSettings.php b/app/Models/Traits/PublicationSettings.php index a049f478e..0c0de8422 100644 --- a/app/Models/Traits/PublicationSettings.php +++ b/app/Models/Traits/PublicationSettings.php @@ -1995,6 +1995,7 @@ trait PublicationSettings $this->addSettingField('section_downloads', FormSection::class, $this->__('Versions disponibles au téléchargement')); $this->addSettingField('hosting_loadbalancer', Checkbox::class, $this->__('Hébergement "Load balancer"')); + $this->addSettingField('hosting_loadbalancer_ignore', Textarea::class, __('Ne pas charger ces éléments via le load balancer'), ['when' => ['hosting_loadbalancer' => 1], 'hint' => __('Certains contenus doivent accéder ne doivent pas se trouver sur un autre domaine pour fonctionner')]); foreach (self::getDownloadVersions() as $name => $downloadVersion) { $this->addSettingField('download_' . $name, Checkbox::class, $downloadVersion['label'], [ -- 2.39.5