Beispiel #1
0
 /**
  * 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;
     }
 }
Beispiel #2
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++;
     }
 }
Beispiel #3
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;
 }
Beispiel #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()));
 }
Beispiel #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();
 }
Beispiel #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());
     }
 }
Beispiel #7
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();
 }
Beispiel #8
0
 public function testGetTitle()
 {
     $cfg = Db_Object_Config::getInstance('Page');
     $data = $cfg->getData();
     $data['link_title'] = '/ {code} / {menu_title} /';
     $cfg->setData($data);
     $page = new Db_Object('Page');
     $page->set('code', 'pageCode');
     $page->set('menu_title', 'pageTitle');
     //echo $page->getTitle();exit;
     $this->assertEquals('/ pageCode / pageTitle /', $page->getTitle());
 }
Beispiel #9
0
 /**
  * (non-PHPdoc)
  * @see Backend_Controller_Crud::updateObject()
  */
 public function updateObject(Db_Object $object)
 {
     $author = $object->get('author_id');
     if (empty($author)) {
         $object->set('author_id', $this->_user->getId());
     }
     if (!$object->saveVersion()) {
         Response::jsonError($this->_lang->CANT_CREATE);
     }
     $stagingUrl = $this->getStagingUrl($object);
     Response::jsonSuccess(array('id' => $object->getId(), 'version' => $object->getVersion(), 'staging_url' => $stagingUrl, 'published_version' => $object->get('published_version'), 'published' => $object->get('published')));
 }
Beispiel #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();
 }
Beispiel #11
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;
 }
Beispiel #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);
         }
     }
 }