]> _ Git - fluidbook-toolbox.git/commitdiff
wip #5700 @2
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 6 Feb 2023 15:52:29 +0000 (16:52 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 6 Feb 2023 15:52:29 +0000 (16:52 +0100)
app/Fluidbook/Packager/Download.php
app/Models/FluidbookDocument.php
app/Models/FluidbookExternalInstallServer.php
resources/views/vendor/backpack/crud/buttons/fluidbook_publication/download.blade.php

index 70636d6e2c1c97902abf77ad78ae3469deb38801..e2fe01d4df1c9eb1e68da3692abd3435862529b1 100644 (file)
@@ -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)
index 18cc1cbc4d9ef7f13de83ec7a3c271373b13a6ed..5c73078fb0b6da545cafaba82cc8b770eec04eac 100644 (file)
@@ -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();
index caec2f7c0112553aca7943389c66bff4fe76e2a7..2d6809ab25df809db4da6b4d41ad64d62a257f99 100644 (file)
@@ -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/');
         }
     }
+
 }
index fd133dc5ac91303e559764c6ac53adf0524dc4de..852bc5e52e766627422ab64a00170df7f6cc951d 100644 (file)
@@ -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=[
                 ];
         }
     }
-    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').' <span class="small"><span class="grey">https://hosting.fluidbook.com/</span>'.$entry->install_online_hosting.'</span>',
-                'url'=> $basePackage.'/install_hosting/online',
-                ];
-        }
-
-        if($entry->install_online_ftp){
-            $actions['install_online_ftp']=[
-                'label'=>__('Installer sur un serveur FTP').' <span class="small"><span class="grey">ftp://</span>'.$entry->install_online_ftp.'</span>',
-                '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'=>'<strong>'.$server['name'].'</strong>']).' <span class="small"><span class="grey">'.$server['base_url'].'</span>'.$entry->install_online->path.'</span>',
+                    'url'=> $basePackage.'/install/online',
+                    ];
+            }
         }
 
         if($entry->scorm_enable){