/** * update comment * @param array $p optional properties. If not specified then $this-data is used * @return boolean */ public function update($p = false) { //disable default log from parent Object class //we'll set comments add as comment action for parent Config::setFlag('disableActivityLog', true); $rez = parent::update($p); Config::setFlag('disableActivityLog', false); $p =& $this->data; // log the action $logParams = array('type' => 'comment_update', 'new' => Objects::getCachedObject($p['pid']), 'comment' => $p['data']['_title']); Log::add($logParams); return $rez; }
/** * add action to log * @param varchar $type * @param array $params * @return void */ protected function logAction($type, $params = array()) { if (!Cache::get('disable_logs', false) && !Config::getFlag('disableActivityLog')) { $params['type'] = $type; $obj =& $this; if (empty($params['new'])) { $params['new'] =& $this; } else { $obj =& $params['new']; } $logActionId = Log::add($params); $uid = User::getId(); //add action to object sys_data $data = $obj->getData(); $lastAction = $obj->getLastActionData(); if ($lastAction['type'] != $type) { $lastAction = array('type' => $type, 'time' => Util\dateMysqlToISO('now'), 'users' => array()); } /*$sysData = empty($data['sys_data']) ? $this->getSysData() : $data['sys_data']; $lastAction = array( 'type' => $type ,'time' => Util\dateMysqlToISO('now') ,'users' => array() ); if (!empty($sysData['lastAction']) && ($sysData['lastAction']['type'] == $type) ) { $lastAction['users'] = $sysData['lastAction']['users']; } /**/ unset($lastAction['users'][$uid]); $lastAction['users'][$uid] = $logActionId; $obj->setSysDataProperty('lastAction', $lastAction); } }
public function getLogRecords() { $s = Log::getSolrLogConnection(); $this->requestParams['sort'] = array('action_date desc'); $p = array('rows' => 50, 'fl' => 'id,action_id,user_id,object_id,object_pid,object_data', 'fq' => $this->fq, 'strictSort' => 'action_date desc'); $id = substr($this->lastNode->id, 1); switch (substr($this->lastNode->id, 0, 1)) { case 'd': $p['fq'][] = 'action_date:["' . $id . 'T00:00:00Z" TO "' . $id . 'T23:59:99Z"]'; break; case 'm': $p['fq'][] = 'action_date:["' . date('Y-m') . '-01T00:00:00Z" TO *]'; break; case 't': $p['fq'][] = 'action_type:' . $id; break; case 'u': $p['fq'][] = 'user_id:' . $id; break; case 't': $p['fq'][] = 'action_type:' . $id; break; } $rez = $s->query($p); foreach ($rez['data'] as &$doc) { $k = @$doc['action_id']; $data = Util\toJSONArray($doc['object_data']); $doc['id'] = $this->getId($k); $doc['pid'] = @$doc['object_pid']; unset($doc['object_pid']); $doc['name'] = Util\coalesce($data['name'], $doc['object_data']); $doc['iconCls'] = $data['iconCls']; $doc['path'] = $data['path']; // $doc['template_id'] = $data['template_id']; $doc['case_id'] = $data['case_id']; if ($data['date']) { $doc['date'] = $data['date']; } $doc['size'] = $data['size']; $doc['cid'] = @$data['cid']; $doc['oid'] = @$data['oid']; $doc['uid'] = @$data['uid']; $doc['cdate'] = $data['cdate']; $doc['udate'] = $data['udate']; $doc['user'] = User::getDisplayName($doc['user_id'], true); $doc['has_childs'] = false; } return $rez; }
/** * update file * @param array $p optional properties. If not specified then $this-data is used * @return boolean */ public function update($p = false) { //disable default log from parent Object class Config::setFlag('disableActivityLog', true); $rez = parent::update($p); Config::setFlag('disableActivityLog', false); $p =& $this->data; // log the action $logParams = array('type' => 'file_update', 'new' => Objects::getCachedObject($p['pid']), 'file' => array('id' => $p['id'], 'name' => $p['name'])); Log::add($logParams); return $rez; }
/** * move an object to $pid or over $targetId * * we'll use the same principle as for copy * * @param int $pid if not specified then will be set to pid of targetId * @param int $targetId * @return int the id of moved object or false */ public function moveTo($pid = false, $targetId = false) { // check input params if (!is_numeric($this->id) || !is_numeric($pid) && !is_numeric($targetId)) { return false; } /* security check */ if (!\CB\Security::canRead($this->id)) { return false; } /* end of security check */ //load current object from db into a variable to be passed to log and events $this->oldObject = clone $this; $this->oldObject->load($this->id); if (is_numeric($targetId)) { /* target security check */ if (!\CB\Security::canWrite($targetId)) { return false; } /* end of target security check */ // marking overwriten object with dstatus = 3 DB\dbQuery('UPDATE tree SET updated = 1 ,dstatus = 3 ,did = $2 WHERE id = $1', array($targetId, $_SESSION['user']['id'])) or die(DB\dbQueryError()); //get pid from target if not specified $res = DB\dbQuery('SELECT pid FROM tree WHERE id = $1', $targetId) or die(DB\dbQueryError()); if ($r = $res->fetch_assoc()) { $pid = $r['pid']; } $res->close(); } else { /* pid security check */ if (!\CB\Security::canWrite($pid)) { return false; } /* end of pid security check */ } /* check again if we have pid set It can be unset when not existent $targetId is specified */ if (!is_numeric($pid)) { return false; } // moving the object to $pid DB\dbQuery('UPDATE tree SET updated = 1 ,pid = $2 WHERE id = $1', array($this->id, $pid)) or die(DB\dbQueryError()); $this->moveCustomDataTo($pid); // move childs from overwriten targetId (which has been marked with dstatus = 3) // to newly copied object if (is_numeric($targetId)) { DB\dbQuery('UPDATE tree SET updated = 1 ,pid = $2 WHERE pid = $1 AND dstatus = 0', array($targetId, $this->id)) or die(DB\dbQueryError()); } $this->load(); // log the action $logParams = array('type' => 'move', 'old' => $this->oldObject, 'new' => $this); Log::add($logParams); return $this->id; }