From 64b025317b5bde43f866c37a339025d12c45d4af Mon Sep 17 00:00:00 2001 From: "vincent@cubedesigners.com" Date: Wed, 21 Jul 2021 12:59:47 +0000 Subject: [PATCH] wip #4210 @3 --- inc/ws/Controlleur/class.ws.flash.php | 15 +++-- inc/ws/Controlleur/class.ws.maintenance.php | 6 ++ inc/ws/DAO/class.ws.dao.book.php | 11 +++- inc/ws/DAO/class.ws.dao.theme.php | 61 ++++++++++++--------- inc/ws/Util/class.ws.ws3api.php | 2 + 5 files changed, 57 insertions(+), 38 deletions(-) diff --git a/inc/ws/Controlleur/class.ws.flash.php b/inc/ws/Controlleur/class.ws.flash.php index e26d4c414..a4d572972 100644 --- a/inc/ws/Controlleur/class.ws.flash.php +++ b/inc/ws/Controlleur/class.ws.flash.php @@ -216,8 +216,12 @@ class wsFlash extends cubeFlashGateway } move_uploaded_file($infos['tmp_name'], $dest); - $api = new ws3API(); - $api->uploadThemeField($this->args['theme_id'], $this->args['fieldname'], $dest); + try { + $api = new ws3API(); + $api->uploadThemeFile($this->args['theme_id'], $this->args['fieldname'], $dest); + }catch (Exception $e){ + + } if (isset($this->args['type']) && $this->args['type'] == 'favicon') { $icotool = new cubeCommandLine('icotool'); @@ -491,8 +495,8 @@ class wsFlash extends cubeFlashGateway { global $core; $dao = new wsDAOTheme($core->con); - $theme = $dao->duplicate($this->args['theme_id'], $core->user->utilisateur_id); + $this->xml->addChild('theme_id', $theme->theme_id); if (isset($this->args['book_id'])) { $dao = new wsDAOBook($core->con); @@ -508,11 +512,6 @@ class wsFlash extends cubeFlashGateway $dao->setTheme($this->args['book_id'], $this->args['theme']); } - public function postThemeShot() - { - file_put_contents(WS_THEMES . '/' . $this->args['theme_id'] . '.jpg', base64_decode($this->args['data'])); - } - public function getAllIcones() { global $core; diff --git a/inc/ws/Controlleur/class.ws.maintenance.php b/inc/ws/Controlleur/class.ws.maintenance.php index 1f4dc36a1..9db165417 100644 --- a/inc/ws/Controlleur/class.ws.maintenance.php +++ b/inc/ws/Controlleur/class.ws.maintenance.php @@ -1556,6 +1556,12 @@ class wsMaintenance } } } + + public static function test(){ + global $core; + $dao=new wsDAOTheme($core->con); + print_r($dao->selectById('3641')); + } } diff --git a/inc/ws/DAO/class.ws.dao.book.php b/inc/ws/DAO/class.ws.dao.book.php index ae86af0d0..d53e76a28 100644 --- a/inc/ws/DAO/class.ws.dao.book.php +++ b/inc/ws/DAO/class.ws.dao.book.php @@ -1198,7 +1198,12 @@ class wsDAOBook extends commonDAO return; } - $this->_compileLock = WS_BOOKS . '/locks/' . $book_id . '.lock'; + $lockId = $book_id; + if ($forceTheme) { + $lockId .= '-' . wsTheme::hashThemeArray($forceTheme); + } + + $this->_compileLock = WS_BOOKS . '/locks/' . $lockId . '.lock'; while (file_exists($this->_compileLock) && filemtime($this->_compileLock) > (time() - 900)) { @@ -1252,14 +1257,14 @@ class wsDAOBook extends commonDAO return wsBook::getAssetDirOfBook($book_id, $dir) . $path; } - public function compileHTML5($book_id, $book, $dev = false, $delete = true,$forceTheme=false) + public function compileHTML5($book_id, $book, $dev = false, $delete = true, $forceTheme = false) { $version = $book->parametres->mobileLVersion; if ($dev) { $version = 'dev'; } - $htmlCompiler = wsHTML5::compilerFactory($book_id, $version, false, 'latest', null, false, false, false, $book,$forceTheme); + $htmlCompiler = wsHTML5::compilerFactory($book_id, $version, false, 'latest', null, false, false, false, $book, $forceTheme); $htmlCompiler->compile($delete); self::$lastHTML5Compiler = $htmlCompiler; diff --git a/inc/ws/DAO/class.ws.dao.theme.php b/inc/ws/DAO/class.ws.dao.theme.php index 3cdcb832d..87e7f262d 100644 --- a/inc/ws/DAO/class.ws.dao.theme.php +++ b/inc/ws/DAO/class.ws.dao.theme.php @@ -59,24 +59,28 @@ class wsDAOTheme extends commonDAO return $theme; } - protected function _table($table) + protected function _table($table, $force_table = false) { + if ($force_table) { + return $table; + } + global $core; - if (false && $core->user->utilisateur_id == 5) { - if ($table === 'themes_vue') { - return 'ws3_theme_vue'; - } else if ($table === 'themes') { - return 'ws3_theme'; - } - } else { - return $table; + //if (is_object($core->user) && $core->user->utilisateur_id == 5) { + if ($table === 'themes_vue') { + return 'ws3_theme_vue'; + } else if ($table === 'themes') { + return 'ws3_theme'; } + //} else { + // return $table; + //} } - public function selectById($theme_id, $table = 'themes_vue') + public function selectById($theme_id, $table = 'themes_vue', $force_table = false) { - $r = $this->con->select('SELECT * FROM ' . $this->_table($table) . ' WHERE theme_id=\'' . $this->con->escape($theme_id) . '\' LIMIT 1'); + $r = $this->con->select('SELECT * FROM ' . $this->_table($table, $force_table) . ' WHERE theme_id=\'' . $this->con->escape($theme_id) . '\' LIMIT 1'); return $this->singleton($r); } @@ -128,9 +132,12 @@ class wsDAOTheme extends commonDAO if (file_exists(WS_THEMES . '/' . $data['theme_id'] . '.jpg')) { unlink(WS_THEMES . '/' . $data['theme_id'] . '.jpg'); } + if (file_exists(WS_FILES . '/themes3/' . $data['theme_id'] . '.jpg')) { + unlink(WS_FILES . '/themes3/' . $data['theme_id'] . '.jpg'); + } $api = new ws3API(); - $api->updateTheme($this->selectById($data['theme_id'])); + $api->updateTheme($this->selectById($data['theme_id'], 'themes_vue', true)); } protected function getNextId() @@ -167,7 +174,7 @@ class wsDAOTheme extends commonDAO $c->nom = $newname; $c->update('WHERE theme_id=\'' . $this->con->escape($theme_id) . '\''); - $theme = $this->selectById($theme_id); + $theme = $this->selectById($theme_id, 'themes_vue', true); $theme->nom = $newname; $api = new ws3API(); $api->updateTheme($theme); @@ -178,10 +185,13 @@ class wsDAOTheme extends commonDAO if (is_null($theme_id) || $theme_id == '') { return; } + + $nextID = $this->getNextId(); + echo $nextID; $theme = $this->selectById($theme_id); // Copie des données $c = $this->con->openCursor('themes'); - $c->theme_id = $this->getNextId(); + $c->theme_id = $nextID; $c->nom = $theme->nom . ' (copy)'; $c->parametres = serialize($theme->parametres); $c->signature = $theme->signature; @@ -190,30 +200,27 @@ class wsDAOTheme extends commonDAO $c->date = TIME; $c->insert(); - $this->delete($c->theme_id, true); + $this->delete($nextID, true); // Copie des fichiers $from = WS_THEMES . '/' . $theme_id; - $to = WS_THEMES . '/' . $c->theme_id; - $dr = opendir($from); + $to = WS_THEMES . '/' . $nextID; if (!file_exists($to)) { mkdir($to, 0777, true); } else { files::deltree($to); mkdir($to, 0777, true); - } //. - while ($file = readdir($dr)) { - if ($file == '.' || $file == '..') { - continue; - } - copy($from . '/' . $file, $to . '/' . $file); - } + } // + `cp -r $from/* $to`; if (file_exists($from . '.jpg')) { copy($from . '.jpg', $to . '.jpg'); } + $thumb = '/data1/extranet/toolbox/storage/themes/'; + if (file_exists($thumb . $theme_id . '.jpg')) { + copy($thumb . $theme_id . '.jpg', $thumb . $nextID . '.jpg'); + } - - $theme = $this->selectById($c->theme_id); try { + $theme = $this->selectById($nextID, 'themes_vue', true); $api = new ws3API(); $api->createTheme($theme); } catch (Exception $e) { @@ -221,7 +228,7 @@ class wsDAOTheme extends commonDAO exit; } - return $theme; + return $this->selectById($c->theme_id); } } \ No newline at end of file diff --git a/inc/ws/Util/class.ws.ws3api.php b/inc/ws/Util/class.ws.ws3api.php index 47d9cfa8c..b0f5a204f 100644 --- a/inc/ws/Util/class.ws.ws3api.php +++ b/inc/ws/Util/class.ws.ws3api.php @@ -9,6 +9,8 @@ class ws3API extends Zend_Rest_Client $uri = 'https://toolbox.fluidbook.com/'; } parent::__construct($uri); + self::getHttpClient()->setConfig([ + 'timeout' => 300]); } -- 2.39.5