Skip to content

Commit

Permalink
Updated feature Plugin new before<classname>DeleteMany events are now…
Browse files Browse the repository at this point in the history
… fired on the LSActiveRecord deleteAllByAttributes method

Dev overriden the inherited method deleteAllByAttributes within LSActiveRecord to new before<classname>DeleteMany PluginEvent before calling the overriden method
  • Loading branch information
kfegert committed Aug 15, 2013
1 parent 3a19bf7 commit 7512a3d
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions application/models/LSActiveRecord.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ public function getMaxId($field = null, $forceRefresh = false) {
}

/**
* Deletes records which match the specified attribute values.
* this method overrides the parent implementation in order to ensure that the beforeDelete event is fired for each record.
* this method overrides the parent implementation in order to raise a
* before<classname>DeleteMany PluginEvent before calling the overriden method.
*
* See {@link find()} for detailed explanation about $condition and $params.
* @param array $attributes list of attribute values (indexed by attribute names) that the active records should match.
Expand All @@ -154,11 +154,10 @@ public function getMaxId($field = null, $forceRefresh = false) {
*/
public function deleteAllByAttributes($attributes,$condition='',$params=array())
{
$iNumberOfAffectedRows=0;
$aData = $this->findAllByAttributes($attributes,$condition,$params);
foreach ($aData AS $oModel) {
$iNumberOfAffectedRows+=$oModel->delete();
}
return $iNumberOfAffectedRows;
$sEventName = 'before'.get_class($this).'DeleteMany';
$oPluginEvent = new PluginEvent($sEventName, $this);
$oPluginEvent->set($sEventName, array('attributes' => $attributes, 'condition' => $condition, 'params' => $params));
$result = App()->getPluginManager()->dispatchEvent($oPluginEvent);
return parent::deleteAllByAttributes($attributes, $condition, $params);
}
}

0 comments on commit 7512a3d

Please sign in to comment.