Skip to content
Permalink
Browse files

Code Cleanup

- Send delete signal within delete methods
- Make sure we are not unnecessarily calling PluginManager::auditPlugin()
  • Loading branch information...
aydreeihn committed Sep 30, 2019
1 parent 54a175a commit 5ba9e899ea3d6081f8f1fa7e723d76e67349ad44
@@ -203,6 +203,9 @@ function delete(){
if (!parent::delete())
return false;
$type = array('type' => 'deleted');
Signal::send('object.deleted', $this, $type);
$this->attachments->deleteAll();
return true;
@@ -519,6 +519,9 @@ function delete() {
$id = $this->getId();
if (parent::delete()) {
$type = array('type' => 'deleted');
Signal::send('object.deleted', $this, $type);
// DO SOME HOUSE CLEANING
//Move tickets to default Dept. TODO: Move one ticket at a time and send alerts + log notes.
Ticket::objects()
@@ -824,17 +827,19 @@ function update($vars, &$errors) {
return false;
$vars['disable_auto_claim'] = isset($vars['disable_auto_claim']) ? 1 : 0;
if (PluginManager::auditPlugin() && $this->getId()) {
if ($this->getId()) {
//flags
$disableAutoClaim = $this->flagChanged(self::FLAG_DISABLE_AUTO_CLAIM, $vars['disable_auto_claim']);
$disableAutoAssign = $this->flagChanged(self::FLAG_DISABLE_REOPEN_AUTO_ASSIGN, $vars['disable_reopen_auto_assign']);
$ticketAssignment = ($this->getAssignmentFlag() != $vars['assignment_flag']);
foreach ($vars as $key => $value) {
if ($key == 'status' && $this->getStatus() && strtolower($this->getStatus()) != $value) {
$type = array('type' => 'edited', 'status' => ucfirst($value));
Signal::send('object.edited', $this, $type);
} elseif ((isset($this->$key) && ($this->$key != $value) && $key != 'members') ||
($disableAutoClaim && $key == 'disable_auto_claim') ||
$ticketAssignment && $key == 'assignment_flag') {
$ticketAssignment && $key == 'assignment_flag' ||
$disableAutoAssign && $key == 'disable_reopen_auto_assign') {
$type = array('type' => 'edited', 'key' => $key);
Signal::send('object.edited', $this, $type);
}
@@ -197,6 +197,8 @@ function delete() {
// Soft Delete: Mark the form as deleted.
$this->setFlag(self::FLAG_DELETED);
$type = array('type' => 'deleted');
Signal::send('object.deleted', $this, $type);
return $this->save();
}
@@ -199,6 +199,9 @@ function delete() {
if (!parent::delete())
return false;
$type = array('type' => 'deleted');
Signal::send('object.deleted', $this, $type);
Dept::objects()
->filter(array('email_id' => $this->getId()))
->update(array(
@@ -302,6 +302,8 @@ function getAttachments($lang=null) {
function delete() {
try {
parent::delete();
$type = array('type' => 'deleted');
Signal::send('object.deleted', $this, $type);
// Cleanup help topics.
$this->topics->expunge();
// Cleanup attachments.
@@ -409,6 +409,8 @@ function update($vars,&$errors) {
function delete() {
try {
parent::delete();
$type = array('type' => 'deleted');
Signal::send('object.deleted', $this, $type);
$this->rules->expunge();
$this->actions->expunge();
}
@@ -441,6 +441,9 @@ function delete() {
if (!parent::delete())
return false;
$type = array('type' => 'deleted');
Signal::send('object.deleted', $this, $type);
if (($form = $this->getForm(false))) {
$form->delete(false);
$form->fields->delete();
@@ -528,6 +528,9 @@ function delete() {
if (!parent::delete())
return false;
$type = array('type' => 'deleted');
Signal::send('object.deleted', $this, $type);
// Remove users from this organization
User::objects()
->filter(array('org' => $this))
@@ -201,6 +201,9 @@ function delete() {
if (!parent::delete())
return false;
$type = array('type' => 'deleted');
Signal::send('object.deleted', $this, $type);
// Remove dept access entries
StaffDeptAccess::objects()
->filter(array('role_id'=>$this->getId()))
@@ -228,6 +228,9 @@ function delete() {
db_query('UPDATE '.TICKET_TABLE.' SET sla_id='.db_input($cfg->getDefaultSLAId()).' WHERE sla_id='.db_input($id));
}
$type = array('type' => 'deleted');
Signal::send('object.deleted', $this, $type);
return $num;
}
@@ -827,6 +827,9 @@ function delete() {
if (!parent::delete())
return false;
$type = array('type' => 'deleted');
Signal::send('object.deleted', $this, $type);
// DO SOME HOUSE CLEANING
//Move remove any ticket assignments...TODO: send alert to Dept. manager?
Ticket::objects()
@@ -1266,15 +1269,15 @@ function updatePerms($vars, &$errors=array()) {
}
$permissions = $this->getPermission();
foreach ($vars as $k => $val) {
if (!array_key_exists($val, $permissions->perms) && PluginManager::auditPlugin()) {
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 (!in_array($k, $vars) && array_key_exists($k, $permissions->perms) && 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);
}
@@ -272,6 +272,9 @@ function delete() {
if (!parent::delete())
return false;
$type = array('type' => 'deleted');
Signal::send('object.deleted', $this, $type);
# Remove members of this team
$this->members->delete();
@@ -413,6 +413,9 @@ function delete(){
.' WHERE tpl_id='.db_input($this->getId()));
}
$type = array('type' => 'deleted');
Signal::send('object.deleted', $this, $type);
return $num;
}
@@ -456,7 +459,7 @@ function save($id, $vars, &$errors) {
if($errors) return false;
foreach ($vars as $key => $value) {
if ($id && PluginManager::auditPlugin() && isset($this->ht[$key]) && ($this->ht[$key] != $value)) {
if ($id && isset($this->ht[$key]) && ($this->ht[$key] != $value)) {
$type = array('type' => 'edited', 'key' => $key);
Signal::send('object.edited', $this, $type);
}
@@ -149,11 +149,8 @@
$i=0;
foreach($_POST['ids'] as $k=>$v) {
if(($c=Canned::lookup($v)) && $c->delete()) {
$type = array('type' => 'deleted');
Signal::send('object.deleted', $c, $type);
if(($c=Canned::lookup($v)) && $c->delete())
$i++;
}
}
if($i==$count)
@@ -193,8 +193,6 @@
$i=0;
foreach($_POST['ids'] as $k=>$v) {
if($v!=$cfg->getDefaultDeptId() && ($d=Dept::lookup($v))) {
$type = array('type' => 'deleted');
Signal::send('object.deleted', $d, $type);
$d->delete();
$i++;
}
@@ -59,12 +59,8 @@
case 'delete':
$i=0;
foreach($_POST['ids'] as $k=>$v) {
if($v!=$cfg->getDefaultEmailId() && ($e=Email::lookup($v)) && $e->delete()) {
$type = array('type' => 'deleted');
Signal::send('object.deleted', $e, $type);
if($v!=$cfg->getDefaultEmailId() && ($e=Email::lookup($v)) && $e->delete())
$i++;
}
}
if($i && $i==$count)
@@ -130,8 +130,6 @@
$category = $faq->getCategory();
if($faq->delete()) {
$msg=sprintf(__('Successfully deleted %s.'), Format::htmlchars($faq->getQuestion()));
$type = array('type' => 'deleted');
Signal::send('object.deleted', $faq, $type);
$faq=null;
} else {
$errors['err']=sprintf(__('Unable to delete %s.'), __('this FAQ article'));
@@ -105,12 +105,8 @@
case 'delete':
$i=0;
foreach($_POST['ids'] as $k=>$v) {
if(($f=Filter::lookup($v)) && !$f->isSystemBanlist() && $f->delete()) {
$type = array('type' => 'deleted');
Signal::send('object.deleted', $f, $type);
if(($f=Filter::lookup($v)) && !$f->isSystemBanlist() && $f->delete()
$i++;
}
}
if($i && $i==$count)
@@ -90,11 +90,8 @@
case 'delete':
$i=0;
foreach($_POST['ids'] as $k=>$v) {
if(($t=DynamicForm::lookup($v)) && $t->delete()) {
$type = array('type' => 'deleted');
Signal::send('object.deleted', $t, $type);
if(($t=DynamicForm::lookup($v)) && $t->delete())
$i++;
}
}
if ($i && $i==$count)
$msg = sprintf(__('Successfully deleted %s.'),
@@ -126,11 +126,8 @@
case 'delete':
$i=0;
foreach($_POST['ids'] as $k=>$v) {
if(($t=DynamicList::lookup($v)) && $t->delete()) {
$type = array('type' => 'deleted');
Signal::send('object.deleted', $t, $type);
if(($t=DynamicList::lookup($v)) && $t->delete())
$i++;
}
}
if ($i && $i==$count)
$msg = sprintf(__('Successfully deleted %s.'),
@@ -73,8 +73,6 @@
switch (strtolower($_POST['do'])) {
case 'delete':
foreach ($orgs as $O) {
$type = array('type' => 'deleted');
Signal::send('object.deleted', $O, $type);
if ($O->delete())
$count++;
}
@@ -115,11 +115,8 @@
case 'delete':
$i=0;
foreach ($_POST['ids'] as $k=>$v) {
if (($r=Role::lookup($v)) && $r->isDeleteable() && $r->delete()) {
$type = array('type' => 'deleted');
Signal::send('object.deleted', $r, $type);
if (($r=Role::lookup($v)) && $r->isDeleteable() && $r->delete())
$i++;
}
}
if ($i && $i==$count)
$msg = sprintf(__('Successfully deleted %s.'),
@@ -102,8 +102,6 @@
if (($p=SLA::lookup($v))
&& $p->getId() != $cfg->getDefaultSLAId()
&& $p->delete()) {
$type = array('type' => 'deleted');
Signal::send('object.deleted', $p, $type);
$i++;
}
}
@@ -104,8 +104,6 @@
$i = 0;
foreach($members as $s) {
if ($s->staff_id != $thisstaff->getId()) {
$type = array('type' => 'deleted');
Signal::send('object.deleted', $s, $type);
$s->delete();
$i++;
}
@@ -99,8 +99,6 @@
case 'delete':
foreach($_POST['ids'] as $k=>$v) {
if(($t=Team::lookup($v))) {
$type = array('type' => 'deleted');
Signal::send('object.deleted', $t, $type);
$t->delete();
$i++;
}
@@ -146,12 +146,8 @@
case 'delete':
$i=0;
foreach($_POST['ids'] as $k=>$v) {
if(($t=EmailTemplateGroup::lookup($v)) && !$t->isInUse() && $t->delete()) {
$type = array('type' => 'deleted');
Signal::send('object.deleted', $t, $type);
if(($t=EmailTemplateGroup::lookup($v)) && !$t->isInUse() && $t->delete())
$i++;
}
}
if($i && $i==$count)
@@ -496,7 +496,7 @@
$f->filterFields(function($f) { return !$f->isStorable(); });
$f->addMissingFields();
}
} elseif($_REQUEST['a'] == 'print' && !$ticket->pdfExport($_REQUEST['psize'], $_REQUEST['notes'], $_REQUEST['events'])) {
} elseif($_REQUEST['a'] == 'print') {
if (!extension_loaded('mbstring'))
$errors['err'] = sprintf('%s %s',
'mbstring',

0 comments on commit 5ba9e89

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