Index: branches/5.2.x/core/units/agents/agent_eh.php =================================================================== diff -u -N -r14092 -r14095 --- branches/5.2.x/core/units/agents/agent_eh.php (.../agent_eh.php) (revision 14092) +++ branches/5.2.x/core/units/agents/agent_eh.php (.../agent_eh.php) (revision 14095) @@ -1,6 +1,6 @@ Application->EventManager->getRegularEvents(true); + $regular_events = $this->Application->EventManager->getAgents(true); $object =& $event->getObject( Array ('skip_autoload' => true) ); /* @var $object kDBItem */ $processed_ids = Array (); + $agents = $this->Conn->Query($object->GetSelectSQL(), 'AgentName'); + foreach ($regular_events as $run_mode => $events) { - foreach ($events as $agent_name => $agent_params) { - $object->Load($agent_name, 'AgentName'); - if (!$object->isLoaded()) { + foreach ($events as $agent_name => $agent_params) { + if ( !isset($agents[$agent_name]) ) { $fields_hash = Array ( 'Event' => $agent_params['EventName'], 'AgentName' => $agent_name, - 'AgentType' => AGENT_TYPE_SYSTEM, + 'AgentType' => Agent::AGENT_TYPE_SYSTEM, 'Status' => array_key_exists('Status', $agent_params) ? $agent_params['Status'] : STATUS_ACTIVE, 'RunInterval' => $agent_params['RunInterval'], 'RunMode' => $run_mode, ); + $object->Clear(); $object->SetDBFieldsFromHash($fields_hash); $object->Create(); } + else { + $object->LoadFromHash( $agents[$agent_name] ); + } $processed_ids[] = $object->GetID(); } + } // delete all non-processed agents (ones, that were deleted from unit configs) $sql = 'SELECT ' . $object->IDField . ' FROM ' . $object->TableName . ' - WHERE (AgentType = ' . AGENT_TYPE_SYSTEM . ') AND (' . $object->IDField . ' NOT IN (' . implode(',', $processed_ids) . '))'; + WHERE (AgentType = ' . Agent::AGENT_TYPE_SYSTEM . ') AND (' . $object->IDField . ' NOT IN (' . implode(',', $processed_ids) . '))'; $delete_ids = $this->Conn->GetCol($sql); if ($delete_ids) { @@ -103,7 +109,7 @@ $sql = 'SELECT ' . $id_field . ' FROM ' . $table_name . ' - WHERE ' . $id_field . ' IN (' . implode(',', $ids) . ') AND AgentType <> ' . AGENT_TYPE_SYSTEM; + WHERE ' . $id_field . ' IN (' . implode(',', $ids) . ') AND AgentType <> ' . Agent::AGENT_TYPE_SYSTEM; $allowed_ids = $this->Conn->GetCol($sql); $event->setEventParam('ids', $allowed_ids); @@ -127,9 +133,9 @@ foreach ($ids as $id) { $object->Load($id); - if ($object->GetDBField('LastRunStatus') == AGENT_LAST_RUN_RUNNING) { + if ($object->GetDBField('LastRunStatus') == Agent::LAST_RUN_RUNNING) { // only changes status, doesn't affect currency running agents - $object->SetDBField('LastRunStatus', AGENT_LAST_RUN_FAILED); + $object->SetDBField('LastRunStatus', Agent::LAST_RUN_FAILED); $object->Update(); } }