The item must be uniquely identified by $guid. Any other details about
the event are passed in $attributes. Standard suggested attributes are:
- who: The id of the user that performed the action (will be added
automatically if not present).
- ts: Timestamp of the action (this will be added automatically if it
is not present).
public log ( string $guid, array $attributes = [], boolean $replaceAction = false ) | ||
$guid | string | The unique identifier of the entry to add to. |
$attributes | array | The hash of name => value entries that describe this event. |
$replaceAction | boolean | If $attributes['action'] is already present in the item's history log, update that entry instead of creating a new one. |
/** * @see Horde_History::log() * * Overridden to ensure we have the current auth username. */ public function log($guid, array $attributes = array(), $replaceAction = false) { if (empty($attributes['who'])) { $attributes['who'] = $GLOBALS['registry']->getAuth() ? $GLOBALS['registry']->getAuth() : ''; } $this->_history->log($guid, $attributes, $replaceAction); }
/** */ public function saveLog(IMP_Maillog_Message $msg, IMP_Maillog_Log_Base $log) { if (!$this->isAvailable($msg, $log)) { return false; } $data = array_merge($log->addData(), array('action' => $log->action, 'ts' => $log->timestamp)); try { $this->_history->log($this->_getUniqueHistoryId($msg), $data); return true; } catch (RuntimeException $e) { /* This is an invalid/missing Message-ID. Ignore. */ } catch (Exception $e) { /* On error, log the error message only since informing the user is * just a waste of time and a potential point of confusion, * especially since they most likely don't even know the message * is being logged. */ Horde::log(sprintf('Could not log message details to Horde_History. Error returned: %s', $e->getMessage()), 'ERR'); } return false; }
/** * Handles a bad login. * * @param string $userId The user with a bad login. * * @throws Horde_Auth_Exception */ protected function _badLogin($userId) { if (!$this->_history_api) { throw new Horde_Auth_Exception('Unsupported.'); } $history_identifier = $userId . '@logins.failed'; try { $this->_history_api->log($history_identifier, array('action' => 'login_failed', 'who' => $userId)); $history_log = $this->_history_api->getHistory($history_identifier); if ($this->_params['login_block_count'] > 0 && $this->_params['login_block_count'] <= $history_log->count() && $this->hasCapability('lock')) { $this->lockUser($userId, $this->_params['login_block_time']); } } catch (Horde_History_Exception $e) { throw new Horde_Auth_Exception($e); } }
/** * Update the history log for an object. * * @param string $object The object ID. * @param string $bid The backend ID of * the object. * @param Horde_Kolab_Storage_Folder_Stamp $stamp The folder stamp. * * @return NULL */ private function _updateLog($object, $bid, $stamp) { $log = $this->history->getHistory($object); if (count($log) == 0) { $this->history->log($object, array('action' => 'add', 'bid' => $bid, 'stamp' => $stamp)); } else { $last = array('ts' => 0); foreach ($log as $entry) { if ($entry['ts'] > $last['ts']) { $last = $entry; } } if (!isset($last['bid']) || $last['bid'] != $bid || isset($last['stamp']) && $last['stamp']->isReset($stamp)) { $this->history->log($object, array('action' => 'modify', 'bid' => $bid, 'stamp' => $stamp)); } } }
/** * Update the history log for an object. * * @param string $object The object ID. * @param string $bid The backend ID of the object. * @param boolean $force Force update */ protected function _updateLog($object, $bid, $force = false) { $last = $this->_history->getLatestEntry($object); if ($last === false) { // New, unknown object $this->_logger->debug(sprintf('[KOLAB_STORAGE] New object to log in Horde_History: %s, uid: %d', $object, $bid)); $this->_history->log($object, array('action' => 'add', 'bid' => $bid), true); } else { // If the last action for this object was 'delete', we issue an 'add'. // Objects can vanish and re-appear using the same object uid. // (a foreign client is sending an update over a slow link) if ($last['action'] == 'delete') { $this->_logger->debug(sprintf('[KOLAB_STORAGE] Re-adding previously deleted object in Horde_History: %s, uid: %d', $object, $bid)); $this->_history->log($object, array('action' => 'add', 'bid' => $bid), true); } if (!isset($last['bid']) || $last['bid'] != $bid || $force) { $this->_logger->debug(sprintf('[KOLAB_STORAGE] Modifying object in Horde_History: %s, uid: %d, force: %d', $object, $bid, $force)); $this->_history->log($object, array('action' => 'modify', 'bid' => $bid), true); } } }