Admin - add filter for periodic runs

- Store & display exec results for periodic runs
This commit is contained in:
nathangray 2018-09-25 13:17:52 -06:00
parent b7c359a6f1
commit d7c5dc71cf
3 changed files with 48 additions and 5 deletions

View File

@ -498,6 +498,16 @@ abstract class admin_cmd
{ {
$query['col_filter']['remote_id'] = null; $query['col_filter']['remote_id'] = null;
} }
if ((string)$query['col_filter']['periodic'] === '0')
{
$query['col_filter']['rrule'] = null;
}
else if ((string)$query['col_filter']['periodic'] === '1')
{
$query['col_filter'][] = 'cmd_rrule IS NOT NULL';
}
unset($query['col_filter']['periodic']);
return admin_cmd::$sql->get_rows($query,$rows,$readonlys); return admin_cmd::$sql->get_rows($query,$rows,$readonlys);
} }
@ -1048,15 +1058,17 @@ abstract class admin_cmd
// instanciate single periodic execution object // instanciate single periodic execution object
$single = $cmd->as_array(); $single = $cmd->as_array();
$single['parent'] = $single['id']; $single['parent'] = $single['id'];
unset($single['id'], $single['uid'], $single['rrule'], $single['created'], $single['modified'], $single['modifier']); unset($single['id'], $single['uid'], $single['rrule'], $single['created'], $single['modified'], $single['modifier'], $single['async_job_id']);
$periodic = admin_cmd::instanciate($single); $periodic = admin_cmd::instanciate($single);
try { try {
$periodic->run(null, false); $value = $periodic->run(null, false);
} }
catch (Exception $ex) { catch (Exception $ex) {
error_log(__METHOD__."(".array2string($data).") periodic execution failed: ".$ex->getMessage()); error_log(__METHOD__."(".array2string($data).") periodic execution failed: ".$ex->getMessage());
} }
$periodic->value = $value;
$periodic->save();
} }
/** /**

View File

@ -38,6 +38,7 @@ class admin_cmds
if (!$rows) return array(); if (!$rows) return array();
$async = new Api\Asyncservice();
foreach($rows as &$row) foreach($rows as &$row)
{ {
try { try {
@ -47,10 +48,31 @@ class admin_cmds
catch (Exception $e) { catch (Exception $e) {
$row['title'] = $e->getMessage(); $row['title'] = $e->getMessage();
} }
$row['data'] = !($data = json_php_unserialize($row['data'])) ? '' :
json_encode($data+(empty($row['rrule'])?array():array('rrule' => $row['rrule'])),
JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES);
if(method_exists($cmd, 'summary'))
{
$row['data'] = $cmd->summary();
}
else
{
$row['data'] = !($data = json_php_unserialize($row['data'])) ? '' :
json_encode($data+(empty($row['rrule'])?array():array('rrule' => $row['rrule'])),
JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES);
}
if($row['rrule'])
{
$rrule = calendar_rrule::event2rrule(calendar_rrule::parseRrule($row['rrule'],true)+array(
'start' => time(),
'tzid'=> Api\DateTime::$server_timezone->getName()
));
$row['rrule'] = ''.$rrule;
}
if(!$row['scheduled'] && $cmd && $cmd->async_job_id)
{
$job = $async->read($cmd->async_job_id);
$row['scheduled'] = $job ? $job[$cmd->async_job_id]['next'] : null;
}
if ($row['status'] == admin_cmd::scheduled) if ($row['status'] == admin_cmd::scheduled)
{ {
$row['class'] = 'AllowDelete'; $row['class'] = 'AllowDelete';
@ -98,7 +120,12 @@ class admin_cmds
} }
unset($cmd); unset($cmd);
} }
$periodic = array(
0 => 'no',
1 => 'yes'
);
$tpl->exec('admin.admin_cmds.index',$content,array( $tpl->exec('admin.admin_cmds.index',$content,array(
'periodic' => $periodic,
'status' => admin_cmd::$stati, 'status' => admin_cmd::$stati,
'remote_id' => admin_cmd::remote_sites(), 'remote_id' => admin_cmd::remote_sites(),
),array(),$content); ),array(),$content);

View File

@ -11,6 +11,7 @@
<column/> <column/>
<column width="120"/> <column width="120"/>
<column width="120"/> <column width="120"/>
<column width="120"/>
<column width="30%" minWidth="120"/> <column width="30%" minWidth="120"/>
<column/> <column/>
<column/> <column/>
@ -20,6 +21,7 @@
<nextmatch-header label="Title" id="title"/> <nextmatch-header label="Title" id="title"/>
<nextmatch-header label="Requested" id="requested"/> <nextmatch-header label="Requested" id="requested"/>
<nextmatch-sortheader label="Scheduled" id="scheduled"/> <nextmatch-sortheader label="Scheduled" id="scheduled"/>
<nextmatch-filterheader empty_label="Periodic" id="periodic"/>
<nextmatch-filterheader options="Remote" id="remote_id"/> <nextmatch-filterheader options="Remote" id="remote_id"/>
<nextmatch-sortheader label="Created" id="created"/> <nextmatch-sortheader label="Created" id="created"/>
<nextmatch-accountfilter empty_label="Creator" id="creator"/> <nextmatch-accountfilter empty_label="Creator" id="creator"/>
@ -31,12 +33,14 @@
<description id="${row}[title]" statustext="$row_cont[data]"/> <description id="${row}[title]" statustext="$row_cont[data]"/>
<url-email id="${row}[requested_email]" readonly="true" statustext="$row_cont[comment]"/> <url-email id="${row}[requested_email]" readonly="true" statustext="$row_cont[comment]"/>
<date-time id="${row}[scheduled]" readonly="true"/> <date-time id="${row}[scheduled]" readonly="true"/>
<description id="${row}[rrule]"/>
<select id="${row}[remote_id]" readonly="true"/> <select id="${row}[remote_id]" readonly="true"/>
<date-time id="${row}[created]" readonly="true"/> <date-time id="${row}[created]" readonly="true"/>
<select-account id="${row}[creator]" readonly="true" statustext="$row_cont[creator_email]"/> <select-account id="${row}[creator]" readonly="true" statustext="$row_cont[creator_email]"/>
<vbox> <vbox>
<select id="${row}[status]" readonly="true"/> <select id="${row}[status]" readonly="true"/>
<description id="${row}[error]" class="redItalic"/> <description id="${row}[error]" class="redItalic"/>
<description id="${row}[value]"/>
</vbox> </vbox>
<date-time id="${row}[modified]" readonly="true"/> <date-time id="${row}[modified]" readonly="true"/>
<select-account id="${row}[modifier]" readonly="true" statustext="$row_cont[modifier_email]"/> <select-account id="${row}[modifier]" readonly="true" statustext="$row_cont[modifier_email]"/>