/** * Updates the current object to the database. * Only the value is updated!!! * * @param bool $strPrevId * * @return bool */ public function updateObjectToDb($strPrevId = false) { $objChangelog = new class_module_system_changelog(); $objChangelog->createLogEntry($this, class_module_system_changelog::$STR_ACTION_EDIT); self::$arrInstanceCache = null; if (!class_module_system_setting::checkConfigExisting($this->getStrName())) { class_logger::getInstance()->addLogRow("new constant " . $this->getStrName() . " with value " . $this->getStrValue(), class_logger::$levelInfo); $strQuery = "INSERT INTO " . _dbprefix_ . "system_config\n (system_config_id, system_config_name, system_config_value, system_config_type, system_config_module) VALUES\n (?, ?, ?, ?, ?)"; return $this->objDB->_pQuery($strQuery, array(generateSystemid(), $this->getStrName(), $this->getStrValue(), (int) $this->getIntType(), (int) $this->getIntModule())); } else { class_logger::getInstance()->addLogRow("updated constant " . $this->getStrName() . " to value " . $this->getStrValue(), class_logger::$levelInfo); $strQuery = "UPDATE " . _dbprefix_ . "system_config\n SET system_config_value = ?\n WHERE system_config_name = ?"; return $this->objDB->_pQuery($strQuery, array($this->getStrValue(), $this->getStrName())); } }
public function testPerformance() { $objChanges = new class_module_system_changelog(); $objChanges->processCachedInserts(); $intFired = class_carrier::getInstance()->getObjDB()->getNumber() - class_carrier::getInstance()->getObjDB()->getNumberCache(); for ($intI = 0; $intI < 100; $intI++) { $objChanges->createLogEntry(new dummyObject(generateSystemid()), "1"); $objChanges->processCachedInserts(); } $intFiredAfter = class_carrier::getInstance()->getObjDB()->getNumber() - class_carrier::getInstance()->getObjDB()->getNumberCache(); $this->assertTrue($intFiredAfter - $intFired >= 100); echo "Queries: " . ($intFiredAfter - $intFired) . "\n"; $intFired = class_carrier::getInstance()->getObjDB()->getNumber() - class_carrier::getInstance()->getObjDB()->getNumberCache(); $objChanges = new class_module_system_changelog(); for ($intI = 0; $intI < 100; $intI++) { $objChanges->createLogEntry(new dummyObject(generateSystemid()), "1"); } $objChanges->processCachedInserts(); $intFiredAfter = class_carrier::getInstance()->getObjDB()->getNumber() - class_carrier::getInstance()->getObjDB()->getNumberCache(); $this->assertTrue($intFiredAfter - $intFired < 10); echo "Queries: " . ($intFiredAfter - $intFired) . "\n"; }
/** * Deletes the object from the database. The record is removed in total, so no restoring will be possible. * * @return bool * @throws class_exception */ public function deleteObjectFromDatabase() { if (!$this->getLockManager()->isAccessibleForCurrentUser()) { return false; } if ($this instanceof interface_versionable) { $objChanges = new class_module_system_changelog(); $objChanges->createLogEntry($this, class_module_system_changelog::$STR_ACTION_DELETE); } /** @var $this class_root|interface_model */ $this->objDB->transactionBegin(); //validate, if there are subrecords, so child nodes to be deleted $arrChilds = $this->objDB->getPArray("SELECT system_id FROM " . _dbprefix_ . "system where system_prev_id = ?", array($this->getSystemid())); foreach ($arrChilds as $arrOneChild) { if (validateSystemid($arrOneChild["system_id"])) { $objInstance = class_objectfactory::getInstance()->getObject($arrOneChild["system_id"]); if ($objInstance !== null) { $objInstance->deleteObjectFromDatabase(); } } } $objORM = new class_orm_objectdelete($this); $bitReturn = $objORM->deleteObject(); $this->objSortManager->fixSortOnDelete(); $bitReturn = $bitReturn && $this->deleteSystemRecord($this->getSystemid()); class_objectfactory::getInstance()->removeFromCache($this->getSystemid()); class_orm_rowcache::removeSingleRow($this->getSystemid()); //try to call other modules, maybe wanting to delete anything in addition, if the current record //is going to be deleted $bitReturn = $bitReturn && class_core_eventdispatcher::getInstance()->notifyGenericListeners(class_system_eventidentifier::EVENT_SYSTEM_RECORDDELETED, array($this->getSystemid(), get_class($this))); if ($bitReturn) { class_logger::getInstance()->addLogRow("successfully deleted record " . $this->getSystemid() . " / " . $this->getStrDisplayName(), class_logger::$levelInfo); $this->objDB->transactionCommit(); $this->objDB->flushQueryCache(); return true; } else { class_logger::getInstance()->addLogRow("error deleting record " . $this->getSystemid() . " / " . $this->getStrDisplayName(), class_logger::$levelInfo); $this->objDB->transactionRollback(); $this->objDB->flushQueryCache(); return false; } }
/** * Called whenever a update-request was fired. * Use this method to synchronize the current object with the database. * Use only updates, inserts are not required to be implemented. * Provides a default implementation based on the current objects column mappings. * Override this method whenever you want to perform additional actions or escaping. * * @throws class_exception * @return bool */ public function updateStateToDb() { if (!validateSystemid($this->getObjObject()->getSystemid()) || !$this->hasTargetTable()) { return true; } //fetch properties with annotations $objReflection = new class_reflection($this->getObjObject()); $arrTargetTables = $objReflection->getAnnotationValuesFromClass(class_orm_base::STR_ANNOTATION_TARGETTABLE); if (count($arrTargetTables) == 0) { //no table mapping found - skip return true; } $bitReturn = true; foreach ($arrTargetTables as $strOneTable) { $arrTableDef = explode(".", $strOneTable); //scan all properties $arrColValues = array(); $arrEscapes = array(); //get the mapped properties $arrProperties = $objReflection->getPropertiesWithAnnotation(class_orm_base::STR_ANNOTATION_TABLECOLUMN); foreach ($arrProperties as $strPropertyName => $strColumn) { //check if there are table annotation available $arrColumnDef = explode(".", $strColumn); //if the column doesn't declare a target table whereas the class defines more then one - skip it. if (count($arrColumnDef) == 1 && count($arrTargetTables) > 1) { throw new class_orm_exception("property " . $strPropertyName . " declares no target table, class " . get_class($this->getObjObject()) . " declares more than one target table.", class_exception::$level_FATALERROR); } //skip if property targets another table if (count($arrColumnDef) == 2 && $arrColumnDef[0] != $arrTableDef[0]) { continue; } if (count($arrColumnDef) == 2) { $strColumn = $arrColumnDef[1]; } //all prerequisites match, start creating query $strGetter = $objReflection->getGetter($strPropertyName); if ($strGetter !== null) { //explicit casts required? could be relevant, depending on the target column type / database system $mixedValue = call_user_func(array($this->getObjObject(), $strGetter)); if ($mixedValue !== null && (uniStrtolower(uniSubstr($strGetter, 0, 6)) == "getint" || uniStrtolower(uniSubstr($strGetter, 0, 6)) == "getbit")) { //different casts on 32bit / 64bit if ($mixedValue > PHP_INT_MAX) { $mixedValue = (double) $mixedValue; } else { $mixedValue = (int) $mixedValue; } } $arrColValues[$strColumn] = $mixedValue; $arrEscapes[] = !$objReflection->hasPropertyAnnotation($strPropertyName, class_orm_base::STR_ANNOTATION_BLOCKESCAPING); } } //update table if (count($arrColValues) > 0) { $bitReturn = $bitReturn && $this->updateSingleTable($arrColValues, $arrEscapes, $arrTableDef[0], $arrTableDef[1]); } } //see, if we should process object lists, too if ($bitReturn) { $bitReturn = $this->updateAssignments(); } if ($this->getObjObject() instanceof interface_versionable) { $objChanges = new class_module_system_changelog(); $objChanges->createLogEntry($this->getObjObject(), class_module_system_changelog::$STR_ACTION_EDIT); } return $bitReturn; }
/** * Updates the current object to the database * * @return bool */ protected function updateStateToDb() { //Make texts db-safe $strName = $this->generateNonexistingPagename($this->getStrName()); $this->setStrName($strName); //create change-logs $objChanges = new class_module_system_changelog(); $objChanges->createLogEntry($this, class_module_system_changelog::$STR_ACTION_EDIT); $this->updatePath(); //Update the baserecord $bitBaseUpdate = parent::updateStateToDb(); //and the properties record //properties for this language already existing? $strCountQuery = "SELECT COUNT(*)\n FROM " . _dbprefix_ . "page_properties\n\t\t WHERE pageproperties_id= ?\n\t\t AND pageproperties_language= ?"; $arrCountRow = $this->objDB->getPRow($strCountQuery, array($this->getSystemid(), $this->getStrLanguage()), 0, false); if ((int) $arrCountRow["COUNT(*)"] >= 1) { //Already existing, updating properties $strQuery2 = "UPDATE " . _dbprefix_ . "page_properties\n \t\t\t\t\tSET pageproperties_description=?,\n \t\t\t\t\t\tpageproperties_template=?,\n \t\t\t\t\t\tpageproperties_keywords=?,\n \t\t\t\t\t\tpageproperties_browsername=?,\n \t\t\t\t\t\tpageproperties_seostring=?,\n \t\t\t\t\t\tpageproperties_alias=?,\n \t\t\t\t\t\tpageproperties_target=?,\n pageproperties_path=?\n \t\t\t\t WHERE pageproperties_id=?\n \t\t\t\t AND pageproperties_language=?"; $arrParams = array($this->getStrDesc(), $this->getStrTemplate(), $this->getStrKeywords(), $this->getStrBrowsername(), $this->getStrSeostring(), $this->getStrAlias(), $this->getStrTarget(), $this->getStrPath(), $this->getSystemid(), $this->getStrLanguage()); } else { //Not existing, create one $strQuery2 = "INSERT INTO " . _dbprefix_ . "page_properties\n\t\t\t\t\t\t(pageproperties_id, pageproperties_keywords, pageproperties_description, pageproperties_template, pageproperties_browsername,\n\t\t\t\t\t\t pageproperties_seostring, pageproperties_alias, pageproperties_target, pageproperties_language, pageproperties_path) VALUES\n\t\t\t\t\t\t(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; $arrParams = array($this->getSystemid(), $this->getStrKeywords(), $this->getStrDesc(), $this->getStrTemplate(), $this->getStrBrowsername(), $this->getStrSeostring(), $this->getStrAlias(), $this->getStrTarget(), $this->getStrLanguage(), $this->getStrPath()); } $bitBaseUpdate = $bitBaseUpdate && $this->objDB->_pQuery($strQuery2, $arrParams); $arrChildIds = $this->getChildNodesAsIdArray(); foreach ($arrChildIds as $strChildId) { $objInstance = class_objectfactory::getInstance()->getObject($strChildId); $objInstance->updateObjectToDb(); } return $bitBaseUpdate; }