Esempio n. 1
0
File: Vc.php Progetto: vgrish/dvelum
 /**
  * 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;
     }
 }
Esempio n. 2
0
 /**
  * Log action. Fill history table
  * @param integer $user_id
  * @param integer $record_id
  * @param integer $type
  * @param string $table_name
  * @throws Exception
  * @return boolean
  */
 public function log($user_id, $record_id, $type, $table_name)
 {
     if (!is_integer($type)) {
         throw new Exception('History::log Invalid type');
     }
     $obj = new Db_Object($this->_name);
     $obj->setValues(array('user_id' => intval($user_id), 'record_id' => intval($record_id), 'type' => intval($type), 'date' => date('Y-m-d H:i:s'), 'table_name' => $table_name));
     return $obj->save(false, false);
 }
Esempio n. 3
0
 /**
  * Update pages order_no
  * @param array $data
  */
 public function updateSortOrder(array $sortedIds)
 {
     $i = 0;
     foreach ($sortedIds as $v) {
         $obj = new Db_Object($this->_name, intval($v));
         $obj->set('order_no', $i);
         $obj->save();
         $i++;
     }
 }
Esempio n. 4
0
 /**
  * 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()));
 }
Esempio n. 5
0
 /**
  * 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();
 }
Esempio n. 6
0
 /**
  * Sort media categories
  */
 public function sortcatalogAction()
 {
     $this->_checkCanEdit();
     $id = Request::post('id', 'integer', false);
     $newParent = Request::post('newparent', 'integer', false);
     $order = Request::post('order', 'array', array());
     if (!$id || !strlen($newParent) || empty($order)) {
         Response::jsonError($this->_lang->WRONG_REQUEST);
     }
     try {
         $pObject = new Db_Object('mediacategory', $id);
         $pObject->set('parent_id', $newParent);
         $pObject->save();
         Model::factory('Mediacategory')->updateSortOrder($order);
         Response::jsonSuccess();
     } catch (Exception $e) {
         Response::jsonError($this->_lang->CANT_EXEC . ' ' . $e->getMessage());
     }
 }
Esempio n. 7
0
 /**
  * Add block map for page
  * @param integer $pageId
  * @param string $code
  * @param array $blockIds
  */
 public function addBlocks($pageId, $code, array $blockIds)
 {
     if (empty($blockIds)) {
         return true;
     }
     $order = 0;
     foreach ($blockIds as $id) {
         $blockmapItem = new Db_Object('blockmapping');
         $blockmapItem->set('block_id', $id);
         if ($pageId) {
             $blockmapItem->set('page_id', $pageId);
         }
         $blockmapItem->set('place', $code);
         $blockmapItem->set('order_no', $order);
         $blockmapItem->save(false);
         $order++;
     }
     return true;
 }
Esempio n. 8
0
 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;
 }
Esempio n. 9
0
 /**
  * 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()));
 }
Esempio n. 10
0
 /**
  * Reset childs elements set parent 0
  * @param page $id
  */
 public function resetChilds($id)
 {
     $obj = new Db_Object($this->_name, intval($id));
     $obj->set('parent_id', 0);
     $obj->save();
 }
Esempio n. 11
0
 /**
  * (non-PHPdoc)
  * @see Bgtask_Storage::addTaskRecord()
  */
 public function addTaskRecord($description)
 {
     $object = new Db_Object('bgtask');
     $object->title = $description;
     $pid = $object->save();
     $this->_objects[$pid] = $object;
     return $pid;
 }
Esempio n. 12
0
 protected function findParentClass($data)
 {
     $classModel = Model::factory('sysdocs_class');
     $objectId = $data['id'];
     $parentName = $data['extends'];
     $classData = $classModel->getList(array('limit' => 1), array('vers' => $this->vers, 'name' => $parentName), array('id'));
     if (!empty($classData)) {
         $parentId = $classData[0]['id'];
         $object = new Db_Object('sysdocs_class', $objectId);
         $object->set('parentId', $parentId);
         if (!$object->save(false, false)) {
             throw new Exception('Cannot save sysdocs_class parentId ' . $objectId);
         }
     }
 }
Esempio n. 13
0
 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;
     }
 }
Esempio n. 14
0
 /**
  * Update menu links
  * @param integer $objectId
  * @param array $links
  * @return boolean
  */
 public function updateLinks($objectId, $links)
 {
     $this->_db->delete($this->table(), 'menu_id = ' . intval($objectId));
     if (!empty($links)) {
         foreach ($links as $k => $item) {
             $obj = new Db_Object('Menu_Item');
             try {
                 $obj->tree_id = $item['id'];
                 $obj->page_id = $item['page_id'];
                 $obj->title = $item['title'];
                 $obj->published = $item['published'];
                 $obj->menu_id = $objectId;
                 $obj->parent_id = $item['parent_id'];
                 $obj->order = $item['order'];
                 $obj->link_type = $item['link_type'];
                 $obj->url = $item['url'];
                 $obj->resource_id = $item['resource_id'];
                 if (!$obj->save(false)) {
                     throw new Exception(Lang::lang()->CANT_CREATE);
                 }
             } catch (Exception $e) {
                 return false;
             }
         }
     }
     return true;
 }
Esempio n. 15
0
 /**
  * Add new object version
  * @param Db_Object $object
  * @param boolean $log - optional, log changes
  * @param boolean $useTransaction - optional , use transaction if available
  * @return boolean|integer - vers number
  */
 public function addVersion(Db_Object $object, $log = true, $useTransaction = true)
 {
     if ($object->getConfig()->isReadOnly()) {
         if ($this->_log) {
             $this->_log->log('ORM :: cannot addVersion for readonly object ' . $object->getConfig()->getName());
         }
         return false;
     }
     /*
      * Check object id
      */
     if (!$object->getId()) {
         return false;
     }
     if (!$object->getConfig()->isRevControl()) {
         if ($this->_log) {
             $this->_log->log($object->getName() . '::publish Cannot addVersion. Object is not under version control');
         }
         return false;
     }
     /*
      * Fire "BEFORE_ADD_VERSION" Event if event manager exists
      */
     if ($this->_eventManager) {
         $this->_eventManager->fireEvent(Db_Object_Event_Manager::BEFORE_ADD_VERSION, $object);
     }
     /*
      * Create new revision
      */
     $versNum = Model::factory($this->_versionObject)->newVersion($object);
     if (!$versNum) {
         return false;
     }
     try {
         $oldObject = new Db_Object($object->getName(), $object->getId());
         /**
          * Update object if not published
          */
         if (!$oldObject->get('published')) {
             $data = $object->getData();
             foreach ($data as $k => $v) {
                 if (!is_null($v)) {
                     $oldObject->set($k, $v);
                 }
             }
         }
         $oldObject->set('date_updated', $object->get('date_updated'));
         $oldObject->set('editor_id', $object->get('editor_id'));
         if (!$oldObject->save(false, $useTransaction)) {
             throw new Exception('Cannot save object');
         }
     } catch (Exception $e) {
         if ($this->_log) {
             $this->_log->log('Cannot update unpublished object data ' . $e->getMessage());
         }
         return false;
     }
     /*
      * Save history if required
      * @todo удалить жесткую связанность
      */
     if ($log && $object->getConfig()->get('save_history')) {
         Model::factory($this->_historyObject)->log(User::getInstance()->getId(), $object->getId(), Model_Historylog::NewVersion, $object->getTable());
     }
     /*
      * Fire "AFTER_ADD_VERSION" Event if event manager exists
      */
     if ($this->_eventManager) {
         $this->_eventManager->fireEvent(Db_Object_Event_Manager::AFTER_ADD_VERSION, $object);
     }
     return $versNum;
 }
Esempio n. 16
0
 /**
  * (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()));
 }
Esempio n. 17
0
 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());
 }
Esempio n. 18
0
File: Vc.php Progetto: vgrish/dvelum
 /**
  * (non-PHPdoc)
  * @see Backend_Controller_Crud::insertObject()
  */
 public function insertObject(Db_Object $object)
 {
     $object->published = false;
     $object->author_id = User::getInstance()->id;
     $object->date_created = date('Y-m-d H:i:s');
     if (!($recId = $object->save())) {
         Response::jsonError($this->_lang->CANT_CREATE);
     }
     $versNum = Model::factory('Vc')->newVersion($object);
     if (!$versNum) {
         Response::jsonError($this->_lang->CANT_CREATE);
     }
     $stagingUrl = $this->getStagingUrl($object);
     Response::jsonSuccess(array('id' => $recId, 'version' => $versNum, 'published' => false, 'staging_url' => $stagingUrl));
 }
Esempio n. 19
0
 /**
  * Update description
  * @param string $fileHid
  * @param integer $vers
  * @param string $language
  * @param string $text
  */
 public function setDescription($objectId, $fileHid, $vers, $language, $text, $docObject)
 {
     $data = Model::factory('sysdocs_localization')->getList(array('start' => 0, 'limit' => 1, 'sort' => 'vers', 'dir' => 'DESC'), array('lang' => $language, 'object_class' => $docObject, 'hid' => $fileHid, 'object_id' => $objectId, 'field' => 'description', 'vers' => $vers), array('id'));
     if (!empty($data)) {
         $id = $data[0]['id'];
     } else {
         $id = false;
     }
     try {
         $o = new Db_Object('sysdocs_localization', $id);
         $o->setValues(array('field' => 'description', 'hid' => $fileHid, 'lang' => $language, 'object_class' => $docObject, 'object_id' => $objectId, 'value' => $text, 'vers' => $vers));
         if (!$o->save()) {
             throw new Exception('Cannot update class description');
         }
         return true;
     } catch (Exception $e) {
         Model::factory('sysdocs_localization')->logError($e->getMessage());
         return false;
     }
 }
Esempio n. 20
0
 /**
  * Update group permissions
  * @param integer $groupId
  * @param array $data - permissions like array(
  * array(
  * 			'object'=>'object',
  * 			'view'=>true,
  *             'create'=>false,
  * 			'edit'=>false,
  * 			'delete'=>false,
  * 			'publish'=>false
  * 	),
  * 	...
  * )
  * @return boolean
  */
 public function updateGroupPermissions($groupId, array $data)
 {
     $groupPermissions = $this->getList(false, array('group_id' => $groupId, 'user_id' => null));
     $sorted = Utils::rekey('object', $groupPermissions);
     $modulesToRemove = array();
     if (!empty($sorted)) {
         $modulesToRemove = array_diff(array_keys($sorted), Utils::fetchCol('object', $data));
     }
     if (!empty($modulesToRemove)) {
         $this->_db->delete($this->table(), '`object` IN (\'' . implode("','", $modulesToRemove) . '\') AND `group_id`=' . intval($groupId));
     }
     $errors = false;
     foreach ($data as $values) {
         if (empty($values)) {
             return false;
         }
         /**
          * Check if all needed fields are present
          */
         $diff = array_diff(self::$_fields, array_keys($values));
         if (!empty($diff)) {
             continue;
         }
         try {
             if (isset($sorted[$values['object']])) {
                 $obj = new Db_Object($this->_name, $sorted[$values['object']][$this->_objectConfig->getPrimaryKey()]);
                 $obj->setValues(array('view' => (bool) $values['view'], 'create' => (bool) $values['create'], 'edit' => (bool) $values['edit'], 'delete' => (bool) $values['delete'], 'publish' => (bool) $values['publish']));
             } else {
                 $obj = new Db_Object($this->_name);
                 $obj->setValues(array('view' => (bool) $values['view'], 'create' => (bool) $values['create'], 'edit' => (bool) $values['edit'], 'delete' => (bool) $values['delete'], 'publish' => (bool) $values['publish'], 'object' => $values['object'], 'group_id' => $groupId, 'user_id' => null));
             }
             if (!$obj->save()) {
                 $errors = true;
             }
         } catch (Exception $e) {
             $this->logError($e->getMessage());
             $errors = true;
         }
     }
     if ($errors) {
         return false;
     } else {
         return true;
     }
 }
Esempio n. 21
0
 /**
  * (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;
 }
Esempio n. 22
0
 /**
  * Mark object as hand croped
  * @param integer $id
  * @return void
  */
 public function markCroped($id)
 {
     $obj = new Db_Object($this->_name, $id);
     $obj->set('croped', 1);
     $obj->save();
 }
Esempio n. 23
0
 /**
  * Set group permissions
  * @param integer $group
  * @param string $module
  * @param boolean $view
  * @param boolean $edit
  * @param boolean $delete
  * @param boolean $publish
  * @return boolean
  */
 public function setGroupPermissions($group, $module, $view, $edit, $delete, $publish)
 {
     $data = $this->getList(false, array('group_id' => $group, 'user_id' => null, 'module' => $module), array('id'), false);
     $objectId = false;
     if (!empty($data)) {
         $objectId = $data[0]['id'];
     }
     try {
         $groupObj = new Db_Object('permissions', $objectId);
     } catch (Exception $e) {
         $groupObj = new Db_Object('permissions');
     }
     $groupObj->module = $module;
     $groupObj->view = $view;
     $groupObj->edit = $edit;
     $groupObj->delete = $delete;
     $groupObj->publish = $publish;
     $groupObj->group_id = $group;
     $groupObj->user_id = 0;
     return $groupObj->save(true);
 }