From: vincent@cubedesigners.com Date: Wed, 18 Oct 2023 07:31:58 +0000 (+0000) Subject: wip #6407 @1.5 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=e45dbf9e9250d79702978db9507bcb01dccf341e;p=fluidbook-v3.git wip #6407 @1.5 --- diff --git a/framework/application/Fluidbook/ToolboxAPI.php b/framework/application/Fluidbook/ToolboxAPI.php new file mode 100644 index 0000000..0f61acb --- /dev/null +++ b/framework/application/Fluidbook/ToolboxAPI.php @@ -0,0 +1,120 @@ +token = $token; + } + parent::__construct($uri); + self::getHttpClient()->setConfig([ + 'timeout' => 1800]); + + } + + public function clearCache($tag = null) + { + set_time_limit(300); + return $this->restPost('/api/cache/clear' . (null === $tag ? '' : '/' . $tag), ['api_token' => $this->token]); + } + + public function renameTheme($theme_id, $newname) + { + return $this->restPut('/api/fluidbook-theme/' . $theme_id . '/rename', ['api_token' => $this->token, 'newname' => $newname]); + } + + public function cloneTheme($theme_id) + { + return $this->restPost('/api/fluidbook-theme/' . $theme_id . '/clone', ['api_token' => $this->token]); + } + + public function updateTheme($data) + { + return $this->restPut('/api/fluidbook-theme/' . $data['theme_id'], ['api_token' => $this->token, 'data' => $data]); + } + + public function deleteTheme($themeId) + { + return $this->restDelete('/api/fluidbook-theme/' . $themeId, ['api_token' => $this->token]); + } + + public function uploadThemeFile($themeId, $field, $path) + { + return $this->restPut('/api/fluidbook-theme/' . $themeId . '/uploadfile/' . $field, ['api_token' => $this->token, 'path' => $path]); + } + + public function getPublicationMetadata($id) + { + return json_decode($this->restGet('/api/fluidbook-publication/' . $id . '/metadata', ['api_token' => $this->token])->getBody()); + } + + public function downloadPublication($id, $version = 'online') + { + return $this->restGet('/api/fluidbook-publication/' . $id . '/download/' . $version, ['api_token' => $this->token])->getBody(); + } + + public function installBookIfNeeded($id, $dir, $timestamp = 'auto', $version = 'online') + { + if ($timestamp == 'auto') { + $timestamp = max($this->getPublicationMetadata($id)->date, time() - (3600 * 48)); + } + + $install = false; + if (!file_exists($dir) || (!file_exists($dir . '/TIME') && !file_exists($dir . '/_TIME')) || !file_exists($dir . '/index.html')) { + $install = true; + } else if ($timestamp != 'skip') { + if (file_exists($dir . '/TIME')) { + $date = file_get_contents($dir . '/TIME'); + } else { + $date = file_get_contents($dir . '/_TIME'); + } + if ($date < $timestamp) { + $install = true; + } + } + + if ($install) { + return $this->installBook($id, $dir, $version); + } + return false; + } + + public function installBook($id, $dir, $version = 'online', $tries = 3, $beforeInstallCallback = null) + { + $url = $this->downloadPublication($id, $version); + set_time_limit(0); + // Unzip + $tmp = CubeIT_Files::tempnam() . '.zip'; + copy($url, $tmp); + $tdir = $dir . '.temp'; + CubeIT_Util_Zip::extract($tmp, $tdir); + unlink($tmp); + file_put_contents($tdir . '/TIME', time()); + + set_time_limit(0); + CubeIT_Files::rmdir($dir); + + if (null !== $beforeInstallCallback && is_callable($beforeInstallCallback)) { + call_user_func($beforeInstallCallback); + } + mkdir($dir, 0777, true); + echo `mv -f $tdir/* $dir`; + if (!file_exists($dir . '/_TIME')) { + file_put_contents($dir . '/_TIME', time()); + } + CubeIT_Files::rmdir($tdir); + return false; + } + + public static function getResponseBody(Zend_Http_Response $response) + { + return $response->getBody(); + } + +} \ No newline at end of file diff --git a/framework/application/configs/application.ini b/framework/application/configs/application.ini index 367c018..dbe95a5 100644 --- a/framework/application/configs/application.ini +++ b/framework/application/configs/application.ini @@ -41,7 +41,7 @@ navigation.containers.Sitemap = -4; webhost = www.fluidbook.com -locales.redirect = true +locales.redirect = false locales.fr = www.fluidbook.com locales.en = en.fluidbook.com diff --git a/framework/application/controllers/AjaxController.php b/framework/application/controllers/AjaxController.php index a6d0330..c8c8bc0 100644 --- a/framework/application/controllers/AjaxController.php +++ b/framework/application/controllers/AjaxController.php @@ -5,6 +5,8 @@ class AjaxController extends CubeIT_Controller_AjaxController public function requestQuote($formID = null) { + @file_put_contents(FRAMEWORK_PATH . '/log/quote.' . time() . '.log', var_export($_POST, true)); + CubeIT_Util_PHP::neverStop(); $form = new Fluidbook_Form_RequestQuote(); @@ -23,10 +25,8 @@ class AjaxController extends CubeIT_Controller_AjaxController $data['gclid'] = Bootstrap::getInstance()->getSession()->gclid; } -// $url = 'https://workshop.fluidbook.com/ajax/demandeDevis?devis_form=' . base64_encode(json_encode($data)); -// file_get_contents($url); - $url = 'https://toolbox.fluidbook.com/fluidbook-quote/create-from-website?data=' . base64_encode(json_encode($data)); + $this->_datas->addDebug($url); $json = json_decode(file_get_contents($url)); $this->_datas->addDebug($json); @@ -43,12 +43,17 @@ class AjaxController extends CubeIT_Controller_AjaxController } $this->_datas->addGAEvent('form', 'sent', 'quote'); + + @file_put_contents(FRAMEWORK_PATH . '/log/quote.' . time() . '.details.log', var_export($_POST, true) . "\n\n" . json_encode($data) . "\n\n" . base64_encode(json_encode($data))); } else { $this->_datas->refreshForm($form); // Respond with validation errors $this->_datas->addAction('eval', "displayErrors('$formID')"); $this->_datas->addGAEvent('form', 'error', 'quote'); } + + + } } diff --git a/framework/application/controllers/MaintenanceController.php b/framework/application/controllers/MaintenanceController.php index 09e74ea..fd0c31a 100644 --- a/framework/application/controllers/MaintenanceController.php +++ b/framework/application/controllers/MaintenanceController.php @@ -24,7 +24,7 @@ class MaintenanceController extends CubeIT_Controller_MaintenanceController /** * @return CubeIT_Services_Fluidbook */ - protected static function getFluidbookAPI() + protected static function getWorkshopAPI() { $res = new CubeIT_Services_Fluidbook(); $res->login('api@fluidbook.com', '#fTJAx!Ea5kanhX'); @@ -36,7 +36,8 @@ class MaintenanceController extends CubeIT_Controller_MaintenanceController set_time_limit(0); ignore_user_abort(true); - $ws = self::getFluidbookAPI(); + $ws = self::getWorkshopAPI(); + $references = Fluidbook_Model_Reference::factory()->find(); if (isset($_GET['id'])) { @@ -62,37 +63,59 @@ class MaintenanceController extends CubeIT_Controller_MaintenanceController break; } try { - $meta = $ws->getMetadata($fluidbook); - $dir = PUBLIC_PATH . '/references/' . $fluidbook . '-' . CubeIT_Text::str2URL(trim($meta->title)); - - try { - $res = $ws->installBookIfNeeded($fluidbook, $dir, isset($_GET['force']) ? time() : 'auto'); - if ($res) { - $n++; - } - } catch (exception $e) { - echo 'Error installing book '.$fluidbook . '
'; - exit; + $res = self::importReference($id, true); + if ($res) { + $n++; } } catch (exception $e) { - echo 'Error getting metadata for book '.$fluidbook . '
'; + echo 'Error installing book ' . $fluidbook . '
'; exit; } } } - public static function importReference($id) + public static function importReference($id, $onlyIfNeeded = false) { - $ws = self::getFluidbookAPI(); + if ($id < 30000) { + return self::importWSReference($id, $onlyIfNeeded); + } + return self::importToolboxReference($id, $onlyIfNeeded); + } + + public static function importToolboxReference($id, $onlyIfNeeded = false) + { + $api = self::getToolboxAPI(); + $meta = $api->getPublicationMetadata($id); + return self::_install($api, $id, $meta, $onlyIfNeeded); + } + + /** + * @return Fluidbook_ToolboxAPI + */ + public static function getToolboxAPI() + { + return new Fluidbook_ToolboxAPI('https://toolbox.fluidbook.com/', 'Dxsm2nqsvbV4ubH8KUEMRpbfsRrsDZagJkCZV2Nvuy83oPqsSEKC6ircWdC2'); + } + + public static function importWSReference($id, $onlyIfNeeded = false) + { + $ws = self::getWorkshopAPI(); $meta = $ws->getMetadata($id); + + return self::_install($ws, $id, $meta, $onlyIfNeeded); + } + + protected static function _install($api, $id, $meta, $onlyIfNeeded) + { $dir = PUBLIC_PATH . '/references/' . $id . '-' . CubeIT_Text::str2URL(trim($meta->title)); - $res = $ws->installBook($id, $dir, 'online', 3, function () use ($id) { + if ($onlyIfNeeded) { + return $api->installBookIfNeeded($id, $dir, isset($_GET['force']) ? time() : 'auto'); + } + return $api->installBook($id, $dir, 'online', 3, function () use ($id) { $delete = PUBLIC_PATH . '/references/' . $id . '-*'; $deleteCmd = "rm -rf $delete !(*.temp)"; `$deleteCmd`; }); - - echo $id . ' : ' . $dir . ' // ' . print_r($res, true); } }