From d71ee2f7f84c2d4002947fd27bf0005b63e657c3 Mon Sep 17 00:00:00 2001 From: "vincent@cubedesigners.com" Date: Thu, 2 Feb 2023 14:06:43 +0000 Subject: [PATCH] wip #5701 @2 --- inc/ws/Controlleur/class.ws.flash.php | 58 +++++++++++++++++++++- inc/ws/Metier/class.ws.book.php | 10 ++-- inc/ws/Util/packager/class.ws.packager.php | 5 +- 3 files changed, 66 insertions(+), 7 deletions(-) diff --git a/inc/ws/Controlleur/class.ws.flash.php b/inc/ws/Controlleur/class.ws.flash.php index 6a31c50d5..f015b4ad5 100644 --- a/inc/ws/Controlleur/class.ws.flash.php +++ b/inc/ws/Controlleur/class.ws.flash.php @@ -62,6 +62,8 @@ class wsFlash extends cubeFlashGateway } $dao = new wsDAODocument($core->con); + $daoBook = new wsDAOBook($core->con); + $book = $daoBook->selectById($this->args['book_id']); $documents = []; foreach ($_FILES as $varname => $infos) { if ($infos['error']) { @@ -69,6 +71,7 @@ class wsFlash extends cubeFlashGateway } // Initialisation du document $data = array(); + $data['region'] = $book->region; $data['proprietaire'] = $core->user->utilisateur_id; $data['pages'] = 0; $data['version'] = 2; @@ -282,6 +285,59 @@ class wsFlash extends cubeFlashGateway } } + public function testDocuments() + { + global $core; + + $toload = $this->xml->addChild('toLoad'); + $alreadyLoaded = $this->xml->addChild('alreadyLoaded'); + + $hash = array(); + + foreach ($this->args['fileName'] as $k => $name) { + $o = new wsDocumentLocalInfos(); + $o->fileName = $name; + $o->fileSize = intval($this->args['fileSize'][$k]); + $o->modificationDate = intval($this->args['modificationDate'][$k]); + $o->creationDate = intval($this->args['creationDate'][$k]); + + $hash[$k] = md5(serialize($o)); + } + + $in = array(); + foreach ($hash as $h) { + $in[] = "'" . $h . "'"; + } + + $sql = 'SELECT document_id,localHash FROM documents WHERE localHash'; + if (count($in) == 1) { + $sql .= ' = ' . implode(',', $in); + } else { + $sql .= ' IN (' . implode(',', $in) . ')'; + } + + $al = array(); + $r = $core->con->select($sql); + while ($r->fetch()) { + $k = array_search($r->localHash, $hash); + + if (!file_exists(wsDocument::getDir($r->document_id) . 'crop.pdf')) { + continue; + } + + $al[$k] = true; + $f = $alreadyLoaded->addChild('file', $this->args['fileName'][$k]); + $f->addAttribute('document_id', $r->document_id); + } + + foreach ($this->args['fileName'] as $k => $name) { + if (!isset($al[$k])) { + $toload->addChild('file', $name); + } + } + } + + public function getPagesOfBook() { global $core; @@ -794,7 +850,7 @@ class wsFlash extends cubeFlashGateway global $core; $dao = new wsDAOBook($core->con); - // $log = $dao->compile($this->args['book_id'], '2'); + // $log = $dao->compile($this->args['book_id'], '2'); $book = $dao->selectById($this->args['book_id']); $viewer = 'viewer'; diff --git a/inc/ws/Metier/class.ws.book.php b/inc/ws/Metier/class.ws.book.php index 322cbd775..4f8ed212b 100644 --- a/inc/ws/Metier/class.ws.book.php +++ b/inc/ws/Metier/class.ws.book.php @@ -137,18 +137,22 @@ class wsBook extends cubeMetier wsMaintenance::timeoutRequest('https://workshop.fluidbook.com/maintenance/processBookPages/' . $book_id, 1); } - public static function getRegionDir($id) + public static function getRegionDir($id, $root = true) { if (!isset(self::$_bookDirs[$id])) { self::$_bookDirs[$id] = self::_getRegion($id); } - return (self::$_bookDirs[$id] === 'UE' ? WS_BOOKS : US_BOOKS) . '/'; + if ($root) { + return (self::$_bookDirs[$id] === 'UE' ? WS_FILES : US_FILES) . '/'; + } else { + return (self::$_bookDirs[$id] === 'UE' ? WS_BOOKS : US_BOOKS) . '/'; + } } public static function getDir($id, $dir, $addSlash = true, $onlyroot = false) { - $res = self::getRegionDir($id); + $res = self::getRegionDir($id,false); $res .= $dir . '/'; if (!$onlyroot) { $res .= $id . '/'; diff --git a/inc/ws/Util/packager/class.ws.packager.php b/inc/ws/Util/packager/class.ws.packager.php index 7d6667e9c..44c18ec3c 100644 --- a/inc/ws/Util/packager/class.ws.packager.php +++ b/inc/ws/Util/packager/class.ws.packager.php @@ -180,7 +180,7 @@ class wsPackager } - $res = $this->getRelativeBase(); + $res .= $this->getRelativeBase(); if ($ext != '') { $res .= '.' . $ext; } @@ -189,7 +189,7 @@ class wsPackager protected function getPathBase($ext = '') { - $base=wsBook::getRegionDir($this->book_id); + $base = wsBook::getRegionDir($this->book_id,true); if (!file_exists($base . '/packager/download')) { mkdir($base . '/packager/download', 0777, true); } @@ -197,7 +197,6 @@ class wsPackager if ($ext != '') { $res .= '.' . $ext; } - return $res; } -- 2.39.5