]> _ Git - odl.git/commitdiff
wip #4666 @0.75
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 16 Sep 2021 18:29:29 +0000 (20:29 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 16 Sep 2021 18:29:29 +0000 (20:29 +0200)
app/Jobs/ProcessFluidbook.php
composer.lock

index da1a2576aaabea59b55e36c15e272dec78fcf66f..9347c8de7880818c8de879931b95b2cf35dd34c1 100644 (file)
 namespace App\Jobs;
 
 use App\Models\Publication;
-use Cubist\Util\Files\Files;
-use Cubist\Util\Files\VirtualDirectory;
-use Cubist\Util\PHP;
-use Exception;
-use Fluidbook\Tools\Jobs\ProcessFile;
-use Fluidbook\Tools\Jobs\ProcessPage;
-use Fluidbook\Tools\PDF\Document;
-use Fluidbook\Tools\Search\SearchIndex;
-use Illuminate\Bus\Queueable;
-use Illuminate\Contracts\Queue\ShouldBeUnique;
-use Illuminate\Contracts\Queue\ShouldQueue;
-use Illuminate\Foundation\Bus\Dispatchable;
-use Illuminate\Queue\InteractsWithQueue;
-use Illuminate\Queue\Jobs\SyncJob;
-use Illuminate\Queue\SerializesModels;
-use JsonException;
+use Fluidbook\Tools\Compiler\Compiler;
 use Spatie\MediaLibrary\MediaCollections\Models\Media;
-use stdClass;
 
-class ProcessFluidbook implements ShouldQueue, ShouldBeUnique
+class ProcessFluidbook extends Compiler
 {
-    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
-
-    /**
-     * @var Document
-     */
-    protected $in;
-
-    /**
-     * @var string
-     */
-    protected $out;
-
-    /**
-     * @var string
-     */
-    protected $stub;
 
     /**
      * @var Publication
      */
     protected $pub;
 
-
-    /** @var VirtualDirectory */
-    protected $vdir;
-
-    /**
-     * @var stdClass
-     */
-    protected $config;
-
-    /**
-     * Create a new job instance.
-     *
-     * @return void
-     */
     public function __construct()
     {
-
         $this->pub = Publication::find(1);
 
         /** @var Media $media */
         $media = $this->pub->getMediaInField($this->pub->getAttributeValue('document'))->first();
+        $this->addSource($media->getPath());
 
-        $this->in = new Document($media->getPath());
         $this->out = storage_path('fluidbook/out/');
-
         $this->stub = resource_path('fluidbook/');
     }
 
-    /**
-     * Execute the job.
-     *
-     * @return void
-     */
-    public function handle()
-    {
-        $sync = ($this->job instanceof SyncJob);
-        if ($sync) {
-            PHP::neverStop(false);
-        }
-
-        start_measure('Process Fluidbook');
-        $this->processPages($sync);
-        $this->getTexts();
-        $this->getLinks();
-        $this->compileFluidbook();
-        stop_measure('Process Fluidbook');
-    }
-
-    public function processPages($sync = false)
-    {
-        start_measure('Process Pages');
-        $out = $this->getConvertPath();
-        Files::mkdir($out);
-        $this->in->processPages($out, $this->getProcessFiles(), $sync);
-        stop_measure('Process Pages');
-    }
-
-    /**
-     * @return ProcessFile[]
-     */
-    public function getProcessFiles()
-    {
-        return [
-            'thumb' => new ProcessFile('jpg', 'thumb'),
-            'back150' => new ProcessFile('jpg', 150, true, false),
-            'text' => new ProcessFile('svg', 300, false, true),
-        ];
-    }
-
-    /**
-     * @param $name
-     * @param null|int $page
-     * @return ProcessFile
-     * @throws Exception
-     */
-    public function getProcessFile($name, $page = null)
-    {
-        $files = $this->getProcessFiles();
-        if (isset($files[$name])) {
-            $res = $files[$name];
-            if (null !== $page) {
-                $res->setJob(new ProcessPage($this->in, $page, $this->getConvertPath()));
-            }
-            return $res;
-        }
-        throw new Exception(sprintf('File %s does not exist', $name));
-    }
-
-    public function getConvertPath()
-    {
-        return storage_path('fluidbook/convert/' . $this->in->getHash() . '/');
-    }
-
-    public function getTexts()
-    {
-        start_measure('Process texts');
-        $this->in->processTexts($this->getConvertPath());
-        start_measure('Process texts');
-    }
-
-    public function getLinks()
-    {
-        start_measure('Process links');
-        $this->in->processLinks($this->getConvertPath());
-        start_measure('Process links');
-    }
-
-    /**
-     * @throws JsonException
-     */
-    protected function compileFluidbook()
-    {
-        start_measure('Compile fluidbook');
-
-        $this->vdir = new VirtualDirectory($this->out);
-        $this->vdir->copyDirectory($this->stub, '/');
-
-        $this->compileContents();
-        $this->compileSearch();
-        $this->compileConfig();
-
-        $this->vdir->sync(true);
-
-        stop_measure('Compile fluidbook');
-    }
-
-    public function compileContents()
-    {
-        for ($i = 1; $i <= $this->in->getPages(); $i++) {
-
-            $this->vdir->copy($this->getProcessFile('back150', $i)->getPath(), 'data/background/150/p' . $i . '.jpg');
-            $this->vdir->copy($this->getProcessFile('text', $i)->getPath(), 'data/contents/p' . $i . '.svg');
-            $this->vdir->copy($this->getProcessFile('thumb', $i)->getPath(), 'data/thumbnails/p' . $i . '.jpg');
-        }
-    }
-
-    public function compileLinks()
-    {
-        return [];
-    }
-
-    public function compileSearch()
-    {
-        $index = new SearchIndex();
-        for ($i = 1; $i <= $this->in->getPages(); $i++) {
-            $index->addPage($i, $i, $this->getConvertPath() . 'texts');
-        }
-
-        $this->vdir->file_put_contents('data/search.highlight.js', 'var HIGHLIGHTS=' . json_encode($index->compileHighlights()) . ';');
-        $this->vdir->file_put_contents('data/search.index.js', 'var INDEX=' . json_encode($index->compileIndex()) . ';');
-    }
-
-    /**
-     * @throws JsonException
-     */
-    public function compileConfig()
-    {
-        $settings = mb_substr(file_get_contents($this->stub . '/data/datas.js'), 13, -2);
-        $this->config = json_decode($settings, false, 512, JSON_THROW_ON_ERROR);
-
-        $this->compileDimensions();
-        $this->compilePageNumbers();
-        $this->compileChapters();
-        $this->config->links = $this->compileLinks();
-
-        $c = 'var SETTINGS=' . json_encode($this->config, JSON_THROW_ON_ERROR) . ';';
-        $this->vdir->file_put_contents('data/datas.js', $c);
-    }
-
-    protected function compileDimensions()
-    {
-        $width = round($this->in->getWidth(), 8);
-        $height = round($this->in->getHeight(), 8);
-
-        $this->config->pageZoomFactor = 3;
-        $this->config->optimalWidth = 567;
-        $this->config->optimalHeight = 709;
-        $imagesize = getimagesize($this->getProcessFile('back150', 1)->getPath());
-        $this->config->pdfZoomFactor = round(($imagesize[0] * 0.48) / $width, 12);
-
-        $this->config->cssScale = $this->config->pageZoomFactor * min($this->config->optimalWidth / $width, $this->config->optimalHeight / $height);
-        $cssWidth = $width * $this->config->cssScale;
-        $cssHeight = $height * $this->config->cssScale;
-
-        $this->config->pages = $this->in->getPages();
-        $this->config->width = $cssWidth;
-        $this->config->height = $cssHeight;
-
-        $this->config->multiply = $this->config->pdfZoomFactor * $this->config->cssScale;
-
-        $this->config->pagesDimensions = [];
-
-        $thumbDimensions = getimagesize($this->getProcessFile('thumb', 1)->getPath());
-        $this->config->thumbWidth = $thumbDimensions[0];
-        $this->config->thumbHeight = $thumbDimensions[1];
-
-        for ($i = 1; $i <= $this->in->getPages(); $i++) {
-            $this->config->pagesDimensions[$i] = [$this->config->width, $this->config->height];
-        }
-    }
-
-    protected function compilePageNumbers()
-    {
-        $this->config->numerotation = $this->in->getPageNumbers();
-    }
-
-    protected function compileChapters()
-    {
-        $this->config->chaptersPagesNumber = 'physical';
-        $this->config->chapters = $this->in->getChapters();
-    }
-
-
 }
index f956c3f4375be57fcab58494cda34507ba033a40..65bf95185cd2e81f137372899198fd4f90b7fa70 100644 (file)
         },
         {
             "name": "backpack/crud",
-            "version": "4.1.52",
+            "version": "4.1.53",
             "source": {
                 "type": "git",
                 "url": "https://github.com/Laravel-Backpack/CRUD.git",
-                "reference": "239e60df0436f8a817facce20a2dffcb2b6e7250"
+                "reference": "8698b8ed51e8b18e311f928f6f80a7161f1eb172"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/Laravel-Backpack/CRUD/zipball/239e60df0436f8a817facce20a2dffcb2b6e7250",
-                "reference": "239e60df0436f8a817facce20a2dffcb2b6e7250",
+                "url": "https://api.github.com/repos/Laravel-Backpack/CRUD/zipball/8698b8ed51e8b18e311f928f6f80a7161f1eb172",
+                "reference": "8698b8ed51e8b18e311f928f6f80a7161f1eb172",
                 "shasum": ""
             },
             "require": {
             ],
             "support": {
                 "issues": "https://github.com/Laravel-Backpack/CRUD/issues",
-                "source": "https://github.com/Laravel-Backpack/CRUD/tree/4.1.52"
+                "source": "https://github.com/Laravel-Backpack/CRUD/tree/4.1.53"
             },
-            "time": "2021-09-06T06:35:01+00:00"
+            "time": "2021-09-16T11:37:48+00:00"
         },
         {
             "name": "backpack/logmanager",
             "source": {
                 "type": "git",
                 "url": "git://git.cubedesigners.com/cubist_util.git",
-                "reference": "625020133b3199d9dacf967225e97deba625a5c5"
+                "reference": "ca9f1c2f7c8e729a1b6ff64ece1e1c1ab1ef4228"
             },
             "dist": {
                 "type": "tar",
-                "url": "https://composer.cubedesigners.com/dist/cubist/util/cubist-util-dev-master-788531.tar",
-                "reference": "625020133b3199d9dacf967225e97deba625a5c5",
-                "shasum": "c86716eaf424939aef3bccbc77f6dfd43d210d12"
+                "url": "https://composer.cubedesigners.com/dist/cubist/util/cubist-util-dev-master-e2358f.tar",
+                "reference": "ca9f1c2f7c8e729a1b6ff64ece1e1c1ab1ef4228",
+                "shasum": "c0c32959b037843d1d053b60223a3e13e0693278"
             },
             "require": {
                 "cubist/net": "dev-master",
                 }
             ],
             "description": "Utilities class",
-            "time": "2021-09-13T17:11:49+00:00"
+            "time": "2021-09-15T15:24:17+00:00"
         },
         {
             "name": "cviebrock/eloquent-sluggable",
             "source": {
                 "type": "git",
                 "url": "git://git.cubedesigners.com/fluidbook_tools.git",
-                "reference": "cee9cbc8c5c8756448b7e6c9d42865d16c2266e8"
+                "reference": "6f09526ee33a67b11840421aa5f606a9cda1176b"
             },
             "dist": {
                 "type": "tar",
-                "url": "https://composer.cubedesigners.com/dist/fluidbook/tools/fluidbook-tools-dev-master-dfaf55.tar",
-                "reference": "cee9cbc8c5c8756448b7e6c9d42865d16c2266e8",
-                "shasum": "204142ce1cff1965fab050bf29165db2544c5875"
+                "url": "https://composer.cubedesigners.com/dist/fluidbook/tools/fluidbook-tools-dev-master-95ddd5.tar",
+                "reference": "6f09526ee33a67b11840421aa5f606a9cda1176b",
+                "shasum": "d0df8b14f7779f175f2628f54a30e3a5e95c6109"
             },
             "require": {
                 "barryvdh/laravel-debugbar": "^3.6",
                 }
             ],
             "description": "Fluidbook Tools",
-            "time": "2021-09-14T12:38:18+00:00"
+            "time": "2021-09-16T17:17:22+00:00"
         },
         {
             "name": "fruitcake/laravel-cors",
         },
         {
             "name": "laravel/framework",
-            "version": "v8.60.0",
+            "version": "v8.61.0",
             "source": {
                 "type": "git",
                 "url": "https://github.com/laravel/framework.git",
-                "reference": "44f16a31a1d4ac8a51605550d7796e2273984a48"
+                "reference": "3d528d3d3c8ecb444b50a266c212a52973a6669b"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/laravel/framework/zipball/44f16a31a1d4ac8a51605550d7796e2273984a48",
-                "reference": "44f16a31a1d4ac8a51605550d7796e2273984a48",
+                "url": "https://api.github.com/repos/laravel/framework/zipball/3d528d3d3c8ecb444b50a266c212a52973a6669b",
+                "reference": "3d528d3d3c8ecb444b50a266c212a52973a6669b",
                 "shasum": ""
             },
             "require": {
                 "tightenco/collect": "<5.5.33"
             },
             "provide": {
-                "psr/container-implementation": "1.0"
+                "psr/container-implementation": "1.0",
+                "psr/simple-cache-implementation": "1.0"
             },
             "replace": {
                 "illuminate/auth": "self.version",
                 "issues": "https://github.com/laravel/framework/issues",
                 "source": "https://github.com/laravel/framework"
             },
-            "time": "2021-09-08T13:37:21+00:00"
+            "time": "2021-09-14T13:31:32+00:00"
         },
         {
             "name": "laravel/sanctum",
         },
         {
             "name": "monolog/monolog",
-            "version": "2.3.2",
+            "version": "2.3.4",
             "source": {
                 "type": "git",
                 "url": "https://github.com/Seldaek/monolog.git",
-                "reference": "71312564759a7db5b789296369c1a264efc43aad"
+                "reference": "437e7a1c50044b92773b361af77620efb76fff59"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/Seldaek/monolog/zipball/71312564759a7db5b789296369c1a264efc43aad",
-                "reference": "71312564759a7db5b789296369c1a264efc43aad",
+                "url": "https://api.github.com/repos/Seldaek/monolog/zipball/437e7a1c50044b92773b361af77620efb76fff59",
+                "reference": "437e7a1c50044b92773b361af77620efb76fff59",
                 "shasum": ""
             },
             "require": {
                 "php": ">=7.2",
-                "psr/log": "^1.0.1"
+                "psr/log": "^1.0.1 || ^2.0 || ^3.0"
             },
             "provide": {
-                "psr/log-implementation": "1.0.0"
+                "psr/log-implementation": "1.0.0 || 2.0.0 || 3.0.0"
             },
             "require-dev": {
                 "aws/aws-sdk-php": "^2.4.9 || ^3.0",
                 "phpunit/phpunit": "^8.5",
                 "predis/predis": "^1.1",
                 "rollbar/rollbar": "^1.3",
-                "ruflin/elastica": ">=0.90 <7.0.1",
+                "ruflin/elastica": ">=0.90@dev",
                 "swiftmailer/swiftmailer": "^5.3|^6.0"
             },
             "suggest": {
                 "doctrine/couchdb": "Allow sending log messages to a CouchDB server",
                 "elasticsearch/elasticsearch": "Allow sending log messages to an Elasticsearch server via official client",
                 "ext-amqp": "Allow sending log messages to an AMQP server (1.0+ required)",
+                "ext-curl": "Required to send log messages using the IFTTTHandler, the LogglyHandler, the SendGridHandler, the SlackWebhookHandler or the TelegramBotHandler",
                 "ext-mbstring": "Allow to work properly with unicode symbols",
                 "ext-mongodb": "Allow sending log messages to a MongoDB server (via driver)",
+                "ext-openssl": "Required to send log messages using SSL",
+                "ext-sockets": "Allow sending log messages to a Syslog server (via UDP driver)",
                 "graylog2/gelf-php": "Allow sending log messages to a GrayLog2 server",
                 "mongodb/mongodb": "Allow sending log messages to a MongoDB server (via library)",
                 "php-amqplib/php-amqplib": "Allow sending log messages to an AMQP server using php-amqplib",
             ],
             "support": {
                 "issues": "https://github.com/Seldaek/monolog/issues",
-                "source": "https://github.com/Seldaek/monolog/tree/2.3.2"
+                "source": "https://github.com/Seldaek/monolog/tree/2.3.4"
             },
             "funding": [
                 {
                     "type": "tidelift"
                 }
             ],
-            "time": "2021-07-23T07:42:52+00:00"
+            "time": "2021-09-15T11:27:21+00:00"
         },
         {
             "name": "mxl/laravel-job",
                     "type": "github"
                 }
             ],
-            "abandoned": true,
             "time": "2020-09-28T06:45:17+00:00"
         },
         {