protected function execute(InputInterface $input, OutputInterface $output)
 {
     $storeId = $input->getArgument('storeId');
     if (!is_numeric($storeId)) {
         throw new \Exception('Invalid store ID');
     }
     $db = Db::get();
     $tableList = $db->fetchAll("show tables like 'object_classificationstore_data_%'");
     foreach ($tableList as $table) {
         $theTable = current($table);
         $sql = "delete from " . $theTable . " where keyId In (select id from classificationstore_keys where storeId = " . $db->quote($storeId) . ")";
         echo $sql . "\n";
         $db->query($sql);
     }
     $tableList = $db->fetchAll("show tables like 'object_classificationstore_groups_%'");
     foreach ($tableList as $table) {
         $theTable = current($table);
         $sql = "delete from " . $theTable . " where groupId In (select id from classificationstore_groups where storeId = " . $db->quote($storeId) . ")";
         echo $sql . "\n";
         $db->query($sql);
     }
     $sql = "delete from classificationstore_keys where storeId = " . $db->quote($storeId);
     echo $sql . "\n";
     $db->query($sql);
     $sql = "delete from classificationstore_groups where storeId = " . $db->quote($storeId);
     echo $sql . "\n";
     $db->query($sql);
     $sql = "delete from classificationstore_collections where storeId = " . $db->quote($storeId);
     echo $sql . "\n";
     $db->query($sql);
     $sql = "delete from classificationstore_stores where id = " . $db->quote($storeId);
     echo $sql . "\n";
     $db->query($sql);
     Cache::clearAll();
 }
Ejemplo n.º 2
0
 public function jobProceduralAction()
 {
     $status = array("success" => true);
     if ($this->getParam("type") == "files") {
         Update::installData($this->getParam("revision"));
     } else {
         if ($this->getParam("type") == "clearcache") {
             \Pimcore\Cache::clearAll();
         } else {
             if ($this->getParam("type") == "preupdate") {
                 $status = Update::executeScript($this->getParam("revision"), "preupdate");
             } else {
                 if ($this->getParam("type") == "postupdate") {
                     $status = Update::executeScript($this->getParam("revision"), "postupdate");
                 } else {
                     if ($this->getParam("type") == "cleanup") {
                         Update::cleanup();
                     }
                 }
             }
         }
     }
     // we use pure PHP here, otherwise this can cause issues with dependencies that changed during the update
     header("Content-type: application/json");
     echo json_encode($status);
     exit;
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $status = ["success" => true];
     $config = $input->getArgument("config");
     if ($config) {
         $job = json_decode($config, true);
         if (is_array($job)) {
             if (isset($job["dry-run"])) {
                 // do not do anything here
                 \Logger::info("skipped update job because it is in dry-run mode", $job);
             } elseif ($job["type"] == "files") {
                 Update::installData($job["revision"]);
             } elseif ($job["type"] == "clearcache") {
                 \Pimcore\Cache::clearAll();
             } elseif ($job["type"] == "preupdate") {
                 $status = Update::executeScript($job["revision"], "preupdate");
             } elseif ($job["type"] == "postupdate") {
                 $status = Update::executeScript($job["revision"], "postupdate");
             } elseif ($job["type"] == "cleanup") {
                 Update::cleanup();
             }
         }
     }
     $this->output->write(json_encode($status));
 }
Ejemplo n.º 4
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     if ($input->getOption("tags")) {
         $tags = explode(",", $input->getOption("tags"));
         Cache::clearTags($tags);
     } elseif ($input->getOption("output")) {
         Cache::clearTag("output");
     } else {
         Cache::clearAll();
     }
 }
Ejemplo n.º 5
0
 /**
  *
  */
 public function dispatchLoopShutdown()
 {
     $code = (string) $this->getResponse()->getHttpResponseCode();
     if ($code && ($code[0] == "4" || $code[0] == "5")) {
         $this->writeLog();
         // put the response into the cache, this is read in Pimcore_Controller_Action_Frontend::checkForErrors()
         $responseData = $this->getResponse()->getBody();
         if (strlen($responseData) > 20) {
             $cacheKey = "error_page_response_" . \Pimcore\Tool\Frontend::getSiteKey();
             \Pimcore\Cache::save($responseData, $cacheKey, array("output"), 900, 9992);
         }
     }
 }
Ejemplo n.º 6
0
 /**
  * @param $domain
  */
 public function __construct($domain)
 {
     $this->_domain = $domain;
     try {
         $robotsUrl = $domain . '/robots.txt';
         $cacheKey = "robots_" . crc32($robotsUrl);
         if (!($robotsTxt = Cache::load($cacheKey))) {
             $robotsTxt = \Pimcore\Tool::getHttpData($robotsUrl);
             Cache::save($robotsTxt, $cacheKey, array("system"), 3600, 999, true);
         }
         $this->_rules = $this->_makeRules($robotsTxt);
     } catch (\Exception $e) {
     }
 }
Ejemplo n.º 7
0
 /**
  *
  */
 public function dispatchLoopShutdown()
 {
     $code = (string) $this->getResponse()->getHttpResponseCode();
     if ($code && ($code[0] == "4" || $code[0] == "5")) {
         $this->writeLog();
         // put the response into the cache, this is read in Pimcore\Controller\Action\Frontend::checkForErrors()
         $responseData = $this->getResponse()->getBody();
         if (strlen($responseData) > 20 && !session_id()) {
             // do not cache if there's no data or an active session
             if ($this->cacheKey) {
                 \Pimcore\Cache::save($responseData, $this->cacheKey, ["output"], 900, 9992);
             }
         }
     }
 }
Ejemplo n.º 8
0
Archivo: Cse.php Proyecto: sfie/pimcore
 /**
  *
  */
 public function load()
 {
     $client = Api::getSimpleClient();
     $config = $this->getConfig();
     $perPage = $this->getPerPage();
     $offset = $this->getOffset();
     $query = $this->getQuery();
     if ($client) {
         $search = new \Google_Service_Customsearch($client);
         // determine language
         $language = "";
         if (\Zend_Registry::isRegistered("Zend_Locale")) {
             $locale = \Zend_Registry::get("Zend_Locale");
             $language = $locale->getLanguage();
         }
         if (!array_key_exists("hl", $config) && !empty($language)) {
             $config["hl"] = $language;
         }
         if (!array_key_exists("lr", $config) && !empty($language)) {
             $config["lr"] = "lang_" . $language;
         }
         if ($query) {
             if ($offset) {
                 $config["start"] = $offset + 1;
             }
             if (empty($perPage)) {
                 $perPage = 10;
             }
             $config["num"] = $perPage;
             $cacheKey = "google_cse_" . md5($query . serialize($config));
             // this is just a protection so that no query get's sent twice in a request (loops, ...)
             if (\Zend_Registry::isRegistered($cacheKey)) {
                 $result = \Zend_Registry::get($cacheKey);
             } else {
                 if (!($result = Cache::load($cacheKey))) {
                     $result = $search->cse->listCse($query, $config);
                     Cache::save($result, $cacheKey, array("google_cse"), 3600, 999);
                     \Zend_Registry::set($cacheKey, $result);
                 }
             }
             $this->readGoogleResponse($result);
             return $this->getResults(false);
         }
         return array();
     } else {
         throw new \Exception("Google Simple API Key is not configured in System-Settings.");
     }
 }
Ejemplo n.º 9
0
 /**
  * @see Document\Tag\TagInterface::frontend
  * @return string
  */
 public function frontend()
 {
     if ($this->url) {
         $config = $this->getOptions();
         if (!isset($config["params"])) {
             $config["params"] = [];
         }
         foreach (["width", "height"] as $property) {
             if (isset($config[$property])) {
                 $config["params"][$property] = $config[$property];
             }
         }
         $cacheKey = "doc_embed_" . crc32(serialize([$this->url, $config]));
         if (!($html = \Pimcore\Cache::load($cacheKey))) {
             $embera = new \Embera\Embera($config);
             $html = $embera->autoEmbed($this->url);
             \Pimcore\Cache::save($html, $cacheKey, ["embed"], 86400, 1, true);
         }
         return $html;
     }
     return "";
 }
Ejemplo n.º 10
0
 /**
  * @return array|mixed
  */
 public function getAllTranslations()
 {
     $cacheKey = static::getTableName() . "_data";
     if (!($translations = Cache::load($cacheKey))) {
         $itemClass = static::getItemClass();
         $translations = array();
         $translationsData = $this->db->fetchAll("SELECT * FROM " . static::getTableName());
         foreach ($translationsData as $t) {
             if (!$translations[$t["key"]]) {
                 $translations[$t["key"]] = new $itemClass();
                 $translations[$t["key"]]->setKey($t["key"]);
             }
             $translations[$t["key"]]->addTranslation($t["language"], $t["text"]);
             //for legacy support
             if ($translations[$t["key"]]->getDate() < $t["creationDate"]) {
                 $translations[$t["key"]]->setDate($t["creationDate"]);
             }
             $translations[$t["key"]]->setCreationDate($t["creationDate"]);
             $translations[$t["key"]]->setModificationDate($t["modificationDate"]);
         }
         Cache::save($translations, $cacheKey, array("translator", "translate"), 999);
     }
     return $translations;
 }
Ejemplo n.º 11
0
 /**
  * @param null $data
  * @param $locale
  * @param array $options
  * @return array
  */
 protected function _loadTranslationData($data, $locale, array $options = array())
 {
     $locale = (string) $locale;
     $tmpKeyParts = explode("\\", self::getBackend());
     $cacheKey = "Translate_" . array_pop($tmpKeyParts) . "_data_" . $locale;
     if (!($data = Cache::load($cacheKey))) {
         $data = array("__pimcore_dummy" => "only_a_dummy");
         $listClass = self::getBackend() . "\\Listing";
         $list = new $listClass();
         if ($list->isCacheable()) {
             $list->setCondition("language = ?", array($locale));
             $translations = $list->loadRaw();
             foreach ($translations as $translation) {
                 $data[mb_strtolower($translation["key"])] = Tool\Text::removeLineBreaks($translation["text"]);
             }
             Cache::save($data, $cacheKey, array("translator", "translator_website", "translate"), null, 999);
             $this->isCacheable = true;
         } else {
             $this->isCacheable = false;
         }
     }
     $this->_translate[$locale] = $data;
     return $this->_translate;
 }
Ejemplo n.º 12
0
 /**
  * @see Document\Tag\TagInterface::frontend
  * @return string
  */
 public function frontend()
 {
     if ($this->getView() instanceof \Zend_View) {
         try {
             if ($this->snippet instanceof Document\Snippet) {
                 $params = $this->options;
                 $params["document"] = $this->snippet;
                 if ($this->snippet->isPublished()) {
                     // check if output-cache is enabled, if so, we're also using the cache here
                     $cacheKey = null;
                     if ($cacheConfig = \Pimcore\Tool\Frontend::isOutputCacheEnabled()) {
                         // cleanup params to avoid serializing Element\ElementInterface objects
                         $cacheParams = $params;
                         array_walk($cacheParams, function (&$value, $key) {
                             if ($value instanceof Model\Element\ElementInterface) {
                                 $value = $value->getId();
                             }
                         });
                         $cacheKey = "tag_snippet__" . md5(serialize($cacheParams));
                         if ($content = Cache::load($cacheKey)) {
                             return $content;
                         }
                     }
                     $content = $this->getView()->action($this->snippet->getAction(), $this->snippet->getController(), $this->snippet->getModule(), $params);
                     // write contents to the cache, if output-cache is enabled
                     if ($cacheConfig) {
                         Cache::save($content, $cacheKey, ["output", "output_inline"], $cacheConfig["lifetime"]);
                     }
                     return $content;
                 }
                 return "";
             }
         } catch (\Exception $e) {
             if (\Pimcore::inDebugMode()) {
                 return "ERROR: " . $e->getMessage() . " (for details see debug.log)";
             }
             \Logger::error($e);
         }
     } else {
         return null;
     }
 }
Ejemplo n.º 13
0
 /**
  * @return void
  */
 public function delete()
 {
     // empty object cache
     try {
         Cache::clearTag("customlayout_" . $this->getId());
     } catch (\Exception $e) {
     }
     // empty output cache
     try {
         Cache::clearTag("output");
     } catch (\Exception $e) {
     }
     $this->getDao()->delete();
 }
Ejemplo n.º 14
0
 /** Clears the column information for the given table.
  * @param $table
  */
 protected function resetValidTableColumnsCache($table)
 {
     $cacheKey = self::CACHEKEY . $table;
     \Zend_Registry::getInstance()->offsetUnset($cacheKey);
     Cache::clearTags(array("system", "resource"));
 }
Ejemplo n.º 15
0
 /**
  * @return void
  */
 public static function clearDependentCache()
 {
     \Pimcore\Cache::clearTags(["translator", "translate"]);
 }
Ejemplo n.º 16
0
 /**
  * @return Property[]
  */
 public function getProperties()
 {
     if ($this->o_properties === null) {
         // try to get from cache
         $cacheKey = "object_properties_" . $this->getId();
         $properties = Cache::load($cacheKey);
         if (!is_array($properties)) {
             $properties = $this->getDao()->getProperties();
             $elementCacheTag = $this->getCacheTag();
             $cacheTags = ["object_properties" => "object_properties", $elementCacheTag => $elementCacheTag];
             Cache::save($properties, $cacheKey, $cacheTags);
         }
         $this->setProperties($properties);
     }
     return $this->o_properties;
 }
Ejemplo n.º 17
0
 /**
  * @static
  * @return mixed|\Zend_Config
  */
 public static function getWebsiteConfig()
 {
     if (\Zend_Registry::isRegistered("pimcore_config_website")) {
         $config = \Zend_Registry::get("pimcore_config_website");
     } else {
         $cacheKey = "website_config";
         $siteId = null;
         if (Model\Site::isSiteRequest()) {
             $siteId = Model\Site::getCurrentSite()->getId();
         } elseif (Tool::isFrontentRequestByAdmin()) {
             // this is necessary to set the correct settings in editmode/preview (using the main domain)
             $front = \Zend_Controller_Front::getInstance();
             $originDocument = $front->getRequest()->getParam("document");
             if ($originDocument) {
                 $site = Tool\Frontend::getSiteForDocument($originDocument);
                 if ($site) {
                     $siteId = $site->getId();
                 }
             }
         }
         if ($siteId) {
             $cacheKey = $cacheKey . "_site_" . $siteId;
         }
         if (!($config = Cache::load($cacheKey))) {
             $settingsArray = [];
             $cacheTags = ["website_config", "system", "config", "output"];
             $list = new Model\WebsiteSetting\Listing();
             $list = $list->load();
             foreach ($list as $item) {
                 $key = $item->getName();
                 $itemSiteId = $item->getSiteId();
                 if ($itemSiteId != 0 && $itemSiteId != $siteId) {
                     continue;
                 }
                 $s = null;
                 switch ($item->getType()) {
                     case "document":
                     case "asset":
                     case "object":
                         $s = Model\Element\Service::getElementById($item->getType(), $item->getData());
                         break;
                     case "bool":
                         $s = (bool) $item->getData();
                         break;
                     case "text":
                         $s = (string) $item->getData();
                         break;
                 }
                 if ($s instanceof Model\Element\ElementInterface) {
                     $cacheTags = $s->getCacheTags($cacheTags);
                 }
                 if (isset($s)) {
                     $settingsArray[$key] = $s;
                 }
             }
             $config = new \Zend_Config($settingsArray, true);
             Cache::save($config, $cacheKey, $cacheTags, null, 998);
         }
         self::setWebsiteConfig($config);
     }
     return $config;
 }
Ejemplo n.º 18
0
 /**
  * @return void
  */
 public function clearDependentCache()
 {
     \Pimcore\Cache::clearTag("website_config");
 }
Ejemplo n.º 19
0
 /**
  * @static
  * @return mixed|\Zend_Config
  */
 public static function getWebsiteConfig()
 {
     if (\Zend_Registry::isRegistered("pimcore_config_website")) {
         $config = \Zend_Registry::get("pimcore_config_website");
     } else {
         $cacheKey = "website_config";
         $siteId = null;
         if (Model\Site::isSiteRequest()) {
             $siteId = Model\Site::getCurrentSite()->getId();
             $cacheKey = $cacheKey . "_site_" . $siteId;
         }
         if (!($config = Cache::load($cacheKey))) {
             $settingsArray = [];
             $cacheTags = ["website_config", "system", "config", "output"];
             $list = new Model\WebsiteSetting\Listing();
             $list = $list->load();
             foreach ($list as $item) {
                 $key = $item->getName();
                 $itemSiteId = $item->getSiteId();
                 if ($itemSiteId != 0 && $itemSiteId != $siteId) {
                     continue;
                 }
                 $s = null;
                 switch ($item->getType()) {
                     case "document":
                     case "asset":
                     case "object":
                         $s = Model\Element\Service::getElementById($item->getType(), $item->getData());
                         break;
                     case "bool":
                         $s = (bool) $item->getData();
                         break;
                     case "text":
                         $s = (string) $item->getData();
                         break;
                 }
                 if ($s instanceof Model\Element\ElementInterface) {
                     $cacheTags = $s->getCacheTags($cacheTags);
                 }
                 if (isset($s)) {
                     $settingsArray[$key] = $s;
                 }
             }
             $config = new \Zend_Config($settingsArray, true);
             Cache::save($config, $cacheKey, $cacheTags, null, 998);
         }
         self::setWebsiteConfig($config);
     }
     return $config;
 }
Ejemplo n.º 20
0
 /**
  * @return void
  */
 public function delete()
 {
     $this->getDao()->delete();
     // clear cache tags
     Cache::clearTags(array("tagmanagement", "output"));
 }
Ejemplo n.º 21
0
 /**
  * @return void
  */
 public function clearDependentCache()
 {
     // this is mostly called in Redirect\Dao not here
     try {
         \Pimcore\Cache::clearTag("redirect");
     } catch (\Exception $e) {
         Logger::crit($e);
     }
 }
Ejemplo n.º 22
0
<?php

// get db connection
$db = \Pimcore\Db::get();
$db->query("DELETE FROM `users_permission_definitions` WHERE `key`='document_style_editor';");
$db->query("ALTER TABLE documents_page DROP COLUMN `css`;");
\Pimcore\Cache::clearAll();
Ejemplo n.º 23
0
 /**
  * @throws \Zend_Controller_Response_Exception
  */
 public function checkForErrors()
 {
     if ($error = $this->getParam('error_handler')) {
         if ($error->exception) {
             if ($error->exception instanceof \Zend_Controller_Router_Exception || $error->exception instanceof \Zend_Controller_Action_Exception) {
                 header('HTTP/1.1 404 Not Found');
                 //$this->getResponse()->setRawHeader('HTTP/1.1 404 Not Found');
                 $this->getResponse()->setHttpResponseCode(404);
                 // check if the resource that wasn't found is a common static file
                 // for them we don't show the error page, as generating this is very heavy in terms of performance
                 if (preg_match("/\\.(js|css|png|jpe?g|gif|eot|ttf|woff|svg|ico|map|swf|txt)\$/", $this->getRequest()->getPathInfo())) {
                     echo "HTTP/1.1 404 Not Found\nFiltered by error handler (static file exception)";
                     exit;
                 }
             } else {
                 header('HTTP/1.1 503 Service Temporarily Unavailable');
                 //$this->getResponse()->setRawHeader('HTTP/1.1 503 Service Temporarily Unavailable');
                 $this->getResponse()->setHttpResponseCode(503);
             }
             \Logger::error("Unable to find URL: " . $_SERVER["REQUEST_URI"]);
             \Logger::error($error->exception);
             \Pimcore::getEventManager()->trigger("frontend.error", $this, ["exception" => $error->exception]);
             try {
                 // check if we have the error page already in the cache
                 // the cache is written in Pimcore\Controller\Plugin\HttpErrorLog::dispatchLoopShutdown()
                 $cacheKey = "error_page_response_" . \Pimcore\Tool\Frontend::getSiteKey();
                 if ($responseBody = \Pimcore\Cache::load($cacheKey)) {
                     $this->getResponse()->setBody($responseBody);
                     $this->getResponse()->sendResponse();
                     // write to http_error log
                     $errorLogPlugin = \Zend_Controller_Front::getInstance()->getPlugin("Pimcore\\Controller\\Plugin\\HttpErrorLog");
                     if ($errorLogPlugin) {
                         $errorLogPlugin->writeLog();
                     }
                     exit;
                 } else {
                     $document = \Zend_Registry::get("pimcore_error_document");
                     $this->setDocument($document);
                     $this->setParam("document", $document);
                     $this->disableLayout();
                     // http_error log writing is done in Pimcore_Controller_Plugin_HttpErrorLog in this case
                 }
             } catch (\Exception $e) {
                 $m = "Unable to load error document";
                 Tool::exitWithError($m);
             }
         }
     }
 }
Ejemplo n.º 24
0
 /**
  *
  */
 public function end()
 {
     if ($this->captureEnabled) {
         $this->captureEnabled = false;
         $tags = array("in_template");
         if (!$this->lifetime) {
             $tags[] = "output";
         }
         $content = ob_get_clean();
         CacheManager::save($content, $this->key, $tags, $this->lifetime, 996, true);
         echo $content;
     }
 }
Ejemplo n.º 25
0
 /**
  *
  */
 public function delete()
 {
     // delete all childs
     $list = new Listing();
     $list->setCondition("parentId = ?", $this->getId());
     $list->load();
     if (is_array($list->getUsers())) {
         foreach ($list->getUsers() as $user) {
             $user->delete();
         }
     }
     // now delete the current user
     $this->getDao()->delete();
     \Pimcore\Cache::clearAll();
 }
Ejemplo n.º 26
0
 /**
  * @return void
  */
 public function delete()
 {
     // delete all objects using this class
     $list = new Listing();
     $list->setCondition("o_classId = ?", $this->getId());
     $list->load();
     foreach ($list->getObjects() as $o) {
         $o->delete();
     }
     $this->deletePhpClasses();
     // empty object cache
     try {
         Cache::clearTag("class_" . $this->getId());
     } catch (\Exception $e) {
     }
     // empty output cache
     try {
         Cache::clearTag("output");
     } catch (\Exception $e) {
     }
     $customLayouts = new ClassDefinition\CustomLayout\Listing();
     $customLayouts->setCondition("classId = " . $this->getId());
     $customLayouts = $customLayouts->load();
     foreach ($customLayouts as $customLayout) {
         $customLayout->delete();
     }
     $this->getDao()->delete();
 }
Ejemplo n.º 27
0
 public function portletFeedAction()
 {
     $dashboard = $this->getCurrentConfiguration();
     $id = $this->getParam("id");
     $cache = \Pimcore\Cache::getInstance();
     if ($cache) {
         $cache->setLifetime(10);
         \Zend_Feed_Reader::setCache($cache);
     }
     $portlet = [];
     foreach ($dashboard["positions"] as $col) {
         foreach ($col as $row) {
             if ($row['id'] == $id) {
                 $portlet = $row;
             }
         }
     }
     $feedUrl = $portlet['config'];
     $feed = null;
     if (!empty($feedUrl)) {
         try {
             $feed = \Zend_Feed_Reader::import($feedUrl);
         } catch (\Exception $e) {
             \Logger::error($e);
         }
     }
     $count = 0;
     $entries = [];
     if ($feed) {
         foreach ($feed as $entry) {
             // display only the latest 11 entries
             $count++;
             if ($count > 10) {
                 break;
             }
             $entry = ["title" => $entry->getTitle(), "description" => $entry->getDescription(), 'authors' => $entry->getAuthors(), 'link' => $entry->getLink(), 'content' => $entry->getContent()];
             foreach ($entry as &$content) {
                 $content = strip_tags($content, "<h1><h2><h3><h4><h5><p><br><a><img><div><b><strong><i>");
                 $content = preg_replace('/on([a-z]+)([ ]+)?=/i', "data-on\$1=", $content);
             }
             $entries[] = $entry;
         }
     }
     $this->_helper->json(["entries" => $entries]);
 }
Ejemplo n.º 28
0
 /**
  * includes a document
  *
  * @param $include
  * @param array $params
  * @return string
  */
 public function inc($include, $params = null, $cacheEnabled = true)
 {
     if (!is_array($params)) {
         $params = [];
     }
     // check if output-cache is enabled, if so, we're also using the cache here
     $cacheKey = null;
     $cacheConfig = false;
     if ($cacheEnabled) {
         if ($cacheConfig = Tool\Frontend::isOutputCacheEnabled()) {
             // cleanup params to avoid serializing Element\ElementInterface objects
             $cacheParams = $params;
             $cacheParams["~~include-document"] = $include;
             array_walk($cacheParams, function (&$value, $key) {
                 if ($value instanceof Element\ElementInterface) {
                     $value = $value->getId();
                 } elseif (is_object($value) && method_exists($value, "__toString")) {
                     $value = (string) $value;
                 }
             });
             $cacheKey = "tag_inc__" . md5(serialize($cacheParams));
             if ($content = Cache::load($cacheKey)) {
                 return $content;
             }
         }
     }
     $editmodeBackup = \Zend_Registry::get("pimcore_editmode");
     \Zend_Registry::set("pimcore_editmode", false);
     $includeBak = $include;
     // this is if $this->inc is called eg. with $this->href() as argument
     if (!$include instanceof Model\Document\PageSnippet && is_object($include) && method_exists($include, "__toString")) {
         $include = (string) $include;
     }
     if (is_string($include)) {
         try {
             $include = Model\Document::getByPath($include);
         } catch (\Exception $e) {
             $include = $includeBak;
         }
     } elseif (is_numeric($include)) {
         try {
             $include = Model\Document::getById($include);
         } catch (\Exception $e) {
             $include = $includeBak;
         }
     }
     $params = array_merge($params, array("document" => $include));
     $content = "";
     if ($include instanceof Model\Document\PageSnippet && $include->isPublished()) {
         if ($include->getAction() && $include->getController()) {
             $content = $this->action($include->getAction(), $include->getController(), $include->getModule(), $params);
         } elseif ($include->getTemplate()) {
             $content = $this->action("default", "default", null, $params);
         }
         // in editmode, we need to parse the returned html from the document include
         // add a class and the pimcore id / type so that it can be opened in editmode using the context menu
         // if there's no first level HTML container => add one (wrapper)
         if ($this->editmode) {
             include_once "simple_html_dom.php";
             $editmodeClass = " pimcore_editable pimcore_tag_inc ";
             // this is if the content that is included does already contain markup/html
             // this is needed by the editmode to highlight included documents
             if ($html = str_get_html($content)) {
                 $childs = $html->find("*");
                 if (is_array($childs)) {
                     foreach ($childs as $child) {
                         $child->class = $child->class . $editmodeClass;
                         $child->pimcore_type = $include->getType();
                         $child->pimcore_id = $include->getId();
                     }
                 }
                 $content = $html->save();
                 $html->clear();
                 unset($html);
             } else {
                 // add a div container if the include doesn't contain markup/html
                 $content = '<div class="' . $editmodeClass . '" pimcore_id="' . $include->getId() . '" pimcore_type="' . $include->getType() . '">' . $content . '</div>';
             }
         }
         // we need to add a component id to all first level html containers
         $componentId = "";
         if ($this->document instanceof Model\Document) {
             $componentId .= 'document:' . $this->document->getId() . '.';
         }
         $componentId .= 'type:inc.name:' . $include->getId();
         $content = \Pimcore\Tool\Frontend::addComponentIdToHtml($content, $componentId);
     }
     \Zend_Registry::set("pimcore_editmode", $editmodeBackup);
     // write contents to the cache, if output-cache is enabled
     if ($cacheConfig) {
         Cache::save($content, $cacheKey, array("output", "output_inline"), $cacheConfig["lifetime"]);
     }
     return $content;
 }
Ejemplo n.º 29
0
 public function glossaryAction()
 {
     if ($this->getParam("data")) {
         $this->checkPermission("glossary");
         Cache::clearTag("glossary");
         if ($this->getParam("xaction") == "destroy") {
             $data = \Zend_Json::decode($this->getParam("data"));
             if (\Pimcore\Tool\Admin::isExtJS6()) {
                 $id = $data["id"];
             } else {
                 $id = $data;
             }
             $glossary = Glossary::getById($id);
             $glossary->delete();
             $this->_helper->json(array("success" => true, "data" => array()));
         } else {
             if ($this->getParam("xaction") == "update") {
                 $data = \Zend_Json::decode($this->getParam("data"));
                 // save glossary
                 $glossary = Glossary::getById($data["id"]);
                 if ($data["link"]) {
                     if ($doc = Document::getByPath($data["link"])) {
                         $tmpLink = $data["link"];
                         $data["link"] = $doc->getId();
                     }
                 }
                 $glossary->setValues($data);
                 $glossary->save();
                 if ($link = $glossary->getLink()) {
                     if (intval($link) > 0) {
                         if ($doc = Document::getById(intval($link))) {
                             $glossary->setLink($doc->getFullPath());
                         }
                     }
                 }
                 $this->_helper->json(array("data" => $glossary, "success" => true));
             } else {
                 if ($this->getParam("xaction") == "create") {
                     $data = \Zend_Json::decode($this->getParam("data"));
                     unset($data["id"]);
                     // save glossary
                     $glossary = new Glossary();
                     if ($data["link"]) {
                         if ($doc = Document::getByPath($data["link"])) {
                             $tmpLink = $data["link"];
                             $data["link"] = $doc->getId();
                         }
                     }
                     $glossary->setValues($data);
                     $glossary->save();
                     if ($link = $glossary->getLink()) {
                         if (intval($link) > 0) {
                             if ($doc = Document::getById(intval($link))) {
                                 $glossary->setLink($doc->getFullPath());
                             }
                         }
                     }
                     $this->_helper->json(array("data" => $glossary, "success" => true));
                 }
             }
         }
     } else {
         // get list of glossaries
         $list = new Glossary\Listing();
         $list->setLimit($this->getParam("limit"));
         $list->setOffset($this->getParam("start"));
         $sortingSettings = \Pimcore\Admin\Helper\QueryParams::extractSortingSettings($this->getAllParams());
         if ($sortingSettings['orderKey']) {
             $list->setOrderKey($sortingSettings['orderKey']);
             $list->setOrder($sortingSettings['order']);
         }
         if ($this->getParam("filter")) {
             $list->setCondition("`text` LIKE " . $list->quote("%" . $this->getParam("filter") . "%"));
         }
         $list->load();
         $glossaries = array();
         foreach ($list->getGlossary() as $glossary) {
             if ($link = $glossary->getLink()) {
                 if (intval($link) > 0) {
                     if ($doc = Document::getById(intval($link))) {
                         $glossary->setLink($doc->getFullPath());
                     }
                 }
             }
             $glossaries[] = $glossary;
         }
         $this->_helper->json(array("data" => $glossaries, "success" => true, "total" => $list->getTotalCount()));
     }
     $this->_helper->json(false);
 }
Ejemplo n.º 30
0
<?php

\Pimcore\Cache::disable();
$customCacheFile = PIMCORE_CONFIGURATION_DIRECTORY . "/cache.xml";
// create legacy config folder
$legacyFolder = PIMCORE_CONFIGURATION_DIRECTORY . "/LEGACY";
if (!is_dir($legacyFolder)) {
    mkdir($legacyFolder, 0777, true);
}
if (file_exists($customCacheFile)) {
    try {
        $conf = new \Zend_Config_Xml($customCacheFile);
        $arrayConf = $conf->toArray();
        $content = json_encode($arrayConf);
        $content = \Zend_Json::prettyPrint($content);
        $jsonFile = \Pimcore\Config::locateConfigFile("cache.json");
        file_put_contents($jsonFile, $content);
        rename($customCacheFile, $legacyFolder . "/cache.xml");
    } catch (\Exception $e) {
    }
}