From: Vincent Vanwaelscappel Date: Sun, 20 Nov 2022 23:16:45 +0000 (+0100) Subject: wip #5590 @10 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=388b59e311d69aadcc21fbc61e779fb44e12f6f7;p=fluidbook-toolbox.git wip #5590 @10 --- diff --git a/.docker/config/httpd/httpd.conf b/.docker/config/httpd/httpd.conf index af7775faf..78f057d99 100644 --- a/.docker/config/httpd/httpd.conf +++ b/.docker/config/httpd/httpd.conf @@ -264,8 +264,8 @@ ServerAdmin you@example.com # documents. By default, all requests are taken from this directory, but # symbolic links and aliases may be used to point to other locations. # -DocumentRoot "/usr/local/apache2/htdocs" - +DocumentRoot "/application/public" + # # Possible values for the Options directive are "None", "All", # or any combination of: @@ -296,9 +296,7 @@ DocumentRoot "/usr/local/apache2/htdocs" ProxyPassMatch ^/(.*\.php(/.*)?)$ "fcgi://fluidbook-toolbox:9000/application/public/$1" timeout=1800 XSendFile on -XSendFilePath /data1/extranet XSendFilePath /application -XSendFilePath /home/extranet # diff --git a/.docker/config/supervisor/default-worker.conf b/.docker/config/supervisor/default-worker.conf index 4228ba9e8..3b4558676 100644 --- a/.docker/config/supervisor/default-worker.conf +++ b/.docker/config/supervisor/default-worker.conf @@ -5,7 +5,7 @@ autostart=true autorestart=true user=toolbox group=www-data -numprocs=3 +numprocs=12 redirect_stderr=true stdout_logfile=/proc/self/fd/2 stopwaitsecs=3600 diff --git a/.docker/config/supervisor/download-worker.conf b/.docker/config/supervisor/download-worker.conf index b3031ef26..0365624f3 100644 --- a/.docker/config/supervisor/download-worker.conf +++ b/.docker/config/supervisor/download-worker.conf @@ -5,7 +5,7 @@ autostart=true autorestart=true user=toolbox group=www-data -numprocs=6 +numprocs=24 redirect_stderr=true stdout_logfile=/proc/self/fd/2 stopwaitsecs=3600 diff --git a/.docker/config/supervisor/fluidbook-process-worker.conf b/.docker/config/supervisor/fluidbook-process-worker.conf index 5a72019cb..03ab24903 100644 --- a/.docker/config/supervisor/fluidbook-process-worker.conf +++ b/.docker/config/supervisor/fluidbook-process-worker.conf @@ -5,7 +5,7 @@ autostart=true autorestart=true user=toolbox group=www-data -numprocs=48 +numprocs=96 redirect_stderr=true stdout_logfile=/proc/self/fd/2 stopwaitsecs=3600 diff --git a/.docker/config/supervisor/theme-worker.conf b/.docker/config/supervisor/theme-worker.conf index b1421bc3d..87eba7db7 100644 --- a/.docker/config/supervisor/theme-worker.conf +++ b/.docker/config/supervisor/theme-worker.conf @@ -5,7 +5,7 @@ autostart=true autorestart=true user=toolbox group=www-data -numprocs=3 +numprocs=6 redirect_stderr=true stdout_logfile=/proc/self/fd/2 stopwaitsecs=3600 diff --git a/.docker/docker-compose.yml b/.docker/docker-compose.yml index 4e5df9534..b97be5beb 100644 --- a/.docker/docker-compose.yml +++ b/.docker/docker-compose.yml @@ -2,14 +2,13 @@ version: '3.1' services: webserver: container_name: fluidbook-toolbox-httpd - build: /data1/extranet/toolbox/.docker/images/httpd + build: /home/toolbox/www/.docker/images/httpd working_dir: /application volumes: - - '/data1/extranet/toolbox/:/application/' - - '/mnt/sshfs/godzilla/data/fluidbook/docs/:/data1/extranet/www/fluidbook/docs/' - - '/data1/extranet/toolbox/storage/app/public/:/usr/local/apache2/htdocs/storage/' - - '/data1/extranet/toolbox/public/:/usr/local/apache2/htdocs/' - - '/data1/extranet/toolbox/.docker/config/httpd/httpd.conf:/usr/local/apache2/conf/httpd.conf' + - '/home/toolbox/www/:/application/' + - '/mnt/sshfs/godzilla/data/fluidbook/docs/:/data/extranet/www/fluidbook/docs/' + - '/home/toolbox/www/storage/app/public/:/usr/local/apache2/htdocs/storage/' + - '/home/toolbox/www/.docker/config/httpd/httpd.conf:/usr/local/apache2/conf/httpd.conf' ports: - '37126:80' environment: @@ -21,35 +20,35 @@ services: php-fpm: container_name: fluidbook-toolbox - build: /data1/extranet/toolbox/.docker/images/php + build: /home/toolbox/www/.docker/images/php working_dir: /application hostname: fluidbook-toolbox environment: TZ: Europe/Paris HOME: /application volumes: - - '/data1/extranet/toolbox/.docker/config/ssh/:/root/.ssh/' - - '/data1/extranet/toolbox/.docker/config/ssh/:/application/.ssh/' - - '/data1/extranet/toolbox/.docker/config/supervisor/:/etc/supervisor/conf.d/' - - '/data1/extranet/toolbox/.docker/config/composer/:/root/.config/composer/' - - '/data1/extranet/toolbox/.docker/config/composer/:/application/.config/composer/' - - '/data1/extranet/toolbox/.docker/config/npm/:/root/.npm/' - - '/data1/extranet/toolbox/.docker/config/gitconfig:/root/.gitconfig' - - '/data1/extranet/toolbox/.docker/config/git/:/root/.config/git/' - - '/data1/extranet/toolbox/.docker/config/git/:/application/.config/git/' - - '/data1/extranet/toolbox/.docker/config/gitconfig:/application/.gitconfig' - - '/data1/extranet/toolbox/.docker/config/monit/:/etc/monit/' - - '/data1/extranet/toolbox/.docker/config/sudoers:/etc/sudoers.d/toolbox' - - '/data1/extranet/toolbox/.docker/config/monit/id:/var/lib/monit/id' - - '/data1/extranet:/data1/extranet' - - '/data1/extranet/tmp:/data1/extranet/tmp' - - '/home/extranet:/home/extranet' + - '/home/toolbox/www/.docker/config/ssh/:/root/.ssh/' + - '/home/toolbox/www/.docker/config/ssh/:/application/.ssh/' + - '/home/toolbox/www/.docker/config/supervisor/:/etc/supervisor/conf.d/' + - '/home/toolbox/www/.docker/config/composer/:/root/.config/composer/' + - '/home/toolbox/www/.docker/config/composer/:/application/.config/composer/' + - '/home/toolbox/www/.docker/config/npm/:/root/.npm/' + - '/home/toolbox/www/.docker/config/gitconfig:/root/.gitconfig' + - '/home/toolbox/www/.docker/config/git/:/root/.config/git/' + - '/home/toolbox/www/.docker/config/git/:/application/.config/git/' + - '/home/toolbox/www/.docker/config/gitconfig:/application/.gitconfig' + - '/home/toolbox/www/.docker/config/monit/:/etc/monit/' + - '/home/toolbox/www/.docker/config/sudoers:/etc/sudoers.d/toolbox' + - '/home/toolbox/www/.docker/config/monit/id:/var/lib/monit/id' + - '/home/extranet/share:/application/share' - '/mnt:/mnt' - - '/data1/extranet/toolbox:/application' - - '/data1/extranet/toolbox/storage/app/public/:/application/public/storage/' - - '/data1/extranet/toolbox/.docker/config/php.ini:/etc/php/8.1/fpm/conf.d/99-overrides.ini' - - '/data1/extranet/toolbox/.docker/config/crontab:/etc/crontab' - - '/mnt/sshfs/godzilla/data/fluidbook/docs/:/data1/extranet/www/fluidbook/docs/' + - '/home/toolbox/www:/application' + - '/home/toolbox/www/storage/app/public/:/application/public/storage/' + - '/home/toolbox/www/.docker/config/php.ini:/etc/php/8.1/fpm/conf.d/99-overrides.ini' + - '/home/toolbox/www/.docker/config/crontab:/etc/crontab' + - '/mnt/sshfs/godzilla/data/fluidbook/docs/:/data/extranet/www/fluidbook/docs/' + - '/home/extranet:/home/extranet' + - '/data/extranet:/data/extranet' tmpfs: - '/tmp:uid=1001,gid=33' - '/application/storage/framework:uid=1001,gid=33' @@ -57,6 +56,7 @@ services: - '58744:8123' networks: - fluidbook-toolbox + - fluidbook-processfarm restart: unless-stopped adminer: image: adminer:latest @@ -99,3 +99,6 @@ networks: fluidbook-toolbox: external: name: fluidbook-toolbox + fluidbook-processfarm: + external: + name: fluidbook-processfarm diff --git a/.docker/images/php/Dockerfile b/.docker/images/php/Dockerfile index 59ca1f4fe..62ed87d89 100644 --- a/.docker/images/php/Dockerfile +++ b/.docker/images/php/Dockerfile @@ -2,7 +2,7 @@ # PHPDocker.io PHP 8.1 / CLI and FPM image # ############################################ -FROM ubuntu:jammy AS cli +FROM ubuntu:latest AS cli WORKDIR "/application" @@ -63,7 +63,7 @@ RUN apt-get -y --no-install-recommends install zip unzip gzip 7zip RUN apt-get -y --no-install-recommends install icoutils fontforge RUN apt-get -y --no-install-recommends install ffmpeg python3 lame x264 vorbis-tools RUN apt-get -y --no-install-recommends install inkscape mupdf-tools librsvg2-bin -RUN apt-get -y --no-install-recommends install cron monit locate +RUN apt-get -y --no-install-recommends install cron monit locate telnet RUN curl -L https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp -o /usr/local/bin/yt-dlp diff --git a/.docker/images/php/overrides.conf b/.docker/images/php/overrides.conf index 9c98459b3..4a99e3e4e 100644 --- a/.docker/images/php/overrides.conf +++ b/.docker/images/php/overrides.conf @@ -30,8 +30,8 @@ user = 1001 group = 33 pm = dynamic -pm.max_children = 80 -pm.start_servers = 24 -pm.min_spare_servers = 20 -pm.max_spare_servers = 40 +pm.max_children = 160 +pm.start_servers = 48 +pm.min_spare_servers = 40 +pm.max_spare_servers = 80 pm.max_requests = 1000 diff --git a/app/Console/Commands/FluidbookCollection.php b/app/Console/Commands/FluidbookCollection.php new file mode 100644 index 000000000..4ae7550ff --- /dev/null +++ b/app/Console/Commands/FluidbookCollection.php @@ -0,0 +1,26 @@ +argument('id')); + $job = new FluidbookCollectionDownload($fluidbook, $this->argument('action'), User::withoutGlobalScope('ownerclause')->findOrFail(5)); + $job->handle(); + } +} diff --git a/app/Fields/FluidbookDevelopmentVersion.php b/app/Fields/FluidbookDevelopmentVersion.php index 4dfe2b6f2..6f8762bfc 100644 --- a/app/Fields/FluidbookDevelopmentVersion.php +++ b/app/Fields/FluidbookDevelopmentVersion.php @@ -2,10 +2,13 @@ namespace App\Fields; +use App\Models\Traits\FluidbookPlayerBranches; use Cubist\Backpack\Magic\Fields\SelectFromArray; class FluidbookDevelopmentVersion extends SelectFromArray { + use FluidbookPlayerBranches; + protected static $__options = null; /** @@ -21,9 +24,7 @@ class FluidbookDevelopmentVersion extends SelectFromArray protected function _getOptions() { - $cacheFile = file_get_contents('/data1/extranet/www/fluidbook/cache/activebranches'); - - $versions = json_decode($cacheFile, true, 512, JSON_THROW_ON_ERROR); + $versions = $this->getActiveBranches(); $res = ['stable' => 'master : git (stable)', 'dev' => 'master : local (dev)']; diff --git a/app/Jobs/FluidbookCollectionDownload.php b/app/Jobs/FluidbookCollectionDownload.php index b027f3a9b..bced42c1d 100644 --- a/app/Jobs/FluidbookCollectionDownload.php +++ b/app/Jobs/FluidbookCollectionDownload.php @@ -17,6 +17,18 @@ class FluidbookCollectionDownload extends DownloadBase // __('Collection ":title" (#:nb) prête au téléchargement') protected $_subject = 'Collection ":title" (#:nb) prête au téléchargement'; + + public function handle() + { + if ($this->action === 'install_hosting') { + $url = $this->installHosting($this->entry->getPageData()); + + $this->sendNotification(__('Collection ":title" (#:nb) installée sur le serveur hosting', ['title' => $this->_title(), 'nb' => $this->_id()]), '', $url); + } else { + parent::handle(); + } + } + protected function _compile() { $compilepath = protected_path('collection/final/' . $this->entry->id); @@ -53,6 +65,9 @@ class FluidbookCollectionDownload extends DownloadBase $options = []; foreach ($this->entry->getPageData()->override_settings as $setting) { + if (!$setting['key']) { + continue; + } $options[$setting['key']] = $setting['value']; } @@ -190,6 +205,25 @@ window.location='./' + locale + '/index.html'; } } + protected function installHosting($data) + { + $ws = $this->_getws2(); + $options = $this->getCollectionGlobalSettings(); + + $res = []; + foreach ($data->publications as $publication) { + $fbid = $publication['fluidbook']; + if ($publication['dir']) { + $options['dir'] = $publication['dir']; + } else { + $metadata = $ws->getMetadata($fbid); + $options['dir'] = $metadata->export->install_hosting->{$data->version}->dir ?? Str::slug($metadata->title); + } + $res['Fluidbook #' . $fbid] = $ws->installBookOnHosting($fbid, $options, $data->version); + } + return $res; + } + protected function compileExport($data, $path) { $ws = $this->_getws2(); diff --git a/app/Jobs/LegacyBookSettingsGenerate.php b/app/Jobs/LegacyBookSettingsGenerate.php index 9c4aba0d5..2865e3ea2 100644 --- a/app/Jobs/LegacyBookSettingsGenerate.php +++ b/app/Jobs/LegacyBookSettingsGenerate.php @@ -88,7 +88,7 @@ class wsBookParametres extends wsParametres $code = str_replace("'%!%", '', $code); $code = str_replace("!%!'", '', $code); - file_put_contents('/data1/extranet/www/inc/ws/Metier/class.ws.book.parametres.php', $code); + file_put_contents('/home/extranet/www/inc/ws/Metier/class.ws.book.parametres.php', $code); } public function __($str) diff --git a/app/Jobs/UpdateWS2ThemeTable.php b/app/Jobs/UpdateWS2ThemeTable.php index 5f57d300c..aa848f1b7 100644 --- a/app/Jobs/UpdateWS2ThemeTable.php +++ b/app/Jobs/UpdateWS2ThemeTable.php @@ -22,7 +22,7 @@ class UpdateWS2ThemeTable extends Base protected $_colorAlphaFields = []; protected $_allFields = []; protected $_ignore = []; - protected $_t3dir = '/data1/extranet/www/fluidbook/themes3/'; + protected $_t3dir = '/home/extranet/www/fluidbook/themes3/'; protected static $_colorToWS2Cache = []; protected static $_colorAlphaToWS2Cache = []; @@ -80,10 +80,10 @@ class UpdateWS2ThemeTable extends Base { $res = $this->_getThemeData($theme); $dest = $this->_t3dir . '/' . $theme->id . '.jpg'; - if (!file_exists($dest)) { - $preview = storage_path('themes/' . $theme->id . '.jpg'); - `ln -sf $preview $dest`; - } + + $preview = storage_path('themes/' . $theme->id . '.jpg'); + \Cubist\Util\Files\Files::copyFile($preview, $dest); + return $res; } @@ -109,15 +109,12 @@ class UpdateWS2ThemeTable extends Base if (null !== $media) { $v = $media->getAttribute('file_name'); $dir = $this->_t3dir . $theme->id; - if (!file_exists($dir)) { - mkdir($dir, 0777, true); - } + \Cubist\Util\Files\Files::mkdir($dir); $dest = $dir . '/' . $v; $path = $media->getPath(); - $exists = file_exists($dest); - if (!$exists || realpath($dest) !== realpath($path)) { - `rm -f $dest;ln -sf $path $dest`; - } + + \Cubist\Util\Files\Files::copyFile($path, $dest); + if (stristr($v, '.svg')) { $png = str_replace('.svg', '.png', $dest); if (!file_exists($png) || filemtime($png) < filemtime($path)) { @@ -141,6 +138,7 @@ class UpdateWS2ThemeTable extends Base return ['theme_id' => $theme->id, 'nom' => $theme->name, 'proprietaire' => $theme->owner, 'icones' => $theme->iconSet, 'date' => strtotime($theme->updated_at), 'parametres' => json_encode($settings)]; } + public static function colorAlphaToWS2($data) { if ($data === '') { diff --git a/app/Models/FluidbookPublication.php b/app/Models/FluidbookPublication.php index 228c38404..0519c9e9c 100644 --- a/app/Models/FluidbookPublication.php +++ b/app/Models/FluidbookPublication.php @@ -183,7 +183,7 @@ class FluidbookPublication extends ToolboxSettingsModel */ protected function _getFreeFileBaseDirectory() { - return '/data1/extranet/www/fluidbook/books/working/' . $this->id; + return '/data/extranet/www/fluidbook/books/working/' . $this->id; } /** @@ -320,7 +320,7 @@ class FluidbookPublication extends ToolboxSettingsModel public function getAssetDir() { - return Files::mkdir('/data1/extranet/www/fluidbook/books/working/' . $this->id); + return Files::mkdir('/data/extranet/www/fluidbook/books/working/' . $this->id); } public function getCompositionUpdate(): int diff --git a/app/Services/WorkshopV2.php b/app/Services/WorkshopV2.php index 714c1c062..98004c48a 100644 --- a/app/Services/WorkshopV2.php +++ b/app/Services/WorkshopV2.php @@ -62,6 +62,16 @@ class WorkshopV2 return true; } + public function _nothing(...$rest) + { + + } + + public function installBookOnHosting($id, $options = [], $version = 'online') + { + return $this->installBook($id, null, $options + ['action' => 'install_hosting'], $version, 3, null, '_nothing'); + } + public function installBookIfNeeded($id, $dir, $options = [], $timestamp = 'auto', $version = 'online') { if ($timestamp === 'auto') { @@ -98,6 +108,7 @@ class WorkshopV2 $res->date = (int)$xml->date; $res->lang = (string)$xml->lang; $res->settings = json_decode((string)$xml->settings); + $res->export = json_decode((string)$xml->export); return $res; } @@ -105,10 +116,33 @@ class WorkshopV2 { $url = 'ajax/exportbookExe'; - $response = $this->_request($url, 'POST', ['version' => $version, 'book_id' => $id, 'action' => 'download', 'options' => $options]); + $action = 'download'; + if (isset($options['action'])) { + $action = $options['action']; + unset($options['action']); + } + + $reqData = ['version' => $version, 'book_id' => $id, 'action' => $action, 'options' => $options]; + if ($action === 'install_hosting') { + $destination = []; + if (isset($options['dir'])) { + $destination['dir'] = $options['dir']; + unset($options['dir']); + } + $reqData['destination'] = $destination; + } + + $response = $this->_request($url, 'POST', $reqData); + + $xml = $this->_getXMLFromResponse($response); + if ($action === 'install_hosting') { + return (string)$xml->truepopup->url; + } + if ($xml !== false && isset($xml->redirection) && !is_null($xml->redirection)) { + $this->$function((string)$xml->redirection, $dir, $beforeInstallCallback); return true; } else { diff --git a/app/Slack/Slack.php b/app/Slack/Slack.php index a77885e86..eade79785 100644 --- a/app/Slack/Slack.php +++ b/app/Slack/Slack.php @@ -44,7 +44,8 @@ class Slack ] ]; } - if (count($actions) > 0) { + $actionsCount = count($actions); + if ($actionsCount > 0) { $a = [ 'type' => 'actions', 'block_id' => 'actions', @@ -56,17 +57,19 @@ class Slack if (is_string($data)) { $data = ['url' => $data]; } - $a['elements'][] = array_merge([ - 'type' => 'button', - 'text' => [ - 'type' => 'plain_text', - 'text' => $label - ], - ], $data); - $i++; + if ($i < 6) { + $a['elements'][] = array_merge([ + 'type' => 'button', + 'text' => [ + 'type' => 'plain_text', + 'text' => $label + ], + ], $data); + } if ($repeatActions) { $text .= '> ' . $label . ' : ' . $data['url'] . "\n"; } + $i++; } if ($text) { $blocks[] = [ diff --git a/app/SubForms/CollectionPublication.php b/app/SubForms/CollectionPublication.php index 28579366a..81fc834e3 100644 --- a/app/SubForms/CollectionPublication.php +++ b/app/SubForms/CollectionPublication.php @@ -14,5 +14,6 @@ class CollectionPublication extends SubForm $this->addField('fluidbook', FluidbookID::class, __('Fluidbook #')); $this->addField('export', Text::class, __('Nom d\'export'), ['hint'=>__('Laisser vide pour laisser le système déterminer le nom')]); + $this->addField('dir', Text::class, __('Répertoire d\'export'), ['hint'=>__('Laisser vide pour laisser le système déterminer le nom')]); } } diff --git a/app/Util/FluidbookFarm.php b/app/Util/FluidbookFarm.php index 87ea8f60a..8be3da479 100644 --- a/app/Util/FluidbookFarm.php +++ b/app/Util/FluidbookFarm.php @@ -10,7 +10,7 @@ use hollodotme\FastCGI\SocketConnections\NetworkSocket; class FluidbookFarm { protected static $_farmServers = [ - ['name' => 'alien', 'host' => 'alien.cubedesigners.com', 'weight' => 1], + ['name' => 'alphaville', 'host' => 'fluidbook-processfarm', 'port' => 9000, 'weight' => 24], ['name' => 'brazil', 'host' => 'brazil.cubedesigners.com', 'weight' => 6], ['name' => 'clockwork', 'host' => 'clockwork.cubedesigners.com', 'weight' => 2], ['name' => 'dracula', 'host' => 'dracula.cubedesigners.com', 'weight' => 3], diff --git a/app/Util/FluidbookLinks.php b/app/Util/FluidbookLinks.php index eb2331be1..411c19d55 100644 --- a/app/Util/FluidbookLinks.php +++ b/app/Util/FluidbookLinks.php @@ -392,7 +392,7 @@ class FluidbookLinks public static function getLinksDir($book_id) { - return Files::mkdir('/data1/extranet/www/fluidbook/books/links/' . $book_id); + return Files::mkdir('/data/extranet/www/fluidbook/books/links/' . $book_id); } public static function getLinksVersions($book_id, $withLinks = false) diff --git a/resources/views/vendor/backpack/crud/buttons/fluidbook_collection/download.blade.php b/resources/views/vendor/backpack/crud/buttons/fluidbook_collection/download.blade.php index 4b6b85208..2295349e4 100644 --- a/resources/views/vendor/backpack/crud/buttons/fluidbook_collection/download.blade.php +++ b/resources/views/vendor/backpack/crud/buttons/fluidbook_collection/download.blade.php @@ -1,5 +1,5 @@ @php - $actions=['download'=>__('Télécharger')]; + $actions=['download'=>__('Télécharger'),'install_hosting'=>__('Installer sur hosting')]; if($entry->type==='scorm_multilang'){ $actions['scormcloud']=__('Tester sur Scorm Cloud'); }