Index: branches/5.2.x/core/units/agents/agent_eh.php =================================================================== diff -u -N -r14670 -r14879 --- branches/5.2.x/core/units/agents/agent_eh.php (.../agent_eh.php) (revision 14670) +++ branches/5.2.x/core/units/agents/agent_eh.php (.../agent_eh.php) (revision 14879) @@ -1,6 +1,6 @@ Array ('self' => 'add|edit'), - 'OnRunAgents' => Array ('self' => 'add|edit'), + 'OnRun' => Array ('self' => 'add|edit'), ); $this->permMapping = array_merge($this->permMapping, $permissions); } /** - * [HOOK] Refreshes agents list in database based on cached data from unit configs + * [HOOK] Refreshes scheduled task list in database based on cached data from unit configs * * @param kEvent $event */ - function OnRefreshAgents(&$event) + function OnRefresh(&$event) { - $regular_events = $this->Application->EventManager->getAgents(true); + $scheduled_tasks_from_cache = $this->Application->EventManager->getScheduledTasks(true); $object =& $event->getObject( Array ('skip_autoload' => true) ); /* @var $object kDBItem */ $processed_ids = Array (); - $agents = $this->Conn->Query($object->GetSelectSQL(), 'AgentName'); + $scheduled_tasks_from_db = $this->Conn->Query($object->GetSelectSQL(), 'Name'); - foreach ($regular_events as $run_mode => $events) { + foreach ($scheduled_tasks_from_cache as $run_mode => $events) { - foreach ($events as $agent_name => $agent_params) { - if ( !isset($agents[$agent_name]) ) { + foreach ($events as $scheduled_task_name => $scheduled_task_params) { + if ( !isset($scheduled_tasks_from_db[$scheduled_task_name]) ) { $fields_hash = Array ( - 'Event' => $agent_params['EventName'], - 'AgentName' => $agent_name, - 'AgentType' => Agent::AGENT_TYPE_SYSTEM, - 'Status' => array_key_exists('Status', $agent_params) ? $agent_params['Status'] : STATUS_ACTIVE, - 'RunInterval' => $agent_params['RunInterval'], + 'Event' => $scheduled_task_params['EventName'], + 'Name' => $scheduled_task_name, + 'Type' => ScheduledTask::TYPE_SYSTEM, + 'Status' => array_key_exists('Status', $scheduled_task_params) ? $scheduled_task_params['Status'] : STATUS_ACTIVE, + 'RunInterval' => $scheduled_task_params['RunInterval'], 'RunMode' => $run_mode, ); @@ -65,18 +65,18 @@ $object->Create(); } else { - $object->LoadFromHash( $agents[$agent_name] ); + $object->LoadFromHash( $scheduled_tasks_from_db[$scheduled_task_name] ); } $processed_ids[] = $object->GetID(); } } - // delete all non-processed agents (ones, that were deleted from unit configs) + // delete all non-processed scheduled tasks (ones, that were deleted from unit configs) $sql = 'SELECT ' . $object->IDField . ' FROM ' . $object->TableName . ' - WHERE (AgentType = ' . Agent::AGENT_TYPE_SYSTEM . ') AND (' . $object->IDField . ' NOT IN (' . implode(',', $processed_ids) . '))'; + WHERE (Type = ' . ScheduledTask::TYPE_SYSTEM . ') AND (' . $object->IDField . ' NOT IN (' . implode(',', $processed_ids) . '))'; $delete_ids = $this->Conn->GetCol($sql); if ($delete_ids) { @@ -101,7 +101,7 @@ { if ($event->Name == 'OnMassDelete' && $type == 'before') { if ($this->Application->isDebugMode()) { - // allow to delete system agents in debug mode + // allow to delete system scheduled tasks in debug mode return ; } @@ -112,7 +112,7 @@ $sql = 'SELECT ' . $id_field . ' FROM ' . $table_name . ' - WHERE ' . $id_field . ' IN (' . implode(',', $ids) . ') AND AgentType <> ' . Agent::AGENT_TYPE_SYSTEM; + WHERE ' . $id_field . ' IN (' . implode(',', $ids) . ') AND Type <> ' . ScheduledTask::TYPE_SYSTEM; $allowed_ids = $this->Conn->GetCol($sql); $event->setEventParam('ids', $allowed_ids); @@ -121,7 +121,7 @@ } /** - * Cancels agents, that are currently running + * Cancels scheduled tasks, that are currently running * * @param kEvent $event */ @@ -136,9 +136,9 @@ foreach ($ids as $id) { $object->Load($id); - if ($object->GetDBField('LastRunStatus') == Agent::LAST_RUN_RUNNING) { - // only changes status, doesn't affect currency running agents - $object->SetDBField('LastRunStatus', Agent::LAST_RUN_FAILED); + if ($object->GetDBField('LastRunStatus') == ScheduledTask::LAST_RUN_RUNNING) { + // only changes status, doesn't affect currency running scheduled tasks + $object->SetDBField('LastRunStatus', ScheduledTask::LAST_RUN_FAILED); $object->Update(); } } @@ -148,11 +148,11 @@ } /** - * Runs selected agents + * Runs selected scheduled tasks * * @param kEvent $event */ - function OnRunAgents(&$event) + function OnRun(&$event) { $ids = $this->StoreSelectedIDs($event); @@ -163,16 +163,16 @@ $where_clause = Array ( $object->TableName . '.' . $object->IDField . ' IN (' . implode(',', $ids) . ')', $object->TableName . '.Status = ' . STATUS_ACTIVE, - $object->TableName . '.LastRunStatus <> ' . Agent::LAST_RUN_RUNNING, + $object->TableName . '.LastRunStatus <> ' . ScheduledTask::LAST_RUN_RUNNING, ); $sql = $object->GetSelectSQL() . ' WHERE (' . implode(') AND (', $where_clause) . ')'; - $agents = $this->Conn->Query($sql); + $scheduled_tasks = $this->Conn->Query($sql); - foreach ($agents as $agent_data) { - $agent_data['EventName'] = $agent_data['Event']; - $this->Application->EventManager->runAgent($agent_data); + foreach ($scheduled_tasks as $scheduled_task_data) { + $scheduled_task_data['EventName'] = $scheduled_task_data['Event']; + $this->Application->EventManager->runScheduledTask($scheduled_task_data); } }