mirror of
https://github.com/processwire/processwire.git
synced 2025-08-15 11:14:12 +02:00
Minor updates in ProcessLogger, plus this should fix processwire/processwire-issues#1084
This commit is contained in:
@@ -3,7 +3,7 @@
|
|||||||
/**
|
/**
|
||||||
* ProcessWire Logger (Logs Viewer)
|
* ProcessWire Logger (Logs Viewer)
|
||||||
*
|
*
|
||||||
* ProcessWire 3.x, Copyright 2019 by Ryan Cramer
|
* ProcessWire 3.x, Copyright 2023 by Ryan Cramer
|
||||||
* https://processwire.com
|
* https://processwire.com
|
||||||
*
|
*
|
||||||
* @method string formatLogText($text, $logName = '')
|
* @method string formatLogText($text, $logName = '')
|
||||||
@@ -52,7 +52,7 @@ class ProcessLogger extends Process {
|
|||||||
$options['itemLabel2'] = 'when';
|
$options['itemLabel2'] = 'when';
|
||||||
$options['add'] = false;
|
$options['add'] = false;
|
||||||
$options['edit'] = 'view/{name}/';
|
$options['edit'] = 'view/{name}/';
|
||||||
$options['items'] = $this->wire('log')->getLogs(true);
|
$options['items'] = $this->wire()->log->getLogs(true);
|
||||||
$options['sort'] = false;
|
$options['sort'] = false;
|
||||||
|
|
||||||
foreach($options['items'] as $key => $item) {
|
foreach($options['items'] as $key => $item) {
|
||||||
@@ -78,12 +78,14 @@ class ProcessLogger extends Process {
|
|||||||
$this->_x('Entries', 'th'),
|
$this->_x('Entries', 'th'),
|
||||||
$this->_x('Size', 'th'),
|
$this->_x('Size', 'th'),
|
||||||
));
|
));
|
||||||
$logs = $this->wire('log')->getLogs();
|
$logs = $this->wire()->log->getLogs();
|
||||||
foreach($logs as $log) {
|
foreach($logs as $log) {
|
||||||
|
$logName = $log['name'];
|
||||||
|
if(ctype_digit($logName)) $logName = " $logName";
|
||||||
$table->row(array(
|
$table->row(array(
|
||||||
$log['name'] => "./view/$log[name]/",
|
$logName => "./view/$log[name]/",
|
||||||
"<span style='font-size: 0;'>$log[modified] </span>" . wireRelativeTimeStr($log['modified']),
|
"<span style='font-size: 0;'>$log[modified] </span>" . wireRelativeTimeStr($log['modified']),
|
||||||
$this->wire('log')->getTotalEntries($log['name']),
|
$this->wire()->log->getTotalEntries($log['name']),
|
||||||
"<span style='font-size: 0;'>$log[size] </span>" . wireBytesStr($log['size'])
|
"<span style='font-size: 0;'>$log[size] </span>" . wireBytesStr($log['size'])
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
@@ -101,42 +103,46 @@ class ProcessLogger extends Process {
|
|||||||
|
|
||||||
protected function processAction($action, $name) {
|
protected function processAction($action, $name) {
|
||||||
|
|
||||||
if(!$this->wire('input')->post("submit_$action")) {
|
$log = $this->wire()->log;
|
||||||
|
$input = $this->wire()->input;
|
||||||
|
$session = $this->wire()->session;
|
||||||
|
|
||||||
|
if(!$input->post("submit_$action")) {
|
||||||
throw new WireException("Action missing submit");
|
throw new WireException("Action missing submit");
|
||||||
}
|
}
|
||||||
|
|
||||||
if($action != 'download' && !$this->wire('user')->hasPermission('logs-edit')) {
|
if($action != 'download' && !$this->wire()->user->hasPermission('logs-edit')) {
|
||||||
throw new WirePermissionException("You don't have permission to execute that action");
|
throw new WirePermissionException("You don't have permission to execute that action");
|
||||||
}
|
}
|
||||||
|
|
||||||
switch($action) {
|
switch($action) {
|
||||||
|
|
||||||
case 'delete':
|
case 'delete':
|
||||||
if($this->wire('log')->delete($name)) $this->message(sprintf($this->_('Deleted log: %s'), $name));
|
if($log->delete($name)) $this->message(sprintf($this->_('Deleted log: %s'), $name));
|
||||||
$this->wire('session')->redirect($this->wire('page')->url);
|
$session->location($this->wire()->page->url);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'prune':
|
case 'prune':
|
||||||
$days = (int) $this->wire('input')->post('prune_days');
|
$days = (int) $input->post('prune_days');
|
||||||
$qty = $this->wire('log')->prune($name, $days);
|
$qty = $log->prune($name, $days);
|
||||||
$this->message(sprintf($this->_('Pruned "%s" log file (now contains %d entries)'), $name, $qty));
|
$this->message(sprintf($this->_('Pruned "%s" log file (now contains %d entries)'), $name, $qty));
|
||||||
$this->wire('session')->redirect('./');
|
$session->location('./');
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'download':
|
case 'download':
|
||||||
$filename = $this->wire('log')->getFilename($name);
|
$filename = $log->getFilename($name);
|
||||||
if(file_exists($filename)) wireSendFile($filename, array('forceDownload' => true));
|
if(file_exists($filename)) wireSendFile($filename, array('forceDownload' => true));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'add':
|
case 'add':
|
||||||
$text = $this->wire('sanitizer')->text($this->wire('input')->post('add_text'));
|
$text = $this->wire()->sanitizer->text($input->post('add_text'));
|
||||||
if(strlen($text)) {
|
if(strlen($text)) {
|
||||||
$this->wire('log')->save($name, $text);
|
$log->save($name, $text);
|
||||||
$this->message(sprintf($this->_('Saved new log entry to "%s"'), $name));
|
$this->message(sprintf($this->_('Saved new log entry to "%s"'), $name));
|
||||||
} else {
|
} else {
|
||||||
$this->error($this->_('Log entry text was blank'));
|
$this->error($this->_('Log entry text was blank'));
|
||||||
}
|
}
|
||||||
$this->wire('session')->redirect('./');
|
$session->location('./');
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -155,7 +161,7 @@ class ProcessLogger extends Process {
|
|||||||
$logs = $log->getLogs();
|
$logs = $log->getLogs();
|
||||||
if(!isset($logs[$name])) {
|
if(!isset($logs[$name])) {
|
||||||
$this->error(sprintf('Unknown log: %s', $name));
|
$this->error(sprintf('Unknown log: %s', $name));
|
||||||
$session->redirect('../');
|
$session->location('../');
|
||||||
}
|
}
|
||||||
$action = $input->post('action');
|
$action = $input->post('action');
|
||||||
if($action) $this->processAction($action, $name);
|
if($action) $this->processAction($action, $name);
|
||||||
@@ -277,6 +283,7 @@ class ProcessLogger extends Process {
|
|||||||
$f->showIf = 'action=prune';
|
$f->showIf = 'action=prune';
|
||||||
$fieldset->add($f);
|
$fieldset->add($f);
|
||||||
|
|
||||||
|
/** @var InputfieldSubmit $f */
|
||||||
$f = $modules->get('InputfieldSubmit');
|
$f = $modules->get('InputfieldSubmit');
|
||||||
$f->value = $this->_('Burn this log now (permanently delete)');
|
$f->value = $this->_('Burn this log now (permanently delete)');
|
||||||
$f->icon = 'fire';
|
$f->icon = 'fire';
|
||||||
@@ -284,6 +291,7 @@ class ProcessLogger extends Process {
|
|||||||
$f->showIf = 'action=delete';
|
$f->showIf = 'action=delete';
|
||||||
$fieldset->add($f);
|
$fieldset->add($f);
|
||||||
|
|
||||||
|
/** @var InputfieldSubmit $f */
|
||||||
$f = $modules->get('InputfieldSubmit');
|
$f = $modules->get('InputfieldSubmit');
|
||||||
$f->value = $this->_('Add this log entry');
|
$f->value = $this->_('Add this log entry');
|
||||||
$f->icon = 'leaf';
|
$f->icon = 'leaf';
|
||||||
@@ -351,11 +359,10 @@ class ProcessLogger extends Process {
|
|||||||
|
|
||||||
protected function renderLog(array $items, $name, $time = 0) {
|
protected function renderLog(array $items, $name, $time = 0) {
|
||||||
|
|
||||||
/** @var Sanitizer $sanitizer */
|
$sanitizer = $this->wire()->sanitizer;
|
||||||
$sanitizer = $this->wire('sanitizer');
|
|
||||||
|
|
||||||
/** @var MarkupAdminDataTable $table */
|
/** @var MarkupAdminDataTable $table */
|
||||||
$table = $this->wire('modules')->get('MarkupAdminDataTable');
|
$table = $this->wire()->modules->get('MarkupAdminDataTable');
|
||||||
$table->setSortable(false);
|
$table->setSortable(false);
|
||||||
$table->setEncodeEntities(false);
|
$table->setEncodeEntities(false);
|
||||||
$templateItem = reset($items);
|
$templateItem = reset($items);
|
||||||
@@ -387,7 +394,7 @@ class ProcessLogger extends Process {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(strpos($entry['text'], '&') !== false) {
|
if(strpos($entry['text'], '&') !== false) {
|
||||||
$entry['text'] = $this->wire('sanitizer')->unentities($entry['text']);
|
$entry['text'] = $sanitizer->unentities($entry['text']);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach($entry as $key => $value) {
|
foreach($entry as $key => $value) {
|
||||||
@@ -415,6 +422,7 @@ class ProcessLogger extends Process {
|
|||||||
$table->row($row);
|
$table->row($row);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @var LogEntriesArray $entries */
|
||||||
$entries = $this->wire(new LogEntriesArray());
|
$entries = $this->wire(new LogEntriesArray());
|
||||||
|
|
||||||
if(count($items)) {
|
if(count($items)) {
|
||||||
@@ -427,7 +435,7 @@ class ProcessLogger extends Process {
|
|||||||
$entries->setStart($start);
|
$entries->setStart($start);
|
||||||
$entries->setTotal($total);
|
$entries->setTotal($total);
|
||||||
/** @var MarkupPagerNav $pager */
|
/** @var MarkupPagerNav $pager */
|
||||||
$pager = $this->wire('modules')->get('MarkupPagerNav');
|
$pager = $this->wire()->modules->get('MarkupPagerNav');
|
||||||
$options = array('baseUrl' => "../$name/");
|
$options = array('baseUrl' => "../$name/");
|
||||||
$pagerOut = $pager->render($entries, $options);
|
$pagerOut = $pager->render($entries, $options);
|
||||||
$pagerHeadline = $entries->getPaginationString();
|
$pagerHeadline = $entries->getPaginationString();
|
||||||
@@ -474,7 +482,7 @@ class ProcessLogger extends Process {
|
|||||||
$url = preg_replace('{^https?://[^/]+}', '', $url);
|
$url = preg_replace('{^https?://[^/]+}', '', $url);
|
||||||
}
|
}
|
||||||
|
|
||||||
$config = $this->wire('config');
|
$config = $this->wire()->config;
|
||||||
$rootUrl = $config->urls->root;
|
$rootUrl = $config->urls->root;
|
||||||
$adminUrl = $config->urls->admin;
|
$adminUrl = $config->urls->admin;
|
||||||
$isAdmin = false;
|
$isAdmin = false;
|
||||||
@@ -509,7 +517,7 @@ class ProcessLogger extends Process {
|
|||||||
*/
|
*/
|
||||||
protected function ___formatLogText($text, $logName = '') {
|
protected function ___formatLogText($text, $logName = '') {
|
||||||
|
|
||||||
$config = $this->wire('config');
|
$config = $this->wire()->config;
|
||||||
|
|
||||||
// shorten paths
|
// shorten paths
|
||||||
foreach(array('site', 'wire') as $name) {
|
foreach(array('site', 'wire') as $name) {
|
||||||
@@ -565,4 +573,3 @@ class ProcessLogger extends Process {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user