Example #1
0
 /**
  * update object
  * @param  array   $p optional properties. If not specified then $this-data is used
  * @return boolean
  */
 public function update($p = false)
 {
     if ($p !== false) {
         $this->data = $p;
         unset($this->linearData);
         if (array_key_exists('id', $p)) {
             $this->id = $p['id'];
         }
         $this->template = null;
         if (!empty($this->data['template_id']) && $this->loadTemplate) {
             $this->template = \CB\Templates\SingletonCollection::getInstance()->getTemplate($this->data['template_id']);
         }
     }
     if (!is_numeric($this->id)) {
         throw new \Exception("No object id specified for update", 1);
     }
     //load current object from db into a variable to be passed to log and events
     $this->oldObject = clone $this;
     $od = $this->oldObject->load($this->id);
     $wasDraft = !empty($od['draft']);
     \CB\fireEvent('beforeNodeDbUpdate', $this);
     $p =& $this->data;
     $tableFields = array('pid', 'user_id', 'system', 'template_id', 'tag_id', 'target_id', 'name', 'date', 'date_end', 'size', 'cfg', 'oid', 'did', 'dstatus');
     $data = $this->collectModelData($p);
     $data = array_merge($data, array('draft' => 0, 'uid' => User::getId(), 'udate' => 'CURRENT_TIMESTAMP'));
     DM\Tree::update($data);
     DM\Tree::activateChildDrafts($this->id);
     $this->updateCustomData();
     // set/update this object to cache
     Cache::set('Objects[' . $this->id . ']', $this);
     \CB\fireEvent('nodeDbUpdate', $this);
     if ($wasDraft) {
         $this->logAction('create', array('mentioned' => $this->lastMentionedUserIds));
     } else {
         $this->logAction('update', array('old' => $this->oldObject, 'mentioned' => $this->lastMentionedUserIds));
     }
     return true;
 }