From 12fe8d29ba4b778ce5015831b2ee77b2a73daf96 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Fri, 3 Feb 2023 16:11:54 +0100 Subject: [PATCH] wip #5701 @5 --- app/src/ProcessFile.php | 249 +++++++++++++++++++++------------------- 1 file changed, 133 insertions(+), 116 deletions(-) diff --git a/app/src/ProcessFile.php b/app/src/ProcessFile.php index 1183dc0..c9eeb66 100644 --- a/app/src/ProcessFile.php +++ b/app/src/ProcessFile.php @@ -5,121 +5,138 @@ namespace Fluidbook\Farmer; use Cubist\PDF\PDFTools; use Cubist\Util\Files\Files; -class ProcessFile extends \Fluidbook\Tools\Jobs\ProcessFile -{ - protected const DISTANT_ROOT = '/application/fluidbook/docs/'; - protected const LOCAL_ROOT = '/files/'; - - protected $page; - protected $out; - protected $force = false; - protected $mobileRatio = 1; - protected $resolutionRatio = 1; - protected $filespath; - protected $_job = null; - - public function __construct($out, $page, $resolutionRatio, $mobileRatio, $format = 'jpg', $resolution = 150, $withGraphics = true, $withTexts = true, $version = 'html', $force = false) - { - - $this->setOut($out); - $this->setPage($page); - $this->setForce(!!$force); - $this->setResolutionRatio($resolutionRatio); - $this->setMobileRatio($mobileRatio); - parent::__construct($format, $resolution, $withGraphics, $withTexts, $version); - } - - /** - * @param float $mobileRatio - */ - public function setMobileRatio(float $mobileRatio): void - { - $this->mobileRatio = $mobileRatio; - } - - /** - * @param float $resolutionRatio - */ - public function setResolutionRatio(float $resolutionRatio): void - { - $this->resolutionRatio = $resolutionRatio; - } - - public function getMobileRatio(): float - { - return $this->mobileRatio; - } - - public function getResolutionRatio(): float - { - return $this->resolutionRatio; - } - - - /** - * @return bool - */ - public function isForce(): bool - { - return $this->force; - } - - /** - * @param bool $force - */ - public function setForce(bool $force): void - { - $this->force = $force; - } - - /** - * @param mixed $page - */ - public function setPage($page): void - { - $this->page = $page; - } - - public function getPage(): int - { - return $this->page; - } - - public function getDistantOut() - { - return $this->out; - } - - public function getLocalOut() - { - return $this->getOut(); - } - - public function getOut() - { - return str_replace(self::DISTANT_ROOT, self::LOCAL_ROOT, $this->getDistantOut()); - } - - /** - * @param mixed $out - */ - public function setOut($out): void - { - $this->out = $out; - } - - public function process() - { - return str_replace(self::LOCAL_ROOT, self::DISTANT_ROOT, $this->getPath($this->isForce())); - } - - public function getSplittedPDFPage() - { - $res = $this->getOut() . 'pdf/p' . $this->getPage() . '.pdf'; - if (!file_exists($res)) { - PDFTools::split(Files::firstThatExists($this->getOut() . '/crop.pdf', $this->getOut() . '/fixed.pdf', $this->getOut() . '/original.pdf'), $this->getOut() . '/pdf'); - } - return $res; - } +class ProcessFile extends \Fluidbook\Tools\Jobs\ProcessFile { + protected const DISTANT_ROOT = '/application/fluidbook/docs/'; + protected const LOCAL_ROOT = '/files/'; + + protected const US_DISTANT_ROOT = '/application/usstorage/docs/'; + protected const US_LOCAL_ROOT = '/usfiles/'; + + /** + * @var string + */ + protected $region = 'UE'; + + protected $page; + protected $out; + protected $force = false; + protected $mobileRatio = 1; + protected $resolutionRatio = 1; + protected $filespath; + protected $_job = null; + + public function __construct($out, $page, $resolutionRatio, $mobileRatio, $format = 'jpg', $resolution = 150, $withGraphics = true, $withTexts = true, $version = 'html', $force = false) { + + if (stristr($out, 'usstorage')) { + $this->setRegion('US'); + } + $this->setOut($out); + $this->setPage($page); + $this->setForce(!!$force); + $this->setResolutionRatio($resolutionRatio); + $this->setMobileRatio($mobileRatio); + parent::__construct($format, $resolution, $withGraphics, $withTexts, $version); + } + + /** + * @param float $mobileRatio + */ + public function setMobileRatio(float $mobileRatio): void { + $this->mobileRatio = $mobileRatio; + } + + /** + * @param float $resolutionRatio + */ + public function setResolutionRatio(float $resolutionRatio): void { + $this->resolutionRatio = $resolutionRatio; + } + + public function getMobileRatio(): float { + return $this->mobileRatio; + } + + public function getResolutionRatio(): float { + return $this->resolutionRatio; + } + + + /** + * @return bool + */ + public function isForce(): bool { + return $this->force; + } + + /** + * @param bool $force + */ + public function setForce(bool $force): void { + $this->force = $force; + } + + /** + * @param mixed $page + */ + public function setPage($page): void { + $this->page = $page; + } + + public function getPage(): int { + return $this->page; + } + + public function getDistantOut() { + return $this->out; + } + + public function getLocalOut() { + return $this->getOut(); + } + + public function getOut() { + if ($this->getRegion() === 'UE') { + return str_replace(self::DISTANT_ROOT, self::LOCAL_ROOT, $this->getDistantOut()); + } else { + return str_replace(self::US_DISTANT_ROOT, self::US_LOCAL_ROOT, $this->getDistantOut()); + } + } + + /** + * @param mixed $out + */ + public function setOut($out): void { + $this->out = $out; + } + + /** + * @return string + */ + public function getRegion(): string { + return $this->region; + } + + /** + * @param string $region + */ + public function setRegion(string $region): void { + $this->region = $region; + } + + public function process() { + if ($this->getRegion() === 'UE') { + return str_replace(self::LOCAL_ROOT, self::DISTANT_ROOT, $this->getPath($this->isForce())); + } else { + return str_replace(self::US_LOCAL_ROOT, self::US_DISTANT_ROOT, $this->getPath($this->isForce())); + } + } + + public function getSplittedPDFPage() { + $res = $this->getOut() . 'pdf/p' . $this->getPage() . '.pdf'; + if (!file_exists($res)) { + PDFTools::split(Files::firstThatExists($this->getOut() . '/crop.pdf', $this->getOut() . '/fixed.pdf', $this->getOut() . '/original.pdf'), $this->getOut() . '/pdf'); + } + return $res; + } } \ No newline at end of file -- 2.39.5