Beispiel #1
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);
 }
Beispiel #2
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;
 }
Beispiel #3
0
 /**
  * Update media item
  * @param integer $id
  * @param array $data
  * @return boolean
  */
 public function update($id, array $data)
 {
     if (!$id) {
         return false;
     }
     try {
         $obj = new Db_Object($this->_name, $id);
         $obj->setValues($data);
         $obj->save();
         $hLog = Model::factory('Historylog');
         $hLog->log(User::getInstance()->id, $id, Model_Historylog::Update, $this->table());
         return true;
     } catch (Exception $e) {
         return false;
     }
 }
Beispiel #4
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());
 }
Beispiel #5
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;
     }
 }
Beispiel #6
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;
 }
Beispiel #7
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;
     }
 }
Beispiel #8
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;
     }
 }