public function __construct()
 {
     $pimDb = Pimcore_Resource_Mysql::get();
     $rev = Pimcore_Version::$revision;
     if ($rev > 1350) {
         Zend_Db_Table::setDefaultAdapter($pimDb->getResource());
     } else {
         Zend_Db_Table::setDefaultAdapter($pimDb);
     }
     $this->table = new Formbuilder_DbTable_Formbuilder();
 }
Example #2
0
 public function runUpdates()
 {
     $db = Pimcore_Resource_Mysql::get()->getResource();
     $tableDescription = $db->describeTable(PimTools_ImportReport_Resource::TABLE_NAME);
     if (!$tableDescription['message']) {
         $query = "ALTER TABLE " . PimTools_ImportReport_Resource::TABLE_NAME . " ADD message LONGTEXT";
         $db->query($query);
     }
     if (!$tableDescription['type']) {
         $query = "ALTER TABLE " . PimTools_ImportReport_Resource::TABLE_NAME . " ADD type VARCHAR(20) NULL DEFAULT NULL";
         $db->query($query);
     }
 }
Example #3
0
 /**
  * @param Element_Interface $object
  * @param string $type
  * @return boolean $hasRated
  */
 public static function hasRated($ratingTarget, $type, $user)
 {
     try {
         $db = Pimcore_Resource_Mysql::get("database");
         $data = $db->fetchRow("SELECT count(*) as amount from plugin_ratingscomments_ratings where type = ? ratingTargetId = ? and userId = ?", array($type, $ratingTarget->getId(), $user->getO_Id()));
         if ($data['amount'] > 0) {
             return true;
         } else {
             return false;
         }
     } catch (Exception $e) {
         return false;
     }
 }
 public function getTreeAction()
 {
     $allowed = $this->getRequest()->getParam('allowed');
     $classesList = new Object_Class_List();
     $classesList->setOrderKey("name");
     $classesList->setOrder("asc");
     if ($allowed) {
         $classesList->setCondition(Pimcore_Resource_Mysql::get()->quoteInto('id IN (?)', explode(',', $allowed)));
     }
     $classes = $classesList->load();
     $classItems = array();
     foreach ($classes as $classItem) {
         $classItems[] = array("id" => $classItem->getId(), "text" => $classItem->getName(), "icon" => $classItem->getIcon(), "propertyVisibility" => $classItem->getPropertyVisibility(), "qtipCfg" => array("title" => "ID: " . $classItem->getId()));
     }
     $this->_helper->json($classItems);
 }
 public function __construct($config = array())
 {
     // initialise the DB
     // get the db and revision number
     $db = Pimcore_Resource_Mysql::get();
     $rev = Pimcore_Version::$revision;
     // older versions return the resource
     if ($rev > 1350) {
         Zend_Db_Table::setDefaultAdapter($db->getResource());
     } else {
         Zend_Db_Table::setDefaultAdapter($db);
     }
     // set the params
     $this->_name = 'plugin_groupdocs';
     $this->_primary = 'id';
     parent::__construct($config);
 }
<?php

// get db connection
$db = Pimcore_Resource_Mysql::get();
$db->query("DROP TABLE IF EXISTS `cache_tags`;");
$db->query("CREATE TABLE `cache_tags` (\r\n  `id` varchar(165) NOT NULL DEFAULT '',\r\n  `tag` varchar(165) NULL DEFAULT NULL,\r\n  PRIMARY KEY (`id`,`tag`),\r\n  INDEX `id` (`id`),\r\n  INDEX `tag` (`tag`)\r\n) ENGINE=MEMORY;");
<?php

// get db connection
$db = Pimcore_Resource_Mysql::get("database");
$db->getConnection()->exec("INSERT INTO `users_permission_definitions` SET `key`='forms',`translation`='permission_forms';");
Example #8
0
 /**
  * @return Object_BlogCategory_List
  */
 public function getCategories()
 {
     $list = new Object_BlogCategory_List();
     $limit = (int) @$this->_options->snippet->category->limit;
     $list->setLimit($limit ? $limit : 10);
     $ids = $return = array();
     foreach ($list as $cat) {
         $ids[] = $cat->getId();
     }
     if (empty($ids)) {
         return $list;
     }
     // count entries in categories
     $entry = new Object_BlogEntry();
     $select = new Zend_Db_Select(Pimcore_Resource_Mysql::get()->getResource());
     $select->from('object_relations_' . $entry->getClassId(), array('id' => 'dest_id', 'count' => 'count(*)'))->where('dest_id IN (?)', $ids)->group('dest_id');
     $counts = array();
     foreach ($select->query()->fetchAll() as $row) {
         $counts[$row['id']] = (int) $row['count'];
     }
     foreach ($list as $cat) {
         $count = isset($counts[$cat->getId()]) ? $counts[$cat->getId()] : 0;
         $cat->setEntryCount($count);
     }
     return $list;
 }
Example #9
0
 /**
  * @return void
  */
 public function continueWithFoundLinks()
 {
     //reset DB in case this is executed in a forked child process
     $this->db = Pimcore_Resource_Mysql::reset();
     try {
         $row = $this->db->fetchRow("SELECT * FROM plugin_searchphp_frontend_crawler_todo ORDER BY id", array());
         $nextLink = $row['uri'];
         $depth = $row['depth'];
         $cookieJar = unserialize($row['cookiejar']);
     } catch (Exception $e) {
         // probably table was already removed because crawler is finished
         logger::log(get_class($this) . ": Could not extract next link from table plugin_searchphp_frontend_crawler_todo ", Zend_Log::DEBUG);
         return;
     }
     if (empty($nextLink)) {
         return;
     }
     $client = Pimcore_Tool::getHttpClient();
     $client->setUri($nextLink);
     $client->setConfig(array('maxredirects' => $this->maxRedirects, 'keepalive' => true, 'timeout' => $this->timeout));
     $client->setCookieJar($cookieJar);
     $client->setHeaders('If-Modified-Since', null);
     while ($nextLink) {
         try {
             $this->db->delete("plugin_searchphp_frontend_crawler_todo", "id = '" . md5($nextLink) . "'");
         } catch (Exception $e) {
             logger::warn(get_class($this) . ": Could not delete from plugin_searchphp_frontend_crawler_todo - maybe forcing crawler stop right now?");
         }
         if ($depth <= $this->maxLinkDepth) {
             logger::debug(get_class($this) . ": Link depth [ {$depth} ]");
             try {
                 $nextLink = $this->addEvictOutputFilterParameter($nextLink);
                 $client->setUri($nextLink);
                 $client->setCookieJar($cookieJar);
                 $client->setHeaders('If-Modified-Since', null);
                 try {
                     $response = $client->request();
                 } catch (Zend_Http_Client_Adapter_Exception $e) {
                     logger::log(get_class($this) . ": Could not get response for Link [ {$nextLink} ] ", Zend_Log::ERR);
                 }
                 if ($response instanceof Zend_Http_Response and ($response->isSuccessful() or $response->isRedirect())) {
                     //we don't use port - crawler ist limited to standard port 80
                     $client->getUri()->setPort(null);
                     //update url - maybe we were redirected
                     $nextLink = $client->getUri(true);
                     $nextLink = $this->removeOutputFilterParameters($nextLink);
                     $valid = $this->validateLink($nextLink);
                     if ($valid) {
                         //see if we were redirected to a place we already have in fetch list or done
                         try {
                             $rowTodo = $this->db->fetchRow("SELECT count(*) as count from plugin_searchphp_frontend_crawler_todo WHERE id ='" . md5($nextLink) . "'");
                         } catch (Exception $e) {
                             logger::log(get_class($this) . ": could not fetch from plugin_searchphp_contents_temp", Zend_Log::DEBUG);
                         }
                         try {
                             $rowDone = $this->db->fetchRow("SELECT count(*) as count from plugin_searchphp_contents_temp WHERE id ='" . md5($nextLink) . "'");
                         } catch (Exception $e) {
                             logger::log(get_class($this) . ": could not fetch from plugin_searchphp_contents_temp", Zend_Log::DEBUG);
                         }
                         try {
                             $rowNoIndex = $this->db->fetchRow("SELECT count(*) as count from plugin_searchphp_frontend_crawler_noindex WHERE id ='" . md5($nextLink) . "'");
                         } catch (Exception $e) {
                             logger::log(get_class($this) . ": could not fetch from plugin_searchphp_frontend_crawler_noindex", Zend_Log::DEBUG);
                         }
                         if ($rowTodo['count'] > 0 or $rowDone['count'] > 0 or $rowNoIndex['count'] > 0) {
                             logger::log(get_class($this) . " Redirected to uri [ {$nextLink} ] - which has already been processed", Zend_Log::DEBUG);
                         } else {
                             try {
                                 $success = $this->parse($nextLink, $response, $client->getUri()->getHost(), $client->getCookieJar(), $depth);
                                 logger::log(get_class($this) . ": parsed  [ {$nextLink} ] ", Zend_Log::DEBUG);
                             } catch (Exception $e) {
                                 logger::log($e, Zend_Log::ERR);
                             }
                         }
                     } else {
                         logger::log("We were redirected to an invalid Link [ {$nextLink}]", Zend_Log::DEBUG);
                     }
                 } else {
                     logger::log(get_class($this) . ": Error parsing  [ {$nextLink} ] ", Zend_Log::ERR);
                 }
             } catch (Zend_Uri_Exception $e) {
                 logger::log(get_class($this) . ": Invalid URI  [ {$nextLink} ] ", Zend_Log::ERR);
             }
         } else {
             logger::alert(get_class($this) . ": Stopping with uri [ {$nextLink} ] because maximum link depth of [ {$depth} ] has been reached.");
         }
         //get next from DB
         try {
             $row = $this->db->fetchRow("SELECT * FROM plugin_searchphp_frontend_crawler_todo ORDER BY id", array());
             $nextLink = $row['uri'];
             $depth = $row['depth'];
             $cookieJar = unserialize($row['cookiejar']);
         } catch (Exception $e) {
             //wait 2 seconds then try again
             sleep(2);
             try {
                 $row = $this->db->fetchRow("SELECT * FROM plugin_searchphp_frontend_crawler_todo ORDER BY id", array());
                 $nextLink = $row['uri'];
                 $depth = $row['depth'];
                 $cookieJar = unserialize($row['cookiejar']);
             } catch (Exception $e) {
                 // probably table was already removed because crawler is finished
                 logger::log(get_class($this) . ": Could not extract next link from table plugin_searchphp_frontend_crawler_todo ", Zend_Log::DEBUG);
                 $nextLink = false;
             }
         }
     }
 }
Example #10
0
 /**
  * @static
  * @param string $sql
  */
 public static function logDefinitionModification($sql)
 {
     if (!self::$_sqlLogFilename) {
         self::$_sqlLogFilename = "db-change-log_" . time() . "-" . uniqid() . ".sql";
     }
     // write sql change log for deploying to production system
     $sql .= "\n\n\n";
     $file = PIMCORE_SYSTEM_TEMP_DIRECTORY . "/" . self::$_sqlLogFilename;
     if (defined("PIMCORE_DB_CHANGELOG_DIRECTORY")) {
         $file = PIMCORE_DB_CHANGELOG_DIRECTORY . "/" . self::$_sqlLogFilename;
     }
     $handle = fopen($file, "a");
     fwrite($handle, $sql);
     fclose($handle);
 }
Example #11
0
 /**
  * @param  $configArray
  * @return void
  */
 public function frontendCrawl($configArray = null)
 {
     if (!is_array($configArray)) {
         $configArray = self::getSearchConfigArray();
     }
     if (self::frontendConfigComplete()) {
         ini_set('memory_limit', '2048M');
         ini_set("max_execution_time", "-1");
         $indexDir = self::getFrontendSearchIndex();
         if ($indexDir) {
             //TODO nix specific
             exec("rm -Rf " . str_replace("/index/", "/tmpindex", $indexDir));
             logger::debug("rm -Rf " . str_replace("/index/", "/tmpindex", $indexDir));
             try {
                 $urls = explode(",", $configArray['search']['frontend']['urls']);
                 $validLinkRegexes = explode(",", $configArray['search']['frontend']['validLinkRegexes']);
                 $invalidLinkRegexesSystem = $configArray['search']['frontend']['invalidLinkRegexes'];
                 $invalidLinkRegexesEditable = $configArray['search']['frontend']['invalidLinkRegexesEditable'];
                 if (!empty($invalidLinkRegexesEditable) and !empty($invalidLinkRegexesSystem)) {
                     $invalidLinkRegexes = explode(",", $invalidLinkRegexesEditable . "," . $invalidLinkRegexesSystem);
                 } else {
                     if (!empty($invalidLinkRegexesEditable)) {
                         $invalidLinkRegexes = explode(",", $invalidLinkRegexesEditable);
                     } else {
                         if (!empty($invalidLinkRegexesSystem)) {
                             $invalidLinkRegexes = explode(",", $invalidLinkRegexesSystem);
                         } else {
                             $invalidLinkRegexes = array();
                         }
                     }
                 }
                 self::setCrawlerState("frontend", "started", true);
                 $maxLinkDepth = $configArray['search']['frontend']['crawler']['maxLinkDepth'];
                 if (is_numeric($maxLinkDepth) and $maxLinkDepth > 0) {
                     $crawler = new SearchPhp_Frontend_Crawler($validLinkRegexes, $invalidLinkRegexes, 10, 30, $configArray['search']['frontend']['crawler']['contentStartIndicator'], $configArray['search']['frontend']['crawler']['contentEndIndicator'], $configArray['search']['frontend']['crawler']['maxThreads'], $maxLinkDepth);
                 } else {
                     $crawler = new SearchPhp_Frontend_Crawler($validLinkRegexes, $invalidLinkRegexes, 10, 30, $configArray['search']['frontend']['crawler']['contentStartIndicator'], $configArray['search']['frontend']['crawler']['contentEndIndicator'], $configArray['search']['frontend']['crawler']['maxThreads']);
                 }
                 $crawler->findLinks($urls);
                 self::setCrawlerState("frontend", "finished", false);
                 logger::debug("SearchPhp_Plugin: replacing old index ...");
                 $db = Pimcore_Resource_Mysql::get();
                 $db->query("DROP TABLE IF EXISTS `plugin_searchphp_contents`;");
                 $db->query("RENAME TABLE `plugin_searchphp_contents_temp` TO `plugin_searchphp_contents`;");
                 //TODO nix specific
                 exec("rm -Rf " . $indexDir);
                 logger::debug("rm -Rf " . $indexDir);
                 $tmpIndex = str_replace("/index", "/tmpindex", $indexDir);
                 exec("cp -R " . substr($tmpIndex, 0, -1) . " " . substr($indexDir, 0, -1));
                 logger::debug("cp -R " . substr($tmpIndex, 0, -1) . " " . substr($indexDir, 0, -1));
                 logger::debug("SearchPhp_Plugin: replaced old index");
                 logger::info("SearchPhp_Plugin: Finished crawl");
             } catch (Exception $e) {
                 logger::err($e);
                 throw $e;
             }
         }
     } else {
         logger::info("SearchPhp_Plugin: Did not start frontend crawler, because config incomplete");
     }
 }
Example #12
0
 /**
  * @return void
  */
 public static function generateSitemap()
 {
     $sitemapDir = PIMCORE_WEBSITE_PATH . "/var/search/sitemap";
     if (is_dir($sitemapDir) and !is_writable($sitemapDir)) {
         $sitemapDirAvailable = false;
     } else {
         if (!is_dir($sitemapDir)) {
             $sitemapDirAvailable = mkdir($sitemapDir, 0755, true);
             chmod($sitemapDir, 0755);
         } else {
             $sitemapDirAvailable = true;
         }
     }
     if ($sitemapDirAvailable) {
         $db = Pimcore_Resource_Mysql::get();
         $hosts = $db->fetchAll("SELECT DISTINCT host from plugin_searchphp_contents");
         if (is_array($hosts)) {
             //create domain sitemaps
             foreach ($hosts as $row) {
                 $host = $row['host'];
                 $data = $db->fetchAll("SELECT * FROM plugin_searchphp_contents WHERE host = '" . $host . "' AND content != 'canonical' AND content!='noindex' ORDER BY uri", array());
                 $name = str_replace(".", "-", $host);
                 $filePath = $sitemapDir . "/sitemap-" . $name . ".xml";
                 $fh = fopen($filePath, 'w');
                 fwrite($fh, '<?xml version="1.0" encoding="UTF-8"?>' . "\r\n");
                 fwrite($fh, '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">');
                 fwrite($fh, "\r\n");
                 foreach ($data as $row) {
                     $uri = str_replace("&pimcore_outputfilters_disabled=1", "", $row['uri']);
                     $uri = str_replace("?pimcore_outputfilters_disabled=1", "", $uri);
                     fwrite($fh, '<url>' . "\r\n");
                     fwrite($fh, '    <loc>' . htmlspecialchars($uri, ENT_QUOTES) . '</loc>' . "\r\n");
                     fwrite($fh, '</url>' . "\r\n");
                 }
                 fwrite($fh, '</urlset>' . "\r\n");
                 fclose($fh);
             }
             //create sitemap index file
             $filePath = $sitemapDir . "/sitemap.xml";
             $fh = fopen($filePath, 'w');
             fwrite($fh, '<?xml version="1.0" encoding="UTF-8"?>' . "\r\n");
             fwrite($fh, '<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">');
             fwrite($fh, "\r\n");
             foreach ($hosts as $row) {
                 $host = $row['host'];
                 $name = str_replace(".", "-", $host);
                 //first host must be main domain - see hint in plugin settings
                 $currenthost = $hosts[0]['host'];
                 fwrite($fh, '<sitemap>' . "\r\n");
                 fwrite($fh, '    <loc>http://' . $currenthost . "/plugin/SearchPhp/frontend/sitemap/?sitemap=sitemap-" . $name . ".xml" . '</loc>' . "\r\n");
                 fwrite($fh, '</sitemap>' . "\r\n");
             }
             fwrite($fh, '</sitemapindex>' . "\r\n");
             fclose($fh);
         } else {
             logger::warn("SearchPhp_Tool: could not generate sitemaps, did not find any hosts in index.");
         }
     } else {
         logger::emerg("SearchPhp_Tool: Cannot generate sitemap. Sitemap directory [ " . $sitemapDir . " ]  not available/not writeable and cannot be created");
     }
 }
 public function __construct()
 {
     $this->db = Pimcore_Resource_Mysql::get();
 }