Attached Files |
run_agent_button.patch [^] (9,741 bytes) 2010-09-11 14:17
[Show Content]
Index: admin/system_presets/simple/agents_agent.php
===================================================================
--- admin/system_presets/simple/agents_agent.php (revision 13931)
+++ admin/system_presets/simple/agents_agent.php (working copy)
@@ -15,7 +15,7 @@
// toolbar buttons
$remove_buttons = Array (
// list of agents
-// 'agent_list' => Array ('new_item', 'edit', 'delete', 'approve', 'decline', 'cancel', 'view', 'dbl-click'),
+// 'agent_list' => Array ('new_item', 'edit', 'delete', 'approve', 'decline', 'process', 'cancel', 'view', 'dbl-click'),
// edit agent
// 'agent_edit' => Array ('select', 'cancel', 'reset_edit', 'prev', 'next'),
Index: core/admin_templates/agents/agent_list.tpl
===================================================================
--- core/admin_templates/agents/agent_list.tpl (revision 13931)
+++ core/admin_templates/agents/agent_list.tpl (working copy)
@@ -47,8 +47,20 @@
)
);
+ a_toolbar.AddButton( new ToolBarSeparator('sep2') );
+
a_toolbar.AddButton(
new ToolBarButton(
+ 'process',
+ '<inp2:m_phrase label="la_ToolTip_Run" escape="1"/>',
+ function() {
+ submit_event('agent', 'OnRunAgents');
+ }
+ )
+ );
+
+ a_toolbar.AddButton(
+ new ToolBarButton(
'cancel',
'<inp2:m_phrase label="la_ToolTip_Cancel" escape="1"/>',
function() {
@@ -57,7 +69,7 @@
)
);
- a_toolbar.AddButton( new ToolBarSeparator('sep2') );
+ a_toolbar.AddButton( new ToolBarSeparator('sep3') );
a_toolbar.AddButton( new ToolBarButton('view', '<inp2:m_phrase label="la_ToolTip_View" escape="1"/>', function() {
show_viewmenu(a_toolbar,'view');
@@ -74,6 +86,6 @@
<inp2:m_RenderElement name="grid" PrefixSpecial="agent" IdField="AgentId" grid="Default"/>
<script type="text/javascript">
- Grids['agent'].SetDependantToolbarButtons( new Array('edit','delete', 'approve', 'decline', 'cancel') );
+ Grids['agent'].SetDependantToolbarButtons( new Array('edit','delete', 'approve', 'decline', 'process', 'cancel') );
</script>
<inp2:m_include t="incs/footer"/>
\ No newline at end of file
Index: core/install/english.lang
===================================================================
--- core/install/english.lang (revision 13931)
+++ core/install/english.lang (working copy)
@@ -1412,6 +1412,7 @@
<PHRASE Label="la_ToolTip_Reset" Module="Core" Type="1">UmVzZXQ=</PHRASE>
<PHRASE Label="la_ToolTip_ResetSettings" Module="Core" Type="1">UmVzZXQgUGVyc2lzdGVudCBTZXR0aW5ncw==</PHRASE>
<PHRASE Label="la_ToolTip_ResetToBase" Module="Core" Type="1">UmVzZXQgVG8gQmFzZQ==</PHRASE>
+ <PHRASE Label="la_ToolTip_Run" Module="Core" Type="1">UnVu</PHRASE>
<PHRASE Label="la_ToolTip_RunSQL" Module="Core" Type="1">UnVuIFNRTA==</PHRASE>
<PHRASE Label="la_ToolTip_save" Module="Core" Type="1">U2F2ZQ==</PHRASE>
<PHRASE Label="la_ToolTip_SaveAsDraft" Module="Core" Type="1">U2F2ZSBhcyBEcmFmdA==</PHRASE>
Index: core/kernel/event_manager.php
===================================================================
--- core/kernel/event_manager.php (revision 13931)
+++ core/kernel/event_manager.php (working copy)
@@ -736,10 +736,15 @@
*/
function RunRegularEvents($event_type = reBEFORE, $from_cron=false)
{
- if (defined('IS_INSTALL')) return ;
- // if RegularEvents are set to run from cron
- if (!$from_cron && $this->Application->ConfigValue('UseCronForRegularEvent')) return ;
+ if (defined('IS_INSTALL')) {
+ return ;
+ }
+ if (!$from_cron && $this->Application->ConfigValue('UseCronForRegularEvent')) {
+ // if RegularEvents are set to run from cron
+ return ;
+ }
+
$agents = $this->getRegularEvents();
$events_source = $agents[$event_type];
@@ -747,58 +752,69 @@
$this->Application->StoreVar('user_id', USER_ROOT, true); // to prevent permission checking inside events, true for optional storage
foreach ($events_source as $short_name => $event_data) {
- $next_run = $event_data['NextRunOn'];
- $last_run = $event_data['LastRunOn'];
+ $event_data['AgentName'] = $short_name;
+ $this->runAgent($event_data);
+ }
- if ($next_run && ($next_run > adodb_mktime())) {
- continue;
- }
- else {
- $event = new kEvent($event_data['EventName']);
- if (!$this->Application->prefixRegistred($event->Prefix)) {
- // don't process agents, left from disabled modules
- continue;
- }
+ $this->Application->StoreVar('user_id', $user_id, true); // true for optional
+ }
- $start_time = adodb_mktime();
- $fields_hash = Array (
- 'LastRunOn' => $start_time,
- 'LastRunStatus' => AGENT_LAST_RUN_RUNNING,
- 'NextRunOn' => $start_time + $event_data['RunInterval'],
- );
+ function runAgent($agent_data)
+ {
+ $next_run = $agent_data['NextRunOn'];
- $this->Conn->doUpdate(
- $fields_hash,
- $this->Application->getUnitOption('agent', 'TableName'),
- 'AgentName = ' . $this->Conn->qstr($short_name)
- );
+ if ($next_run && ($next_run > adodb_mktime())) {
+ return false;
+ }
- $event->redirect = false;
- $this->Application->HandleEvent($event);
+ $last_run = $agent_data['LastRunOn'];
+ $event = new kEvent($agent_data['EventName']);
- $now = adodb_mktime();
- $next_run = $event_data['RunInterval'] ? $start_time + $event_data['RunInterval'] : $now;
+ if (!$this->Application->prefixRegistred($event->Prefix)) {
+ // don't process agents, left from disabled modules
+ return false;
+ }
- while ($next_run < $now) {
- // in case event execution took longer, then RunInterval (don't use <=, because RunInterval can be 0)
- $next_run += $event_data['RunInterval'];
- }
+ $start_time = adodb_mktime();
- $fields_hash = Array (
- 'NextRunOn' => $next_run,
- 'RunTime' => round(($now - $start_time) / 60),
- 'LastRunStatus' => $event->status == erSUCCESS ? AGENT_LAST_RUN_SUCCEDED : AGENT_LAST_RUN_FAILED,
- );
+ // remember, when agent execution started
+ $fields_hash = Array (
+ 'LastRunOn' => $start_time,
+ 'LastRunStatus' => AGENT_LAST_RUN_RUNNING,
+ 'NextRunOn' => $start_time + $agent_data['RunInterval'],
+ );
- $this->Conn->doUpdate(
- $fields_hash,
- $this->Application->getUnitOption('agent', 'TableName'),
- 'AgentName = ' . $this->Conn->qstr($short_name)
- );
- }
+ $this->Conn->doUpdate(
+ $fields_hash,
+ $this->Application->getUnitOption('agent', 'TableName'),
+ 'AgentName = ' . $this->Conn->qstr($agent_data['AgentName'])
+ );
+
+ $event->redirect = false;
+ $this->Application->HandleEvent($event);
+
+ $now = adodb_mktime();
+ $next_run = $agent_data['RunInterval'] ? $start_time + $agent_data['RunInterval'] : $now;
+
+ while ($next_run < $now) {
+ // in case event execution took longer, then RunInterval (don't use <=, because RunInterval can be 0)
+ $next_run += $agent_data['RunInterval'];
}
- $this->Application->StoreVar('user_id', $user_id, true); // true for optional
+ // remember, when agent execution ended
+ $fields_hash = Array (
+ 'NextRunOn' => $next_run,
+ 'RunTime' => round(($now - $start_time) / 60),
+ 'LastRunStatus' => $event->status == erSUCCESS ? AGENT_LAST_RUN_SUCCEDED : AGENT_LAST_RUN_FAILED,
+ );
+
+ $this->Conn->doUpdate(
+ $fields_hash,
+ $this->Application->getUnitOption('agent', 'TableName'),
+ 'AgentName = ' . $this->Conn->qstr($agent_data['AgentName'])
+ );
+
+ return true;
}
/**
Index: core/units/agents/agent_eh.php
===================================================================
--- core/units/agents/agent_eh.php (revision 13931)
+++ core/units/agents/agent_eh.php (working copy)
@@ -26,6 +26,7 @@
$permissions = Array (
'OnMassCancel' => 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
Index: core/units/agents/agents_config.php
===================================================================
--- core/units/agents/agents_config.php (revision 13931)
+++ core/units/agents/agents_config.php (working copy)
@@ -61,7 +61,7 @@
'agent_list' => Array (
'prefixes' => Array ('agent_List'), 'format' => "!la_title_Agents!",
- 'toolbar_buttons' => Array ('new_item', 'edit', 'delete', 'approve', 'decline', 'cancel', 'view', 'dbl-click'),
+ 'toolbar_buttons' => Array ('new_item', 'edit', 'delete', 'approve', 'decline', 'process', 'cancel', 'view', 'dbl-click'),
),
'agent_edit' => Array ('prefixes' => Array ('agent'), 'format' => "#agent_status# '#agent_titlefield#'",
run_agent_button_v2.patch [^] (9,442 bytes) 2010-09-12 05:06
[Show Content]
Index: admin/system_presets/simple/agents_agent.php
===================================================================
--- admin/system_presets/simple/agents_agent.php (revision 13931)
+++ admin/system_presets/simple/agents_agent.php (working copy)
@@ -15,7 +15,7 @@
// toolbar buttons
$remove_buttons = Array (
// list of agents
-// 'agent_list' => Array ('new_item', 'edit', 'delete', 'approve', 'decline', 'cancel', 'view', 'dbl-click'),
+// 'agent_list' => Array ('new_item', 'edit', 'delete', 'approve', 'decline', 'process', 'cancel', 'view', 'dbl-click'),
// edit agent
// 'agent_edit' => Array ('select', 'cancel', 'reset_edit', 'prev', 'next'),
Index: core/admin_templates/agents/agent_list.tpl
===================================================================
--- core/admin_templates/agents/agent_list.tpl (revision 13931)
+++ core/admin_templates/agents/agent_list.tpl (working copy)
@@ -47,8 +47,20 @@
)
);
+ a_toolbar.AddButton( new ToolBarSeparator('sep2') );
+
a_toolbar.AddButton(
new ToolBarButton(
+ 'process',
+ '<inp2:m_phrase label="la_ToolTip_Run" escape="1"/>',
+ function() {
+ submit_event('agent', 'OnRunAgents');
+ }
+ )
+ );
+
+ a_toolbar.AddButton(
+ new ToolBarButton(
'cancel',
'<inp2:m_phrase label="la_ToolTip_Cancel" escape="1"/>',
function() {
@@ -57,7 +69,7 @@
)
);
- a_toolbar.AddButton( new ToolBarSeparator('sep2') );
+ a_toolbar.AddButton( new ToolBarSeparator('sep3') );
a_toolbar.AddButton( new ToolBarButton('view', '<inp2:m_phrase label="la_ToolTip_View" escape="1"/>', function() {
show_viewmenu(a_toolbar,'view');
@@ -74,6 +86,6 @@
<inp2:m_RenderElement name="grid" PrefixSpecial="agent" IdField="AgentId" grid="Default"/>
<script type="text/javascript">
- Grids['agent'].SetDependantToolbarButtons( new Array('edit','delete', 'approve', 'decline', 'cancel') );
+ Grids['agent'].SetDependantToolbarButtons( new Array('edit','delete', 'approve', 'decline', 'process', 'cancel') );
</script>
<inp2:m_include t="incs/footer"/>
\ No newline at end of file
Index: core/install/english.lang
===================================================================
--- core/install/english.lang (revision 13931)
+++ core/install/english.lang (working copy)
@@ -1412,6 +1412,7 @@
<PHRASE Label="la_ToolTip_Reset" Module="Core" Type="1">UmVzZXQ=</PHRASE>
<PHRASE Label="la_ToolTip_ResetSettings" Module="Core" Type="1">UmVzZXQgUGVyc2lzdGVudCBTZXR0aW5ncw==</PHRASE>
<PHRASE Label="la_ToolTip_ResetToBase" Module="Core" Type="1">UmVzZXQgVG8gQmFzZQ==</PHRASE>
+ <PHRASE Label="la_ToolTip_Run" Module="Core" Type="1">UnVu</PHRASE>
<PHRASE Label="la_ToolTip_RunSQL" Module="Core" Type="1">UnVuIFNRTA==</PHRASE>
<PHRASE Label="la_ToolTip_save" Module="Core" Type="1">U2F2ZQ==</PHRASE>
<PHRASE Label="la_ToolTip_SaveAsDraft" Module="Core" Type="1">U2F2ZSBhcyBEcmFmdA==</PHRASE>
Index: core/kernel/event_manager.php
===================================================================
--- core/kernel/event_manager.php (revision 13931)
+++ core/kernel/event_manager.php (working copy)
@@ -736,10 +736,15 @@
*/
function RunRegularEvents($event_type = reBEFORE, $from_cron=false)
{
- if (defined('IS_INSTALL')) return ;
- // if RegularEvents are set to run from cron
- if (!$from_cron && $this->Application->ConfigValue('UseCronForRegularEvent')) return ;
+ if (defined('IS_INSTALL')) {
+ return ;
+ }
+ if (!$from_cron && $this->Application->ConfigValue('UseCronForRegularEvent')) {
+ // if RegularEvents are set to run from cron
+ return ;
+ }
+
$agents = $this->getRegularEvents();
$events_source = $agents[$event_type];
@@ -748,57 +753,67 @@
foreach ($events_source as $short_name => $event_data) {
$next_run = $event_data['NextRunOn'];
- $last_run = $event_data['LastRunOn'];
if ($next_run && ($next_run > adodb_mktime())) {
continue;
}
- else {
- $event = new kEvent($event_data['EventName']);
- if (!$this->Application->prefixRegistred($event->Prefix)) {
- // don't process agents, left from disabled modules
- continue;
- }
- $start_time = adodb_mktime();
- $fields_hash = Array (
- 'LastRunOn' => $start_time,
- 'LastRunStatus' => AGENT_LAST_RUN_RUNNING,
- 'NextRunOn' => $start_time + $event_data['RunInterval'],
- );
+ $event_data['AgentName'] = $short_name;
+ $this->runAgent($event_data);
+ }
- $this->Conn->doUpdate(
- $fields_hash,
- $this->Application->getUnitOption('agent', 'TableName'),
- 'AgentName = ' . $this->Conn->qstr($short_name)
- );
+ $this->Application->StoreVar('user_id', $user_id, true); // true for optional
+ }
- $event->redirect = false;
- $this->Application->HandleEvent($event);
+ function runAgent($agent_data)
+ {
+ $event = new kEvent($agent_data['EventName']);
- $now = adodb_mktime();
- $next_run = $event_data['RunInterval'] ? $start_time + $event_data['RunInterval'] : $now;
+ if (!$this->Application->prefixRegistred($event->Prefix)) {
+ // don't process agents, left from disabled modules
+ return false;
+ }
- while ($next_run < $now) {
- // in case event execution took longer, then RunInterval (don't use <=, because RunInterval can be 0)
- $next_run += $event_data['RunInterval'];
- }
+ $start_time = adodb_mktime();
- $fields_hash = Array (
- 'NextRunOn' => $next_run,
- 'RunTime' => round(($now - $start_time) / 60),
- 'LastRunStatus' => $event->status == erSUCCESS ? AGENT_LAST_RUN_SUCCEDED : AGENT_LAST_RUN_FAILED,
- );
+ // remember, when agent execution started
+ $fields_hash = Array (
+ 'LastRunOn' => $start_time,
+ 'LastRunStatus' => AGENT_LAST_RUN_RUNNING,
+ 'NextRunOn' => $start_time + $agent_data['RunInterval'],
+ );
- $this->Conn->doUpdate(
- $fields_hash,
- $this->Application->getUnitOption('agent', 'TableName'),
- 'AgentName = ' . $this->Conn->qstr($short_name)
- );
- }
+ $this->Conn->doUpdate(
+ $fields_hash,
+ $this->Application->getUnitOption('agent', 'TableName'),
+ 'AgentName = ' . $this->Conn->qstr($agent_data['AgentName'])
+ );
+
+ $event->redirect = false;
+ $this->Application->HandleEvent($event);
+
+ $now = adodb_mktime();
+ $next_run = $agent_data['RunInterval'] ? $start_time + $agent_data['RunInterval'] : $now;
+
+ while ($next_run < $now) {
+ // in case event execution took longer, then RunInterval (don't use <=, because RunInterval can be 0)
+ $next_run += $agent_data['RunInterval'];
}
- $this->Application->StoreVar('user_id', $user_id, true); // true for optional
+ // remember, when agent execution ended
+ $fields_hash = Array (
+ 'NextRunOn' => $next_run,
+ 'RunTime' => round(($now - $start_time) / 60),
+ 'LastRunStatus' => $event->status == erSUCCESS ? AGENT_LAST_RUN_SUCCEDED : AGENT_LAST_RUN_FAILED,
+ );
+
+ $this->Conn->doUpdate(
+ $fields_hash,
+ $this->Application->getUnitOption('agent', 'TableName'),
+ 'AgentName = ' . $this->Conn->qstr($agent_data['AgentName'])
+ );
+
+ return true;
}
/**
Index: core/units/agents/agent_eh.php
===================================================================
--- core/units/agents/agent_eh.php (revision 13931)
+++ core/units/agents/agent_eh.php (working copy)
@@ -26,6 +26,7 @@
$permissions = Array (
'OnMassCancel' => 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
Index: core/units/agents/agents_config.php
===================================================================
--- core/units/agents/agents_config.php (revision 13931)
+++ core/units/agents/agents_config.php (working copy)
@@ -61,7 +61,7 @@
'agent_list' => Array (
'prefixes' => Array ('agent_List'), 'format' => "!la_title_Agents!",
- 'toolbar_buttons' => Array ('new_item', 'edit', 'delete', 'approve', 'decline', 'cancel', 'view', 'dbl-click'),
+ 'toolbar_buttons' => Array ('new_item', 'edit', 'delete', 'approve', 'decline', 'process', 'cancel', 'view', 'dbl-click'),
),
'agent_edit' => Array ('prefixes' => Array ('agent'), 'format' => "#agent_status# '#agent_titlefield#'",
run_agent_button_modules.patch [^] (566 bytes) 2010-09-12 05:07
[Show Content]
Index: units/orders/orders_event_handler.php
===================================================================
--- units/orders/orders_event_handler.php (revision 13931)
+++ units/orders/orders_event_handler.php (working copy)
@@ -3764,6 +3764,11 @@
$this->Conn->Query($sql);
}
+ if ( !is_object($event->MasterEvent) ) {
+ // not called as hook
+ return ;
+ }
+
$pre_expiration = adodb_mktime() + $this->Application->ConfigValue('User_MembershipExpirationReminder') * 3600 * 24;
$to_charge = $this->getRecurringOrders($pre_expiration);
|