From: Vincent Vanwaelscappel Date: Wed, 25 Jan 2023 12:44:48 +0000 (+0100) Subject: wip #5661 @0.5 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=24607fd655540e85ed19bfac982a970987b2c819;p=fluidbook-toolbox.git wip #5661 @0.5 --- diff --git a/app/Console/Commands/FluidbookPackage.php b/app/Console/Commands/FluidbookPackage.php index c2e5bc570..b8281c1b5 100644 --- a/app/Console/Commands/FluidbookPackage.php +++ b/app/Console/Commands/FluidbookPackage.php @@ -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; diff --git a/app/Fluidbook/Packager/Download.php b/app/Fluidbook/Packager/Download.php index 547149651..5dca3e4eb 100644 --- a/app/Fluidbook/Packager/Download.php +++ b/app/Fluidbook/Packager/Download.php @@ -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);