Index: branches/5.2.x/core/units/agents/agent_eh.php =================================================================== diff -u -N -r13840 -r14092 --- branches/5.2.x/core/units/agents/agent_eh.php (.../agent_eh.php) (revision 13840) +++ branches/5.2.x/core/units/agents/agent_eh.php (.../agent_eh.php) (revision 14092) @@ -1,6 +1,6 @@ Array ('self' => 'add|edit'), + 'OnRunAgents' => Array ('self' => 'add|edit'), ); $this->permMapping = array_merge($this->permMapping, $permissions); @@ -136,4 +137,36 @@ $this->clearSelectedIDs($event); } + + /** + * Runs selected agents + * + * @param kEvent $event + */ + function OnRunAgents(&$event) + { + $ids = $this->StoreSelectedIDs($event); + + if ($ids) { + $object =& $event->getObject( Array ('skip_autoload' => true) ); + /* @var $object kDBItem */ + + $where_clause = Array ( + $object->TableName . '.' . $object->IDField . ' IN (' . implode(',', $ids) . ')', + $object->TableName . '.Status = ' . STATUS_ACTIVE, + $object->TableName . '.LastRunStatus <> ' . AGENT_LAST_RUN_RUNNING, + ); + + $sql = $object->GetSelectSQL() . ' + WHERE (' . implode(') AND (', $where_clause) . ')'; + $agents = $this->Conn->Query($sql); + + foreach ($agents as $agent_data) { + $agent_data['EventName'] = $agent_data['Event']; + $this->Application->EventManager->runAgent($agent_data); + } + } + + $this->clearSelectedIDs($event); + } } \ No newline at end of file