public function clearBlockCache(Db_Object $object) { if (!$this->_cache) { return; } $menuModel = Model::factory('Menu'); $this->_cache->remove($menuModel->resetCachedMenuLinks($object->getId())); $blockManager = new Blockmanager(); $blockManager->invalidateCacheBlockMenu($object->getId()); }
/** * Create new version * @property Db_Object $object * @return boolean */ public function newVersion(Db_Object $object) { $object->commitChanges(); $newVersion = $this->getLastVersion($object->getName(), $object->getId()) + 1; $newData = $object->getData(); if ($object->getConfig()->hasEncrypted()) { $ivField = $object->getConfig()->getIvField(); $ivKey = $object->get($ivField); if (empty($ivKey)) { $ivKey = Utils_String::createEncryptIv(); $newData[$ivField] = $ivKey; } $newData = $this->getStore()->encryptData($object, $newData); } $newData['id'] = $object->getId(); try { $vObject = new Db_Object('vc'); $vObject->set('date', date('Y-m-d')); $vObject->set('data', base64_encode(serialize($newData))); $vObject->set('user_id', User::getInstance()->id); $vObject->set('version', $newVersion); $vObject->set('record_id', $object->getId()); $vObject->set('object_name', $object->getName()); $vObject->set('date', date('Y-m-d H:i:s')); if ($vObject->save()) { return $newVersion; } return false; } catch (Exception $e) { $this->logError('Cannot create new version for ' . $object->getName() . '::' . $object->getId() . ' ' . $e->getMessage()); return false; } }
protected function createPage() { $group = new Db_Object('Group'); $group->setValues(array('title' => date('YmdHis'), 'system' => false)); $group->save(); $user = new Db_Object('User'); try { $user->setValues(array('login' => uniqid() . date('YmdHis'), 'pass' => '111', 'email' => uniqid() . date('YmdHis') . '@mail.com', 'enabled' => 1, 'admin' => 1, 'name' => 'Test User', 'group_id' => $group->getId())); } catch (Exception $e) { echo $e->getMessage(); } $saved = $user->save(); $this->assertTrue(!empty($saved)); $u = User::getInstance(); $u->setId($user->getId()); $u->setAuthorized(); $page = new Db_Object('Page'); $page->setValues(array('code' => uniqid() . date('YmdHis'), 'is_fixed' => 1, 'html_title' => 'Index', 'menu_title' => 'Index', 'page_title' => 'Index', 'meta_keywords' => '', 'meta_description' => '', 'parent_id' => null, 'text' => '[Index page content]', 'func_code' => '', 'order_no' => 1, 'show_blocks' => true, 'published' => true, 'published_version' => 0, 'editor_id' => $user->getId(), 'author_id' => $user->getId(), 'date_created' => date('Y-m-d H:i:s'), 'date_updated' => date('Y-m-d H:i:s'), 'author_id' => $user->getId(), 'blocks' => '', 'theme' => 'default', 'date_published' => date('Y-m-d H:i:s'), 'in_site_map' => true, 'default_blocks' => true)); $page->save(); return $page; }
/** * Add media item * @param string $name * @param string $path * @param integer $size (bytes) * @param string $type * @param string $ext - extension * @return integer */ public function addItem($name, $path, $size, $type, $ext, $category = null) { $size = number_format($size / 1024 / 1024, 3); $data = array('title' => $name, 'path' => $path, 'size' => $size, 'type' => $type, 'user_id' => User::getInstance()->id, 'ext' => $ext, 'date' => date('Y-m-d H:i:s'), 'category' => $category); $obj = new Db_Object($this->_name); $obj->setValues($data); if ($obj->save()) { return $obj->getId(); } else { return false; } }
/** * Add users group * @param string $title - group name */ public function addGroup($title) { $obj = new Db_Object($this->_name); $obj->set('title', $title); if (!$obj->save()) { return false; } $cache = self::$_dataCache; /** * Invalidate cache */ if ($cache) { $cache->remove('groups_list'); } return $obj->getId(); }
/** * Get Associated objects * @param Db_Object $object * @return array like * array( * 'single' => array( * 'objectName'=>array(id1,id2,id3), * ... * 'objectNameN'=>array(id1,id2,id3), * ), * 'multy' =>array( * 'objectName'=>array(id1,id2,id3), * ... * 'objectNameN'=>array(id1,id2,id3), * ) * ) */ public static function getAssociatedObjects(Db_Object $object) { $linkedObjects = array('single' => array(), 'multy' => array()); self::_buildAssociations(); $objectName = $object->getName(); $objectId = $object->getId(); if (!isset(self::$_objectAssociations[$objectName])) { return array(); } foreach (self::$_objectAssociations as $testObject => $links) { if (!isset($links[$objectName])) { continue; } $sLinks = self::_getSingleLinks($objectId, $testObject, $links[$objectName]); if (!empty($sLinks)) { $linkedObjects['single'][$testObject] = $sLinks; } } $linkedObjects['multy'] = self::_getMultyLinks($objectName, $objectId); return $linkedObjects; }
/** * Define the object data preview page URL * (needs to be redefined in the child class * as per the application structure) * @param Db_Object $object * @return string */ public function getStagingUrl(Db_Object $object) { $frontendRouter = new Frontend_Router(); $stagingUrl = $frontendRouter->findUrl(strtolower($object->getName())); if (!strlen($stagingUrl)) { return Request::url(array('404')); } return Request::url(array($stagingUrl, 'item', $object->getId())); }
/** * Update ORM object data * Sends JSON reply in the result and * closes the application * @param Db_Object $object */ public function updateObject(Db_Object $object) { if (!$object->save()) { Response::jsonError($this->_lang->CANT_EXEC); } Response::jsonSuccess(array('id' => $object->getId())); }
/** * Update object * @param Db_Object $object * @return void */ public function updateObject(Db_Object $object) { $changeVal = Request::post('changeVal', 'bool', false); if ($changeVal) { $object->set('hash', Utils::hash($object->get('hash'))); } if (!$object->save()) { Response::jsonError($this->_lang->CANT_EXEC); } Response::jsonSuccess(array('id' => $object->getId())); }
public function clearBlockCache(Db_Object $object) { $blockManager = new Blockmanager(); $blockManager->invalidateCacheBlockId($object->getId()); }
protected function processMethods(Db_Object $class, sysdocs_Analyzer $analyzer) { $methods = $analyzer->getMethods(); $paramsList = array(); if (!empty($methods)) { foreach ($methods as $method) { $data = array('classId' => $class->getId(), 'name' => $method['name'], 'returnType' => $method['returnType'], 'deprecated' => intval($method['deprecated']), 'description' => $this->clearDescription($method['description']), 'abstract' => $method['abstract'], 'throws' => $method['throws'], 'vers' => $this->vers, 'hid' => '', 'static' => intval($method['static']), 'visibility' => $method['visibility'], 'classHid' => $class->get('hid'), 'inherited' => $method['inherited'], 'returnsReference' => $method['returnsReference']); $methodObject = $this->storeMethod($data); $params = $analyzer->getParametrs($method['name']); if (!empty($params)) { $methodId = $methodObject->getId(); $methodHid = $methodObject->get('hid'); foreach ($params as $param) { $paramsList[] = array('methodId' => $methodId, 'hid' => $this->historyId->getParamHid($methodHid, $param['name']), 'name' => $param['name'], 'vers' => $this->vers, 'index' => $param['index'], 'default' => $param['default'], 'isRef' => $param['isRef'], 'description' => $this->clearDescription($param['description']), 'methodHid' => $methodObject->get('hid'), 'optional' => $param['optional']); } } } if (!Model::factory('sysdocs_class_method_param')->multiInsert($paramsList)) { throw new Exception('Cannot save sysdocs_class_method_param'); } } }
protected function _getItemCacheKey(Db_Object $object) { $objectModel = Model::factory($object->getName()); return $objectModel->getCacheKey(array('item', $object->getId())); }
/** * (non-PHPdoc) * @see Filestorage_Simple::add() */ public function add($filePath, $useName = false) { $data = parent::add($filePath, $useName); if (empty($data)) { return array(); } foreach ($data as $k => &$v) { try { $o = new Db_Object($this->_object); $o->setValues(array('path' => $v['path'], 'date' => date('Y-m-d H:i:s'), 'ext' => $v['ext'], 'size' => number_format($v['size'] / 1024 / 1024, 3), 'user_id' => $this->_config->get('user_id'), 'name' => $v['old_name'])); if (!$o->save()) { throw new Exception('Cannot save object'); } $v['id'] = $o->getId(); } catch (Exception $e) { echo $e->getMessage(); Model::factory($this->_object)->logError('Filestorage_Orm: ' . $e->getMessage()); } } unset($v); return $data; }
/** * Delete Db object * @param Db_Object $object * @param boolean $log - optional, log changes * @param boolean $transaction - optional , use transaction if available * @return boolean */ public function delete(Db_Object $object, $log = true, $transaction = true) { if ($object->getConfig()->isReadOnly()) { if ($this->_log) { $this->_log->log('ORM :: cannot delete readonly object ' . $object->getName()); } return false; } if (!$object->getId()) { return false; } if ($this->_eventManager) { $this->_eventManager->fireEvent(Db_Object_Event_Manager::BEFORE_DELETE, $object); } $transact = $object->getConfig()->isTransact(); $db = $this->_getDbConnection($object); if ($transact && $transaction) { $db->beginTransaction(); } Model::factory($this->_linksObject)->clearObjectLinks($object); if ($db->delete($object->getTable(), $db->quoteIdentifier($object->getConfig()->getPrimaryKey()) . ' =' . $object->getId())) { /** * @todo убрать жесткую связанность */ if ($log && $object->getConfig()->hasHistory()) { Model::factory($this->_historyObject)->log(User::getInstance()->id, $object->getId(), Model_Historylog::Delete, $object->getTable()); } $success = true; } else { $success = false; } if ($transact && $transaction) { if ($success) { $db->commit(); } else { $db->rollBack(); } } if ($this->_eventManager) { $this->_eventManager->fireEvent(Db_Object_Event_Manager::AFTER_DELETE, $object); } return $success; }
protected function _prepareRecords($adminPass, $adminEmail, $adminName) { try { $toCleanModels = array(Model::factory('User'), Model::factory('Group'), Model::factory('Permissions'), Model::factory('Page')); foreach ($toCleanModels as $model) { $model->getDbConnection()->delete($model->table()); } // Add group $group = new Db_Object('Group'); $group->setValues(array('title' => $this->_dictionary['ADMINISTRATORS'], 'system' => true)); $group->save(true, false); $groupId = $group->getId(); // Add user $user = new Db_Object('user'); $user->setValues(array('name' => 'Admin', 'email' => $adminEmail, 'login' => $adminName, 'pass' => Utils::hash($adminPass), 'enabled' => true, 'admin' => true, 'registration_date' => date('Y-m-d H:i:s'), 'confirmation_code' => md5(date('Y-m-d H:i:s')), 'group_id' => $groupId, 'confirmed' => true, 'avatar' => '', 'registration_ip' => $_SERVER['REMOTE_ADDR'], 'last_ip' => $_SERVER['REMOTE_ADDR'], 'confirmation_date' => date('Y-m-d H:i:s'))); $userId = $user->save(false, false); if (!$userId) { return false; } // Add permissions $permissionsModel = Model::factory('Permissions'); $modulesManager = new Backend_Modules_Manager(); $modules = $modulesManager->getList(); foreach ($modules as $name => $config) { if (!$permissionsModel->setGroupPermissions($groupId, $name, true, true, true, true)) { return false; } } $u = User::getInstance(); $u->setId($userId); $u->setAuthorized(); // Add index Page $page = new Db_Object('Page'); $page->setValues(array('code' => 'index', 'is_fixed' => 1, 'html_title' => 'Index', 'menu_title' => 'Index', 'page_title' => 'Index', 'meta_keywords' => '', 'meta_description' => '', 'parent_id' => null, 'text' => '[Index page content]', 'func_code' => '', 'order_no' => 1, 'show_blocks' => true, 'published' => true, 'published_version' => 0, 'editor_id' => $userId, 'date_created' => date('Y-m-d H:i:s'), 'date_updated' => date('Y-m-d H:i:s'), 'author_id' => $userId, 'blocks' => '', 'theme' => 'default', 'date_published' => date('Y-m-d H:i:s'), 'in_site_map' => true, 'default_blocks' => true)); if (!$page->save(true, false)) { return false; } //404 Page $page = new Db_Object('Page'); $page->setValues(array('code' => '404', 'is_fixed' => 1, 'html_title' => 'Error 404. Page not found', 'menu_title' => '404', 'page_title' => 'We cannot find the page you are looking for.', 'meta_keywords' => '', 'meta_description' => '', 'parent_id' => null, 'text' => 'We cannot find the page you are looking for.', 'func_code' => '', 'order_no' => 2, 'show_blocks' => true, 'published' => true, 'published_version' => 0, 'editor_id' => $userId, 'date_created' => date('Y-m-d H:i:s'), 'date_updated' => date('Y-m-d H:i:s'), 'author_id' => $userId, 'blocks' => '', 'theme' => 'default', 'date_published' => date('Y-m-d H:i:s'), 'in_site_map' => false, 'default_blocks' => true)); if (!$page->save(true, false)) { return false; } //API Page $page = new Db_Object('Page'); $page->setValues(array('code' => 'api', 'is_fixed' => 1, 'html_title' => 'API [System]', 'menu_title' => 'API', 'page_title' => 'API [System]', 'meta_keywords' => '', 'meta_description' => '', 'parent_id' => null, 'text' => '', 'func_code' => 'api', 'order_no' => 3, 'show_blocks' => false, 'published' => true, 'published_version' => 0, 'editor_id' => $userId, 'date_created' => date('Y-m-d H:i:s'), 'date_updated' => date('Y-m-d H:i:s'), 'author_id' => $userId, 'blocks' => '', 'theme' => 'default', 'date_published' => date('Y-m-d H:i:s'), 'in_site_map' => false, 'default_blocks' => false)); if (!$page->save(true, false)) { return false; } return true; } catch (Exception $e) { return false; } }
public function testSetInsertId() { $somePage = $this->createPage(); $iId = time(); $o = new Db_Object('Page'); $o->setInsertId($iId); $userId = User::getInstance()->id; $this->assertEquals($iId, $o->getInssertId()); $o->setValues(array('code' => $iId, 'is_fixed' => 1, 'html_title' => 'Index', 'menu_title' => 'Index', 'page_title' => 'Index', 'meta_keywords' => '', 'meta_description' => '', 'parent_id' => null, 'text' => '[Index page content]', 'func_code' => '', 'order_no' => 1, 'show_blocks' => true, 'published' => true, 'published_version' => 0, 'editor_id' => $userId, 'date_created' => date('Y-m-d H:i:s'), 'date_updated' => date('Y-m-d H:i:s'), 'author_id' => $userId, 'blocks' => '', 'theme' => 'default', 'date_published' => date('Y-m-d H:i:s'), 'in_site_map' => true, 'default_blocks' => true)); $this->assertTrue((bool) $o->save()); $this->assertTrue(Db_Object::objectExists('Page', $iId)); $this->assertEquals($iId, $o->getId()); }
/** * Clear object links * @param Db_Object $object */ public function clearObjectLinks(Db_Object $object) { $this->_db->delete($this->table(), 'src = ' . $this->_db->quote($object->getName()) . ' AND src_id = ' . intval($object->getId())); }
/** * (non-PHPdoc) * @see Backend_Controller_Crud::updateObject() */ public function updateObject(Db_Object $object) { if (!$object->save()) { Response::jsonError($this->_lang->CANT_EXEC); } $linksData = Request::post('data', 'raw', false); if (strlen($linksData)) { $linksData = json_decode($linksData, true); } else { $linksData = array(); } $menuModel = Model::factory('Menu_Item'); if (!$menuModel->updateLinks($object->getId(), $linksData)) { Response::jsonError($this->_lang->CANT_CREATE); } Response::jsonSuccess(array('id' => $object->getId())); }