Skip to content
Permalink
Browse files

Remove State Enum, Use Event Table

This commit allows us to use the event table's event_ids instead of using an enum field for states in the audit table.
  • Loading branch information...
aydreeihn committed Jan 22, 2019
1 parent bb3d092 commit 46a764f3dc2666b568c07cff8c4d08317f48eedc
@@ -488,8 +488,8 @@ function login($staff, $bk) {
sprintf(_S("%s logged in [%s], via %s"), $staff->getUserName(),
$_SERVER['REMOTE_ADDR'], get_class($bk))); //Debug.
$type = array('type' => 'Login', 'data' => array('id' => $staff->getId(), 'name' => $staff->getName()->name));
Signal::send('staff.login', $staff, $type);
$type = array('type' => 'login', 'data' => array('id' => $staff->getId(), 'name' => $staff->getName()->name));
Signal::send('staff.login', Staff::lookup($staff->getId()), $type);
// Tag the authkey.
$authkey = $bk::$id.':'.$authkey;
@@ -531,8 +531,8 @@ static function signOut($staff) {
$staff->getUserName(),
$_SERVER['REMOTE_ADDR'])); //Debug.
$type = array('type' => 'Logout', 'data' => array('id' => $staff->getId(), 'name' => $staff->getName()->name));
Signal::send('staff.logout', $staff, $type);
$type = array('type' => 'logout', 'data' => array('id' => $staff->getId(), 'name' => $staff->getName()->name));
Signal::send('staff.logout', Staff::lookup($staff->getId()), $type);
Signal::send('auth.logout', $staff);
}
@@ -682,8 +682,8 @@ function login($user, $bk) {
$user->getUserName(), $user->getId(), $_SERVER['REMOTE_ADDR']);
$ost->logDebug(_S('User login'), $msg);
$type = array('type' => 'Login', 'data' => array('id' => $user->getId(), 'name' => $user->getName()->name));
Signal::send('user.login', $user, $type);
$type = array('type' => 'login', 'data' => array('id' => $user->getId(), 'name' => $user->getName()->name));
Signal::send('user.login', User::lookup($user->getId()), $type);
if ($bk->supportsInteractiveAuthentication() && ($acct=$user->getAccount()))
$acct->cancelResetTokens();
@@ -721,8 +721,8 @@ static function signOut($user) {
sprintf(_S("%s logged out [%s]" /* Tokens are <username> and <ip> */),
$user->getUserName(), $_SERVER['REMOTE_ADDR']));
$type = array('type' => 'Logout', 'data' => array('id' => $user->getId(), 'name' => $user->getName()->name));
Signal::send('user.logout', $user, $type);
$type = array('type' => 'logout', 'data' => array('id' => $user->getId(), 'name' => $user->getName()->name));
Signal::send('user.logout', User::lookup($user->getId()), $type);
}
protected function getAuthKey($user) {
@@ -907,10 +907,10 @@ function authstrike($credentials) {
if ($staffId)
$staff = Staff::lookup($staffId[0]);
if ($staff) {
$type = array('type' => 'Login',
$type = array('type' => 'login',
'data' => array('id' => $staff->getId(), 'name' => $staff->getName()->name,
'msg' => 'Excessive login attempts (' . $authsession['strikes'] . ')'));
Signal::send('staff.login', $staff, $type);
Signal::send('staff.login', Staff::lookup($staff->getId()), $type);
}
}
@@ -984,10 +984,10 @@ function authstrike($credentials) {
$user = User::lookup($id);
if ($user) {
$type = array('type' => 'Login',
$type = array('type' => 'login',
'data' => array('id' => $user->getId(), 'name' => $user->getName()->name,
'msg' => 'Excessive login attempts (' . $authsession['strikes'] . ')'));
Signal::send('user.login', $user, $type);
Signal::send('user.login', User::lookup($user->getId()), $type);
}
}
@@ -521,7 +521,7 @@ static function fromVars($vars) {
}
Signal::send('organization.created', $org);
$type = array('type' => 'Created');
$type = array('type' => 'created');
Signal::send('object.created', $org, $type);
return $org;
}
@@ -556,7 +556,7 @@ function setStatus($status, $comments='', &$errors=array()) {
$ecb = function ($t) use($thisstaff) {
$t->logEvent('reopened', false, null, 'closed');
$type = array('type' => 'Reopened', 'data' => array('name' => $this->getNumber()));
$type = array('type' => 'reopened', 'data' => array('name' => $this->getNumber()));
Signal::send('object.edited', $this, $type);
if ($t->ticket) {
@@ -587,7 +587,7 @@ function setStatus($status, $comments='', &$errors=array()) {
$ecb = function($t) use($thisstaff) {
$t->logEvent('closed');
$type = array('type' => 'Closed', 'data' => array('name' => $t->getNumber()));
$type = array('type' => 'closed', 'data' => array('name' => $t->getNumber()));
Signal::send('object.edited', $t, $type);
if ($t->ticket) {
$vars = array(
@@ -705,7 +705,7 @@ function assignToStaff($staff, $note, $alert=true) {
$this->logEvent('assigned', $data);
$type = array('type' => 'Assigned', 'data' => array('name' => $this->getNumber(), 'staff' => $staff->getName()->name));
$type = array('type' => 'assigned', 'data' => array('name' => $this->getNumber(), 'staff' => $staff->getName()->name));
Signal::send('object.edited', $this, $type);
return true;
@@ -758,7 +758,7 @@ function assign(AssignmentForm $form, &$errors, $alert=true) {
$this->logEvent('assigned', $evd);
$type = array('type' => 'Assigned', 'data' => $audit);
$type = array('type' => 'assigned', 'data' => $audit);
Signal::send('object.edited', $this, $type);
$this->onAssignment($assignee,
@@ -863,7 +863,7 @@ function transfer(TransferForm $form, &$errors, $alert=true) {
// Log transfer event
$this->logEvent('transferred');
$type = array('type' => 'Transferred', 'data' => array('name' => $this->getNumber(), 'dept' => $dept->getName()));
$type = array('type' => 'transferred', 'data' => array('name' => $this->getNumber(), 'dept' => $dept->getName()));
Signal::send('object.edited', $this, $type);
// Post internal note if any
@@ -1317,7 +1317,7 @@ function update($forms, $vars, &$errors) {
if ($changes)
$this->logEvent('edited', array('fields' => $changes));
$type = array('type' => 'Edited', 'data' => array('name' => $this->getNumber(), 'fields' => $changes));
$type = array('type' => 'edited', 'data' => array('name' => $this->getNumber(), 'fields' => $changes));
Signal::send('object.edited', $this, $type);
Signal::send('model.updated', $this);
return $this->save();
@@ -1370,7 +1370,7 @@ static function create($vars=false) {
$task->logEvent('created', null, $thisstaff);
$type = array('type' => 'Created');
$type = array('type' => 'created');
Signal::send('object.created', $task, $type);
// Get role for the dept
@@ -1406,7 +1406,7 @@ function delete($comments='') {
$thread->delete();
$this->logEvent('deleted');
$type = array('type' => 'Deleted', 'data' => array('name' => $this->getNumber()));
$type = array('type' => 'deleted', 'data' => array('name' => $this->getNumber()));
Signal::send('object.deleted', $this, $type);
Draft::deleteForNamespace('task.%.' . $this->getId());
@@ -193,7 +193,7 @@ function addCollaborator($user, $vars, &$errors, $event=true) {
)
);
$type = array('type' => 'Collaborator', 'data' => array('name' => $this->getObject()->getNumber(), 'add' => array($user->getId() => array(
$type = array('type' => 'collab', 'data' => array('name' => $this->getObject()->getNumber(), 'add' => array($user->getId() => array(
'name' => $user->getName()->name,
'src' => @$vars['source'],
))));
@@ -222,7 +222,7 @@ function updateCollaborators($vars, &$errors) {
'del' => array($c->user_id => array('name' => $c->getName()->getOriginal()))
));
$type = array('type' => 'Collaborator', 'data' => array('name' => $this->getObject()->getNumber(), 'del' => array($c->user_id => array('name' => $c->getName()->name))));
$type = array('type' => 'collab', 'data' => array('name' => $this->getObject()->getNumber(), 'del' => array($c->user_id => array('name' => $c->getName()->name))));
Signal::send('object.deleted', $this->getObject(), $type);
}
}
@@ -2222,6 +2222,18 @@ static function getIds() {
return $ids;
}
static function getStates($dropdown=false) {
$names = array();
if ($dropdown)
$names = array(__('All'));
$events = self::objects()->values_flat('name');
foreach ($events as $val)
$names[] = ucfirst($val[0]);
return $names;
}
static function create($vars=false, &$errors=array()) {
$event = new static($vars);
return $event;
@@ -398,7 +398,7 @@ function resend($response) {
// Log an event that the item was resent
$object->logEvent('resent', array('entry' => $response->id));
$type = array('type' => 'Resent', 'data' => array('name' => $object->getNumber()));
$type = array('type' => 'resent', 'data' => array('name' => $object->getNumber()));
Signal::send('object.edited', $object, $type);
// Flag the entry as resent
@@ -1255,7 +1255,7 @@ function updateCollaborators($vars, &$errors) {
$collabs[] = (string) $c;
}
$this->logEvent('collab', array('del' => $collabs));
$type = array('type' => 'Collaborator', 'data' => array('name' => $this->getNumber(), 'del' => $collabs));
$type = array('type' => 'collab', 'data' => array('name' => $this->getNumber(), 'del' => $collabs));
Signal::send('object.deleted', $this, $type);
}
@@ -1495,7 +1495,7 @@ function setStatus($status, $comments='', &$errors=array(), $set_closing_agent=t
$ecb = function($t) use ($status) {
$t->logEvent('closed', array('status' => array($status->getId(), $status->getName())), null, 'closed');
$type = array('type' => 'Closed', 'data' => array('name' => $t->getNumber()));
$type = array('type' => 'closed', 'data' => array('name' => $t->getNumber()));
Signal::send('object.edited', $t, $type);
$t->deleteDrafts();
@@ -1508,7 +1508,7 @@ function setStatus($status, $comments='', &$errors=array(), $set_closing_agent=t
$ecb = function ($t) {
$t->logEvent('reopened', false, null, 'closed');
$type = array('type' => 'Reopened', 'data' => array('name' => $t->getNumber()));
$type = array('type' => 'reopened', 'data' => array('name' => $t->getNumber()));
Signal::send('object.edited', $t, $type);
};
}
@@ -2625,7 +2625,7 @@ function transfer(TransferForm $form, &$errors, $alert=true) {
// Log transfer event
$this->logEvent('transferred');
$type = array('type' => 'Transferred', 'data' => array('name' => $this->getNumber(), 'dept' => $dept->getName()));
$type = array('type' => 'transferred', 'data' => array('name' => $this->getNumber(), 'dept' => $dept->getName()));
Signal::send('object.edited', $this, $type);
// Post internal note if any
@@ -2742,7 +2742,7 @@ function assignToStaff($staff, $note, $alert=true, $user=null) {
$this->logEvent('assigned', $data, $user);
$type = array('type' => 'Assigned', 'data' => array('name' => $this->getNumber(), 'staff' => $staff->getName()->name));
$type = array('type' => 'assigned', 'data' => array('name' => $this->getNumber(), 'staff' => $staff->getName()->name));
Signal::send('object.edited', $this, $type);
return true;
@@ -2820,7 +2820,7 @@ function assign(AssignmentForm $form, &$errors, $alert=true) {
$this->logEvent('assigned', $evd);
$type = array('type' => 'Assigned', 'data' => $audit);
$type = array('type' => 'assigned', 'data' => $audit);
Signal::send('object.edited', $this, $type);
$this->onAssign($assignee, $form->getComments(), $alert);
@@ -2853,12 +2853,20 @@ function unassign() {
}
function release($info=array(), &$errors) {
if ($info['sid'] && $info['tid'])
$type = array('type' => 'released', 'data' => array('name' => $this->getNumber()));
if ($info['sid'] && $info['tid']) {
Signal::send('object.edited', $this, $type);
return $this->unassign();
elseif ($info['sid'] && $this->setStaffId(0))
}
elseif ($info['sid'] && $this->setStaffId(0)) {
Signal::send('object.edited', $this, $type);
return true;
elseif ($info['tid'] && $this->setTeamId(0))
}
elseif ($info['tid'] && $this->setTeamId(0)) {
Signal::send('object.edited', $this, $type);
return true;
}
return false;
}
@@ -2921,7 +2929,7 @@ function refer(ReferralForm $form, &$errors, $alert=true) {
$this->logEvent('referred', $evd);
$type = array('type' => 'Referred', 'data' => $audit);
$type = array('type' => 'referred', 'data' => $audit);
Signal::send('object.edited', $this, $type);
return true;
@@ -2975,7 +2983,7 @@ function changeOwner($user) {
$this->logEvent('edited', array('owner' => $user->getId()));
$type = array('type' => 'Edited', 'data' => array('name' => $this->getNumber(), 'fields' => array('id' => $user->getId(), 'user' => $user->getName()->name)));
$type = array('type' => 'edited', 'data' => array('name' => $this->getNumber(), 'fields' => array('id' => $user->getId(), 'user' => $user->getName()->name)));
Signal::send('object.edited', $this, $type);
return true;
@@ -3168,7 +3176,7 @@ function postMessage($vars, $origin='', $alerts=true) {
$sentlist[] = $staff->getEmail();
}
}
$type = array('type' => 'Message', 'uid' => $vars['userId']);
$type = array('type' => 'message', 'uid' => $vars['userId']);
Signal::send('object.created', $this, $type);
return $message;
@@ -3516,7 +3524,7 @@ function delete($comments='') {
$this->logEvent('deleted');
$type = array('type' => 'Deleted', 'data' => array('name' => $this->getNumber()));
$type = array('type' => 'deleted', 'data' => array('name' => $this->getNumber()));
Signal::send('object.deleted', $this, $type);
foreach (DynamicFormEntry::forTicket($this->getId()) as $form)
@@ -3672,7 +3680,7 @@ function update($vars, &$errors) {
if ($changes) {
$this->logEvent('edited', $changes);
$type = array('type' => 'Edited', 'data' => array('name' => $this->getNumber(), 'fields' => $changes));
$type = array('type' => 'edited', 'data' => array('name' => $this->getNumber(), 'fields' => $changes));
Signal::send('object.edited', $this, $type);
}
@@ -3764,7 +3772,7 @@ function updateField($form, &$errors) {
// Record the changes
$this->logEvent('edited', $changes);
$type = array('type' => 'Edited', 'data' => array('name' => $this->getNumber(), 'fields' => $changes));
$type = array('type' => 'edited', 'data' => array('name' => $this->getNumber(), 'fields' => $changes));
Signal::send('object.edited', $this, $type);
// Log comments (if any)
@@ -4274,7 +4282,7 @@ static function create($vars, &$errors, $origin, $autorespond=true,
// Start tracking ticket lifecycle events (created should come first!)
$ticket->logEvent('created', null, $thisstaff ?: $user);
$type = array('type' => 'Created');
$type = array('type' => 'created');
Signal::send('object.created', $ticket, $type);
// Add collaborators (if any)
@@ -586,7 +586,7 @@ function updateInfo($vars, &$errors, $staff=false) {
$this->updated = SqlFunction::NOW();
}
}
$type = array('type' => 'Edited', 'data' => array('id' => $this->getId(), 'name' => $this->getName()->name));
$type = array('type' => 'edited', 'data' => array('id' => $this->getId(), 'name' => $this->getName()->name));
Signal::send('object.edited', $this, $type);
return $this->save();
@@ -3,7 +3,7 @@
$info=($_POST && $errors)?Format::htmlchars($_POST):array();
$type = array('type' => 'Viewed');
$type = array('type' => 'viewed');
Signal::send('object.view', $ticket, $type);
$dept = $ticket->getDept();
@@ -86,7 +86,7 @@
$info=($_POST && $errors)?Format::input($_POST):array();
$type = array('type' => 'Viewed');
$type = array('type' => 'viewed');
Signal::send('object.view', $task, $type);
if ($task->isOverdue())
@@ -8,7 +8,7 @@
//Re-use the post info on error...savekeyboards.org (Why keyboard? -> some people care about objects than users!!)
$info=($_POST && $errors)?Format::input($_POST):array();
$type = array('type' => 'Viewed');
$type = array('type' => 'viewed');
Signal::send('object.view', $ticket, $type);
//Get the goodies.
@@ -46,7 +46,7 @@
$category = Category::create();
if ($category->update($_POST, $errors)) {
$msg=sprintf(__('Successfully added %s.'), Format::htmlchars($_POST['name']));
$type = array('type' => 'Created');
$type = array('type' => 'created');
Signal::send('object.created', $category, $type);
$_REQUEST['a']=null;
} elseif(!$errors['err']) {

0 comments on commit 46a764f

Please sign in to comment.
You can’t perform that action at this time.