Exemplo n.º 1
0
 function testSortOnDelete()
 {
     $objRootAspect = new class_module_system_aspect();
     $objRootAspect->setStrName("testroot");
     $objRootAspect->updateObjectToDb();
     /** @var class_module_system_aspect[] $arrAspects */
     $arrAspects = array();
     for ($intI = 0; $intI < 100; $intI++) {
         $objAspect = new class_module_system_aspect();
         $objAspect->setStrName("autotest_" . $intI);
         $objAspect->updateObjectToDb($objRootAspect->getSystemid());
         $arrAspects[] = $objAspect;
     }
     //delete the 5th element - massive queries required
     $intQueriesPre = class_db::getInstance()->getNumber();
     echo " Setting new position\n";
     $arrAspects[5]->deleteObjectFromDatabase();
     $intQueriesPost = class_db::getInstance()->getNumber();
     echo "Queries: " . ($intQueriesPost - $intQueriesPre) . " \n";
     $objOrm = new class_orm_objectlist();
     $arrChilds = $objOrm->getObjectList("class_module_system_aspect", $objRootAspect->getSystemid());
     $this->assertEquals(count($arrChilds), 99);
     for ($intI = 1; $intI <= 99; $intI++) {
         $this->assertEquals($arrChilds[$intI - 1]->getIntSort(), $intI);
     }
     $objRootAspect->deleteObjectFromDatabase();
 }
Exemplo n.º 2
0
 /**
  * Singleton, use getInstance() instead
  */
 private function __construct()
 {
     //Loading the needed Objects
     $this->objDB = class_db::getInstance();
     //Generating a session-key using a few characteristic values
     $this->strKey = md5(_realpath_ . getServer("REMOTE_ADDR"));
     $this->sessionStart();
     $this->arrRequestArray = array();
 }
Exemplo n.º 3
0
 /**
  * @param class_root|interface_versionable|null $objObject
  */
 function __construct($objObject = null)
 {
     $this->objObject = $objObject;
     if (self::$bitLogcialDeleteAvailable === null) {
         $arrColumns = class_db::getInstance()->getColumnsOfTable(_dbprefix_ . "system");
         self::$bitLogcialDeleteAvailable = count(array_filter($arrColumns, function ($arrOneTable) {
             return $arrOneTable["columnName"] == "system_deleted";
         })) > 0;
     }
 }
 public function testObjectIndexerPerformance()
 {
     if (class_module_system_module::getModuleByName("news") === null) {
         return;
     }
     $arrNewsIds = array();
     echo "Indexing without deferred indexer...\n";
     class_module_system_changelog::$bitChangelogEnabled = false;
     $intTimeStart = microtime(true);
     $intQueriesStart = class_db::getInstance()->getNumber();
     for ($intI = 0; $intI < 15; $intI++) {
         $objNews = new class_module_news_news();
         $objNews->setStrTitle("demo 1");
         $objNews->setStrIntro("intro demo news");
         $objNews->setStrText("text demo news");
         $objNews->updateObjectToDb();
         $arrNewsIds[] = $objNews->getSystemid();
     }
     echo "Queries pre indexing: ", class_db::getInstance()->getNumber() - $intQueriesStart . " \n";
     $objHandler = new class_module_search_request_endprocessinglistener();
     $objHandler->handleEvent(class_system_eventidentifier::EVENT_SYSTEM_REQUEST_AFTERCONTENTSEND, array());
     $intTimeEnd = microtime(true);
     $time = $intTimeEnd - $intTimeStart;
     echo "Object updates: ", sprintf('%f', $time), " sec.\n";
     echo "Queries total: ", class_db::getInstance()->getNumber() - $intQueriesStart . " \n";
     echo "\nIndexing with deferred indexer...\n";
     $objConfig = class_module_system_setting::getConfigByName("_search_deferred_indexer_");
     $objConfig->setStrValue("true");
     $objConfig->updateObjectToDb();
     $intTimeStart = microtime(true);
     $intQueriesStart = class_db::getInstance()->getNumber();
     for ($intI = 0; $intI < 15; $intI++) {
         $objNews = new class_module_news_news();
         $objNews->setStrTitle("demo 1");
         $objNews->setStrIntro("intro demo news");
         $objNews->setStrText("text demo news");
         $objNews->updateObjectToDb();
         $arrNewsIds[] = $objNews->getSystemid();
     }
     echo "Queries pre indexing: ", class_db::getInstance()->getNumber() - $intQueriesStart . " \n";
     echo "Triggering queue update event...\n";
     $objHandler = new class_module_search_request_endprocessinglistener();
     $objHandler->handleEvent(class_system_eventidentifier::EVENT_SYSTEM_REQUEST_AFTERCONTENTSEND, array());
     $intTimeEnd = microtime(true);
     $time = $intTimeEnd - $intTimeStart;
     echo "Object updates: ", sprintf('%f', $time), " sec.\n";
     echo "Queries total: ", class_db::getInstance()->getNumber() - $intQueriesStart . " \n";
     $objConfig = class_module_system_setting::getConfigByName("_search_deferred_indexer_");
     $objConfig->setStrValue("false");
     $objConfig->updateObjectToDb();
     foreach ($arrNewsIds as $strNewsId) {
         class_objectfactory::getInstance()->getObject($strNewsId)->deleteObjectFromDatabase();
     }
 }
 public function testImportExport()
 {
     class_carrier::getInstance()->getObjRights()->setBitTestMode(true);
     $strName = generateSystemid();
     $strBrowsername = generateSystemid();
     $strSeoString = generateSystemid();
     $strDesc = generateSystemid();
     $objPage = new class_module_pages_page();
     $objPage->setStrName($strName);
     $objPage->setStrBrowsername($strBrowsername);
     $objPage->setStrSeostring($strSeoString);
     $objPage->setStrDesc($strDesc);
     $objPage->setStrTemplate("standard.tpl");
     $objPage->updateObjectToDb();
     $strPagesystemid = $objPage->getSystemid();
     $objPagelement = new class_module_pages_pageelement();
     $objPagelement->setStrPlaceholder("text_paragraph");
     $objPagelement->setStrName("text");
     $objPagelement->setStrElement("paragraph");
     $objPagelement->updateObjectToDb($objPage->getSystemid());
     $objElement = new class_element_paragraph_admin($objPagelement->getSystemid());
     $objElement->setSystemid($objPagelement->getSystemid());
     $objElement->loadElementData();
     $objElement->setStrTitle("para_title");
     $objElement->updateForeignElement();
     $objPagelement = new class_module_pages_pageelement($objPagelement->getSystemid());
     class_carrier::getInstance()->setParam("pageExport", $strName);
     $objPageExport = new class_systemtask_pageexport();
     $objPageExport->executeTask();
     $objPage->deleteObjectFromDatabase();
     class_orm_rowcache::flushCache();
     class_db::getInstance()->flushQueryCache();
     $this->assertNull(class_module_pages_page::getPageByName($strName));
     $this->assertFileExists(_realpath_ . _projectpath_ . "/temp/" . $strPagesystemid . ".xml");
     class_carrier::getInstance()->setParam("pageimport_file", _projectpath_ . "/temp/" . $strPagesystemid . ".xml");
     $objImport = new class_systemtask_pageimport();
     $objImport->executeTask();
     $objPage = class_module_pages_page::getPageByName($strName);
     $this->assertNotNull($objPage);
     $this->assertEquals($objPage->getStrName(), $strName);
     $this->assertEquals($objPage->getStrDesc(), $strDesc);
     $this->assertEquals($objPage->getStrSeostring(), $strSeoString);
     $this->assertEquals($objPage->getStrBrowsername(), $strBrowsername);
     $objElements = class_module_pages_pageelement::getAllElementsOnPage($objPage->getSystemid());
     $this->assertEquals(1, count($objElements));
     $objElements = $objElements[0];
     $this->assertEquals($objElements->getStrClassAdmin(), "class_element_paragraph_admin.php");
     $objElement = $objElements->getConcreteAdminInstance();
     $objElement->setSystemid($objElements->getSystemid());
     $objElement->loadElementData();
     $this->assertEquals("para_title", $objElement->getStrTitle());
     $objPage->deleteObjectFromDatabase();
 }
Exemplo n.º 6
0
 /**
  * Cleans up the database structure. This method should delete all database entries which were previously created
  *
  * @return void
  */
 protected function cleanStructure()
 {
     /** @var class_model $objOneModel */
     foreach (array_reverse($this->arrStructure, true) as $objOneModel) {
         $strSystemId = $objOneModel->getStrSystemid();
         $objOneModel->deleteObjectFromDatabase();
         //if it is a user also delete the user from the database completeley
         if ($objOneModel instanceof class_module_user_user) {
             $strQuery = "DELETE FROM " . _dbprefix_ . "user WHERE user_id=?";
             //call other models that may be interested
             $bitDelete = class_db::getInstance()->_pQuery($strQuery, array($strSystemId));
         }
     }
 }
Exemplo n.º 7
0
 protected function setUp()
 {
     $this->arrTestStartDate = gettimeofday();
     if (!defined("_block_config_db_loading_")) {
         define("_block_config_db_loading_", true);
     }
     if (!defined("_autotesting_")) {
         define("_autotesting_", true);
     }
     if (!defined("_autotesting_sqlite_checks_")) {
         if (class_config::getInstance("config.php")->getConfig("dbdriver") == "sqlite3") {
             class_db::getInstance()->_pQuery("PRAGMA journal_mode = MEMORY", array());
         }
         define("_autotesting_sqlite_checks_", true);
     }
     class_carrier::getInstance()->flushCache(class_carrier::INT_CACHE_TYPE_APC | class_carrier::INT_CACHE_TYPE_DBQUERIES);
     parent::setUp();
 }
 /**
  * Fetches all Configs from the database
  *
  * @return class_module_system_setting[]
  * @static
  */
 public static function getAllConfigValues()
 {
     if (self::$arrInstanceCache == null) {
         if (count(class_db::getInstance()->getTables()) == 0) {
             return array();
         }
         $strQuery = "SELECT * FROM " . _dbprefix_ . "system_config ORDER BY system_config_module ASC, system_config_name DESC";
         $arrIds = class_carrier::getInstance()->getObjDB()->getPArray($strQuery, array(), null, null, false);
         foreach ($arrIds as $arrOneId) {
             $arrOneId["system_id"] = $arrOneId["system_config_id"];
             class_orm_rowcache::addSingleInitRow($arrOneId);
             self::$arrInstanceCache[$arrOneId["system_config_id"]] = new class_module_system_setting($arrOneId["system_config_id"]);
         }
     }
     if (self::$arrInstanceCache == null) {
         return array();
     }
     return self::$arrInstanceCache;
 }
Exemplo n.º 9
0
 public function testTreeDelete()
 {
     $objAspect = new class_module_system_aspect();
     $objAspect->updateObjectToDb("0");
     $strRootNodeId = $objAspect->getSystemid();
     $objAspect = new class_module_system_aspect();
     $objAspect->updateObjectToDb($strRootNodeId);
     $strSub1Node1Id = $objAspect->getSystemid();
     $objAspect = new class_module_system_aspect();
     $objAspect->updateObjectToDb($strRootNodeId);
     $strSub1Node2Id = $objAspect->getSystemid();
     $objAspect = new class_module_system_aspect();
     $objAspect->updateObjectToDb($strRootNodeId);
     $strSub1Node2Id = $objAspect->getSystemid();
     $objAspect = new class_module_system_aspect();
     $objAspect->updateObjectToDb($strSub1Node1Id);
     $strSub2Node1aId = $objAspect->getSystemid();
     $objAspect = new class_module_system_aspect();
     $objAspect->updateObjectToDb($strSub1Node1Id);
     $strSub2Node1bId = $objAspect->getSystemid();
     $objAspect = new class_module_system_aspect();
     $objAspect->updateObjectToDb($strSub1Node1Id);
     $strSub2Node1cId = $objAspect->getSystemid();
     $this->assertEquals(3, count($objAspect->getChildNodesAsIdArray($strRootNodeId)));
     $this->assertEquals(3, count($objAspect->getChildNodesAsIdArray($strSub1Node1Id)));
     $objAspect = new class_module_system_aspect($strRootNodeId);
     $objAspect->deleteObjectFromDatabase();
     class_db::getInstance()->flushQueryCache();
     $this->assertEquals(0, count($objAspect->getChildNodesAsIdArray($strRootNodeId)));
     $this->assertEquals(0, count($objAspect->getChildNodesAsIdArray($strSub1Node1Id)));
 }
Exemplo n.º 10
0
 public function testObjectIndexerPerformance()
 {
     if (class_module_system_module::getModuleByName("news") === null) {
         return;
     }
     $objNews = new class_module_news_news();
     $objNews->setStrTitle("demo 1");
     $objNews->setStrIntro("intro demo news");
     $objNews->setStrText("text demo news");
     $objNews->updateObjectToDb();
     $strNewsId = $objNews->getSystemid();
     echo "Status changes with disabled changelog indexer integration...\n";
     class_module_system_changelog::$bitChangelogEnabled = false;
     $intTimeStart = microtime(true);
     $intQueriesStart = class_db::getInstance()->getNumber();
     for ($intI = 0; $intI < 150; $intI++) {
         $objNews->setIntRecordStatus($intI % 2);
         $objNews->updateObjectToDb();
     }
     $intTimeEnd = microtime(true);
     $time = $intTimeEnd - $intTimeStart;
     echo "Object updates: ", sprintf('%f', $time), " sec.\n";
     echo "Queries: ", class_db::getInstance()->getNumber() - $intQueriesStart . " \n";
     echo "Status changes with enabled changelog indexer integration...\n";
     class_module_system_changelog::$bitChangelogEnabled = true;
     $intTimeStart = microtime(true);
     $intQueriesStart = class_db::getInstance()->getNumber();
     for ($intI = 0; $intI < 150; $intI++) {
         $objNews->setIntRecordStatus($intI % 2);
         $objNews->updateObjectToDb();
     }
     $intTimeEnd = microtime(true);
     $time = $intTimeEnd - $intTimeStart;
     echo "Object updates: ", sprintf('%f', $time), " sec.\n";
     echo "Queries: ", class_db::getInstance()->getNumber() - $intQueriesStart . " \n";
     class_objectfactory::getInstance()->getObject($strNewsId)->deleteObjectFromDatabase();
 }
Exemplo n.º 11
0
 /**
  * Used to handle the current exception.
  * Decides, if the execution should be stopped, or continued.
  * Therefore the errorlevel defines the "weight" of the exception
  *
  * @return void
  */
 public function processException()
 {
     //set which POST parameters should read out
     $arrPostParams = array("module", "action", "page", "systemid");
     $objHistory = new class_history();
     //send an email to the admin?
     $strAdminMail = "";
     try {
         if (class_db::getInstance()->getBitConnected()) {
             $strAdminMail = class_module_system_setting::getConfigValue("_system_admin_email_");
         }
     } catch (Exception $objEx) {
     }
     if ($strAdminMail != "") {
         $strMailtext = "";
         $strMailtext .= "The system installed at " . _webpath_ . " registered an error!\n\n";
         $strMailtext .= "The error message was:\n";
         $strMailtext .= "\t" . $this->getMessage() . "\n\n";
         $strMailtext .= "The level of this error was:\n";
         $strMailtext .= "\t";
         if ($this->getErrorlevel() == self::$level_FATALERROR) {
             $strMailtext .= "FATAL ERROR";
         }
         if ($this->getErrorlevel() == self::$level_ERROR) {
             $strMailtext .= "REGULAR ERROR";
         }
         $strMailtext .= "\n\n";
         $strMailtext .= "File and line number the error was thrown:\n";
         $strMailtext .= "\t" . basename($this->getFile()) . " in line " . $this->getLine() . "\n\n";
         $strMailtext .= "Callstack / Backtrace:\n\n";
         $strMailtext .= $this->getTraceAsString();
         $strMailtext .= "\n\n";
         $strMailtext .= "User: "******" (" . class_carrier::getInstance()->getObjSession()->getUsername() . ")\n";
         $strMailtext .= "Source host: " . getServer("REMOTE_ADDR") . " (" . @gethostbyaddr(getServer("REMOTE_ADDR")) . ")\n";
         $strMailtext .= "Query string: " . getServer("REQUEST_URI") . "\n";
         $strMailtext .= "POST data (selective):\n";
         foreach ($arrPostParams as $strParam) {
             if (getPost($strParam) != "") {
                 $strMailtext .= "\t" . $strParam . ": " . getPost($strParam) . "\n";
             }
         }
         $strMailtext .= "\n\n";
         $strMailtext .= "Last actions called:\n";
         $strMailtext .= "Admin:\n";
         $arrHistory = $objHistory->getArrAdminHistory();
         if (is_array($arrHistory)) {
             foreach ($arrHistory as $intIndex => $strOneUrl) {
                 $strMailtext .= " #" . $intIndex . ": " . $strOneUrl . "\n";
             }
         }
         $strMailtext .= "Portal:\n";
         $arrHistory = $objHistory->getArrPortalHistory();
         if (is_array($arrHistory)) {
             foreach ($arrHistory as $intIndex => $strOneUrl) {
                 $strMailtext .= " #" . $intIndex . ": " . $strOneUrl . "\n";
             }
         }
         $strMailtext .= "\n\n";
         $strMailtext .= "If you don't know what to do, feel free to open a ticket.\n\n";
         $strMailtext .= "For more help visit http://www.kajona.de.\n\n";
         $objMail = new class_mail();
         $objMail->setSubject("Error on website " . _webpath_ . " occured!");
         $objMail->setSender($strAdminMail);
         $objMail->setText($strMailtext);
         $objMail->addTo($strAdminMail);
         $objMail->sendMail();
         $objMessageHandler = new class_module_messaging_messagehandler();
         $objMessage = new class_module_messaging_message();
         $objMessage->setStrBody($strMailtext);
         $objMessage->setObjMessageProvider(new class_messageprovider_exceptions());
         $objMessageHandler->sendMessageObject($objMessage, new class_module_user_group(class_module_system_setting::getConfigValue("_admins_group_id_")));
     }
     if ($this->intErrorlevel == class_exception::$level_FATALERROR) {
         //Handle fatal errors.
         $strLogMessage = basename($this->getFile()) . ":" . $this->getLine() . " -- " . $this->getMessage();
         class_logger::getInstance()->addLogRow($strLogMessage, class_logger::$levelError);
         //fatal errors are displayed in every case
         if (_xmlLoader_ === true) {
             $strErrormessage = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
             $strErrormessage .= "<error>" . xmlSafeString($this->getMessage()) . "</error>";
         } else {
             $strErrormessage = "<html><head></head><body><div style=\"border: 1px solid red; padding: 5px; margin: 20px; font-family: arial,verdana,sans-serif; font-size: 12px;  \">\n";
             $strErrormessage .= "<div style=\"background-color: #cccccc; color: #000000; font-weight: bold; \">A fatal error occurred:</div>\n";
             $strErrormessage .= "<pre>" . htmlspecialchars($this->getMessage(), ENT_QUOTES, "UTF-8", false) . "</pre><br />";
             $strErrormessage .= "Please inform the administration about the error above.";
             $strErrormessage .= "</div></body></html>";
         }
         print $strErrormessage;
         //Execution has to be stopped here!
         if (class_response_object::getInstance()->getStrStatusCode() == "" || class_response_object::getInstance()->getStrStatusCode() == class_http_statuscodes::SC_OK) {
             class_response_object::getInstance()->setStrStatusCode(class_http_statuscodes::SC_INTERNAL_SERVER_ERROR);
         }
         class_response_object::getInstance()->sendHeaders();
         die;
     } elseif ($this->intErrorlevel == class_exception::$level_ERROR) {
         //handle regular errors
         $strLogMessage = basename($this->getFile()) . ":" . $this->getLine() . " -- " . $this->getMessage();
         class_logger::getInstance()->addLogRow($strLogMessage, class_logger::$levelWarning);
         //check, if regular errors should be displayed:
         if ($this->intDebuglevel >= 1) {
             if (_xmlLoader_ === true) {
                 $strErrormessage = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
                 $strErrormessage .= "<error>" . xmlSafeString($this->getMessage()) . "</error>";
             } else {
                 $strErrormessage = "<html><head></head><body><div style=\"border: 1px solid red; padding: 5px; margin: 20px; font-family: arial,verdana,sans-serif; font-size: 12px; \">\n";
                 $strErrormessage .= "<div style=\"background-color: #cccccc; color: #000000; font-weight: bold; \">An error occurred:</div>\n";
                 $strErrormessage .= "<pre>" . htmlspecialchars($this->getMessage(), ENT_QUOTES, "UTF-8", false) . "</pre><br />";
                 //$strErrormessage .= basename($this->getFile()) ." in Line ".$this->getLine();
                 $strErrormessage .= "Please inform the administration about the error above.";
                 $strErrormessage .= "</div></body></html>";
             }
             print $strErrormessage;
             //if error was displayed, stop execution
             //die();
         }
     }
 }
Exemplo n.º 12
0
 /**
  * Looks up the columns of the given table.
  * Should return an array for each row consisting of:
  * array ("columnName", "columnType")
  *
  * @param string $strTableName
  *
  * @return array
  */
 public function getColumnsOfTable($strTableName)
 {
     $arrReturn = array();
     $arrTemp = $this->getPArray("SHOW COLUMNS FROM " . $this->encloseTableName(class_db::getInstance()->dbsafeString($strTableName)), array());
     if (empty($arrTemp)) {
         return array();
     }
     foreach ($arrTemp as $arrOneColumn) {
         $arrReturn[] = array("columnName" => $arrOneColumn["Field"], "columnType" => $arrOneColumn["Type"]);
     }
     return $arrReturn;
 }
Exemplo n.º 13
0
 /**
  * Managing access to the database object. Use ONLY this method to
  * get an instance!
  *
  * @return class_db
  */
 public function getObjDB()
 {
     //Do we have to generate the object?
     if ($this->objDB == null) {
         $this->objDB = class_db::getInstance();
         //Now we have to set up the database connection
         //SIR 2010/03: connection is established on request, lazy loading
         //$this->objDB->dbconnect();
     }
     return $this->objDB;
 }
 /**
  * Loads an array containing all installed modules from database
  *
  * @param bool $intStart
  * @param bool $intEnd
  *
  * @return class_module_system_module[]
  * @static
  */
 public static function getAllModules($intStart = null, $intEnd = null)
 {
     if (count(self::$arrModules) == 0) {
         if (count(class_db::getInstance()->getTables()) == 0) {
             return array();
         }
         self::$arrModules = parent::getObjectList();
     }
     if ($intStart === null || $intEnd === null) {
         return self::$arrModules;
     }
     $arrReturn = array();
     $intI = 0;
     foreach (self::$arrModules as $objOneModule) {
         if ($intI >= $intStart && $intI <= $intEnd) {
             $arrReturn[] = $objOneModule;
         }
         $intI++;
     }
     return $arrReturn;
 }