Exemple #1
0
 /**
  * @return Zend_Db_Adapter_Abstract
  */
 protected function getDb()
 {
     if (!$this->db) {
         $this->db = Pimcore_Resource::get();
     }
     return $this->db;
 }
 /**
  *
  */
 public function httpErrorLogCleanup()
 {
     // keep the history for 14 days
     $limit = time() - 14 * 86400;
     $db = Pimcore_Resource::get();
     $db->delete("http_error_log", "date < " . $limit);
 }
Exemple #3
0
 public function installAction()
 {
     // try to establish a mysql connection
     try {
         $db = Zend_Db::factory($this->_getParam("mysql_adapter"), array('host' => $this->_getParam("mysql_host"), 'username' => $this->_getParam("mysql_username"), 'password' => $this->_getParam("mysql_password"), 'dbname' => $this->_getParam("mysql_database"), "port" => $this->_getParam("mysql_port")));
         $db->getConnection();
         // check utf-8 encoding
         $result = $db->fetchRow('SHOW VARIABLES LIKE "character\\_set\\_database"');
         if ($result['Value'] != "utf8") {
             $errors[] = "Database charset is not utf-8";
         }
     } catch (Exception $e) {
         $errors[] = "Couldn't establish connection to mysql: " . $e->getMessage();
     }
     // check username & password
     if (strlen($this->_getParam("admin_password")) < 4 || strlen($this->_getParam("admin_username")) < 4) {
         $errors[] = "Username and password should have at least 4 characters";
     }
     if (empty($errors)) {
         // write configuration file
         $settings = array("general" => array("timezone" => "Europe/Berlin", "language" => "en", "validLanguages" => "en", "debug" => "1", "theme" => "/pimcore/static/js/lib/ext/resources/css/xtheme-gray.css", "loginscreenimageservice" => "1", "welcomescreen" => "1", "loglevel" => array("debug" => "1", "info" => "1", "notice" => "1", "warning" => "1", "error" => "1", "critical" => "1", "alert" => "1", "emergency" => "1")), "database" => array("adapter" => $this->_getParam("mysql_adapter"), "params" => array("host" => $this->_getParam("mysql_host"), "username" => $this->_getParam("mysql_username"), "password" => $this->_getParam("mysql_password"), "dbname" => $this->_getParam("mysql_database"), "port" => $this->_getParam("mysql_port"))), "documents" => array("versions" => array("steps" => "10"), "default_controller" => "default", "default_action" => "default", "error_page" => "/", "allowtrailingslash" => "no", "allowcapitals" => "no"), "objects" => array("versions" => array("steps" => "10")), "assets" => array("versions" => array("steps" => "10")), "services" => array(), "cache" => array("excludeCookie" => "pimcore_admin_sid"), "httpclient" => array("adapter" => "Zend_Http_Client_Adapter_Socket"));
         $config = new Zend_Config($settings, true);
         $writer = new Zend_Config_Writer_Xml(array("config" => $config, "filename" => PIMCORE_CONFIGURATION_SYSTEM));
         $writer->write();
         // insert db dump
         $db = Pimcore_Resource::get();
         $mysqlInstallScript = file_get_contents(PIMCORE_PATH . "/modules/install/mysql/install.sql");
         // remove comments in SQL script
         $mysqlInstallScript = preg_replace("/\\s*(?!<\")\\/\\*[^\\*]+\\*\\/(?!\")\\s*/", "", $mysqlInstallScript);
         // get every command as single part
         $mysqlInstallScripts = explode(";", $mysqlInstallScript);
         // execute every script with a separate call, otherwise this will end in a PDO_Exception "unbufferd queries, ..." seems to be a PDO bug after some googling
         foreach ($mysqlInstallScripts as $m) {
             $sql = trim($m);
             if (strlen($sql) > 0) {
                 $sql .= ";";
                 $db->query($m);
             }
         }
         // get a new database connection
         $db = Pimcore_Resource::reset();
         // insert data into database
         $db->insert("assets", array("id" => 1, "parentId" => 0, "type" => "folder", "filename" => "", "path" => "/", "creationDate" => time(), "modificationDate" => time(), "userOwner" => 1, "userModification" => 1));
         $db->insert("documents", array("id" => 1, "parentId" => 0, "type" => "page", "key" => "", "path" => "/", "index" => 999999, "published" => 1, "creationDate" => time(), "modificationDate" => time(), "userOwner" => 1, "userModification" => 1));
         $db->insert("documents_page", array("id" => 1, "controller" => "", "action" => "", "template" => "", "title" => "", "description" => "", "keywords" => ""));
         $db->insert("objects", array("o_id" => 1, "o_parentId" => 0, "o_type" => "folder", "o_key" => "", "o_path" => "/", "o_index" => 999999, "o_published" => 1, "o_creationDate" => time(), "o_modificationDate" => time(), "o_userOwner" => 1, "o_userModification" => 1));
         $userPermissions = array(array("key" => "assets", "translation" => "permission_assets"), array("key" => "classes", "translation" => "permission_classes"), array("key" => "clear_cache", "translation" => "permission_clear_cache"), array("key" => "clear_temp_files", "translation" => "permission_clear_temp_files"), array("key" => "document_types", "translation" => "permission_document_types"), array("key" => "documents", "translation" => "permission_documents"), array("key" => "objects", "translation" => "permission_objects"), array("key" => "plugins", "translation" => "permission_plugins"), array("key" => "predefined_properties", "translation" => "permission_predefined_properties"), array("key" => "routes", "translation" => "permission_routes"), array("key" => "seemode", "translation" => "permission_seemode"), array("key" => "system_settings", "translation" => "permission_system_settings"), array("key" => "thumbnails", "translation" => "permission_thumbnails"), array("key" => "translations", "translation" => "permission_translations"), array("key" => "users", "translation" => "permission_users"), array("key" => "update", "translation" => "permissions_update"), array("key" => "redirects", "translation" => "permissions_redirects"), array("key" => "glossary", "translation" => "permissions_glossary"), array("key" => "reports", "translation" => "permissions_reports_marketing"));
         foreach ($userPermissions as $up) {
             $db->insert("users_permission_definitions", $up);
         }
         Pimcore::initConfiguration();
         $user = User::create(array("parentId" => 0, "username" => $this->_getParam("admin_username"), "password" => Pimcore_Tool_Authentication::getPasswordHash($this->_getParam("admin_username"), $this->_getParam("admin_password")), "hasCredentials" => true, "active" => true));
         $user->setAdmin(true);
         $user->save();
         $this->_helper->json(array("success" => true));
     } else {
         echo implode("<br />", $errors);
         die;
     }
 }
 public function __construct($classId, $idField = null, $storetable = null, $querytable = null, $relationtable = null)
 {
     $this->db = Pimcore_Resource::get();
     $this->fields = array();
     $this->relations = array();
     $this->fieldIds = array();
     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;
     }
 }
 /**
  * @param string $method
  * @param array $args
  * @return mixed
  */
 public function callResourceMethod($method, $args)
 {
     $capture = false;
     if (Pimcore::inAdmin()) {
         $methodsToCheck = array("query", "update", "delete", "insert");
         if (in_array($method, $methodsToCheck)) {
             $capture = true;
             Pimcore_Resource::startCapturingDefinitionModifications($method, $args);
         }
     }
     //HACK - do not execute transaction methods when
     //Zend_Registry::set('explicit_transactions', true) was set earlier in code
     $transactionMethodsToCheck = array('beginTransaction', 'rollBack', 'commit');
     try {
         $explicitTransactions = Zend_Registry::get('explicit_transactions');
     } catch (Exception $e) {
         $explicitTransactions = false;
     }
     if (!$explicitTransactions || !in_array($method, $transactionMethodsToCheck)) {
         $r = call_user_func_array(array($this->getResource(), $method), $args);
     }
     if (Pimcore::inAdmin() && $capture) {
         Pimcore_Resource::stopCapturingDefinitionModifications();
     }
     return $r;
 }
Exemple #6
0
 /**
  * @throws Exception
  * @param  $method
  * @param  $args
  * @return mixed
  */
 public function __call($method, $args)
 {
     try {
         $r = $this->callResourceMethod($method, $args);
         return $r;
     } catch (Exception $e) {
         return Pimcore_Resource::errorHandler($method, $args, $e);
     }
 }
function sendQuery($sql)
{
    try {
        $db = Pimcore_Resource::get();
        $db->query($sql);
    } catch (Exception $e) {
        echo $e->getMessage();
        echo "Please execute the following query manually: <br />";
        echo "<pre>" . $sql . "</pre><hr />";
    }
}
 public function dispatchLoopShutdown()
 {
     $code = (string) $this->getResponse()->getHttpResponseCode();
     if ($code && ($code[0] == "4" || $code[0] == "5")) {
         $db = Pimcore_Resource::get();
         try {
             $db->insert("http_error_log", array("path" => $this->getRequest()->getPathInfo(), "code" => (int) $code, "parametersGet" => serialize($_GET), "parametersPost" => serialize($_POST), "cookies" => serialize($_COOKIE), "serverVars" => serialize($_SERVER), "date" => time()));
         } catch (Exception $e) {
             Logger::error("Unable to log http error");
             Logger::error($e);
         }
     }
 }
 public function unitListAction()
 {
     $list = new \Pimcore\Model\Object\QuantityValue\Unit\Listing();
     if ($this->_getParam("filter")) {
         $array = explode(",", $this->_getParam("filter"));
         $quotedArray = array();
         $db = Pimcore_Resource::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()));
 }
Exemple #10
0
 public static function cleanup()
 {
     // remove database tmp table
     $db = Pimcore_Resource::get();
     $db->query("DROP TABLE IF EXISTS `" . self::$tmpTable . "`");
     //delete tmp data
     recursiveDelete(PIMCORE_SYSTEM_TEMP_DIRECTORY . "/update", true);
 }
Exemple #11
0
 /**
  * Update question and answers.
  * @return Poll_Question
  * @throws Exception
  */
 protected function update()
 {
     $db = Pimcore_Resource::getConnection()->getResource();
     try {
         $db->beginTransaction();
         $answers = $this->getAnswers();
         foreach ($answers as $key => $answer) {
             if (in_array($answer->getId(), $this->_answersToDelete)) {
                 $answers->offsetUnset($key);
             } else {
                 $answer->save();
             }
         }
         if (count($answers) < 2) {
             $this->setIsActive(false);
         }
         $this->getResource()->update();
         $db->commit();
     } catch (Exception $e) {
         $db->rollBack();
         throw $e;
     }
     return $this;
 }
 public function indexAction()
 {
     $checksPHP = array();
     $checksMySQL = array();
     $checksFS = array();
     // check for memory limit
     $memoryLimit = ini_get("memory_limit");
     $memoryLimit = filesize2bytes($memoryLimit . "B");
     $state = "ok";
     if ($memoryLimit < 134217728) {
         $state = "error";
     } else {
         if ($memoryLimit < 268435456) {
             $state = "warning";
         }
     }
     $checksPHP[] = array("name" => "memory_limit (in php.ini)", "link" => "http://www.php.net/memory_limit", "state" => $state);
     // check for safe_mode
     $safemode = strtolower(ini_get("safe_mode"));
     $checksPHP[] = array("name" => "safe_mode (in php.ini)", "link" => "http://www.php.net/safe_mode", "state" => $safemode == "on" ? "error" : "ok");
     // 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");
     // multibyte support
     $checksPHP[] = array("name" => "Multibyte String (mbstring)", "link" => "http://www.php.net/mbstring", "state" => function_exists("mb_get_info") ? "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");
     // APC
     $checksPHP[] = array("name" => "APC", "link" => "http://www.php.net/apc", "state" => function_exists("apc_add") ? "ok" : "warning");
     // memcache
     $checksPHP[] = array("name" => "Memcache", "link" => "http://www.php.net/memcache", "state" => class_exists("Memcache") ? "ok" : "warning");
     // PCNTL
     $checksPHP[] = array("name" => "PCNTL", "link" => "http://www.php.net/pcntl", "state" => function_exists("pcntl_exec") ? "ok" : "warning");
     // soap
     $checksPHP[] = array("name" => "Soap", "link" => "http://www.php.net/soap", "state" => class_exists("SoapClient") ? "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 {
             $db = Zend_Db::factory($this->_getParam("mysql_adapter"), array('host' => $this->_getParam("mysql_host"), 'username' => $this->_getParam("mysql_username"), 'password' => $this->_getParam("mysql_password"), 'dbname' => $this->_getParam("mysql_database"), "port" => $this->_getParam("mysql_port")));
             $db->getConnection();
         } catch (Exception $e) {
             $db = null;
         }
     } else {
         // this is after installing, eg. after a migration, ...
         $db = Pimcore_Resource::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 (\r\n                  id int(11) NOT NULL AUTO_INCREMENT,\r\n                  field varchar(255) CHARACTER SET latin1 NULL DEFAULT NULL,\r\n                  PRIMARY KEY (id)\r\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\r\n                  CHANGE COLUMN id id int(11) NOT NULL,\r\n                  CHANGE COLUMN field field varchar(255) NULL DEFAULT NULL,\r\n                  CHANGE COLUMN alter_field alter_field varchar(255) NULL DEFAULT NULL,\r\n                  ADD INDEX field (field(255)),\r\n                  DROP PRIMARY KEY ,\r\n                 DEFAULT CHARSET=utf8");
             $db->query("ALTER TABLE __pimcore_req_check\r\n                  CHANGE COLUMN id id int(11) NOT NULL AUTO_INCREMENT,\r\n                  CHANGE COLUMN field field varchar(255) NULL DEFAULT NULL,\r\n                  CHANGE COLUMN alter_field alter_field varchar(255) NULL DEFAULT NULL,\r\n                  ADD PRIMARY KEY (id) ,\r\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;
     $files = rscandir(PIMCORE_WEBSITE_PATH . "/var");
     foreach ($files as $file) {
         if (!is_writable($file)) {
             $websiteVarWritable = false;
         }
     }
     $checksFS[] = array("name" => "/website/var/ writeable", "state" => $websiteVarWritable ? "ok" : "error");
     // pimcore writeable
     $checksFS[] = array("name" => "/pimcore/ writeable", "state" => Pimcore_Update::isWriteable() ? "ok" : "warning");
     $this->view->checksPHP = $checksPHP;
     $this->view->checksMySQL = $checksMySQL;
     $this->view->checksFS = $checksFS;
 }
 public function addCollectionsAction()
 {
     $ids = \Zend_Json::decode($this->_getParam("collectionIds"));
     if ($ids) {
         $db = Pimcore_Resource::get();
         $query = "select * from classificationstore_groups g, classificationstore_collectionrelations c where colId IN (" . implode(",", $ids) . ") and g.id = c.groupId";
         $mappedData = array();
         $groupsData = $db->fetchAll($query);
         foreach ($groupsData as $groupData) {
             $mappedData[$groupData["id"]] = $groupData;
         }
         $groupIdList = array();
         $allowedGroupIds = null;
         if ($this->getParam("oid")) {
             $object = Object_Concrete::getById($this->getParam("oid"));
             $class = $object->getClass();
             $fd = $class->getFieldDefinition($this->getParam("fieldname"));
             $allowedGroupIds = $fd->getAllowedGroupIds();
         }
         foreach ($groupsData as $groupItem) {
             $groupId = $groupItem["groupId"];
             if (!$allowedGroupIds || $allowedGroupIds && in_array($groupId, $allowedGroupIds)) {
                 $groupIdList[] = $groupId;
             }
         }
         $groupCondition = "id in (" . implode(",", $groupIdList) . ")";
         $groupList = new Classificationstore\GroupConfig\Listing();
         $groupList->setCondition($groupCondition);
         //            $groupList->setOrderKey(array("sorter", "id"));
         //            $groupList->setOrder(array("ASC", "ASC"));
         $groupList = $groupList->load();
         $keyCondition = "groupId in (" . implode(",", $groupIdList) . ")";
         $keyList = new Classificationstore\KeyGroupRelation\Listing();
         $keyList->setCondition($keyCondition);
         $keyList->setOrderKey(array("sorter", "id"));
         $keyList->setOrder(array("ASC", "ASC"));
         $keyList = $keyList->load();
         foreach ($groupList as $groupData) {
             $data[$groupData->getId()] = array("name" => $groupData->getName(), "id" => $groupData->getId(), "description" => $groupData->getDescription(), "keys" => array(), "collectionId" => $mappedData[$groupId]["colId"]);
         }
         foreach ($keyList as $keyData) {
             $groupId = $keyData->getGroupId();
             $keyList = $data[$groupId]["keys"];
             $definition = $keyData->getDefinition();
             $keyList[] = array("name" => $keyData->getName(), "id" => $keyData->getKeyId(), "description" => $keyData->getDescription(), "definition" => json_decode($definition));
             $data[$groupId]["keys"] = $keyList;
         }
     }
     return $this->_helper->json($data);
 }
 public function portletModificationStatisticsAction()
 {
     $db = Pimcore_Resource::get();
     $days = 31;
     $startDate = mktime(23, 59, 59, date("m"), date("d"), date("Y"));
     $currentDate = $startDate;
     $data = array();
     for ($i = 0; $i < $days; $i++) {
         // documents
         $end = $startDate - $i * 86400;
         $start = $end - 86399;
         $o = $db->fetchRow("SELECT COUNT(*) AS count FROM objects WHERE o_modificationDate > " . $start . " AND o_modificationDate < " . $end);
         $a = $db->fetchRow("SELECT COUNT(*) AS count FROM assets WHERE modificationDate > " . $start . " AND modificationDate < " . $end);
         $d = $db->fetchRow("SELECT COUNT(*) AS count FROM documents WHERE modificationDate > " . $start . " AND modificationDate < " . $end);
         $date = new Zend_Date($start);
         $data[] = array("timestamp" => $start, "datetext" => $date->get(Zend_Date::DATE_LONG), "objects" => (int) $o["count"], "documents" => (int) $d["count"], "assets" => (int) $a["count"]);
     }
     $data = array_reverse($data);
     //p_r($data);
     //exit;
     $this->_helper->json(array("data" => $data));
 }
<?php

// get db connection
$db = Pimcore_Resource::get();
try {
    $db->query("CREATE TABLE `keyvalue_translator_configuration` (\r\n      `id` INT(10) NOT NULL AUTO_INCREMENT,\r\n      `name` VARCHAR(200) NULL DEFAULT NULL,\r\n      `translator` VARCHAR(200) NULL DEFAULT NULL,\r\n      PRIMARY KEY (`id`)\r\n    ) DEFAULT CHARSET=utf8;");
} catch (\Exception $e) {
    echo $e->getMessage();
}
Exemple #16
0
 private function dbexec($sql, $classId)
 {
     $db = Pimcore_Resource::get();
     $db->query($sql);
     $this->logSql($sql, $classId);
 }
Exemple #17
0
 /**
  * Launch a job from the job queue
  * @param Schedule_Maintenance_Job $job
  */
 protected function launchJob($job)
 {
     $pid = pcntl_fork();
     if ($pid == -1) {
         //Problem launching the job
         Logger::error('Could not launch new job with id [ ' . $job->getId() . ' ], exiting');
         return false;
     } else {
         if ($pid) {
             $this->currentJobs[$pid] = $job->getId();
             if (isset($this->signalQueue[$pid])) {
                 $this->childSignalHandler(SIGCHLD, $pid, $this->signalQueue[$pid]);
                 unset($this->signalQueue[$pid]);
             }
         } else {
             //Forked child
             try {
                 Logger::debug("Executing job [ " . $job->getId() . " ] as forked child");
                 Pimcore_Resource::reset();
                 $job->execute();
             } catch (Exception $e) {
                 Logger::error($e);
                 Logger::error("Failed to execute job with id [ " . $job->getId() . " ] and method [ " . $job->getMethod() . " ]");
             }
             $job->unlock();
             Logger::debug("Done with job [ " . $job->getId() . " ]");
             exit(0);
         }
     }
     return true;
 }
Exemple #18
0
 /**
  * @return string $statusMessage
  */
 public static function uninstall()
 {
     $db = Pimcore_Resource::get();
     $db->query("DROP TABLE IF EXISTS `" . PimTools_ImportReport_Resource::TABLE_NAME . "`;");
 }
 /**
  * @throws Exception
  * @param string $key
  * @return void
  */
 public function initResource($key = null)
 {
     $myClass = get_class($this);
     $resource = null;
     if (!$key) {
         // check for a resource in the cache
         if (array_key_exists($myClass, self::$resourceClassCache)) {
             $resource = self::$resourceClassCache[$myClass];
         } else {
             $classes = $this->getParentClasses($myClass);
             foreach ($classes as $class) {
                 $classParts = explode("_", $class);
                 $length = count($classParts);
                 $className = null;
                 for ($i = 0; $i < $length; $i++) {
                     // check for a specialized resource adapter for the current DBMS
                     $tmpClassName = implode("_", $classParts) . "_Resource_" . ucfirst(Pimcore_Resource::getType());
                     if ($className = $this->determineResourceClass($tmpClassName)) {
                         break;
                     }
                     // check for a general DBMS resource adapter
                     $tmpClassName = implode("_", $classParts) . "_Resource";
                     if ($className = $this->determineResourceClass($tmpClassName)) {
                         break;
                     }
                     array_pop($classParts);
                 }
                 if ($className) {
                     Logger::debug("Found resource implementation " . $className . " for " . $myClass);
                     $resource = $className;
                     self::$resourceClassCache[$myClass] = $resource;
                     break;
                 }
             }
         }
     } else {
         // check in cache
         $cacheKey = $myClass . "-" . $key;
         if (array_key_exists($cacheKey, self::$resourceClassCache)) {
             $resource = self::$resourceClassCache[$cacheKey];
         } else {
             // check for a specialized resource adapter for the current DBMS
             $resourceClass = $key . "_Resource_" . ucfirst(Pimcore_Resource::getType());
             if (!($resource = $this->determineResourceClass($resourceClass))) {
                 $resource = $key . "_Resource";
             }
             self::$resourceClassCache[$cacheKey] = $resource;
         }
     }
     if (!$resource) {
         Logger::critical("No resource implementation found for: " . $myClass);
         throw new Exception("No resource implementation found for: " . $myClass);
     }
     $this->resource = new $resource();
     $this->resource->setModel($this);
     $db = Pimcore_Resource::get();
     $this->resource->configure($db);
     if (method_exists($this->resource, "init")) {
         $this->resource->init();
     }
 }
Exemple #20
0
 public function mysqlData($name, $type)
 {
     $db = Pimcore_Resource::reset();
     $dumpData = "\n\n";
     if ($type != "VIEW") {
         // backup tables
         $tableData = $db->fetchAll("SELECT * FROM " . $name);
         foreach ($tableData as $row) {
             $cells = array();
             foreach ($row as $cell) {
                 $cells[] = $db->quote($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";
         $viewData = $db->fetchRow("SHOW CREATE VIEW " . $name);
         $dumpData .= $viewData["Create View"] . ";";
     }
     $dumpData .= "\n\n";
     $h = fopen(PIMCORE_SYSTEM_TEMP_DIRECTORY . "/backup-dump.sql", "a+");
     fwrite($h, $dumpData);
     fclose($h);
     return array("success" => true);
 }
Exemple #21
0
 /**
  *
  * @param string $queryStr
  * @param string $field
  * @param string $webResourceType
  * @param string $subtype
  * @param integer[] $modifiedRange
  * @param integer[] $createdRange
  * @return array Zend_Search_Lucene_Search_QueryHit
  */
 public function findInDb($queryStr, $type = null, $subtype = null, $classname = null, $modifiedRange = null, $createdRange = null, $userOwner = null, $userModification = null, $offset = 0, $limit = 25)
 {
     $this->createBackendSearchQuery($queryStr, $type, $subtype, $classname, $modifiedRange, $createdRange, $userOwner, $userModification, false);
     $db = Pimcore_Resource::get();
     return $db->fetchAll($this->backendQuery, $this->backendQueryParams);
 }
 /**
  * @param Object_Concrete|Object_Fieldcollection_Data_Abstract|Object_Localizedfield $object
  * @return null | array
  */
 public function load($object, $params = array())
 {
     $db = Pimcore_Resource::get();
     $data = null;
     if ($object instanceof Object_Concrete) {
         if (!method_exists($this, "getLazyLoading") or !$this->getLazyLoading() or $params["force"]) {
             $relations = $db->fetchAll("SELECT * FROM object_relations_" . $object->getClassId() . " WHERE src_id = ? AND fieldname = ? AND ownertype = 'object'", array($object->getO_id(), $this->getName()));
         } else {
             return null;
         }
     } else {
         if ($object instanceof Object_Fieldcollection_Data_Abstract) {
             $relations = $db->fetchAll("SELECT * FROM object_relations_" . $object->getObject()->getClassId() . " WHERE src_id = ? AND fieldname = ? AND ownertype = 'fieldcollection' AND ownername = ? AND position = ?", array($object->getObject()->getId(), $this->getName(), $object->getFieldname(), $object->getIndex()));
         } else {
             if ($object instanceof Object_Localizedfield) {
                 $relations = $db->fetchAll("SELECT * FROM object_relations_" . $object->getObject()->getClassId() . " WHERE src_id = ? AND fieldname = ? AND ownertype = 'localizedfield' AND ownername = 'localizedfield' AND position = ?", array($object->getObject()->getId(), $this->getName(), $params["language"]));
             } else {
                 if ($object instanceof Object_Objectbrick_Data_Abstract) {
                     $relations = $db->fetchAll("SELECT * FROM object_relations_" . $object->getObject()->getClassId() . " WHERE src_id = ? AND fieldname = ? AND ownertype = 'objectbrick' AND ownername = ? AND position = ?", array($object->getObject()->getId(), $this->getName(), $object->getFieldname(), $object->getType()));
                     // THIS IS KIND A HACK: it's necessary because of this bug PIMCORE-1454 and therefore cannot be removed
                     if (count($relations) < 1) {
                         $relations = $db->fetchAll("SELECT * FROM object_relations_" . $object->getObject()->getClassId() . " WHERE src_id = ? AND fieldname = ? AND ownertype = 'objectbrick' AND ownername = ? AND (position IS NULL OR position = '')", array($object->getObject()->getId(), $this->getName(), $object->getFieldname()));
                     }
                     // HACK END
                 }
             }
         }
     }
     // using PHP sorting to order the relations, because "ORDER BY index ASC" in the queries above will cause a
     // filesort in MySQL which is extremly slow especially when there are millions of relations in the database
     usort($relations, function ($a, $b) {
         if ($a["index"] == $b["index"]) {
             return 0;
         }
         return $a["index"] < $b["index"] ? -1 : 1;
     });
     $data = $this->getDataFromResource($relations);
     return $data;
 }
Exemple #23
0
 /**
  * find all elements which the user may not list and therefore may never be shown to the user
  * @param  string $type asset|object|document
  * @return array
  */
 public static function findForbiddenPaths($type, $user)
 {
     $parentIds = array();
     $parent = $user->getParent();
     while ($parent instanceof User) {
         $parentIds[] = "userId = " . $parent->getId();
         $parent = $parent->getParent();
     }
     $userCondition = "( userId= " . $user->getId();
     if (count($parentIds) > 0) {
         $userCondition .= " OR " . implode(" or ", $parentIds) . ")";
     } else {
         $userCondition .= ")";
     }
     $condition = "SELECT cpath FROM (SELECT cid,cpath,\r\n                sum(`list`) as `list`\r\n                FROM " . $type . "s_permissions\r\n                WHERE " . $userCondition . "\r\n                GROUP by cid\r\n                ORDER BY cpath DESC ) temp WHERE list = 0";
     //Logger::log($condition);
     $db = Pimcore_Resource::get();
     $data = $db->fetchAll($condition);
     $forbidden = array();
     if (is_array($data)) {
         foreach ($data as $row) {
             $forbidden[] = $row["cpath"];
         }
     }
     return $forbidden;
 }
 /**
  * @param  $value
  * @return void
  */
 public function quote($value, $type = null)
 {
     $db = Pimcore_Resource::get();
     return $db->quote($value, $type);
 }
Exemple #25
0
 /**
  * @param Object_Concrete|Object_Fieldcollection_Data_Abstract|Object_Localizedfield $object
  * @return null | array
  */
 public function load($object, $params = array())
 {
     $db = Pimcore_Resource::get();
     if ($object instanceof Object_Concrete) {
         if (!method_exists($this, "getLazyLoading") or !$this->getLazyLoading() or $params["force"]) {
             $relations = $db->fetchAll("SELECT * FROM object_relations_" . $object->getClassId() . " WHERE src_id = ? AND fieldname = ? AND ownertype = 'object' ORDER BY `index` ASC", array($object->getO_id(), $this->getName()));
             return $this->getDataFromResource($relations);
         } else {
             return null;
         }
     } else {
         if ($object instanceof Object_Fieldcollection_Data_Abstract) {
             $relations = $db->fetchAll("SELECT * FROM object_relations_" . $object->getObject()->getClassId() . " WHERE src_id = ? AND fieldname = ? AND ownertype = 'fieldcollection' AND ownername = ? AND position = ? ORDER BY `index` ASC", array($object->getObject()->getId(), $this->getName(), $object->getFieldname(), $object->getIndex()));
             return $this->getDataFromResource($relations);
         } else {
             if ($object instanceof Object_Localizedfield) {
                 $relations = $db->fetchAll("SELECT * FROM object_relations_" . $object->getObject()->getClassId() . " WHERE src_id = ? AND fieldname = ? AND ownertype = 'localizedfield' AND ownername = 'localizedfield' AND position = ? ORDER BY `index` ASC", array($object->getObject()->getId(), $this->getName(), $params["language"]));
                 return $this->getDataFromResource($relations);
             } else {
                 if ($object instanceof Object_Objectbrick_Data_Abstract) {
                     $relations = $db->fetchAll("SELECT * FROM object_relations_" . $object->getObject()->getClassId() . " WHERE src_id = ? AND fieldname = ? AND ownertype = 'objectbrick' AND ownername = ? ORDER BY `index` ASC", array($object->getObject()->getId(), $this->getName(), $object->getFieldname()));
                     return $this->getDataFromResource($relations);
                 }
             }
         }
     }
 }
Exemple #26
0
 /**
  * foreces a garbage collection
  * @static
  * @return void
  */
 public static function collectGarbage($keepItems = array())
 {
     // close mysql-connection
     Pimcore_Resource::close();
     $protectedItems = array("pimcore_config_system", "Zend_Locale", "pimcore_tag_block_current", "pimcore_tag_block_numeration", "pimcore_user", "Zend_Translate", "pimcore_admin_user", "pimcore_admin_initialized", "Pimcore_API_Plugin_Broker", "pimcore_config_website", "pimcore_editmode", "pimcore_error_document", "pimcore_site");
     if (is_array($keepItems) && count($keepItems) > 0) {
         $protectedItems = array_merge($protectedItems, $keepItems);
     }
     $registryBackup = array();
     foreach ($protectedItems as $item) {
         if (Zend_Registry::isRegistered($item)) {
             $registryBackup[$item] = Zend_Registry::get($item);
         }
     }
     Zend_Registry::_unsetInstance();
     foreach ($registryBackup as $key => $value) {
         Zend_Registry::set($key, $value);
     }
     Pimcore_Resource::reset();
 }
 protected static function getDb()
 {
     $db = Pimcore_Resource::getConnection();
     return $db;
 }
Exemple #28
0
 /**
  *
  * @param string $filterJson
  * @param Object_Class $class
  * @return string
  */
 public static function getFilterCondition($filterJson, $class)
 {
     $systemFields = array("o_path", "o_key", "o_id", "o_published", "o_creationDate", "o_modificationDate");
     // create filter condition
     $conditionPartsFilters = array();
     if ($filterJson) {
         $filters = Zend_Json::decode($filterJson);
         foreach ($filters as $filter) {
             $operator = "=";
             if ($filter["type"] == "string") {
                 $operator = "LIKE";
             } else {
                 if ($filter["type"] == "numeric") {
                     if ($filter["comparison"] == "lt") {
                         $operator = "<";
                     } else {
                         if ($filter["comparison"] == "gt") {
                             $operator = ">";
                         } else {
                             if ($filter["comparison"] == "eq") {
                                 $operator = "=";
                             }
                         }
                     }
                 } else {
                     if ($filter["type"] == "date") {
                         if ($filter["comparison"] == "lt") {
                             $operator = "<";
                         } else {
                             if ($filter["comparison"] == "gt") {
                                 $operator = ">";
                             } else {
                                 if ($filter["comparison"] == "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($filter["field"]);
             $brickField = null;
             $brickType = null;
             if (!$field) {
                 // if the definition doesn't exist check for a localized field
                 $localized = $class->getFieldDefinition("localizedfields");
                 if ($localized instanceof Object_Class_Data_Localizedfields) {
                     $field = $localized->getFieldDefinition($filter["field"]);
                 }
                 //if the definition doesn't exist check for object brick
                 $keyParts = explode("~", $filter["field"]);
                 if (count($keyParts) > 1) {
                     $brickType = $keyParts[0];
                     $brickKey = $keyParts[1];
                     $key = self::getFieldForBrickType($class, $brickType);
                     $field = $class->getFieldDefinition($key);
                     $brickClass = Object_Objectbrick_Definition::getByKey($brickType);
                     $brickField = $brickClass->getFieldDefinition($brickKey);
                 }
             }
             if ($field instanceof Object_Class_Data_Objectbricks) {
                 // custom field
                 $db = Pimcore_Resource::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 Object_Class_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_" . $filter["field"], $systemFields)) {
                         // system field
                         $conditionPartsFilters[] = "`o_" . $filter["field"] . "` " . $operator . " '" . $filter["value"] . "' ";
                     }
                 }
             }
         }
     }
     $conditionFilters = "";
     if (count($conditionPartsFilters) > 0) {
         $conditionFilters = " AND (" . implode(" AND ", $conditionPartsFilters) . ")";
     }
     Logger::log("ObjectController filter condition:" . $conditionFilters);
     return $conditionFilters;
 }
 /**
  * @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"));
     $offset = intval($this->_getParam("start"));
     $limit = intval($this->_getParam("limit"));
     $offset = $offset ? $offset : 0;
     $limit = $limit ? $limit : 50;
     $searcherList = new Search_Backend_Data_List();
     $conditionParts = array();
     $db = Pimcore_Resource::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 (count($parts) > 1) {
                 $bricks[$parts[0]] = $parts[0];
             }
         }
     }
     // filtering for objects
     if ($this->_getParam("filter")) {
         $class = Object_Class::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 1=1 " . $conditionFilters . ") )";
     }
     if (is_array($types) and !empty($types[0])) {
         foreach ($types as $type) {
             $conditionTypeParts[] = $db->quote($type);
         }
         $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")) {
         $searcherList->setOrderKey($this->_getParam("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_Abstract) {
                 $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();
 }
 /**
  * @param Object_Concrete $object
  * @return void
  */
 public function delete($object)
 {
     $db = Pimcore_Resource::get();
     $db->delete("object_metadata_" . $object->getO_classId(), $db->quoteInto("o_id = ?", $object->getId()) . " AND " . $db->quoteInto("fieldname = ?", $this->getName()));
 }