]> _ Git - fluidbook-toolbox.git/commitdiff
wip #5661 @0.5
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 25 Jan 2023 12:44:48 +0000 (13:44 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 25 Jan 2023 12:44:48 +0000 (13:44 +0100)
app/Console/Commands/FluidbookPackage.php
app/Fluidbook/Packager/Download.php

index c2e5bc570a2621f010b52489871fa227a12bb2b0..b8281c1b58766299c7f1e44263af1def11af7099 100644 (file)
@@ -3,7 +3,6 @@
 namespace App\Console\Commands;
 
 use App\Fluidbook\Packager\Download;
-use App\Fluidbook\Packager\Packager;
 use App\Models\FluidbookPublication;
 use App\Models\User;
 use Cubist\Backpack\Console\Commands\CubistCommand;
index 547149651c73a73b5ed55c2374b3443568153257..5dca3e4ebbdc712e61cb6d140804d63b4c56be61 100644 (file)
@@ -4,7 +4,9 @@ namespace App\Fluidbook\Packager;
 
 use App\Jobs\DownloadBase;
 use App\Services\ScormCloud;
+use Cubist\Util\CommandLine\Rsync;
 use Cubist\Util\Files\Files;
+use Cubist\Util\Text;
 use Illuminate\Support\Facades\Log;
 
 class Download extends DownloadBase
@@ -13,8 +15,10 @@ class Download extends DownloadBase
     protected $version = 'online';
 
     protected $type = 'Fluidbook';
-    // __('Fluidbppl ":title" (#:nb) prêt au téléchargement')
+    // __('Fluidbook ":title" (#:nb) prêt au téléchargement')
     protected $_subject = 'Fluidbook ":title" (#:nb) prêt au téléchargement';
+    // __('Fluidbook ":title" (#:nb) installé sur hosting')
+    protected $_installHostingSubject = 'Fluidbook ":title" (#:nb) installé sur hosting';
 
     public function __construct($entry, $version, $action, $user)
     {
@@ -77,8 +81,21 @@ 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);
+                if (!$dest) {
+                    throw new \Exception('No path defined for hosting installation');
+                }
+                $subject = __($this->_installHostingSubject, ['title' => $this->_title(), 'nb' => $this->_id()]);
                 $path = $this->_compileandpackage(false);
-                dd($path);
+
+                $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 . '/'];
+
             } else if ($this->action === 'install_ftp') {
 
             }
@@ -91,6 +108,15 @@ class Download extends DownloadBase
         $this->sendNotification($subject, $text, $actions);
     }
 
+    protected static function _cleanInstallDir($path)
+    {
+        $path = str_replace('/\.{2,}/', '', $path);
+        $path = preg_replace('/\/{2,}/', '/', $path);
+        $path = trim($path, '/');
+        $path = Text::str2URL($path, '-', true);
+        return $path;
+    }
+
     protected function _compileandpackage($zip = true)
     {
         $packager = Packager::package($this->entry->id, $this->version, $zip);