2017-07-19 18:45:12 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Icinga\Module\Director\Web\Table;
|
|
|
|
|
|
|
|
use Icinga\Module\Director\Util;
|
|
|
|
use ipl\Html\BaseElement;
|
|
|
|
use ipl\Html\Link;
|
|
|
|
use ipl\Web\Table\ZfQueryBasedTable;
|
|
|
|
|
|
|
|
class ActivityLogTable extends ZfQueryBasedTable
|
|
|
|
{
|
|
|
|
protected $filters = [];
|
|
|
|
|
|
|
|
protected $lastDeployedId;
|
|
|
|
|
|
|
|
protected $extraParams = [];
|
|
|
|
|
|
|
|
protected $columnCount;
|
|
|
|
|
2017-07-25 14:20:39 +02:00
|
|
|
protected $hasObjectFilter = false;
|
|
|
|
|
2017-07-19 18:45:12 +02:00
|
|
|
/** @var BaseElement */
|
|
|
|
protected $currentHead;
|
|
|
|
|
|
|
|
/** @var BaseElement */
|
|
|
|
protected $currentBody;
|
|
|
|
|
|
|
|
protected $searchColumns = array(
|
2017-07-26 09:25:58 +02:00
|
|
|
'author',
|
|
|
|
'object_name',
|
|
|
|
'object_type',
|
|
|
|
'action_name',
|
2017-07-19 18:45:12 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
public function assemble()
|
|
|
|
{
|
|
|
|
$this->attributes()->add('class', 'activity-log');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setLastDeployedId($id)
|
|
|
|
{
|
|
|
|
$this->lastDeployedId = $id;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function renderRow($row)
|
|
|
|
{
|
|
|
|
$this->splitByDay($row->ts_change_time);
|
|
|
|
$action = 'action-' . $row->action. ' ';
|
|
|
|
if ($row->id > $this->lastDeployedId) {
|
|
|
|
$action .= 'undeployed';
|
|
|
|
} else {
|
|
|
|
$action .= 'deployed';
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this::tr([
|
|
|
|
$this::td($this->makeLink($row))->setSeparator(' '),
|
|
|
|
$this::td(strftime('%H:%M:%S', $row->ts_change_time))
|
|
|
|
])->addAttributes(['class' => $action]);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function makeLink($row)
|
|
|
|
{
|
2017-07-26 09:25:58 +02:00
|
|
|
$type = $row->object_type;
|
|
|
|
$name = $row->object_name;
|
|
|
|
if (substr($type, 0, 7) === 'icinga_') {
|
|
|
|
$type = substr($type, 7);
|
|
|
|
}
|
|
|
|
|
2017-07-19 18:45:12 +02:00
|
|
|
if (Util::hasPermission('director/showconfig')) {
|
|
|
|
// Later on replacing, service_set -> serviceset
|
|
|
|
|
|
|
|
// multi column key :(
|
2017-07-25 14:20:39 +02:00
|
|
|
if ($type === 'service' || $this->hasObjectFilter) {
|
2017-07-19 18:45:12 +02:00
|
|
|
$object = "\"$name\"";
|
|
|
|
} else {
|
|
|
|
$object = Link::create(
|
|
|
|
"\"$name\"",
|
|
|
|
'director/' . str_replace('_', '', $type),
|
|
|
|
['name' => $name],
|
|
|
|
['title' => $this->translate('Jump to this object')]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return [
|
|
|
|
'[' . $row->author . ']',
|
|
|
|
Link::create(
|
|
|
|
$row->action,
|
2017-08-18 16:55:10 +02:00
|
|
|
'director/config/activity',
|
2017-07-19 18:45:12 +02:00
|
|
|
array_merge(['id' => $row->id], $this->extraParams),
|
|
|
|
['title' => $this->translate('Show details related to this change')]
|
|
|
|
),
|
|
|
|
str_replace('_', ' ', $type),
|
|
|
|
$object
|
|
|
|
];
|
|
|
|
} else {
|
2017-07-26 09:25:58 +02:00
|
|
|
return sprintf(
|
|
|
|
'[%s] %s %s "%s"',
|
|
|
|
$row->author,
|
|
|
|
$row->action,
|
|
|
|
$type,
|
|
|
|
$name
|
|
|
|
);
|
2017-07-19 18:45:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function filterObject($type, $name)
|
|
|
|
{
|
2017-07-25 14:20:39 +02:00
|
|
|
$this->hasObjectFilter = true;
|
2017-07-19 18:45:12 +02:00
|
|
|
$this->filters[] = ['l.object_type = ?', $type];
|
|
|
|
$this->filters[] = ['l.object_name = ?', $name];
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getColumns()
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'author' => 'l.author',
|
|
|
|
'action' => 'l.action_name',
|
|
|
|
'object_name' => 'l.object_name',
|
|
|
|
'object_type' => 'l.object_type',
|
|
|
|
'id' => 'l.id',
|
|
|
|
'change_time' => 'l.change_time',
|
|
|
|
'ts_change_time' => 'UNIX_TIMESTAMP(l.change_time)',
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function prepareQuery()
|
|
|
|
{
|
|
|
|
$query = $this->db()->select()->from(
|
|
|
|
['l' => 'director_activity_log'],
|
|
|
|
$this->getColumns()
|
|
|
|
)->order('change_time DESC')->order('id DESC')->limit(100);
|
|
|
|
|
|
|
|
foreach ($this->filters as $filter) {
|
|
|
|
$query->where($filter[0], $filter[1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $query;
|
|
|
|
}
|
|
|
|
}
|