Beispiel #1
1
 public function showAction()
 {
     $offset = $this->getParam("start");
     $limit = $this->getParam("limit");
     $orderby = "ORDER BY id DESC";
     $sortingSettings = \Pimcore\Admin\Helper\QueryParams::extractSortingSettings($this->getAllParams());
     if ($sortingSettings['orderKey']) {
         $orderby = "ORDER BY " . $sortingSettings['orderKey'] . " " . $sortingSettings['order'];
     }
     $queryString = " WHERE 1=1";
     if ($this->getParam("priority") != "-1" && ($this->getParam("priority") == "0" || $this->getParam("priority"))) {
         $levels = [];
         foreach (["emergency", "alert", "critical", "error", "warning", "notice", "info", "debug"] as $level) {
             $levels[] = "priority = '" . $level . "'";
             if ($this->getParam("priority") == $level) {
                 break;
             }
         }
         $queryString .= " AND (" . implode(" OR ", $levels) . ")";
     }
     if ($this->getParam("fromDate")) {
         $datetime = $this->getParam("fromDate");
         if ($this->getParam("fromTime")) {
             $datetime = substr($datetime, 0, 11) . $this->getParam("fromTime") . ":00";
         }
         $queryString .= " AND timestamp >= '" . $datetime . "'";
     }
     if ($this->getParam("toDate")) {
         $datetime = $this->getParam("toDate");
         if ($this->getParam("toTime")) {
             $datetime = substr($datetime, 0, 11) . $this->getParam("toTime") . ":00";
         }
         $queryString .= " AND timestamp <= '" . $datetime . "'";
     }
     if ($this->getParam("component")) {
         $queryString .= " AND component =  '" . $this->getParam("component") . "'";
     }
     if ($this->getParam("relatedobject")) {
         $queryString .= " AND relatedobject = " . $this->getParam("relatedobject");
     }
     if ($this->getParam("message")) {
         $queryString .= " AND message like '%" . $this->getParam("message") . "%'";
     }
     $db = Db::get();
     $count = $db->fetchCol("SELECT count(*) FROM " . \Pimcore\Log\Handler\ApplicationLoggerDb::TABLE_NAME . $queryString);
     $total = $count[0];
     $result = $db->fetchAll("SELECT * FROM " . \Pimcore\Log\Handler\ApplicationLoggerDb::TABLE_NAME . $queryString . " {$orderby} LIMIT {$offset}, {$limit}");
     $errorDataList = array();
     if (!empty($result)) {
         foreach ($result as $r) {
             $parts = explode("/", $r['filelink']);
             $filename = $parts[count($parts) - 1];
             $fileobject = str_replace(PIMCORE_DOCUMENT_ROOT, "", $r['fileobject']);
             $errorData = array("id" => $r['id'], "pid" => $r['pid'], "message" => $r['message'], "timestamp" => $r['timestamp'], "priority" => $this->getPriorityName($r['priority']), "filename" => $filename, "fileobject" => $fileobject, "relatedobject" => $r['relatedobject'], "component" => $r['component'], "source" => $r['source']);
             $errorDataList[] = $errorData;
         }
     }
     $results = array("p_totalCount" => $total, "p_results" => $errorDataList);
     $this->_helper->json($results);
 }
Beispiel #2
0
 /**
  * @param $file
  * @throws \Zend_Db_Adapter_Exception
  */
 public function insertDump($file)
 {
     $sql = file_get_contents($file);
     //replace document root placeholder with current document root
     $docRoot = str_replace("\\", "/", PIMCORE_DOCUMENT_ROOT);
     // Windows fix
     $sql = str_replace("~~DOCUMENTROOT~~", $docRoot, $sql);
     // we have to use the raw connection here otherwise \Zend_Db uses prepared statements, which causes problems with inserts (: placeholders)
     // and mysqli causes troubles because it doesn't support multiple queries
     if ($this->db->getResource() instanceof \Zend_Db_Adapter_Mysqli) {
         $mysqli = $this->db->getConnection();
         $mysqli->multi_query($sql);
         // loop through results, because ->multi_query() is asynchronous
         do {
             if ($result = $mysqli->store_result()) {
                 $mysqli->free_result();
             }
         } while ($mysqli->next_result());
     } elseif ($this->db->getResource() instanceof \Zend_Db_Adapter_Pdo_Mysql) {
         $this->db->getConnection()->exec($sql);
     }
     \Pimcore\Db::reset();
     // set the id of the system user to 0
     $this->db->update("users", ["id" => 0], $this->db->quoteInto("name = ?", "system"));
 }
 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();
 }
Beispiel #4
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     // display error message
     if (!$input->getOption("mode")) {
         $this->writeError("Please specify the mode!");
         exit;
     }
     $db = \Pimcore\Db::get();
     if ($input->getOption("mode") == "optimize") {
         $tables = $db->fetchAll("SHOW TABLES");
         foreach ($tables as $table) {
             $t = current($table);
             try {
                 \Logger::debug("Running: OPTIMIZE TABLE " . $t);
                 $db->query("OPTIMIZE TABLE " . $t);
             } catch (\Exception $e) {
                 \Logger::error($e);
             }
         }
     } elseif ($input->getOption("mode") == "warmup") {
         $tables = $db->fetchAll("SHOW TABLES");
         foreach ($tables as $table) {
             $t = current($table);
             try {
                 \Logger::debug("Running: SELECT COUNT(*) FROM {$t}");
                 $res = $db->fetchOne("SELECT COUNT(*) FROM {$t}");
                 \Logger::debug("Result: " . $res);
             } catch (\Exception $e) {
                 \Logger::error($e);
             }
         }
     }
 }
 /**
  * @param $classId
  * @param null $idField
  * @param null $storetable
  * @param null $querytable
  * @param null $relationtable
  */
 public function __construct($classId, $idField = null, $storetable = null, $querytable = null, $relationtable = null)
 {
     $this->db = \Pimcore\Db::get();
     $this->fields = array();
     $this->relations = array();
     $this->fieldIds = array();
     $this->deletionFieldIds = array();
     $this->fieldDefinitions = [];
     if ($storetable == null) {
         $this->storetable = self::STORE_TABLE . $classId;
     } else {
         $this->storetable = $storetable;
     }
     if ($querytable == null) {
         $this->querytable = self::QUERY_TABLE . $classId;
     } else {
         $this->querytable = $querytable;
     }
     if ($relationtable == null) {
         $this->relationtable = self::RELATION_TABLE . $classId;
     } else {
         $this->relationtable = $relationtable;
     }
     if ($idField == null) {
         $this->idField = self::ID_FIELD;
     } else {
         $this->idField = $idField;
     }
 }
 public function indexAction()
 {
     $this->enableLayout();
     // get a list of news objects and order them by date
     $blogList = new Object\BlogArticle\Listing();
     $blogList->setOrderKey("date");
     $blogList->setOrder("DESC");
     $conditions = [];
     if ($this->getParam("category")) {
         $conditions[] = "categories LIKE " . $blogList->quote("%," . (int) $this->getParam("category") . ",%");
     }
     if ($this->getParam("archive")) {
         $conditions[] = "DATE_FORMAT(FROM_UNIXTIME(date), '%Y-%c') = " . $blogList->quote($this->getParam("archive"));
     }
     if (!empty($conditions)) {
         $blogList->setCondition(implode(" AND ", $conditions));
     }
     $paginator = \Zend_Paginator::factory($blogList);
     $paginator->setCurrentPageNumber($this->getParam('page'));
     $paginator->setItemCountPerPage(5);
     $this->view->articles = $paginator;
     // get all categories
     $categories = Object\BlogCategory::getList();
     // this is an alternative way to get an object list
     $this->view->categories = $categories;
     // archive information, we have to do this in pure SQL
     $db = \Pimcore\Db::get();
     $ranges = $db->fetchCol("SELECT DATE_FORMAT(FROM_UNIXTIME(date), '%Y-%c') as ranges FROM object_5 GROUP BY DATE_FORMAT(FROM_UNIXTIME(date), '%b-%Y') ORDER BY ranges ASC");
     $this->view->archiveRanges = $ranges;
 }
Beispiel #7
0
 /**
  * @return \Zend_Db_Adapter_Abstract
  */
 protected function getDb()
 {
     if (!$this->db) {
         // we're using a new mysql connection here to avoid problems with active (nested) transactions
         \Logger::debug("Initialize dedicated MySQL connection for the cache adapter");
         $this->db = Db::getConnection();
     }
     return $this->db;
 }
Beispiel #8
0
 /**
  * Creates a condition string from the passed ExtJs filter definitions
  *
  * @param $filterString
  * @param array $matchExact
  * @param bool $returnString
  * @param array $callbacks
  * @return array|string
  * @throws \Exception
  */
 public static function getFilterCondition($filterString, $matchExact = ['id', 'o_id'], $returnString = true, $callbacks = [])
 {
     if (!$filterString) {
         return '';
     }
     $conditions = [];
     $filters = json_decode($filterString);
     $db = \Pimcore\Db::get();
     foreach ($filters as $f) {
         if ($f->type == 'string') {
             if (in_array($f->property, $matchExact)) {
                 $conditions[$f->property][] = ' ' . $db->getQuoteIdentifierSymbol() . $f->property . $db->getQuoteIdentifierSymbol() . " = " . $db->quote($f->value) . ' ';
             } else {
                 $conditions[$f->property][] = ' ' . $db->getQuoteIdentifierSymbol() . $f->property . $db->getQuoteIdentifierSymbol() . " LIKE " . $db->quote("%" . $f->value . "%") . ' ';
             }
         } elseif ($f->type == 'numeric') {
             if ($f->operator == 'eq') {
                 $symbol = ' = ';
             } elseif ($f->operator == 'lt') {
                 $symbol = ' < ';
             } elseif ($f->operator == 'gt') {
                 $symbol = ' > ';
             }
             $conditions[$f->property][] = ' ' . $db->getQuoteIdentifierSymbol() . $f->property . $db->getQuoteIdentifierSymbol() . $symbol . $db->quote($f->value) . ' ';
         } elseif ($f->type == 'date') {
             /**
              * make sure you pass the date as timestamp
              *
              * filter: {type : 'date',dateFormat: 'timestamp'}
              */
             $date = Carbon::createFromTimestamp($f->value)->setTime(0, 0, 0);
             if ($f->operator == 'eq') {
                 $conditions[$f->property][] = ' ' . $f->property . ' >= ' . $db->quote($date->getTimestamp());
                 $conditions[$f->property][] = ' ' . $f->property . ' <= ' . $db->quote($date->addDay(1)->subSecond(1)->getTimestamp());
             } elseif ($f->operator == 'lt') {
                 $conditions[$f->property][] = ' ' . $f->property . ' < ' . $db->quote($date->getTimestamp());
             } elseif ($f->operator == 'gt') {
                 $conditions[$f->property][] = ' ' . $f->property . ' > ' . $db->quote($date->addDay(1)->subSecond(1)->getTimestamp());
             }
         } else {
             throw new \Exception("Filer of type " . $f->type . " not jet supported.");
         }
     }
     $conditionsGrouped = [];
     foreach ($conditions as $fieldName => $fieldConditions) {
         if (count($fieldConditions) > 1) {
             $conditionsGrouped[$fieldName] = ' (' . implode(' AND ', $fieldConditions) . ') ';
         } else {
             $conditionsGrouped[$fieldName] = $fieldConditions[0];
         }
     }
     if ($returnString) {
         return implode(' OR ', $conditionsGrouped);
     } else {
         return $conditionsGrouped;
     }
 }
 public function showAction()
 {
     $offset = $this->_getParam("start");
     $limit = $this->_getParam("limit");
     $orderby = "ORDER BY id DESC";
     $sortingSettings = \Pimcore\Admin\Helper\QueryParams::extractSortingSettings($this->getAllParams());
     if ($sortingSettings['orderKey']) {
         $orderby = "ORDER BY " . $sortingSettings['orderKey'] . " " . $sortingSettings['order'];
     }
     $queryString = " WHERE 1=1";
     if ($this->_getParam("priority") != "-1" && ($this->_getParam("priority") == "0" || $this->_getParam("priority"))) {
         $queryString .= " AND priority <= " . $this->_getParam("priority");
     } else {
         $queryString .= " AND (priority = 6 OR priority = 5 OR priority = 4 OR priority = 3 OR priority = 2 OR priority = 1 OR priority = 0)";
     }
     if ($this->_getParam("fromDate")) {
         $datetime = $this->_getParam("fromDate");
         if ($this->_getParam("fromTime")) {
             $datetime = substr($datetime, 0, 11) . $this->_getParam("fromTime") . ":00";
         }
         $queryString .= " AND timestamp >= '" . $datetime . "'";
     }
     if ($this->_getParam("toDate")) {
         $datetime = $this->_getParam("toDate");
         if ($this->_getParam("toTime")) {
             $datetime = substr($datetime, 0, 11) . $this->_getParam("toTime") . ":00";
         }
         $queryString .= " AND timestamp <= '" . $datetime . "'";
     }
     if ($this->_getParam("component")) {
         $queryString .= " AND component =  '" . $this->_getParam("component") . "'";
     }
     if ($this->_getParam("relatedobject")) {
         $queryString .= " AND relatedobject = " . $this->_getParam("relatedobject");
     }
     if ($this->_getParam("message")) {
         $queryString .= " AND message like '%" . $this->_getParam("message") . "%'";
     }
     $db = Db::get();
     $count = $db->fetchCol("SELECT count(*) FROM " . Log\Helper::ERROR_LOG_TABLE_NAME . $queryString);
     $total = $count[0];
     $result = $db->fetchAll("SELECT * FROM " . Log\Helper::ERROR_LOG_TABLE_NAME . $queryString . " {$orderby} LIMIT {$offset}, {$limit}");
     $errorDataList = array();
     if (!empty($result)) {
         foreach ($result as $r) {
             $parts = explode("/", $r['filelink']);
             $filename = $parts[count($parts) - 1];
             $fileobject = str_replace(PIMCORE_DOCUMENT_ROOT, "", $r['fileobject']);
             $errorData = array("id" => $r['id'], "message" => $r['message'], "timestamp" => $r['timestamp'], "priority" => $this->getPriorityName($r['priority']), "filename" => $filename, "fileobject" => $fileobject, "relatedobject" => $r['relatedobject'], "component" => $r['component'], "source" => $r['source']);
             $errorDataList[] = $errorData;
         }
     }
     $results = array("p_totalCount" => $total, "p_results" => $errorDataList);
     $this->_helper->json($results);
 }
 /**
  * @static
  * @return string[]
  */
 public static function getPriorities()
 {
     $priorities = array();
     $priorityNames = array("debug" => "DEBUG", "info" => "INFO", "notice" => "NOTICE", "warning" => "WARN", "error" => "ERR", "critical" => "CRIT", "alert" => "ALERT", "emergency" => "EMERG");
     $db = Database::get();
     $priorityNumbers = $db->fetchCol("SELECT priority FROM " . \Pimcore\Log\Handler\ApplicationLoggerDb::TABLE_NAME . " WHERE NOT ISNULL(priority) GROUP BY priority;");
     foreach ($priorityNumbers as $priorityNumber) {
         $priorities[$priorityNumber] = $priorityNames[$priorityNumber];
     }
     return $priorities;
 }
Beispiel #11
0
 /**
  * @static
  * @return string[]
  */
 public static function getPriorities()
 {
     $priorities = array();
     $priorityNames = array(Zend_Log::DEBUG => "DEBUG", Zend_Log::INFO => "INFO", Zend_Log::NOTICE => "INFO", Zend_Log::WARN => "WARN", Zend_Log::ERR => "ERR", Zend_Log::CRIT => "CRIT", Zend_Log::ALERT => "ALERT", Zend_Log::EMERG => "EMERG");
     $db = Database::get();
     $priorityNumbers = $db->fetchCol("SELECT priority FROM " . Log\Helper::ERROR_LOG_TABLE_NAME . " WHERE NOT ISNULL(priority) GROUP BY priority;");
     foreach ($priorityNumbers as $priorityNumber) {
         $priorities[$priorityNumber] = $priorityNames[$priorityNumber];
     }
     return $priorities;
 }
Beispiel #12
0
 /**
  * @param \Zend_Controller_Request_Abstract $request
  * @return bool|void
  */
 public function routeShutdown(\Zend_Controller_Request_Abstract $request)
 {
     if (!Tool::useFrontendOutputFilters($request)) {
         return $this->disable();
     }
     $db = \Pimcore\Db::get();
     $enabled = $db->fetchOne("SELECT id FROM targeting_personas UNION SELECT id FROM targeting_rules LIMIT 1");
     if (!$enabled) {
         return $this->disable();
     }
     if ($request->getParam("document") instanceof Document\Page) {
         $this->document = $request->getParam("document");
     }
 }
Beispiel #13
0
 /**
  *
  */
 public function writeLog()
 {
     $code = (string) $this->getResponse()->getHttpResponseCode();
     $db = \Pimcore\Db::get();
     try {
         $uri = $this->getRequest()->getScheme() . "://" . $this->getRequest()->getHttpHost() . $this->getRequest()->getRequestUri();
         $exists = $db->fetchOne("SELECT date FROM http_error_log WHERE uri = ?", $uri);
         if ($exists) {
             $db->query("UPDATE http_error_log SET `count` = `count` + 1, date = ? WHERE uri = ?", [time(), $uri]);
         } else {
             $db->insert("http_error_log", ["uri" => $uri, "code" => (int) $code, "parametersGet" => serialize($_GET), "parametersPost" => serialize($_POST), "cookies" => serialize($_COOKIE), "serverVars" => serialize($_SERVER), "date" => time(), "count" => 1]);
         }
     } catch (\Exception $e) {
         \Logger::error("Unable to log http error");
         \Logger::error($e);
     }
 }
Beispiel #14
0
 /**
  * @param $key
  * @param $language
  * @return \Pimcore\Model\Metadata\Predefined
  */
 public static function getByKeyAndLanguage($key, $language, $targetSubtype = null)
 {
     $db = \Pimcore\Db::get();
     $list = new self();
     $condition = "name = " . $db->quote($key);
     if ($language) {
         $condition .= " AND language = " . $db->quote($language);
     } else {
         $condition .= " AND (language = '' OR LANGUAGE IS NULL)";
     }
     if ($targetSubtype) {
         $condition .= " AND targetSubtype = " . $db->quote($targetSubtype);
     }
     $list->setCondition($condition);
     $list = $list->load();
     if ($list) {
         return $list[0];
     }
     return null;
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     // clear all data
     $db = \Pimcore\Db::get();
     $db->query("TRUNCATE `search_backend_data`;");
     $elementsPerLoop = 100;
     $types = ["asset", "document", "object"];
     foreach ($types as $type) {
         $listClassName = "\\Pimcore\\Model\\" . ucfirst($type) . "\\Listing";
         $list = new $listClassName();
         if (method_exists($list, "setUnpublished")) {
             $list->setUnpublished(true);
         }
         $elementsTotal = $list->getTotalCount();
         for ($i = 0; $i < ceil($elementsTotal / $elementsPerLoop); $i++) {
             $list->setLimit($elementsPerLoop);
             $list->setOffset($i * $elementsPerLoop);
             $this->output->writeln("Processing " . $type . ": " . ($list->getOffset() + $elementsPerLoop) . "/" . $elementsTotal);
             $elements = $list->load();
             foreach ($elements as $element) {
                 try {
                     $searchEntry = Search\Backend\Data::getForElement($element);
                     if ($searchEntry instanceof Search\Backend\Data and $searchEntry->getId() instanceof Search\Backend\Data\Id) {
                         $searchEntry->setDataFromElement($element);
                     } else {
                         $searchEntry = new Search\Backend\Data($element);
                     }
                     $searchEntry->save();
                 } catch (\Exception $e) {
                     Logger::err($e);
                 }
             }
             \Pimcore::collectGarbage();
         }
     }
     $db->query("OPTIMIZE TABLE search_backend_data;");
 }
Beispiel #16
0
 public function portletModificationStatisticsAction()
 {
     $db = \Pimcore\Db::get();
     $days = 31;
     $startDate = mktime(23, 59, 59, date("m"), date("d"), date("Y"));
     $currentDate = $startDate;
     $data = [];
     for ($i = 0; $i < $days; $i++) {
         // documents
         $end = $startDate - $i * 86400;
         $start = $end - 86399;
         $o = $db->fetchOne("SELECT COUNT(*) AS count FROM objects WHERE o_modificationDate > " . $start . " AND o_modificationDate < " . $end);
         $a = $db->fetchOne("SELECT COUNT(*) AS count FROM assets WHERE modificationDate > " . $start . " AND modificationDate < " . $end);
         $d = $db->fetchOne("SELECT COUNT(*) AS count FROM documents WHERE modificationDate > " . $start . " AND modificationDate < " . $end);
         $date = new \DateTime();
         $date->setTimestamp($start);
         $data[] = ["timestamp" => $start, "datetext" => $date->format("Y-m-d"), "objects" => (int) $o, "documents" => (int) $d, "assets" => (int) $a];
     }
     $data = array_reverse($data);
     $this->_helper->json(["data" => $data]);
 }
Beispiel #17
0
 /**
  * @param $filters
  * @param $field
  * @param $drillDownFilters
  * @return array|mixed
  */
 public function getAvailableOptions($filters, $field, $drillDownFilters)
 {
     $db = Db::get();
     $baseQuery = $this->getBaseQuery($filters, array($field), true, $drillDownFilters, $field);
     $data = array();
     if ($baseQuery) {
         $sql = $baseQuery["data"] . " GROUP BY " . $db->quoteIdentifier($field);
         $data = $db->fetchAll($sql);
     }
     $filteredData = array();
     foreach ($data as $d) {
         if (!empty($d[$field]) || $d[$field] === 0) {
             $filteredData[] = array("value" => $d[$field]);
         }
     }
     return array("data" => array_merge(array(array("value" => null)), $filteredData));
 }
Beispiel #18
0
 public function httpErrorLogDetailAction()
 {
     $this->checkPermission("http_errors");
     $db = Db::get();
     $data = $db->fetchRow("SELECT * FROM http_error_log WHERE uri = ?", [$this->getParam("uri")]);
     foreach ($data as $key => &$value) {
         if (in_array($key, ["parametersGet", "parametersPost", "serverVars", "cookies"])) {
             $value = unserialize($value);
         }
     }
     $this->view->data = $data;
 }
Beispiel #19
0
 /**
  *
  * @param string $filterJson
  * @param ClassDefinition $class
  * @return string
  */
 public static function getFilterCondition($filterJson, $class)
 {
     $systemFields = array("o_path", "o_key", "o_id", "o_published", "o_creationDate", "o_modificationDate", "o_fullpath");
     // create filter condition
     $conditionPartsFilters = array();
     if ($filterJson) {
         $db = \Pimcore\Db::get();
         $filters = \Zend_Json::decode($filterJson);
         foreach ($filters as $filter) {
             $operator = "=";
             /**
              * @extjs
              */
             $filterField = $filter["field"];
             $filterOperator = $filter["comparison"];
             if (\Pimcore\Tool\Admin::isExtJS6()) {
                 $filterField = $filter["property"];
                 $filterOperator = $filter["operator"];
             }
             if ($filter["type"] == "string") {
                 $operator = "LIKE";
             } else {
                 if ($filter["type"] == "numeric") {
                     if ($filterOperator == "lt") {
                         $operator = "<";
                     } else {
                         if ($filterOperator == "gt") {
                             $operator = ">";
                         } else {
                             if ($filterOperator == "eq") {
                                 $operator = "=";
                             }
                         }
                     }
                 } else {
                     if ($filter["type"] == "date") {
                         if ($filterOperator == "lt") {
                             $operator = "<";
                         } else {
                             if ($filterOperator == "gt") {
                                 $operator = ">";
                             } else {
                                 if ($filterOperator == "eq") {
                                     $operator = "=";
                                 }
                             }
                         }
                         $filter["value"] = strtotime($filter["value"]);
                     } else {
                         if ($filter["type"] == "list") {
                             $operator = "=";
                         } else {
                             if ($filter["type"] == "boolean") {
                                 $operator = "=";
                                 $filter["value"] = (int) $filter["value"];
                             }
                         }
                     }
                 }
             }
             $field = $class->getFieldDefinition($filterField);
             $brickField = null;
             $brickType = null;
             if (!$field) {
                 // if the definition doesn't exist check for a localized field
                 $localized = $class->getFieldDefinition("localizedfields");
                 if ($localized instanceof ClassDefinition\Data\Localizedfields) {
                     $field = $localized->getFieldDefinition($filterField);
                 }
                 //if the definition doesn't exist check for object brick
                 $keyParts = explode("~", $filterField);
                 if (substr($filterField, 0, 1) == "~") {
                     // not needed for now
                     //                            $type = $keyParts[1];
                     //                            $field = $keyParts[2];
                     //                            $keyid = $keyParts[3];
                 } else {
                     if (count($keyParts) > 1) {
                         $brickType = $keyParts[0];
                         $brickKey = $keyParts[1];
                         $key = self::getFieldForBrickType($class, $brickType);
                         $field = $class->getFieldDefinition($key);
                         $brickClass = Objectbrick\Definition::getByKey($brickType);
                         $brickField = $brickClass->getFieldDefinition($brickKey);
                     }
                 }
             }
             if ($field instanceof ClassDefinition\Data\Objectbricks) {
                 // custom field
                 $db = \Pimcore\Db::get();
                 if (is_array($filter["value"])) {
                     $fieldConditions = array();
                     foreach ($filter["value"] as $filterValue) {
                         $fieldConditions[] = $db->getQuoteIdentifierSymbol() . $brickType . $db->getQuoteIdentifierSymbol() . "." . $brickField->getFilterCondition($filterValue, $operator);
                     }
                     $conditionPartsFilters[] = "(" . implode(" OR ", $fieldConditions) . ")";
                 } else {
                     $conditionPartsFilters[] = $db->getQuoteIdentifierSymbol() . $brickType . $db->getQuoteIdentifierSymbol() . "." . $brickField->getFilterCondition($filter["value"], $operator);
                 }
             } else {
                 if ($field instanceof ClassDefinition\Data) {
                     // custom field
                     if (is_array($filter["value"])) {
                         $fieldConditions = array();
                         foreach ($filter["value"] as $filterValue) {
                             $fieldConditions[] = $field->getFilterCondition($filterValue, $operator);
                         }
                         $conditionPartsFilters[] = "(" . implode(" OR ", $fieldConditions) . ")";
                     } else {
                         $conditionPartsFilters[] = $field->getFilterCondition($filter["value"], $operator);
                     }
                 } else {
                     if (in_array("o_" . $filterField, $systemFields)) {
                         // system field
                         if ($filterField == "fullpath") {
                             $conditionPartsFilters[] = "concat(o_path, o_key) " . $operator . " " . $db->quote("%" . $filter["value"] . "%");
                         } else {
                             $conditionPartsFilters[] = "`o_" . $filterField . "` " . $operator . " " . $db->quote($filter["value"]);
                         }
                     }
                 }
             }
         }
     }
     $conditionFilters = "1 = 1";
     if (count($conditionPartsFilters) > 0) {
         $conditionFilters = "(" . implode(" AND ", $conditionPartsFilters) . ")";
     }
     \Logger::log("ObjectController filter condition:" . $conditionFilters);
     return $conditionFilters;
 }
 public function __construct()
 {
     $this->db = \Pimcore\Db::get();
 }
 /**
  * @return void
  */
 public function findAction()
 {
     $user = $this->getUser();
     $query = $this->getParam("query");
     if ($query == "*") {
         $query = "";
     }
     $query = str_replace("%", "*", $query);
     $types = explode(",", $this->getParam("type"));
     $subtypes = explode(",", $this->getParam("subtype"));
     $classnames = explode(",", $this->getParam("class"));
     if ($this->getParam("type") == "object" && is_array($classnames) && empty($classnames[0])) {
         $subtypes = array("object", "variant", "folder");
     }
     $offset = intval($this->getParam("start"));
     $limit = intval($this->getParam("limit"));
     $offset = $offset ? $offset : 0;
     $limit = $limit ? $limit : 50;
     $searcherList = new Data\Listing();
     $conditionParts = array();
     $db = \Pimcore\Db::get();
     //exclude forbidden assets
     if (in_array("asset", $types)) {
         if (!$user->isAllowed("assets")) {
             $forbiddenConditions[] = " `type` != 'asset' ";
         } else {
             $forbiddenAssetPaths = Element\Service::findForbiddenPaths("asset", $user);
             if (count($forbiddenAssetPaths) > 0) {
                 for ($i = 0; $i < count($forbiddenAssetPaths); $i++) {
                     $forbiddenAssetPaths[$i] = " (maintype = 'asset' AND fullpath not like " . $db->quote($forbiddenAssetPaths[$i] . "%") . ")";
                 }
                 $forbiddenConditions[] = implode(" AND ", $forbiddenAssetPaths);
             }
         }
     }
     //exclude forbidden documents
     if (in_array("document", $types)) {
         if (!$user->isAllowed("documents")) {
             $forbiddenConditions[] = " `type` != 'document' ";
         } else {
             $forbiddenDocumentPaths = Element\Service::findForbiddenPaths("document", $user);
             if (count($forbiddenDocumentPaths) > 0) {
                 for ($i = 0; $i < count($forbiddenDocumentPaths); $i++) {
                     $forbiddenDocumentPaths[$i] = " (maintype = 'document' AND fullpath not like " . $db->quote($forbiddenDocumentPaths[$i] . "%") . ")";
                 }
                 $forbiddenConditions[] = implode(" AND ", $forbiddenDocumentPaths);
             }
         }
     }
     //exclude forbidden objects
     if (in_array("object", $types)) {
         if (!$user->isAllowed("objects")) {
             $forbiddenConditions[] = " `type` != 'object' ";
         } else {
             $forbiddenObjectPaths = Element\Service::findForbiddenPaths("object", $user);
             if (count($forbiddenObjectPaths) > 0) {
                 for ($i = 0; $i < count($forbiddenObjectPaths); $i++) {
                     $forbiddenObjectPaths[$i] = " (maintype = 'object' AND fullpath not like " . $db->quote($forbiddenObjectPaths[$i] . "%") . ")";
                 }
                 $forbiddenConditions[] = implode(" AND ", $forbiddenObjectPaths);
             }
         }
     }
     if ($forbiddenConditions) {
         $conditionParts[] = "(" . implode(" AND ", $forbiddenConditions) . ")";
     }
     if (!empty($query)) {
         $queryCondition = "( MATCH (`data`,`properties`) AGAINST (" . $db->quote($query) . " IN BOOLEAN MODE) )";
         // the following should be done with an exact-search now "ID", because the Element-ID is now in the fulltext index
         // if the query is numeric the user might want to search by id
         //if(is_numeric($query)) {
         //$queryCondition = "(" . $queryCondition . " OR id = " . $db->quote($query) ." )";
         //}
         $conditionParts[] = $queryCondition;
     }
     //For objects - handling of bricks
     $fields = array();
     $bricks = array();
     if ($this->getParam("fields")) {
         $fields = $this->getParam("fields");
         foreach ($fields as $f) {
             $parts = explode("~", $f);
             if (substr($f, 0, 1) == "~") {
                 //                    $type = $parts[1];
                 //                    $field = $parts[2];
                 //                    $keyid = $parts[3];
                 // key value, ignore for now
             } else {
                 if (count($parts) > 1) {
                     $bricks[$parts[0]] = $parts[0];
                 }
             }
         }
     }
     // filtering for objects
     if ($this->getParam("filter") && $this->getParam("class")) {
         $class = Object\ClassDefinition::getByName($this->getParam("class"));
         $conditionFilters = Object\Service::getFilterCondition($this->getParam("filter"), $class);
         $join = "";
         foreach ($bricks as $ob) {
             $join .= " LEFT JOIN object_brick_query_" . $ob . "_" . $class->getId();
             $join .= " `" . $ob . "`";
             $join .= " ON `" . $ob . "`.o_id = `object_" . $class->getId() . "`.o_id";
         }
         $conditionParts[] = "( id IN (SELECT `object_" . $class->getId() . "`.o_id FROM object_" . $class->getId() . $join . " WHERE " . $conditionFilters . ") )";
     }
     if (is_array($types) and !empty($types[0])) {
         foreach ($types as $type) {
             $conditionTypeParts[] = $db->quote($type);
         }
         if (in_array("folder", $subtypes)) {
             $conditionTypeParts[] = $db->quote('folder');
         }
         $conditionParts[] = "( maintype IN (" . implode(",", $conditionTypeParts) . ") )";
     }
     if (is_array($subtypes) and !empty($subtypes[0])) {
         foreach ($subtypes as $subtype) {
             $conditionSubtypeParts[] = $db->quote($subtype);
         }
         $conditionParts[] = "( type IN (" . implode(",", $conditionSubtypeParts) . ") )";
     }
     if (is_array($classnames) and !empty($classnames[0])) {
         if (in_array("folder", $subtypes)) {
             $classnames[] = "folder";
         }
         foreach ($classnames as $classname) {
             $conditionClassnameParts[] = $db->quote($classname);
         }
         $conditionParts[] = "( subtype IN (" . implode(",", $conditionClassnameParts) . ") )";
     }
     if (count($conditionParts) > 0) {
         $condition = implode(" AND ", $conditionParts);
         //echo $condition; die();
         $searcherList->setCondition($condition);
     }
     $searcherList->setOffset($offset);
     $searcherList->setLimit($limit);
     // do not sort per default, it is VERY SLOW
     //$searcherList->setOrder("desc");
     //$searcherList->setOrderKey("modificationdate");
     if ($this->getParam("sort")) {
         // we need a special mapping for classname as this is stored in subtype column
         $sortMapping = ["classname" => "subtype"];
         $sort = $this->getParam("sort");
         if (array_key_exists($this->getParam("sort"), $sortMapping)) {
             $sort = $sortMapping[$this->getParam("sort")];
         }
         $searcherList->setOrderKey($sort);
     }
     if ($this->getParam("dir")) {
         $searcherList->setOrder($this->getParam("dir"));
     }
     $hits = $searcherList->load();
     $elements = array();
     foreach ($hits as $hit) {
         $element = Element\Service::getElementById($hit->getId()->getType(), $hit->getId()->getId());
         if ($element->isAllowed("list")) {
             if ($element instanceof Object\AbstractObject) {
                 $data = Object\Service::gridObjectData($element, $fields);
             } else {
                 if ($element instanceof Document) {
                     $data = Document\Service::gridDocumentData($element);
                 } else {
                     if ($element instanceof Asset) {
                         $data = Asset\Service::gridAssetData($element);
                     }
                 }
             }
             $elements[] = $data;
         } else {
             //TODO: any message that view is blocked?
             //$data = Element\Service::gridElementData($element);
         }
     }
     // only get the real total-count when the limit parameter is given otherwise use the default limit
     if ($this->getParam("limit")) {
         $totalMatches = $searcherList->getTotalCount();
     } else {
         $totalMatches = count($elements);
     }
     $this->_helper->json(array("data" => $elements, "success" => true, "total" => $totalMatches));
     $this->removeViewRenderer();
 }
 public function __construct($revision)
 {
     $this->revision = $revision;
     $this->db = \Pimcore\Db::getConnection();
 }
Beispiel #23
0
 public function indexAction()
 {
     $checksPHP = array();
     $checksMySQL = array();
     $checksFS = array();
     $checksApps = array();
     // check for memory limit
     $memoryLimit = ini_get("memory_limit");
     $memoryLimit = filesize2bytes($memoryLimit . "B");
     $state = "ok";
     if ($memoryLimit < 67108000) {
         $state = "error";
     } elseif ($memoryLimit < 134217000) {
         $state = "warning";
     }
     $checksPHP[] = array("name" => "memory_limit (in php.ini)", "link" => "http://www.php.net/memory_limit", "state" => $state);
     // mcrypt
     $checksPHP[] = array("name" => "mcrypt", "link" => "http://www.php.net/mcrypt", "state" => function_exists("mcrypt_encrypt") ? "ok" : "error");
     // pdo_mysql
     $checksPHP[] = array("name" => "PDO_Mysql", "link" => "http://www.php.net/pdo_mysql", "state" => @constant("PDO::MYSQL_ATTR_FOUND_ROWS") ? "ok" : "error");
     // pdo_mysql
     $checksPHP[] = array("name" => "Mysqli", "link" => "http://www.php.net/mysqli", "state" => class_exists("mysqli") ? "ok" : "error");
     // iconv
     $checksPHP[] = array("name" => "iconv", "link" => "http://www.php.net/iconv", "state" => function_exists("iconv") ? "ok" : "error");
     // dom
     $checksPHP[] = array("name" => "dom", "link" => "http://www.php.net/dom", "state" => class_exists("DOMDocument") ? "ok" : "error");
     // simplexml
     $checksPHP[] = array("name" => "SimpleXML", "link" => "http://www.php.net/simplexml", "state" => class_exists("SimpleXMLElement") ? "ok" : "error");
     // gd
     $checksPHP[] = array("name" => "GD", "link" => "http://www.php.net/gd", "state" => function_exists("gd_info") ? "ok" : "error");
     // exif
     $checksPHP[] = array("name" => "EXIF", "link" => "http://www.php.net/exif", "state" => function_exists("exif_read_data") ? "ok" : "error");
     // multibyte support
     $checksPHP[] = array("name" => "Multibyte String (mbstring)", "link" => "http://www.php.net/mbstring", "state" => function_exists("mb_get_info") ? "ok" : "error");
     // file_info support
     $checksPHP[] = array("name" => "File Information (file_info)", "link" => "http://www.php.net/file_info", "state" => function_exists("finfo_open") ? "ok" : "error");
     // zip
     $checksPHP[] = array("name" => "zip", "link" => "http://www.php.net/zip", "state" => class_exists("ZipArchive") ? "ok" : "error");
     // gzip
     $checksPHP[] = array("name" => "zlib / gzip", "link" => "http://www.php.net/zlib", "state" => function_exists("gzcompress") ? "ok" : "error");
     // bzip
     $checksPHP[] = array("name" => "Bzip2", "link" => "http://www.php.net/bzip2", "state" => function_exists("bzcompress") ? "ok" : "error");
     // openssl
     $checksPHP[] = array("name" => "OpenSSL", "link" => "http://www.php.net/openssl", "state" => function_exists("openssl_open") ? "ok" : "error");
     // Imagick
     $checksPHP[] = array("name" => "Imagick", "link" => "http://www.php.net/imagick", "state" => class_exists("Imagick") ? "ok" : "warning");
     // OPcache
     $checksPHP[] = array("name" => "OPcache", "link" => "http://www.php.net/opcache", "state" => function_exists("opcache_reset") ? "ok" : "warning");
     // memcache
     $checksPHP[] = array("name" => "Memcache", "link" => "http://www.php.net/memcache", "state" => class_exists("Memcache") ? "ok" : "warning");
     // Redis
     $checksPHP[] = array("name" => "Redis", "link" => "https://pecl.php.net/package/redis", "state" => class_exists("Redis") ? "ok" : "warning");
     // curl for google api sdk
     $checksPHP[] = array("name" => "curl", "link" => "http://www.php.net/curl", "state" => function_exists("curl_init") ? "ok" : "warning");
     $db = null;
     if ($this->getParam("mysql_adapter")) {
         // this is before installing
         try {
             $dbConfig = ['username' => $this->getParam("mysql_username"), 'password' => $this->getParam("mysql_password"), 'dbname' => $this->getParam("mysql_database")];
             $hostSocketValue = $this->getParam("mysql_host_socket");
             if (file_exists($hostSocketValue)) {
                 $dbConfig["unix_socket"] = $hostSocketValue;
             } else {
                 $dbConfig["host"] = $hostSocketValue;
                 $dbConfig["port"] = $this->getParam("mysql_port");
             }
             $db = \Zend_Db::factory($this->getParam("mysql_adapter"), $dbConfig);
             $db->getConnection();
         } catch (\Exception $e) {
             $db = null;
         }
     } else {
         // this is after installing, eg. after a migration, ...
         $db = \Pimcore\Db::get();
     }
     if ($db) {
         // storage engines
         $engines = array();
         $enginesRaw = $db->fetchAll("SHOW ENGINES;");
         foreach ($enginesRaw as $engineRaw) {
             $engines[] = strtolower($engineRaw["Engine"]);
         }
         // innodb
         $checksMySQL[] = array("name" => "InnoDB Support", "state" => in_array("innodb", $engines) ? "ok" : "error");
         // myisam
         $checksMySQL[] = array("name" => "MyISAM Support", "state" => in_array("myisam", $engines) ? "ok" : "error");
         // memory
         $checksMySQL[] = array("name" => "MEMORY Support", "state" => in_array("memory", $engines) ? "ok" : "error");
         // check database charset =>  utf-8 encoding
         $result = $db->fetchRow('SHOW VARIABLES LIKE "character\\_set\\_database"');
         $checksMySQL[] = array("name" => "Database Charset UTF8", "state" => $result['Value'] == "utf8" ? "ok" : "error");
         // create table
         $queryCheck = true;
         try {
             $db->query("CREATE TABLE __pimcore_req_check (\n                  id int(11) NOT NULL AUTO_INCREMENT,\n                  field varchar(255) CHARACTER SET latin1 NULL DEFAULT NULL,\n                  PRIMARY KEY (id)\n                ) DEFAULT CHARSET=utf8 COLLATE utf8_general_ci");
         } catch (\Exception $e) {
             $queryCheck = false;
         }
         $checksMySQL[] = array("name" => "CREATE TABLE", "state" => $queryCheck ? "ok" : "error");
         // alter table
         $queryCheck = true;
         try {
             $db->query("ALTER TABLE __pimcore_req_check ADD COLUMN alter_field varchar(255) NULL DEFAULT NULL");
         } catch (\Exception $e) {
             $queryCheck = false;
         }
         $checksMySQL[] = array("name" => "ALTER TABLE", "state" => $queryCheck ? "ok" : "error");
         // Manage indexes
         $queryCheck = true;
         try {
             $db->query("ALTER TABLE __pimcore_req_check\n                  CHANGE COLUMN id id int(11) NOT NULL,\n                  CHANGE COLUMN field field varchar(255) NULL DEFAULT NULL,\n                  CHANGE COLUMN alter_field alter_field varchar(255) NULL DEFAULT NULL,\n                  ADD KEY field (field),\n                  DROP PRIMARY KEY ,\n                 DEFAULT CHARSET=utf8");
             $db->query("ALTER TABLE __pimcore_req_check\n                  CHANGE COLUMN id id int(11) NOT NULL AUTO_INCREMENT,\n                  CHANGE COLUMN field field varchar(255) NULL DEFAULT NULL,\n                  CHANGE COLUMN alter_field alter_field varchar(255) NULL DEFAULT NULL,\n                  ADD PRIMARY KEY (id) ,\n                 DEFAULT CHARSET=utf8");
         } catch (\Exception $e) {
             $queryCheck = false;
         }
         $checksMySQL[] = array("name" => "Manage Indexes", "state" => $queryCheck ? "ok" : "error");
         // insert data
         $queryCheck = true;
         try {
             $db->insert("__pimcore_req_check", array("field" => uniqid(), "alter_field" => uniqid()));
         } catch (\Exception $e) {
             $queryCheck = false;
         }
         $checksMySQL[] = array("name" => "INSERT", "state" => $queryCheck ? "ok" : "error");
         // update
         $queryCheck = true;
         try {
             $db->update("__pimcore_req_check", array("field" => uniqid(), "alter_field" => uniqid()));
         } catch (\Exception $e) {
             $queryCheck = false;
         }
         $checksMySQL[] = array("name" => "UPDATE", "state" => $queryCheck ? "ok" : "error");
         // select
         $queryCheck = true;
         try {
             $db->fetchAll("SELECT * FROM __pimcore_req_check");
         } catch (\Exception $e) {
             $queryCheck = false;
         }
         $checksMySQL[] = array("name" => "SELECT", "state" => $queryCheck ? "ok" : "error");
         // create view
         $queryCheck = true;
         try {
             $db->query("CREATE OR REPLACE VIEW __pimcore_req_check_view AS SELECT * FROM __pimcore_req_check");
         } catch (\Exception $e) {
             $queryCheck = false;
         }
         $checksMySQL[] = array("name" => "CREATE VIEW", "state" => $queryCheck ? "ok" : "error");
         // select from view
         $queryCheck = true;
         try {
             $db->fetchAll("SELECT * FROM __pimcore_req_check_view");
         } catch (\Exception $e) {
             $queryCheck = false;
         }
         $checksMySQL[] = array("name" => "SELECT (from view)", "state" => $queryCheck ? "ok" : "error");
         // delete
         $queryCheck = true;
         try {
             $db->delete("__pimcore_req_check");
         } catch (\Exception $e) {
             $queryCheck = false;
         }
         $checksMySQL[] = array("name" => "DELETE", "state" => $queryCheck ? "ok" : "error");
         // show create view
         $queryCheck = true;
         try {
             $db->query("SHOW CREATE VIEW __pimcore_req_check_view");
         } catch (\Exception $e) {
             $queryCheck = false;
         }
         $checksMySQL[] = array("name" => "SHOW CREATE VIEW", "state" => $queryCheck ? "ok" : "error");
         // show create table
         $queryCheck = true;
         try {
             $db->query("SHOW CREATE TABLE __pimcore_req_check");
         } catch (\Exception $e) {
             $queryCheck = false;
         }
         $checksMySQL[] = array("name" => "SHOW CREATE TABLE", "state" => $queryCheck ? "ok" : "error");
         // drop view
         $queryCheck = true;
         try {
             $db->query("DROP VIEW __pimcore_req_check_view");
         } catch (\Exception $e) {
             $queryCheck = false;
         }
         $checksMySQL[] = array("name" => "DROP VIEW", "state" => $queryCheck ? "ok" : "error");
         // drop table
         $queryCheck = true;
         try {
             $db->query("DROP TABLE __pimcore_req_check");
         } catch (\Exception $e) {
             $queryCheck = false;
         }
         $checksMySQL[] = array("name" => "DROP TABLE", "state" => $queryCheck ? "ok" : "error");
     } else {
         die("Not possible... no or wrong database settings given.<br />Please fill out the MySQL Settings in the install form an click again on `Check Requirements´");
     }
     // filesystem checks
     // website/var writable
     $websiteVarWritable = true;
     try {
         $files = $this->rscandir(PIMCORE_WEBSITE_VAR);
         foreach ($files as $file) {
             if (!is_writable($file)) {
                 $websiteVarWritable = false;
             }
         }
         $checksFS[] = array("name" => "/website/var/ writeable", "state" => $websiteVarWritable ? "ok" : "error");
     } catch (\Exception $e) {
         $checksFS[] = array("name" => "/website/var/ (not checked - too many files)", "state" => "warning");
     }
     // pimcore writeable
     $checksFS[] = array("name" => "/pimcore/ writeable", "state" => \Pimcore\Update::isWriteable() ? "ok" : "warning");
     // system & application checks
     // PHP CLI BIN
     try {
         $phpCliBin = (bool) \Pimcore\Tool\Console::getPhpCli();
     } catch (\Exception $e) {
         $phpCliBin = false;
     }
     $checksApps[] = array("name" => "PHP CLI Binary", "state" => $phpCliBin ? "ok" : "error");
     // FFMPEG BIN
     try {
         $ffmpegBin = (bool) \Pimcore\Video\Adapter\Ffmpeg::getFfmpegCli();
     } catch (\Exception $e) {
         $ffmpegBin = false;
     }
     $checksApps[] = array("name" => "FFMPEG (CLI)", "state" => $ffmpegBin ? "ok" : "warning");
     // WKHTMLTOIMAGE BIN
     try {
         $wkhtmltopdfBin = (bool) \Pimcore\Image\HtmlToImage::getWkhtmltoimageBinary();
     } catch (\Exception $e) {
         $wkhtmltopdfBin = false;
     }
     $checksApps[] = array("name" => "wkhtmltoimage (CLI)", "state" => $wkhtmltopdfBin ? "ok" : "warning");
     // HTML2TEXT BIN
     try {
         $html2textBin = (bool) \Pimcore\Mail::determineHtml2TextIsInstalled();
     } catch (\Exception $e) {
         $html2textBin = false;
     }
     $checksApps[] = array("name" => "mbayer html2text (CLI)", "state" => $html2textBin ? "ok" : "warning");
     // ghostscript BIN
     try {
         $ghostscriptBin = (bool) \Pimcore\Document\Adapter\Ghostscript::getGhostscriptCli();
     } catch (\Exception $e) {
         $ghostscriptBin = false;
     }
     $checksApps[] = array("name" => "Ghostscript (CLI)", "state" => $ghostscriptBin ? "ok" : "warning");
     // LibreOffice BIN
     try {
         $libreofficeBin = (bool) \Pimcore\Document\Adapter\LibreOffice::getLibreOfficeCli();
     } catch (\Exception $e) {
         $libreofficeBin = false;
     }
     $checksApps[] = array("name" => "LibreOffice (CLI)", "state" => $libreofficeBin ? "ok" : "warning");
     // PNG optimizer
     try {
         $pngOptimizer = (bool) \Pimcore\Image\Optimizer::getPngOptimizerCli();
     } catch (\Exception $e) {
         $pngOptimizer = false;
     }
     $checksApps[] = array("name" => "PNG Optimizer (pngcrush)", "state" => $pngOptimizer ? "ok" : "warning");
     // JPEG optimizer
     try {
         $jpgOptimizer = (bool) \Pimcore\Image\Optimizer::getJpegOptimizerCli();
     } catch (\Exception $e) {
         $jpgOptimizer = false;
     }
     $checksApps[] = array("name" => "JPEG Optimizer (imgmin, jpegoptim)", "state" => $jpgOptimizer ? "ok" : "warning");
     // timeout binary
     try {
         $timeoutBin = (bool) \Pimcore\Tool\Console::getTimeoutBinary();
     } catch (\Exception $e) {
         $timeoutBin = false;
     }
     $checksApps[] = array("name" => "timeout - (GNU coreutils)", "state" => $timeoutBin ? "ok" : "warning");
     // pdftotext binary
     try {
         $pdftotextBin = (bool) \Pimcore\Document\Adapter\Ghostscript::getPdftotextCli();
     } catch (\Exception $e) {
         $pdftotextBin = false;
     }
     $checksApps[] = array("name" => "pdftotext - (part of poppler-utils)", "state" => $pdftotextBin ? "ok" : "warning");
     $this->view->checksApps = $checksApps;
     $this->view->checksPHP = $checksPHP;
     $this->view->checksMySQL = $checksMySQL;
     $this->view->checksFS = $checksFS;
 }
Beispiel #24
0
 public function archiveLogEntries()
 {
     $conf = Config::getSystemConfig();
     $config = $conf->applicationlog;
     $db = \Pimcore\Db::get();
     $tablename = \Pimcore\Log\Handler\ApplicationLoggerDb::TABLE_ARCHIVE_PREFIX . "_" . \Zend_Date::now()->get(\Zend_Date::MONTH) . '_' . \Zend_Date::now()->get(\Zend_Date::YEAR);
     if ($config->archive_alternative_database) {
         $tablename = $config->archive_alternative_database . '.' . $tablename;
     }
     $archive_treshold = intval($config->archive_treshold) ?: 30;
     $db->query("CREATE TABLE IF NOT EXISTS " . $tablename . " (\n                       id BIGINT(20) NOT NULL,\n                       `pid` INT(11) NULL DEFAULT NULL,\n                       `timestamp` DATETIME NOT NULL,\n                       message VARCHAR(1024),\n                       `priority` ENUM('emergency','alert','critical','error','warning','notice','info','debug') DEFAULT NULL,\n                       fileobject VARCHAR(1024),\n                       info VARCHAR(1024),\n                       component VARCHAR(255),\n                       source VARCHAR(255) NULL DEFAULT NULL,\n                       relatedobject BIGINT(20),\n                       relatedobjecttype ENUM('object', 'document', 'asset'),\n                       maintenanceChecked TINYINT(4)\n                    ) ENGINE = ARCHIVE ROW_FORMAT = DEFAULT;");
     $timestamp = time();
     $db->query("INSERT INTO " . $tablename . " SELECT * FROM " . \Pimcore\Log\Handler\ApplicationLoggerDb::TABLE_NAME . " WHERE `timestamp` < DATE_SUB(FROM_UNIXTIME(" . $timestamp . "), INTERVAL " . $archive_treshold . " DAY);");
     $db->query("DELETE FROM " . \Pimcore\Log\Handler\ApplicationLoggerDb::TABLE_NAME . " WHERE `timestamp` < DATE_SUB(FROM_UNIXTIME(" . $timestamp . "), INTERVAL " . $archive_treshold . " DAY);");
 }
Beispiel #25
0
 /**
  * @param  $value
  * @return string
  */
 public function quote($value, $type = null)
 {
     $db = Db::get();
     return $db->quote($value, $type);
 }
Beispiel #26
0
 /**
  * returns sql query statement to filter according to this data types value(s)
  * @param  $value
  * @param  $operator
  * @return string
  *
  */
 public function getFilterCondition($value, $operator)
 {
     $db = \Pimcore\Db::get();
     $key = $db->quoteIdentifier($this->name);
     if ($value === "NULL") {
         if ($operator == '=') {
             $operator = "IS";
         } elseif ($operator == "!=") {
             $operator = "IS NOT";
         }
     } elseif (!is_array($value) && !is_object($value)) {
         if ($operator == "LIKE") {
             $value = $db->quote("%" . $value . "%");
         } else {
             $value = $db->quote($value);
         }
     }
     if (in_array($operator, Object\ClassDefinition\Data::$validFilterOperators)) {
         return $key . " " . $operator . " " . $value . " ";
     } else {
         return "";
     }
 }
 /**
  * deleteViews
  * delete views for localized fields when languages are removed to
  * prevent mysql errors
  * @param $language
  * @param $dbName
  */
 protected function deleteViews($language, $dbName)
 {
     $db = \Pimcore\Db::get();
     $views = $db->fetchAll("SHOW FULL TABLES IN " . $db->quoteIdentifier($dbName) . " WHERE TABLE_TYPE LIKE 'VIEW'");
     foreach ($views as $view) {
         if (preg_match("/^object_localized_[0-9]+_" . $language . "\$/", $view["Tables_in_" . $dbName])) {
             $sql = "DROP VIEW " . $db->quoteIdentifier($view["Tables_in_" . $dbName]);
             $db->query($sql);
         }
     }
 }
Beispiel #28
0
 /**
  * @param string $method
  * @param array $args
  * @return mixed
  */
 public function callResourceMethod($method, $args)
 {
     $resource = $this->getResource();
     if ($this->inTransaction || Db::isWriteQuery($method, $args)) {
         $resource = $this->getWriteResource();
     }
     $capture = false;
     if (\Pimcore::inAdmin()) {
         $methodsToCheck = array("query", "update", "delete", "insert");
         if (in_array($method, $methodsToCheck)) {
             $capture = true;
             Db::startCapturingDefinitionModifications($resource, $method, $args);
         }
     }
     $r = call_user_func_array(array($resource, $method), $args);
     if (\Pimcore::inAdmin() && $capture) {
         Db::stopCapturingDefinitionModifications($resource);
     }
     return $r;
 }
Beispiel #29
0
 /**
  * @param $name
  * @param $type
  * @return array
  */
 public function mysqlData($name, $type)
 {
     $db = Db::reset();
     $dumpData = "\n\n";
     $name = $db->quoteTableAs($name);
     if ($type != "VIEW") {
         // backup tables
         $tableData = $db->fetchAll("SELECT * FROM " . $name);
         foreach ($tableData as $row) {
             $cells = array();
             foreach ($row as $cell) {
                 if (is_string($cell)) {
                     $cell = $db->quote($cell);
                 } else {
                     if ($cell === null) {
                         $cell = "NULL";
                     }
                 }
                 $cells[] = $cell;
             }
             $dumpData .= "INSERT INTO " . $name . " VALUES (" . implode(",", $cells) . ");";
             $dumpData .= "\n";
         }
     } else {
         // dump view structure
         $dumpData .= "\n\n";
         $dumpData .= "DROP VIEW IF EXISTS " . $name . ";";
         $dumpData .= "\n";
         try {
             $viewData = $db->fetchRow("SHOW CREATE VIEW " . $name);
             $dumpData .= $viewData["Create View"] . ";";
         } catch (\Exception $e) {
             \Logger::error($e);
         }
     }
     $dumpData .= "\n\n";
     $h = fopen(PIMCORE_SYSTEM_TEMP_DIRECTORY . "/backup-dump.sql", "a+");
     fwrite($h, $dumpData);
     fclose($h);
     return array("success" => true);
 }
 public function unitListAction()
 {
     $list = new \Pimcore\Model\Object\QuantityValue\Unit\Listing();
     $list->setOrderKey("abbreviation");
     $list->setOrder("ASC");
     if ($this->getParam("filter")) {
         $array = explode(",", $this->getParam("filter"));
         $quotedArray = array();
         $db = \Pimcore\Db::get();
         foreach ($array as $a) {
             $quotedArray[] = $db->quote($a);
         }
         $string = implode(",", $quotedArray);
         $list->setCondition("id IN (" . $string . ")");
     }
     $units = $list->getUnits();
     $this->_helper->json(array("data" => $units, "success" => true, "total" => $list->getTotalCount()));
 }