2014-05-03 10:54:40 +02:00
|
|
|
<?php
|
2014-05-04 09:11:08 +02:00
|
|
|
class GetLogJob extends AbstractPageJob
|
2014-05-03 10:54:40 +02:00
|
|
|
{
|
|
|
|
public function execute()
|
|
|
|
{
|
2014-05-04 09:11:08 +02:00
|
|
|
$pageSize = $this->getPageSize();
|
2014-05-03 11:43:29 +02:00
|
|
|
$page = $this->getArgument(self::PAGE_NUMBER);
|
|
|
|
$name = $this->getArgument(self::LOG_ID);
|
|
|
|
$query = $this->getArgument(self::QUERY);
|
2014-05-03 10:54:40 +02:00
|
|
|
|
|
|
|
//parse input
|
|
|
|
$page = max(1, intval($page));
|
|
|
|
$name = str_replace(['/', '\\'], '', $name); //paranoia mode
|
|
|
|
$path = TextHelper::absolutePath(getConfig()->main->logsPath . DS . $name);
|
|
|
|
if (!file_exists($path))
|
|
|
|
throw new SimpleNotFoundException('Specified log doesn\'t exist');
|
|
|
|
|
|
|
|
//load lines
|
|
|
|
$lines = file_get_contents($path);
|
|
|
|
$lines = explode(PHP_EOL, str_replace(["\r", "\n"], PHP_EOL, $lines));
|
|
|
|
$lines = array_reverse($lines);
|
|
|
|
|
|
|
|
if (!empty($filter))
|
|
|
|
{
|
|
|
|
$lines = array_filter($lines, function($line) use ($filter)
|
|
|
|
{
|
|
|
|
return stripos($line, $filter) !== false;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
$lineCount = count($lines);
|
2014-05-04 09:11:08 +02:00
|
|
|
$lines = array_slice($lines, ($page - 1) * $pageSize, $pageSize);
|
|
|
|
|
|
|
|
return $this->getPager($lines, $lineCount, $page, $pageSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getDefaultPageSize()
|
|
|
|
{
|
|
|
|
return intval(getConfig()->browsing->logsPerPage);
|
2014-05-03 10:54:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function requiresPrivilege()
|
|
|
|
{
|
|
|
|
return Privilege::ViewLog;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function requiresAuthentication()
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function requiresConfirmedEmail()
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|