]> _ Git - fluidbook-toolbox.git/commitdiff
wip #5661 @3
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 25 Jan 2023 12:24:05 +0000 (13:24 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 25 Jan 2023 12:24:05 +0000 (13:24 +0100)
app/Console/Commands/FluidbookPackage.php
app/Console/Commands/FluidbookQuote.php
app/Fluidbook/Packager/Download.php
app/Fluidbook/Packager/WindowsZIP.php
app/Http/Controllers/Admin/Operations/FluidbookPublication/DownloadOperation.php
app/Models/Traits/PublicationSettings.php

index 441631da3e2cc593578b38fa3ec14aab96031dd0..c2e5bc570a2621f010b52489871fa227a12bb2b0 100644 (file)
@@ -2,12 +2,15 @@
 
 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;
 
 class FluidbookPackage extends CubistCommand
 {
-    protected $signature = 'fluidbook:package {id} {type} {--zip}';
+    protected $signature = 'fluidbook:package {id} {type=online} {action=download} {--zip}';
     protected $description = 'Compile a fluidbook';
 
     /**
@@ -15,7 +18,7 @@ class FluidbookPackage extends CubistCommand
      */
     public function handle()
     {
-        $packager = Packager::package($this->argument('id'), $this->argument('type'), $this->option('zip', false));
-        $packager->handle();
+        $download = new Download(FluidbookPublication::find($this->argument('id')), $this->argument('type'), $this->argument('action'), User::withoutGlobalScope('ownerclause')->findOrFail(5));
+        $download->handle();
     }
 }
index af4973afcf49d2839d6c8e4da3ae51723d70f085..cb124882ffbe1872be2e453bc3408689c3e1accd 100644 (file)
@@ -32,7 +32,5 @@ class FluidbookQuote extends CubistCommand
                 false,
             );
         }
-
-
     }
 }
index 1e98be2f542b36d1642b583ff11438eccd9418bb..547149651c73a73b5ed55c2374b3443568153257 100644 (file)
@@ -76,6 +76,11 @@ 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') {
+                $path = $this->_compileandpackage(false);
+                dd($path);
+            } else if ($this->action === 'install_ftp') {
+
             }
         } catch (\Exception $e) {
             $subject = __('Erreur lors de la compilation du :type :nb', ['nb' => $this->_id(), 'type' => $this->type]);
@@ -86,11 +91,8 @@ class Download extends DownloadBase
         $this->sendNotification($subject, $text, $actions);
     }
 
-    protected function _compileandpackage()
+    protected function _compileandpackage($zip = true)
     {
-        if ($this->action === 'download' || $this->action === '') {
-            $zip = true;
-        }
         $packager = Packager::package($this->entry->id, $this->version, $zip);
         $packager->makePackage($zip);
         $url = $packager->getFinalURL();
index cfe1fd16ccd6cb5a66d75d35569f09c2c2e22a04..726c632ee4ed79cde34f5621097f3cac654e5aff 100644 (file)
@@ -20,7 +20,7 @@ class WindowsZIP extends Packager
     protected $exenameMaxlength = 30;
     protected $_compileOnConstruct = true;
     protected $packageIconExt = 'ico';
-    protected $nwbuildVersion = '4.0.7';
+    protected $nwbuildVersion = '4.0.8';
     protected $nwCacheDir;
 
     protected $_ext = 'html';
@@ -75,16 +75,12 @@ class WindowsZIP extends Packager
         $this->makeJSON();
         `umask 0000;sudo rm -rf $this->buildPath;mkdir -p 0777 $this->buildPath;chmod -R 777 $this->vdir;mkdir -p 0777 /application/tmp;chmod -R 777 /application/tmp`;
 
-        if (version_compare($this->nwbuildVersion, 4, '<')) {
-            $cl = $this->_nwbuilder3();
-        } else {
-            $cl = $this->_nwbuilder4();
-        }
+        $cl = $this->_nwbuilder4();
 
         `sudo chown -R 1001:33 $this->buildPath`;
 
         if (!$this->nwBuildOK()) {
-            throw new \Exception('Error while making exe : ' . $cl->commande . ' // ' . $cl->output);
+            throw new \Exception('Error while making exe : ' . $cl->getCommand() . ' // ' . $cl->getOutput());
         }
     }
 
@@ -96,31 +92,6 @@ class WindowsZIP extends Packager
         return file_exists($this->buildPath);
     }
 
-    /**
-     * @return CommandLine
-     */
-    protected function _nwbuilder3()
-    {
-        $platform = $this->getNWbuilder3Platform();
-
-        $cl = new CommandLine('nwbuild');
-        $cl->setArg(null, $this->vdir . '**');
-        $cl->setLongArgumentSeparator(' ');
-        $cl->setArg('platforms', $platform);
-        $cl->setArg('buildDir', $this->buildPath);
-        $cl->setArg('version', $this->nwversion);
-        $cl->setArg('mode', 'build');
-        $cl->setArg('flavor', 'normal');
-        if ($this->nwplatform === 'win') {
-            $cl->setArg('winIco', $this->vdir . 'icon.ico');
-            $cl->setArg('useRcedit', 'true');
-        } elseif ($this->nwplatform === 'osx') {
-            $cl->setArg('macIcns', $this->vdir . 'icon.icns');
-        }
-        $cl->execute();
-        return $cl;
-    }
-
     /**
      * @return CommandLine
      */
@@ -135,6 +106,7 @@ class WindowsZIP extends Packager
         $cl->setArg('version', $this->nwversion);
         $cl->setArg('arch', $this->arch);
         $cl->execute();
+        $cl->debug();
         return $cl;
     }
 
@@ -160,23 +132,26 @@ class WindowsZIP extends Packager
     function _sign($source, $symbolicLink = false)
     {
         $rand = 'sign-' . hash_file('sha256', $source) . '.exe';
-        $distant = 'C:/Sign/' . $rand;
+        $remote = 'C:/Sign/' . $rand;
         $local = protected_path('signedexe/' . $rand);
         if (!file_exists($local)) {
             $ssh = new SSH2('paris.cubedesigners.com', 'vince', 'Y@mUC9mY2DOYWXkN', '22422');
-            $ssh->send($source, $distant);
+            $ssh->send($source, $remote);
             unlink($source);
+            if (!$ssh->file_exists($remote)) {
+                throw new \Exception("An error occured when sending exe to signing machine");
+            }
 
             $cli = new CommandLine('C:/Program Files (x86)/Windows Kits/10/bin/10.0.18362.0/x64/signtool.exe');
             $cli->setManualArg("sign /f C:/Users/vince/Documents/Cubedesigners.cer /csp \"eToken Base Cryptographic Provider\" /k \"[SafeNet Token JC 0{{TYWjZacq%hAH98}}]=54C3F1B91759268A\" /tr http://timestamp.sectigo.com /td sha256 /fd sha256 /a C:/Sign/$rand");
             $cli->execute($ssh);
             if (!stristr($cli->getOutput(), 'Successfully signed')) {
-                unlink($distant);
-                throw new \Exception('Error while signing exe ' . $rand . ' : ' . $cli->getOutput());
+                $ssh->unlink($remote);
+                throw new \Exception('Error while signing exe ' . $rand . ' : ' . $cli->getCommand() . ' /// ' . $cli->getOutput());
             }
 
-            $ssh->recv($distant, $local);
-            $ssh->unlink($distant);
+            $ssh->recv($remote, $local);
+            $ssh->unlink($remote);
             sleep(2);
         }
         if ($symbolicLink) {
@@ -196,10 +171,17 @@ class WindowsZIP extends Packager
      */
     function makeJSON()
     {
+        $app = [
+            'name' => $this->appName,
+            'icon' => $this->vdir . 'icon.' . $this->packageIconExt,
+            'version' => '1.0.' . $this->_time,
+        ];
+
         $data = ['app_name' => $this->appName,
             'main' => 'index.html',
             'name' => $this->exeName,
             'version' => '1.0.' . $this->_time,
+            'icon' => $this->vdir . 'icon.' . $this->packageIconExt,
             'webkit' => [],
             'window' => [
                 'height' => 768,
@@ -208,6 +190,7 @@ class WindowsZIP extends Packager
                 'id' => 'main',
                 'icon' => 'icon.png',
             ],
+            'app' => $app,
             'nwbuild' => [
                 'platform' => $this->nwplatform,
                 'outDir' => $this->buildPath,
@@ -215,10 +198,7 @@ class WindowsZIP extends Packager
                 'flavour' => 'normal',
                 'version' => $this->nwversion,
                 'arch' => $this->arch,
-                'app' => [
-                    'name' => $this->appName,
-                    'icon' => $this->vdir . 'icon.' . $this->packageIconExt,
-                ],
+                'app' => $app,
             ],
             'dependencies' =>
                 [
@@ -251,11 +231,7 @@ class WindowsZIP extends Packager
 
     public function getFinalPackageDir()
     {
-        if ($this->nwbuildVersion === 3) {
-            return $this->buildPath . '/' . $this->exeName . '/' . $this->getNWBuilder3Platform();
-        } else {
-            return $this->buildPath;
-        }
+        return $this->buildPath;
     }
 
     protected function compile($forceCompile = false)
index 6318db3bb4706cb8a88d2cebf773280d20f07abd..9acca98b1f15ca7c9703d30eeb59e62ab0305ee9 100644 (file)
@@ -61,7 +61,7 @@ trait DownloadOperation
             abort(401, __('Cette version n\'est pas disponible au téléchargement'));
         }
 
-        Download::dispatch($fluidbook, $version, $action, backpack_user())->onQueue('download');;
+        Download::dispatch($fluidbook, $version, $action, backpack_user())->onQueue('download');
         Alert::add('success', __('La compilation a été placée en file d\'attente. Vous recevrez un email lorsqu\'elle sera terminée.'))->flash();
         return redirect(backpack_url('fluidbook-publication'));
     }
index 88b9b76ef90ce1f50ee3dd462e119bb4d090d6f3..e40fec30fd2cca5df8e2465d7e60fb8004908f72 100644 (file)
@@ -16,6 +16,7 @@ use Cubist\Backpack\Magic\Fields\LongText;
 use Cubist\Backpack\Magic\Fields\Number;
 use Cubist\Backpack\Magic\Fields\ReadOnlyValue;
 use Cubist\Backpack\Magic\Fields\SelectFromArray;
+use Cubist\Backpack\Magic\Fields\Text;
 use Cubist\Backpack\Magic\Fields\Textarea;
 
 /**
@@ -30,16 +31,16 @@ trait PublicationSettings
     public static function getDownloadVersions()
     {
         return [
-            'online' => ['label' => __('Version online - Version par défaut'), 'default' => true],
-            'sharepoint' => ['label' => __('Version Sharepoint - Version par défaut'), 'default' => false],
-            'scorm' => ['label' => __('Version SCORM - Version par défaut'), 'default' => false],
-            'win_inss_html' => ['label' => __('Version offline - Executable Windows'), 'default' => false],
-            'win_ins_html' => ['label' => __('Version offline - Installeur Auto-executable Windows'), 'default' => false],
-            'win_exe_html' => ['label' => __('Version offline - ZIP Windows'), 'default' => false],
-            'mac_exe_html' => ['label' => __('Version offline - Exécutable Mac OS X'), 'default' => false],
-            'win_cd_html' => ['label' => __('Version offline - CD-ROM / Clé USB'), 'default' => false],
-            'win_html' => ['label' => __('Version offline - HTML (Non adaptée à l\'installation sur un serveur web)'), 'default' => false],
-            'precompiled' => ['label' => __('Version precompilée'), 'default' => false],
+            'online' => ['label' => __('Version online'), 'default' => true, 'install' => true],
+            'sharepoint' => ['label' => __('Version Sharepoint'), 'default' => false, 'install' => false],
+            'scorm' => ['label' => __('Version SCORM'), 'default' => false, 'install' => false],
+            'win_inss_html' => ['label' => __('Version offline - Executable Windows'), 'default' => false, 'install' => false],
+            'win_ins_html' => ['label' => __('Version offline - Installeur Auto-executable Windows'), 'default' => false, 'install' => false],
+            'win_exe_html' => ['label' => __('Version offline - ZIP Windows'), 'default' => false, 'install' => false],
+            'mac_exe_html' => ['label' => __('Version offline - Exécutable Mac OS X'), 'default' => false, 'install' => false],
+            'win_cd_html' => ['label' => __('Version offline - CD-ROM / Clé USB'), 'default' => false, 'install' => false],
+            'win_html' => ['label' => __('Version offline - HTML (Non adaptée à l\'installation sur un serveur web)'), 'default' => false, 'install' => false],
+            'precompiled' => ['label' => __('Version precompilée'), 'default' => false, 'install' => false],
         ];
     }
 
@@ -2973,14 +2974,24 @@ L,index',
 
         $this->addField('section_downloads', FormSection::class, $this->__('Versions disponibles au téléchargement'));
 
-        foreach (self::getDownloadVersions() as $name=>$downloadVersion) {
-            $this->addField('download_'.$name, Checkbox::class, $downloadVersion['label'], [
-                'v2' => json_encode(['type'=>'boolean','editable'=>true,'default'=>$downloadVersion['default'],'label'=>$downloadVersion['label'],'grade'=>3]),
+        foreach (self::getDownloadVersions() as $name => $downloadVersion) {
+            $this->addField('download_' . $name, Checkbox::class, $downloadVersion['label'], [
+                'v2' => json_encode(['type' => 'boolean', 'editable' => true, 'default' => $downloadVersion['default'], 'label' => $downloadVersion['label'], 'grade' => 3]),
                 'default' => $downloadVersion['default'],
                 'fake' => true,
                 'store_in' => 'settings',
                 'translatable' => false,
             ]);
+            if ($downloadVersion['install']) {
+                $installFields = [
+                    'hosting' => ['prefix' => 'https://hosting.fluidbook.com/', 'label' => __('Chemin sur le serveur hosting'), 'hint' => null],
+                    'ftp' => ['prefix' => 'ftp://', 'label' => __('Chemin de connexion au serveur FTP'), 'hint' => __('username:password@host/path/to/install/folder')],
+                ];
+                foreach ($installFields as $iname => $installField) {
+                    $this->addField('install_' . $name . '_' . $iname, Text::class, $installField['label'], ['default' => '', 'fake' => true, 'translatable' => false, 'store_in' => 'settings', 'prefix' => $installField['prefix'], 'hint' => $installField['hint'], 'when' => ['download_' . $name => 1]]);
+                }
+
+            }
         }
 
         $this->addField('section_elearning', FormSuperSection::class, __('E-Learning'));