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
{
$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];
}
$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);
$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)
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;
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;
}
return new Local($this, '/mnt/sshfs/fluidbook/data/fluidbook/hosting/');
}
}
+
}
@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){