/** * @param string[] $validLinkRegexes * @param string[] $invalidLinkRegexes * @return void */ public function __construct($validLinkRegexes, $invalidLinkRegexes, $maxRedirects = 10, $timeout = 30, $searchStartIndicator = null, $searchEndIndicator = null, $maxThreads = 20, $maxLinkDepth = 15) { $this->validLinkRegexes = $validLinkRegexes; $this->invalidLinkRegexes = $invalidLinkRegexes; $this->maxRedirects = $maxRedirects; $this->timeout = $timeout; $this->searchEndIndicator = $searchEndIndicator; $this->searchStartIndicator = $searchStartIndicator; $this->maxThreads = $maxThreads; $this->maxLinkDepth = $maxLinkDepth; $db = Pimcore_Resource_Mysql::get(); $this->db = $db; $db->query("DROP TABLE IF EXISTS `plugin_searchphp_contents_temp`;"); $db->query("CREATE TABLE `plugin_searchphp_contents_temp` (\r\n `id` VARCHAR(255) NOT NULL,\r\n `uri` TEXT NOT NULL,\r\n `host` VARCHAR(255) NOT NULL,\r\n `content` LONGTEXT NOT NULL ,\r\n `html` LONGTEXT NOT NULL ,\r\n PRIMARY KEY (`id`)\r\n ) ENGINE=InnoDB DEFAULT CHARSET=utf8;"); $db->query("DROP TABLE IF EXISTS `plugin_searchphp_frontend_crawler_todo`;"); $db->query("CREATE TABLE `plugin_searchphp_frontend_crawler_todo` (\r\n `id` VARCHAR(255) NOT NULL,\r\n `uri` TEXT NOT NULL,\r\n `depth` int(11) unsigned,\r\n `cookiejar` TEXT,\r\n PRIMARY KEY (`id`)\r\n ) ENGINE=InnoDB DEFAULT CHARSET=utf8;"); $db->query("DROP TABLE IF EXISTS `plugin_searchphp_frontend_crawler_noindex`;"); $db->query("CREATE TABLE `plugin_searchphp_frontend_crawler_noindex` (\r\n `id` VARCHAR(255) NOT NULL,\r\n `uri` TEXT NOT NULL,\r\n PRIMARY KEY (`id`)\r\n ) ENGINE=InnoDB DEFAULT CHARSET=utf8;"); $db->query("DROP TABLE IF EXISTS `plugin_searchphp_indexer_todo`;"); $db->query("CREATE TABLE `plugin_searchphp_indexer_todo` (\r\n `id` int(11) unsigned NOT NULL AUTO_INCREMENT,\r\n `content` LONGTEXT NOT NULL,\r\n PRIMARY KEY (`id`)\r\n ) ENGINE=InnoDB DEFAULT CHARSET=utf8;"); $result = null; try { $result = $db->describeTable("plugin_searchphp_contents_temp"); $this->readyToCrawl = !empty($result); } catch (Zend_Db_Statement_Exception $e) { Logger::alert(get_class($this) . ": could not set up table for crawler contents.", Zend_Log::ERR); $this->readyToCrawl = false; } }
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(); }
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); } }
/** * @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';");
/** * @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; }
/** * @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"); } }
/** * @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(); }