From: vincent@cubedesigners.com Date: Thu, 22 Jul 2021 15:56:29 +0000 (+0000) Subject: wip #4210 @1.5 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=c8ee13358902a31151dbe2b0caaf2e610a96028b;p=cubeextranet.git wip #4210 @1.5 --- diff --git a/inc/ws/Controlleur/class.ws.flash.php b/inc/ws/Controlleur/class.ws.flash.php index a4d572972..0f6ed14c2 100644 --- a/inc/ws/Controlleur/class.ws.flash.php +++ b/inc/ws/Controlleur/class.ws.flash.php @@ -219,7 +219,7 @@ class wsFlash extends cubeFlashGateway try { $api = new ws3API(); $api->uploadThemeFile($this->args['theme_id'], $this->args['fieldname'], $dest); - }catch (Exception $e){ + } catch (Exception $e) { } @@ -445,7 +445,7 @@ class wsFlash extends cubeFlashGateway $readOnly = array(1); $dao = new wsDAOTheme($core->con); - $themes = $dao->getAllThemes($core->user, 'ORDER BY FIELD (theme_id,' . $this->args['book_id'] . ',' . implode(',', $demos) . ') DESC, theme_id DESC', $demos,$this->xml); + $themes = $dao->getAllThemes($core->user, 'ORDER BY FIELD (theme_id,' . $this->args['book_id'] . ',' . implode(',', $demos) . ') DESC, theme_id DESC', $demos, $this->xml); foreach ($themes as $theme) { $t = $this->xml->addChild('theme'); $t->addAttribute('id', $theme->theme_id); @@ -486,9 +486,9 @@ class wsFlash extends cubeFlashGateway public function renameTheme() { global $core; - $dao = new wsDAOTheme($core->con); $dao->rename($this->args['theme_id'], $this->args['text']); + } public function duplicateTheme() diff --git a/inc/ws/DAO/class.ws.dao.theme.php b/inc/ws/DAO/class.ws.dao.theme.php index 87e7f262d..19d2104a0 100644 --- a/inc/ws/DAO/class.ws.dao.theme.php +++ b/inc/ws/DAO/class.ws.dao.theme.php @@ -129,12 +129,6 @@ class wsDAOTheme extends commonDAO } $c->parametres = serialize($p); $c->update('WHERE theme_id=\'' . $this->con->escape($data['theme_id']) . '\''); - 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'], 'themes_vue', true)); @@ -149,35 +143,20 @@ class wsDAOTheme extends commonDAO return $r->theme_id + 1; } - public function delete($theme_id, $onlyFiles = false) + public function delete($theme_id) { if (is_null($theme_id) || $theme_id == '') { return; } - if (!$onlyFiles) { - $this->con->execute('DELETE FROM themes WHERE theme_id=\'' . $this->con->escape($theme_id) . '\''); - $api = new ws3API(); - $api->deleteTheme($theme_id); - } - $fref = WS_THEMES . '/' . $theme_id; - if (file_exists($fref)) { - files::deltree($fref); - } - if (file_exists($fref . '.jpg')) { - unlink($fref . '.jpg'); - } + + $api = new ws3API(); + $api->deleteTheme($theme_id); } public function rename($theme_id, $newname) { - $c = $this->con->openCursor('themes'); - $c->nom = $newname; - $c->update('WHERE theme_id=\'' . $this->con->escape($theme_id) . '\''); - - $theme = $this->selectById($theme_id, 'themes_vue', true); - $theme->nom = $newname; $api = new ws3API(); - $api->updateTheme($theme); + $api->renameTheme($theme_id, $newname); } public function duplicate($theme_id, $proprietaire) @@ -186,49 +165,11 @@ class wsDAOTheme extends commonDAO return; } - $nextID = $this->getNextId(); - echo $nextID; - $theme = $this->selectById($theme_id); - // Copie des données - $c = $this->con->openCursor('themes'); - $c->theme_id = $nextID; - $c->nom = $theme->nom . ' (copy)'; - $c->parametres = serialize($theme->parametres); - $c->signature = $theme->signature; - $c->icones = $theme->icones; - $c->proprietaire = $proprietaire; - $c->date = TIME; - $c->insert(); - - $this->delete($nextID, true); - // Copie des fichiers - $from = WS_THEMES . '/' . $theme_id; - $to = WS_THEMES . '/' . $nextID; - if (!file_exists($to)) { - mkdir($to, 0777, true); - } else { - files::deltree($to); - mkdir($to, 0777, true); - } // - `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'); - } - try { - $theme = $this->selectById($nextID, 'themes_vue', true); - $api = new ws3API(); - $api->createTheme($theme); - } catch (Exception $e) { - print_r($e); - exit; - } + $api = new ws3API(); + $newId = ws3API::getResponseBody($api->cloneTheme($theme_id)); - return $this->selectById($c->theme_id); + return $this->selectById($newId); } } \ No newline at end of file diff --git a/inc/ws/Metier/class.ws.theme.parametres.php b/inc/ws/Metier/class.ws.theme.parametres.php index 9094171a7..2e865d146 100644 --- a/inc/ws/Metier/class.ws.theme.parametres.php +++ b/inc/ws/Metier/class.ws.theme.parametres.php @@ -14,7 +14,7 @@ class wsThemeParametres extends wsParametres return; } - $themeRoot = 'fluidbook/themes/' . $this->parent->theme_id; + $themeRoot = 'fluidbook/themes3/' . $this->parent->theme_id; $uploadThemeURL = SITE_PATH . 'flash/uploadThemeFile/?theme_id=' . $this->parent->theme_id . '&' . session_name() . '=' . session_id(); parent::initFields(); diff --git a/inc/ws/Util/class.ws.ws3api.php b/inc/ws/Util/class.ws.ws3api.php index b0f5a204f..dea2a93fd 100644 --- a/inc/ws/Util/class.ws.ws3api.php +++ b/inc/ws/Util/class.ws.ws3api.php @@ -24,6 +24,18 @@ class ws3API extends Zend_Rest_Client return $this->restPost('/api/fluidbook-theme', ['api_token' => $core->user->api_token, 'theme' => $this->_themeData($theme)]); } + public function renameTheme($theme_id, $newname) + { + global $core; + return $this->restPut('/api/fluidbook-theme/' . $theme_id . '/rename', ['api_token' => $core->user->api_token, 'newname' => $newname]); + } + + public function cloneTheme($theme_id) + { + global $core; + return $this->restPost('/api/fluidbook-theme/' . $theme_id . '/clone', ['api_token' => $core->user->api_token]); + } + public function updateTheme($theme) { global $core; @@ -56,4 +68,9 @@ class ws3API extends Zend_Rest_Client return $data; } + public static function getResponseBody(Zend_Http_Response $response) + { + return $response->getBody(); + } + } \ No newline at end of file diff --git a/inc/ws/Util/html5/master/class.ws.html5.compiler.php b/inc/ws/Util/html5/master/class.ws.html5.compiler.php index 3846f1851..132e834ba 100644 --- a/inc/ws/Util/html5/master/class.ws.html5.compiler.php +++ b/inc/ws/Util/html5/master/class.ws.html5.compiler.php @@ -306,7 +306,7 @@ class wsHTML5Compiler } else { $this->theme = $daoTheme->getThemeOfBook($book_id, true); } - $this->themeRoot = WS_THEMES . '/' . $this->theme->theme_id . '/'; + $this->themeRoot = WS_FILES . '/themes3/' . $this->theme->theme_id . '/'; $daoDoc = new wsDAODocument($core->con);