Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
46 changes: 23 additions & 23 deletions administrator/components/com_actionlogs/services/provider.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* @package Joomla.Administrator
* @subpackage com_actionlogs
Expand All @@ -25,30 +26,29 @@
*/
return new class implements ServiceProviderInterface
{
/**
* Registers the service provider with a DI container.
*
* @param Container $container The DI container.
*
* @return void
*
* @since 4.0.0
*/
public function register(Container $container)
{
$container->registerServiceProvider(new MVCFactory('\\Joomla\\Component\\Actionlogs'));
$container->registerServiceProvider(new ComponentDispatcherFactory('\\Joomla\\Component\\Actionlogs'));
/**
* Registers the service provider with a DI container.
*
* @param Container $container The DI container.
*
* @return void
*
* @since 4.0.0
*/
public function register(Container $container)
{
$container->registerServiceProvider(new MVCFactory('\\Joomla\\Component\\Actionlogs'));
$container->registerServiceProvider(new ComponentDispatcherFactory('\\Joomla\\Component\\Actionlogs'));

$container->set(
ComponentInterface::class,
function (Container $container)
{
$component = new MVCComponent($container->get(ComponentDispatcherFactoryInterface::class));
$container->set(
ComponentInterface::class,
function (Container $container) {
$component = new MVCComponent($container->get(ComponentDispatcherFactoryInterface::class));

$component->setMVCFactory($container->get(MVCFactoryInterface::class));
$component->setMVCFactory($container->get(MVCFactoryInterface::class));

return $component;
}
);
}
return $component;
}
);
}
};
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* @package Joomla.Administrator
* @subpackage com_actionlogs
Expand All @@ -9,8 +10,6 @@

namespace Joomla\Component\Actionlogs\Administrator\Controller;

\defined('_JEXEC') or die;

use DateTimeZone;
use Exception;
use InvalidArgumentException;
Expand All @@ -33,142 +32,131 @@
*/
class ActionlogsController extends AdminController
{
/**
* Constructor.
*
* @param array $config An optional associative array of configuration settings.
* Recognized key values include 'name', 'default_task', 'model_path', and
* 'view_path' (this list is not meant to be comprehensive).
* @param MVCFactoryInterface $factory The factory.
* @param CMSApplication $app The Application for the dispatcher
* @param Input $input Input
*
* @since 3.9.0
*
* @throws Exception
*/
public function __construct($config = [], MVCFactoryInterface $factory = null, $app = null, $input = null)
{
parent::__construct($config, $factory, $app, $input);

$this->registerTask('exportSelectedLogs', 'exportLogs');
}

/**
* Method to export logs
*
* @return void
*
* @since 3.9.0
*
* @throws Exception
*/
public function exportLogs()
{
// Check for request forgeries.
$this->checkToken();

$task = $this->getTask();

$pks = array();

if ($task == 'exportSelectedLogs')
{
// Get selected logs
$pks = ArrayHelper::toInteger(explode(',', $this->input->post->getString('cids')));
}

/** @var ActionlogsModel $model */
$model = $this->getModel();

// Get the logs data
$data = $model->getLogDataAsIterator($pks);

if (\count($data))
{
try
{
$rows = ActionlogsHelper::getCsvData($data);
}
catch (InvalidArgumentException $exception)
{
$this->setMessage(Text::_('COM_ACTIONLOGS_ERROR_COULD_NOT_EXPORT_DATA'), 'error');
$this->setRedirect(Route::_('index.php?option=com_actionlogs&view=actionlogs', false));

return;
}

// Destroy the iterator now
unset($data);

$date = new Date('now', new DateTimeZone('UTC'));
$filename = 'logs_' . $date->format('Y-m-d_His_T');

$csvDelimiter = ComponentHelper::getComponent('com_actionlogs')->getParams()->get('csv_delimiter', ',');

$this->app->setHeader('Content-Type', 'application/csv', true)
->setHeader('Content-Disposition', 'attachment; filename="' . $filename . '.csv"', true)
->setHeader('Cache-Control', 'must-revalidate', true)
->sendHeaders();

$output = fopen("php://output", "w");

foreach ($rows as $row)
{
fputcsv($output, $row, $csvDelimiter);
}

fclose($output);
$this->app->triggerEvent('onAfterLogExport', array());
$this->app->close();
}
else
{
$this->setMessage(Text::_('COM_ACTIONLOGS_NO_LOGS_TO_EXPORT'));
$this->setRedirect(Route::_('index.php?option=com_actionlogs&view=actionlogs', false));
}
}

/**
* Method to get a model object, loading it if required.
*
* @param string $name The model name. Optional.
* @param string $prefix The class prefix. Optional.
* @param array $config Configuration array for model. Optional.
*
* @return object The model.
*
* @since 3.9.0
*/
public function getModel($name = 'Actionlogs', $prefix = 'Administrator', $config = ['ignore_request' => true])
{
// Return the model
return parent::getModel($name, $prefix, $config);
}

/**
* Clean out the logs
*
* @return void
*
* @since 3.9.0
*/
public function purge()
{
// Check for request forgeries.
$this->checkToken();

$model = $this->getModel();

if ($model->purge())
{
$message = Text::_('COM_ACTIONLOGS_PURGE_SUCCESS');
}
else
{
$message = Text::_('COM_ACTIONLOGS_PURGE_FAIL');
}

$this->setRedirect(Route::_('index.php?option=com_actionlogs&view=actionlogs', false), $message);
}
/**
* Constructor.
*
* @param array $config An optional associative array of configuration settings.
* Recognized key values include 'name', 'default_task', 'model_path', and
* 'view_path' (this list is not meant to be comprehensive).
* @param MVCFactoryInterface $factory The factory.
* @param CMSApplication $app The Application for the dispatcher
* @param Input $input Input
*
* @since 3.9.0
*
* @throws Exception
*/
public function __construct($config = [], MVCFactoryInterface $factory = null, $app = null, $input = null)
{
parent::__construct($config, $factory, $app, $input);

$this->registerTask('exportSelectedLogs', 'exportLogs');
}

/**
* Method to export logs
*
* @return void
*
* @since 3.9.0
*
* @throws Exception
*/
public function exportLogs()
{
// Check for request forgeries.
$this->checkToken();

$task = $this->getTask();

$pks = array();

if ($task == 'exportSelectedLogs') {
// Get selected logs
$pks = ArrayHelper::toInteger(explode(',', $this->input->post->getString('cids')));
}

/** @var ActionlogsModel $model */
$model = $this->getModel();

// Get the logs data
$data = $model->getLogDataAsIterator($pks);

if (\count($data)) {
try {
$rows = ActionlogsHelper::getCsvData($data);
} catch (InvalidArgumentException $exception) {
$this->setMessage(Text::_('COM_ACTIONLOGS_ERROR_COULD_NOT_EXPORT_DATA'), 'error');
$this->setRedirect(Route::_('index.php?option=com_actionlogs&view=actionlogs', false));

return;
}

// Destroy the iterator now
unset($data);

$date = new Date('now', new DateTimeZone('UTC'));
$filename = 'logs_' . $date->format('Y-m-d_His_T');

$csvDelimiter = ComponentHelper::getComponent('com_actionlogs')->getParams()->get('csv_delimiter', ',');

$this->app->setHeader('Content-Type', 'application/csv', true)
->setHeader('Content-Disposition', 'attachment; filename="' . $filename . '.csv"', true)
->setHeader('Cache-Control', 'must-revalidate', true)
->sendHeaders();

$output = fopen("php://output", "w");

foreach ($rows as $row) {
fputcsv($output, $row, $csvDelimiter);
}

fclose($output);
$this->app->triggerEvent('onAfterLogExport', array());
$this->app->close();
} else {
$this->setMessage(Text::_('COM_ACTIONLOGS_NO_LOGS_TO_EXPORT'));
$this->setRedirect(Route::_('index.php?option=com_actionlogs&view=actionlogs', false));
}
}

/**
* Method to get a model object, loading it if required.
*
* @param string $name The model name. Optional.
* @param string $prefix The class prefix. Optional.
* @param array $config Configuration array for model. Optional.
*
* @return object The model.
*
* @since 3.9.0
*/
public function getModel($name = 'Actionlogs', $prefix = 'Administrator', $config = ['ignore_request' => true])
{
// Return the model
return parent::getModel($name, $prefix, $config);
}

/**
* Clean out the logs
*
* @return void
*
* @since 3.9.0
*/
public function purge()
{
// Check for request forgeries.
$this->checkToken();

$model = $this->getModel();

if ($model->purge()) {
$message = Text::_('COM_ACTIONLOGS_PURGE_SUCCESS');
} else {
$message = Text::_('COM_ACTIONLOGS_PURGE_FAIL');
}

$this->setRedirect(Route::_('index.php?option=com_actionlogs&view=actionlogs', false), $message);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* @package Joomla.Administrator
* @subpackage com_actionlogs
Expand All @@ -9,8 +10,6 @@

namespace Joomla\Component\Actionlogs\Administrator\Controller;

\defined('_JEXEC') or die;

use Joomla\CMS\MVC\Controller\BaseController;

/**
Expand All @@ -20,11 +19,11 @@
*/
class DisplayController extends BaseController
{
/**
* The default view.
*
* @var string
* @since 1.6
*/
protected $default_view = 'actionlogs';
/**
* The default view.
*
* @var string
* @since 1.6
*/
protected $default_view = 'actionlogs';
}
Loading