From: Vincent Vanwaelscappel Date: Mon, 6 Feb 2023 15:52:29 +0000 (+0100) Subject: wip #5700 @2 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=835ca53c0d7f69cc7e637c4327c305c537405425;p=fluidbook-toolbox.git wip #5700 @2 --- diff --git a/app/Fluidbook/Packager/Download.php b/app/Fluidbook/Packager/Download.php index 70636d6e2..e2fe01d4d 100644 --- a/app/Fluidbook/Packager/Download.php +++ b/app/Fluidbook/Packager/Download.php @@ -3,11 +3,13 @@ namespace App\Fluidbook\Packager; use App\Jobs\DownloadBase; +use App\Models\FluidbookExternalInstallServer; use App\Services\ScormCloud; use Cubist\Util\CommandLine\Rsync; use Cubist\Util\Files\Files; use Cubist\Util\Text; use Illuminate\Support\Facades\Log; +use Monolog\Logger; class Download extends DownloadBase { @@ -70,6 +72,7 @@ class Download extends DownloadBase $url = $this->_compileandpackage(); $subject = __($this->_subject, ['title' => $this->_title(), 'nb' => $this->_id()]); $text = ''; + $actions = []; if ($this->action === 'download' || $this->action === 'scormcloud') { $actions = ['Télécharger' => $url]; @@ -82,36 +85,34 @@ class Download extends DownloadBase } $text = __('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')]); } - } else if ($this->action === 'install_hosting') { - $dest = self::_cleanInstallDir($this->entry->install_online_hosting); + } else if ($this->action === 'install') { + $s = $this->entry->install_online; + $dest = self::_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) { - throw new \Exception('No path defined for hosting installation'); + throw new \Exception('No path defined for external server installation'); } $subject = __($this->_installHostingSubject, ['title' => $this->_title(), 'nb' => $this->_id()]); $path = $this->_compileandpackage(false); - $rsync = new Rsync($path, '/mnt/sshfs/fluidbook/data/fluidbook/hosting/' . $dest . '/'); - $rsync->setMirror(false); - //$rsync->setDryRun(true); - $rsync->execute(); - //$rsync->dd(); - - $actions = ['Voir sur hosting' => 'https://hosting.fluidbook.com/' . $dest . '/']; + $driver = $server->getTransferDriver(); + $driver->copy($path, $dest, false, true); - } else if ($this->action === 'install_ftp') { - $dest = self::_cleanInstallDir($this->entry->install_online_ftp); - if (!$dest) { - throw new \Exception('No path defined for ftp installation'); + $url = $server->makeURL($dest); + if (null !== $url) { + $actions = [__('Voir sur :server', ['server' => $server->name]) => $url]; } - $subject = __($this->_installFTPSubject, ['title' => $this->_title(), 'nb' => $this->_id()]); - $path = $this->_compileandpackage(false); - $actions = []; } } 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()]); $actions = []; + Log::error($e); } $this->sendNotification($subject, $text, $actions); @@ -122,8 +123,7 @@ class Download extends DownloadBase $path = str_replace('/\.{2,}/', '', $path); $path = preg_replace('/\/{2,}/', '/', $path); $path = trim($path, '/'); - $path = Text::str2URL($path, '-', true); - return $path; + return Text::str2URL($path, '-', true); } protected function _compileandpackage($zip = true) diff --git a/app/Models/FluidbookDocument.php b/app/Models/FluidbookDocument.php index 18cc1cbc4..5c73078fb 100644 --- a/app/Models/FluidbookDocument.php +++ b/app/Models/FluidbookDocument.php @@ -41,7 +41,6 @@ class FluidbookDocument extends ToolboxModel { parent::setFields(); $this->addField('region', SelectFromArray::class, __('Région d\'hébergement des données'), ['options' => ['UE' => __('Union européenne'), 'US' => 'USA'], 'default' => 'UE', 'allows_null' => false, 'databaseDefault' => 'UE']); - $this->addField('file', Text::class); $this->addField('pages', Integer::class); $this->addOwnerField(); diff --git a/app/Models/FluidbookExternalInstallServer.php b/app/Models/FluidbookExternalInstallServer.php index caec2f7c0..2d6809ab2 100644 --- a/app/Models/FluidbookExternalInstallServer.php +++ b/app/Models/FluidbookExternalInstallServer.php @@ -2,6 +2,8 @@ namespace App\Models; +use Cubist\Backpack\Magic\Fields\Checkbox; +use Cubist\Backpack\Magic\Fields\Text; use Cubist\Backpack\Magic\Models\ExternalServer; use Cubist\Net\Transfer\Local; @@ -14,14 +16,26 @@ class FluidbookExternalInstallServer extends ExternalServer protected static $_permissionBase = 'fluidbook-external-install-server'; + + protected static function _getOneServer($server) + { + return array_merge(parent::_getOneServer($server), ['allows_root' => $server->allows_root]); + } + + public function setFields() + { + parent::setFields(); + $this->addField('allows_root', Checkbox::class, __('Autoriser le chargement à la racine (sur le chemin de base)'), ['default' => false]); + } + public function getProtocols() { return parent::getProtocols() + ['hosting' => 'Hosting']; } - public function getTransferDriver($protocol) + public function getTransferDriver() { - $res = parent::getTransferDriver($protocol); + $res = parent::getTransferDriver(); if (null !== $res) { return $res; } @@ -29,4 +43,5 @@ class FluidbookExternalInstallServer extends ExternalServer return new Local($this, '/mnt/sshfs/fluidbook/data/fluidbook/hosting/'); } } + } diff --git a/resources/views/vendor/backpack/crud/buttons/fluidbook_publication/download.blade.php b/resources/views/vendor/backpack/crud/buttons/fluidbook_publication/download.blade.php index fd133dc5a..852bc5e52 100644 --- a/resources/views/vendor/backpack/crud/buttons/fluidbook_publication/download.blade.php +++ b/resources/views/vendor/backpack/crud/buttons/fluidbook_publication/download.blade.php @@ -1,5 +1,7 @@ @php $allVersions=can('fluidbook-publication:download:all-versions'); + + $servers=\App\Models\FluidbookExternalInstallServer::getAllServers(); $base=$crud->route.'/'.$entry->id; $basePackage=$base.'/package'; $actions=[ @@ -18,20 +20,16 @@ ]; } } - if(can('fluibook-publication:download:install-hosting') && ($entry->install_online_hosting || $entry->install_online_ftp || $entry->scorm_enable)){ + if(can('fluibook-publication:download:install-hosting') && ($entry->install_online || $entry->scorm_enable)){ $actions['sep_install']='---------'; - if($entry->install_online_hosting){ - $actions['install_online_hosting']=[ - 'label'=>__('Installer sur le serveur d\'hébergement').' https://hosting.fluidbook.com/'.$entry->install_online_hosting.'', - 'url'=> $basePackage.'/install_hosting/online', - ]; - } - - if($entry->install_online_ftp){ - $actions['install_online_ftp']=[ - 'label'=>__('Installer sur un serveur FTP').' ftp://'.$entry->install_online_ftp.'', - 'url'=> $basePackage.'/install_ftp/online', - ]; + if($entry->install_online && $entry->install_online->server){ + $server=$servers[$entry->install_online->server]; + if($entry->install_online->path || $server['allows_root']){ + $actions['install_online']=[ + 'label'=>__('Installer sur le serveur :server',['server'=>''.$server['name'].'']).' '.$server['base_url'].''.$entry->install_online->path.'', + 'url'=> $basePackage.'/install/online', + ]; + } } if($entry->scorm_enable){