Skip to content
Permalink
Browse files

Remove Unnecessary if Statement

We do not need to check for the plugin each time we want to send a signal.
  • Loading branch information...
aydreeihn committed Sep 23, 2019
1 parent ac1e99c commit 59e5d71a5fb0c4de857ace2b76831bf14dd30d98
@@ -488,11 +488,9 @@ function login($staff, $bk) {
sprintf(_S("%s logged in [%s], via %s"), $staff->getUserName(),
$_SERVER['REMOTE_ADDR'], get_class($bk))); //Debug.
if (PluginManager::auditPlugin()) {
$agent = Staff::lookup($staff->getId());
$type = array('type' => 'login');
Signal::send('person.login', $agent, $type);
}
$agent = Staff::lookup($staff->getId());
$type = array('type' => 'login');
Signal::send('person.login', $agent, $type);
// Tag the authkey.
$authkey = $bk::$id.':'.$authkey;
@@ -533,11 +531,9 @@ static function signOut($staff) {
$staff->getUserName(),
$_SERVER['REMOTE_ADDR'])); //Debug.
if (PluginManager::auditPlugin()) {
$agent = Staff::lookup($staff->getId());
$type = array('type' => 'logout');
Signal::send('person.logout', $agent, $type);
}
$agent = Staff::lookup($staff->getId());
$type = array('type' => 'logout');
Signal::send('person.logout', $agent, $type);
Signal::send('auth.logout', $staff);
}
@@ -687,11 +683,9 @@ function login($user, $bk) {
$user->getUserName(), $user->getId(), $_SERVER['REMOTE_ADDR']);
$ost->logDebug(_S('User login'), $msg);
if (PluginManager::auditPlugin()) {
$u = User::lookup($user->getId());
$type = array('type' => 'login');
Signal::send('person.login', $u, $type);
}
$u = User::lookup($user->getId());
$type = array('type' => 'login');
Signal::send('person.login', $u, $type);
if ($bk->supportsInteractiveAuthentication() && ($acct=$user->getAccount()))
$acct->cancelResetTokens();
@@ -729,11 +723,9 @@ static function signOut($user) {
sprintf(_S("%s logged out [%s]" /* Tokens are <username> and <ip> */),
$user->getUserName(), $_SERVER['REMOTE_ADDR']));
if (PluginManager::auditPlugin()) {
$u = User::lookup($user->getId());
$type = array('type' => 'logout');
Signal::send('person.logout', $u, $type);
}
$u = User::lookup($user->getId());
$type = array('type' => 'logout');
Signal::send('person.logout', $u, $type);
}
protected function getAuthKey($user) {
@@ -918,11 +910,9 @@ function authstrike($credentials) {
if ($staffId)
$staff = Staff::lookup($staffId[0]);
if ($staff) {
if (PluginManager::auditPlugin()) {
$agent = Staff::lookup($staff->getId());
$type = array('type' => 'login', 'msg' => sprintf('Excessive login attempts (%s)', $authsession['strikes']));
Signal::send('person.login', $agent, $type);
}
$agent = Staff::lookup($staff->getId());
$type = array('type' => 'login', 'msg' => sprintf('Excessive login attempts (%s)', $authsession['strikes']));
Signal::send('person.login', $agent, $type);
}
}
@@ -996,11 +986,9 @@ function authstrike($credentials) {
$user = User::lookup($id);
if ($user) {
if (PluginManager::auditPlugin()) {
$u = User::lookup($user->getId());
$type = array('type' => 'login', 'msg' => sprintf('Excessive login attempts (%s)', $authsession['strikes']));
Signal::send('person.login', $u, $type);
}
$u = User::lookup($user->getId());
$type = array('type' => 'login', 'msg' => sprintf('Excessive login attempts (%s)', $authsession['strikes']));
Signal::send('person.login', $u, $type);
}
}
@@ -119,11 +119,9 @@ function update($key, $value) {
$before = $item->value;
$item->value = $value;
if (PluginManager::auditPlugin()) {
if ($before != $item->value) {
$type = array('type' => 'edited', 'key' => $item->ht['key']);
Signal::send('object.edited', $item, $type);
}
if ($before != $item->value) {
$type = array('type' => 'edited', 'key' => $item->ht['key']);
Signal::send('object.edited', $item, $type);
}
return $item->save();
@@ -946,10 +946,8 @@ function updateAccess($access, &$errors) {
'staff_id' => $staff_id, 'role_id' => $role_id
));
$this->extended->add($da);
if (PluginManager::auditPlugin()) {
$type = array('type' => 'edited', 'key' => 'Staff Added');
Signal::send('object.edited', $this, $type);
}
$type = array('type' => 'edited', 'key' => 'Staff Added');
Signal::send('object.edited', $this, $type);
}
else {
$da->role_id = $role_id;
@@ -962,10 +960,8 @@ function updateAccess($access, &$errors) {
return false;
if ($dropped) {
if (PluginManager::auditPlugin()) {
$type = array('type' => 'edited', 'key' => 'Staff Removed');
Signal::send('object.edited', $this, $type);
}
$type = array('type' => 'edited', 'key' => 'Staff Removed');
Signal::send('object.edited', $this, $type);
$this->extended->saveAll();
$this->extended
->filter(array('staff_id__in' => array_keys($dropped)))
@@ -389,12 +389,10 @@ function update($vars, &$errors=false) {
//checkboxes
$vars['noautoresp'] = isset($vars['noautoresp']) ? 1 : 0;
$vars['smtp_spoofing'] = isset($vars['smtp_spoofing']) ? 1 : 0;
if (PluginManager::auditPlugin()) {
foreach ($vars as $key => $value) {
if (isset($this->$key) && ($this->$key != $value)) {
$type = array('type' => 'edited', 'key' => $key);
Signal::send('object.edited', $this, $type);
}
foreach ($vars as $key => $value) {
if (isset($this->$key) && ($this->$key != $value)) {
$type = array('type' => 'edited', 'key' => $key);
Signal::send('object.edited', $this, $type);
}
}
@@ -360,12 +360,10 @@ function update($vars,&$errors) {
$vars['target'] = 'Email';
}
if (PluginManager::auditPlugin()) {
foreach ($vars as $key => $value) {
if (isset($this->$key) && ($this->$key != $value) && $key != 'rules' && $key != 'actions') {
$type = array('type' => 'edited', 'key' => $key);
Signal::send('object.edited', $this, $type);
}
foreach ($vars as $key => $value) {
if (isset($this->$key) && ($this->$key != $value) && $key != 'rules' && $key != 'actions') {
$type = array('type' => 'edited', 'key' => $key);
Signal::send('object.edited', $this, $type);
}
}
@@ -407,10 +407,8 @@ function update($vars, &$errors) {
$errors[$f] = sprintf(__('%s is required'), mb_convert_case($f, MB_CASE_TITLE));
elseif (isset($vars[$f])) {
if ($vars[$f] != $this->get($f)) {
if (PluginManager::auditPlugin()) {
$type = array('type' => 'edited', 'key' => $f);
Signal::send('object.edited', $this, $type);
}
$type = array('type' => 'edited', 'key' => $f);
Signal::send('object.edited', $this, $type);
$this->set($f, $vars[$f]);
}
}
@@ -429,24 +429,20 @@ function update($vars, &$errors) {
return false;
foreach ($this->getDynamicData() as $entry) {
if (PluginManager::auditPlugin()) {
$fields = $entry->getFields();
foreach ($fields as $field) {
$changes = $field->getChanges();
if ((is_array($changes) && $changes[0]) || $changes && !is_array($changes)) {
$type = array('type' => 'edited', 'key' => $field->getLabel());
Signal::send('object.edited', $this, $type);
}
$fields = $entry->getFields();
foreach ($fields as $field) {
$changes = $field->getChanges();
if ((is_array($changes) && $changes[0]) || $changes && !is_array($changes)) {
$type = array('type' => 'edited', 'key' => $field->getLabel());
Signal::send('object.edited', $this, $type);
}
}
if ($entry->getDynamicForm()->get('type') == 'O'
&& ($name = $entry->getField('name'))
) {
if (PluginManager::auditPlugin()) {
if ($this->name != $name->getClean()) {
$type = array('type' => 'edited', 'key' => 'Name');
Signal::send('object.edited', $this, $type);
}
if ($this->name != $name->getClean()) {
$type = array('type' => 'edited', 'key' => 'Name');
Signal::send('object.edited', $this, $type);
}
$this->name = $name->getClean();
$this->save();
@@ -456,27 +452,25 @@ function update($vars, &$errors) {
$this->updated = SqlFunction::NOW();
}
if (PluginManager::auditPlugin()) {
if ($auditCollabAll = $this->autoFlagChanged($this->autoAddMembersAsCollabs(),
$vars['collab-all-flag']))
$key = 'collab-all-flag';
if ($auditCollabPc = $this->autoFlagChanged($this->autoAddPrimaryContactsAsCollabs(),
$vars['collab-pc-flag']))
$key = 'collab-pc-flag';
if ($auditAssignAm = $this->autoFlagChanged($this->autoAssignAccountManager(),
$vars['assign-am-flag']))
$key = 'assign-am-flag';
if ($auditCollabAll || $auditCollabPc || $auditAssignAm) {
$type = array('type' => 'edited', 'key' => $key);
Signal::send('object.edited', $this, $type);
}
if ($auditCollabAll = $this->autoFlagChanged($this->autoAddMembersAsCollabs(),
$vars['collab-all-flag']))
$key = 'collab-all-flag';
if ($auditCollabPc = $this->autoFlagChanged($this->autoAddPrimaryContactsAsCollabs(),
$vars['collab-pc-flag']))
$key = 'collab-pc-flag';
if ($auditAssignAm = $this->autoFlagChanged($this->autoAssignAccountManager(),
$vars['assign-am-flag']))
$key = 'assign-am-flag';
if ($auditCollabAll || $auditCollabPc || $auditAssignAm) {
$type = array('type' => 'edited', 'key' => $key);
Signal::send('object.edited', $this, $type);
}
foreach ($vars as $key => $value) {
if ($key != 'id' && $this->get($key) && $value != $this->get($key)) {
$type = array('type' => 'edited', 'key' => $key);
Signal::send('object.edited', $this, $type);
}
foreach ($vars as $key => $value) {
if ($key != 'id' && $this->get($key) && $value != $this->get($key)) {
$type = array('type' => 'edited', 'key' => $key);
Signal::send('object.edited', $this, $type);
}
}
@@ -501,11 +495,9 @@ function update($vars, &$errors) {
'sharing-primary' => Organization::SHARE_PRIMARY_CONTACT,
'sharing-all' => Organization::SHARE_EVERYBODY,
) as $ck=>$flag) {
if (PluginManager::auditPlugin()) {
if (($sharingPrimary || $sharingEverybody) && $key == $ck) {
$type = array('type' => 'edited', 'key' => 'sharing');
Signal::send('object.edited', $this, $type);
}
if (($sharingPrimary || $sharingEverybody) && $key == $ck) {
$type = array('type' => 'edited', 'key' => 'sharing');
Signal::send('object.edited', $this, $type);
}
if ($vars['sharing'] == $ck)
$this->setStatus($flag);
@@ -569,10 +561,8 @@ static function fromVars($vars) {
}
Signal::send('organization.created', $org);
if (PluginManager::auditPlugin()) {
$type = array('type' => 'created');
Signal::send('object.created', $org, $type);
}
$type = array('type' => 'created');
Signal::send('object.created', $org, $type);
return $org;
}
@@ -268,12 +268,10 @@ function update($vars, &$errors, $allowempty=false) {
if($errors) return false;
if (PluginManager::auditPlugin()) {
foreach ($vars as $key => $value) {
if (isset($this->$key) && ($this->$key != $value)) {
$type = array('type' => 'edited', 'key' => $key);
Signal::send('object.edited', $this, $type);
}
foreach ($vars as $key => $value) {
if (isset($this->$key) && ($this->$key != $value)) {
$type = array('type' => 'edited', 'key' => $key);
Signal::send('object.edited', $this, $type);
}
}
@@ -136,22 +136,18 @@ private function updatePerms($vars, &$errors=array()) {
$config = array();
$permissions = $this->getPermission();
if (PluginManager::auditPlugin()) {
foreach ($vars as $k => $val) {
if (!array_key_exists($val, $permissions->perms)) {
$type = array('type' => 'edited', 'key' => $val);
Signal::send('object.edited', $this, $type);
}
foreach ($vars as $k => $val) {
if (!array_key_exists($val, $permissions->perms)) {
$type = array('type' => 'edited', 'key' => $val);
Signal::send('object.edited', $this, $type);
}
}
foreach (RolePermission::allPermissions() as $g => $perms) {
foreach($perms as $k => $v) {
if (PluginManager::auditPlugin()) {
if (!in_array($k, $vars) && array_key_exists($k, $permissions->perms)) {
$type = array('type' => 'edited', 'key' => $k);
Signal::send('object.edited', $this, $type);
}
if (!in_array($k, $vars) && array_key_exists($k, $permissions->perms)) {
$type = array('type' => 'edited', 'key' => $k);
Signal::send('object.edited', $this, $type);
}
$permissions->set($k, in_array($k, $vars) ? 1 : 0);
}
@@ -171,12 +167,10 @@ function update($vars, &$errors) {
if ($errors)
return false;
if (PluginManager::auditPlugin()) {
foreach ($vars as $key => $value) {
if (isset($this->$key) && ($this->$key != $value) && ($key != 'perms')) {
$type = array('type' => 'edited', 'key' => $key);
Signal::send('object.edited', $this, $type);
}
foreach ($vars as $key => $value) {
if (isset($this->$key) && ($this->$key != $value) && ($key != 'perms')) {
$type = array('type' => 'edited', 'key' => $key);
Signal::send('object.edited', $this, $type);
}
}
$this->name = $vars['name'];
@@ -168,19 +168,17 @@ function update($vars, &$errors) {
$vars['disable_overdue_alerts'] = isset($vars['disable_overdue_alerts']) ? self::FLAG_NOALERTS : 0;
$vars['transient'] = isset($vars['transient']) ? self::FLAG_TRANSIENT : 0;
if (PluginManager::auditPlugin()) {
//flags
$auditDisableOverdue = $this->flagChanged(self::FLAG_NOALERTS, $vars['disable_overdue_alerts']);
$auditTransient = $this->flagChanged(self::FLAG_TRANSIENT, $vars['transient']);
$auditStatus = $this->flagChanged(self::FLAG_ACTIVE, $vars['isactive']);
foreach ($vars as $key => $value) {
if (isset($this->$key) && ($this->$key != $value) ||
($auditDisableOverdue && $key == 'disable_overdue_alerts' ||
$auditTransient && $key == 'transient' || $auditStatus && $key == 'isactive')) {
$type = array('type' => 'edited', 'key' => $key);
Signal::send('object.edited', $this, $type);
}
//flags
$auditDisableOverdue = $this->flagChanged(self::FLAG_NOALERTS, $vars['disable_overdue_alerts']);
$auditTransient = $this->flagChanged(self::FLAG_TRANSIENT, $vars['transient']);
$auditStatus = $this->flagChanged(self::FLAG_ACTIVE, $vars['isactive']);
foreach ($vars as $key => $value) {
if (isset($this->$key) && ($this->$key != $value) ||
($auditDisableOverdue && $key == 'disable_overdue_alerts' ||
$auditTransient && $key == 'transient' || $auditStatus && $key == 'isactive')) {
$type = array('type' => 'edited', 'key' => $key);
Signal::send('object.edited', $this, $type);
}
}

0 comments on commit 59e5d71

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