--- /dev/null
+<?php
+
+namespace App\Console\Commands;
+
+use App\Jobs\FluidbookCompiler;
+use App\Jobs\FluidbookImagesPreprocess;
+use App\Models\FluidbookPublication;
+use Cubist\Backpack\Console\Commands\CubistCommand;
+use Cubist\Util\PHP;
+
+class FluidbookPreprocessImages extends CubistCommand
+{
+ protected $signature = 'fluidbook:preprocess {id}';
+ protected $description = 'Compile a fluidbook';
+
+ /**
+ * @throws \Exception
+ */
+ public function handle()
+ {
+ PHP::neverStop(true);
+ FluidbookImagesPreprocess::dispatchSync($this->argument('id'));
+ }
+}
namespace App\Http\Controllers\Admin\Operations\FluidbookPublication;
use App\Jobs\FluidbookDocumentUpload;
+use App\Jobs\FluidbookImagesPreprocess;
use App\Models\FluidbookDocument;
+use App\Models\FluidbookPublication;
use Cubist\Backpack\Http\Controllers\Base\XSendFileController;
use Cubist\Util\Files\Files;
use Cubist\Util\Str;
{
protected function setupCompositionRoutes($segment, $routeName, $controller)
{
- Route::match(['get'], $segment . '/{id}/composition', $controller . '@getComposition');
Route::match(['get'], $segment . '/docs/{doc_id}/thumb_{doc_page}.jpg', $controller . '@getThumb');
Route::match(['post'], $segment . '/uploaddocument', $controller . '@upload');
Route::match(['get'], $segment . '/uploadProgress/{uploadID}', $controller . '@uploadProgress');
{
}
+
protected function getThumb($doc_id, $doc_page)
{
return XSendFileController::sendfile($path);
}
+
protected function upload()
{
$uploadID = Str::random();
$document->save();
move_uploaded_file($file->getPathname(), Files::mkdir($document->path()) . 'original.pdf');
FluidbookDocumentUpload::updateProgression($uploadID, __('Mise en file d\'attente du traitement du document'), 1.2);
- FluidbookDocumentUpload::dispatch($uploadID, $document, backpack_user());
+ FluidbookDocumentUpload::dispatch($uploadID, $document, backpack_user(), request('fluidbook_id', null));
return response()->json(['uploadID' => $uploadID, 'document' => $document->id]);
}
{
parent::__construct();
+
$this->setFluidbook($book);
$this->setCommand($command);
public function handle()
{
+ $this->log('Preprocess images');
+ FluidbookImagesPreprocess::dispatchSync($this->book_id);
$this->log('Start compile process');
// Raw copy of some directories
if ($this->phonegap) {
- $this->vdir->copy(WS_COMPILE_ASSETS . '/_html5/js/libs/phonegap/' . $this->phonegapVersion . '/cordova-' . $this->phonegap . '.js', 'data/cordova.js');
+ // $this->vdir->copy(WS_COMPILE_ASSETS . '/_html5/js/libs/phonegap/' . $this->phonegapVersion . '/cordova-' . $this->phonegap . '.js', 'data/cordova.js');
}
$this->vdir->copyDirectory($this->assets . '/js/libs/fluidbook/workers', 'js/libs/fluidbook/workers');
$this->vdir->copyDirectory($this->assets . '/js/libs/stand', 'js/libs/stand');
*/
public function isDone()
{
-
- $res = $this->document->hasFile($this->page, $this->format, $this->resolution, $this->withText, $this->withGraphics, $this->version);
- //dd($res, $this->document->_getPath($this->page, $this->format, $this->resolution, $this->withText, $this->withGraphics, $this->version));
- return $res;
+ return $this->document->hasFile($this->page, $this->format, $this->resolution, $this->withText, $this->withGraphics, $this->version);
}
}
*/
protected $document;
+ /**
+ * @var int
+ */
+ protected $fluidbook_id;
/**
* @var User
*/
protected $user;
- public function __construct($uploadID, FluidbookDocument $document, $user)
+ public function __construct($uploadID, FluidbookDocument $document, $user, $fluidbook_id = null)
{
$this->onQueue('fluidbookprocess');
$this->uploadID = $uploadID;
$this->document = $document;
+ $this->fluidbook_id = $fluidbook_id;
$this->setUser($user);
}
--- /dev/null
+<?php
+
+namespace App\Jobs;
+
+use App\Models\FluidbookPublication;
+use Cubist\Util\ArrayUtil;
+
+class FluidbookImagesPreprocess extends Base
+{
+ protected $book_id;
+ /**
+ * @var FluidbookPublication
+ */
+ protected $book;
+
+ /**
+ * @var FluidbookDocumentFileProcess[]
+ */
+ protected $jobs = [];
+
+ public function __construct($book_id)
+ {
+ $this->book_id = $book_id;
+ parent::__construct();
+ }
+
+ public function handle()
+ {
+ $this->book = FluidbookPublication::find($this->book_id);
+ $settings = $this->book->getSettings();
+ $resolutions = FluidbookCompiler::getBookResolutions($this->book);
+ $rasterizePages = ArrayUtil::parseRange($settings->rasterizePages);
+ $vectorPages = array_diff(ArrayUtil::parseRange($settings->vectorPages), $rasterizePages);
+
+ switch ($settings->mobileVersion) {
+ case 'html5-desktop':
+ $globalBackgroundToGenerate = [true, false];
+ $svg = true;
+ break;
+ case 'html5-images':
+ $globalBackgroundToGenerate = [true];
+ $svg = false;
+ break;
+ default:
+ $globalBackgroundToGenerate = [false];
+ $svg = true;
+ break;
+ }
+
+ if ($settings->mobileNavigationType === 'mobilefirst') {
+ $imdir = 'mf';
+ } else {
+ $imdir = 'html';
+ }
+
+ for ($page = 1; $page <= $this->book->getPagesNumber(); $page++) {
+ $thisrasterize = in_array($page, $rasterizePages);
+ $thisimagesvg = !$thisrasterize && $svg;
+ $pageBackgroundsToGenerate = $thisrasterize ? [true] : $globalBackgroundToGenerate;
+ foreach ($resolutions as $r) {
+ foreach ($pageBackgroundsToGenerate as $withText) {
+ $this->getFile($page, $settings->imageFormat, $r, $withText, true, $imdir);
+ }
+ }
+ if ($thisimagesvg) {
+ $this->getFile($page, 'svg', 150, true, in_array($page, $vectorPages), 'html');
+ }
+ $this->getFile($page, $settings->imageFormat, 'thumb');
+ }
+
+ while (true) {
+ if ($this->_checkJobs()) {
+ return;
+ }
+ usleep(0.25 * 1000000);
+ }
+ }
+
+ protected function _checkJobs()
+ {
+ $nbjobs = count($this->jobs);
+ $done = 0;
+ foreach ($this->jobs as $job) {
+ if ($job->isDone()) {
+ $done++;
+ }
+ }
+ echo $done . '/' . $nbjobs . "\n";
+ return $done === $nbjobs;
+ }
+
+ protected function getFile($page, $format = 'jpg', $resolution = 150, $withText = true, $withGraphics = true, $version = 'html')
+ {
+ $c = $this->book->composition[$page];
+ $doc = $this->book->getDocument($page);
+ $doc->clearFilesCache();
+ $job = new FluidbookDocumentFileProcess($doc, $c[1], $format, $resolution, $withText, $withGraphics, $version);
+ if ($job->isDone()) {
+ return;
+ }
+ dispatch($job);
+ $this->jobs[] = $job;
+ }
+}
// Texts
['svg', 150, true, false],
];
+
$nbfiles = count($files);
$delay = 0;
for ($i = 1; $i <= $this->pages; $i++) {
return false;
}
}
- Cache::put($cacheKey, $path);
+ Cache::tags('fluidbook_document_' . $this->id)->put($cacheKey, $path);
return true;
}
}
public function clearAllFiles()
{
$cmd = 'cd ' . $this->path() . ';find . ! -name \'original.pdf\' ! -name \'.\' ! -name \'..\' -exec rm -rf {} +';
- Cache::tags('fluidbook_document_' . $this->id)->flush();
+ $this->clearFilesCache();
`$cmd`;
}
+ public function clearFilesCache()
+ {
+ Cache::tags('fluidbook_document_' . $this->id)->flush();
+ }
+
protected function updateProgression($uploadID, $message, $progress)
{
FluidbookDocumentUpload::updateProgression($uploadID, $message, $progress);
use App\Http\Controllers\Admin\Operations\FluidbookPublication\PreviewOperation;
use App\Http\Controllers\Admin\Operations\FluidbookPublication\StatsOperation;
use App\Http\Controllers\Admin\Operations\FluidbookPublication\EditOperation;
+use App\Jobs\FluidbookImagesPreprocess;
use App\Models\Base\ToolboxSettingsModel;
use App\Models\Traits\PublicationSettings;
use App\Models\Traits\SCORMVersionTrait;
{
$this->setComposedAttributes();
$this->checkHash();
+ FluidbookImagesPreprocess::dispatch($this->id);
return parent::onSaved();
}
return self::$_farmServers[$i];
}
- public static function getFCGIConnexion(array $farm, $timeout = 30): NetworkSocket
+ public static function getFCGIConnexion(array $farm, $timeout = 240): NetworkSocket
{
$timeout *= 1000;
return new NetworkSocket($farm['host'], $farm['port'] ?? 9457, $timeout, $timeout);
}
- public static function sendRequest($farmer, $url, $params = [], $timeout = 30)
+ public static function sendRequest($farmer, $url, $params = [], $timeout = 240)
{
+ set_time_limit(0);
$client = new Client();
$response = $client->sendRequest(self::getFCGIConnexion($farmer, $timeout), new PostRequest($url, http_build_query($params)));
return trim($response->getBody());