Skip to content

Commit

Permalink
Merge branch '4.0-dev' into twelve
Browse files Browse the repository at this point in the history
  • Loading branch information
wilsonge committed Apr 14, 2019
2 parents 4236002 + 5f7bb27 commit 2da9d4c
Show file tree
Hide file tree
Showing 195 changed files with 2,351 additions and 1,482 deletions.
10 changes: 5 additions & 5 deletions .github/SUPPORT.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Where can you get support and help?
====================
* [The Joomla! Documentation](https://docs.joomla.org/Special:MyLanguage/Main_Page);
* [Frequently Asked Questions](https://docs.joomla.org/Special:MyLanguage/Category:FAQ) (FAQ);
* Find the [information you need](https://docs.joomla.org/Special:MyLanguage/Start_here);
* Find [help and other users](https://www.joomla.org/about-joomla/create-and-share.html);
* Post questions at [our forums](https://forum.joomla.org);
* [The Joomla! Documentation](https://docs.joomla.org/Special:MyLanguage/Main_Page).
* [Frequently Asked Questions](https://docs.joomla.org/Special:MyLanguage/Category:FAQ) (FAQ).
* Find the [information you need](https://docs.joomla.org/Special:MyLanguage/Start_here).
* Find [help and other users](https://www.joomla.org/about-joomla/create-and-share.html).
* Post questions at [our forums](https://forum.joomla.org).
* [Joomla Resources Directory](https://resources.joomla.org) (JRD).
31 changes: 27 additions & 4 deletions administrator/components/com_actionlogs/controllers/actionlogs.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function getModel($name = 'Actionlogs', $prefix = 'ActionlogsModel', $con
public function exportLogs()
{
// Check for request forgeries.
JSession::checkToken() or die(JText::_('JINVALID_TOKEN'));
$this->checkToken();

$task = $this->getTask();

Expand All @@ -74,13 +74,33 @@ public function exportLogs()
$pks = ArrayHelper::toInteger(explode(',', $this->input->post->getString('cids')));
}

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

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

if (count($data))
{
$rows = ActionlogsHelper::getCsvData($data);
$filename = 'logs_' . JFactory::getDate()->format('Y-m-d_His_T');

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

return;
}

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

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

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

$app = JFactory::getApplication();
Expand Down Expand Up @@ -116,6 +136,9 @@ public function exportLogs()
*/
public function purge()
{
// Check for request forgeries.
$this->checkToken();

$model = $this->getModel();

if ($model->purge())
Expand Down
71 changes: 47 additions & 24 deletions administrator/components/com_actionlogs/helpers/actionlogs.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

use Joomla\CMS\Filesystem\Path;
use Joomla\String\StringHelper;
use Joomla\Utilities\ArrayHelper;

/**
* Actionlogs component helper.
Expand All @@ -21,37 +20,46 @@
class ActionlogsHelper
{
/**
* Method to convert logs objects array to associative array use for CSV export
* Method to convert logs objects array to an iterable type for use with a CSV export
*
* @param array $data The logs data objects to be exported
* @param array|Traversable $data The logs data objects to be exported
*
* @return array
* @return Generator
*
* @since 3.9.0
* @throws InvalidArgumentException
*/
public static function getCsvData($data)
public static function getCsvData($data): Generator
{
$rows = array();
if (!is_iterable($data))
{
throw new InvalidArgumentException(
sprintf(
'%s() requires an array or object implementing the Traversable interface, a %s was given.',
__METHOD__,
gettype($data) === 'object' ? get_class($data) : gettype($data)
)
);
}

// Header row
$rows[] = array('Id', 'Message', 'Date', 'Extension', 'User', 'Ip');
yield ['Id', 'Message', 'Date', 'Extension', 'User', 'Ip'];

foreach ($data as $log)
{
$extension = strtok($log->extension, '.');

static::loadTranslationFiles($extension);
$row = array();
$row['id'] = $log->id;
$row['message'] = strip_tags(static::getHumanReadableLogMessage($log));
$row['date'] = JHtml::_('date', $log->log_date, JText::_('DATE_FORMAT_LC6'));
$row['extension'] = JText::_($extension);
$row['name'] = $log->name;
$row['ip_address'] = JText::_($log->ip_address);

$rows[] = $row;
}

return $rows;
yield [
'id' => $log->id,
'message' => strip_tags(static::getHumanReadableLogMessage($log, false)),
'date' => (new JDate($log->log_date, new DateTimeZone('UTC')))->format('Y-m-d H:i:s T'),
'extension' => JText::_($extension),
'name' => $log->name,
'ip_address' => JText::_($log->ip_address),
];
}
}

/**
Expand All @@ -66,6 +74,7 @@ public static function getCsvData($data)
public static function loadTranslationFiles($extension)
{
static $cache = array();
$extension = strtolower($extension);

if (isset($cache[$extension]))
{
Expand Down Expand Up @@ -100,8 +109,14 @@ public static function loadTranslationFiles($extension)

}

$lang->load(strtolower($extension), JPATH_ADMINISTRATOR, null, false, true)
|| $lang->load(strtolower($extension), $source, null, false, true);
$lang->load($extension, JPATH_ADMINISTRATOR, null, false, true)
|| $lang->load($extension, $source, null, false, true);

if (!$lang->hasKey(strtoupper($extension)))
{
$lang->load($extension . '.sys', JPATH_ADMINISTRATOR, null, false, true)
|| $lang->load($extension . '.sys', $source, null, false, true);
}

$cache[$extension] = true;
}
Expand Down Expand Up @@ -131,14 +146,17 @@ public static function getLogContentTypeParams($context)
/**
* Get human readable log message for a User Action Log
*
* @param stdClass $log A User Action log message record
* @param stdClass $log A User Action log message record
* @param boolean $generateLinks Flag to disable link generation when creating a message
*
* @return string
*
* @since 3.9.0
*/
public static function getHumanReadableLogMessage($log)
public static function getHumanReadableLogMessage($log, $generateLinks = true)
{
static $links = array();

$message = JText::_($log->message_language_key);
$messageData = json_decode($log->message, true);

Expand All @@ -154,9 +172,14 @@ public static function getHumanReadableLogMessage($log)
foreach ($messageData as $key => $value)
{
// Convert relative url to absolute url so that it is clickable in action logs notification email
if (StringHelper::strpos($value, 'index.php?') === 0)
if ($generateLinks && StringHelper::strpos($value, 'index.php?') === 0)
{
$value = JRoute::link('administrator', $value, false, $linkMode);
if (!isset($links[$value]))
{
$links[$value] = JRoute::link('administrator', $value, false, $linkMode);
}

$value = $links[$value];
}

$message = str_replace('{' . $key . '}', JText::_($value), $message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<?php foreach ($messages as $message) : ?>
<tr>
<td><?php echo $message->message; ?></td>
<td><?php echo $message->log_date; ?></td>
<td><?php echo JHtml::_('date', $message->log_date, 'Y-m-d H:i:s T', 'UTC'); ?></td>
<td><?php echo $message->extension; ?></td>
<td><?php echo $displayData['username']; ?></td>
<?php if ($showIpColumn) : ?>
Expand Down
21 changes: 13 additions & 8 deletions administrator/components/com_actionlogs/models/actionlog.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
defined('_JEXEC') or die;

use Joomla\CMS\Component\ComponentHelper;
use Joomla\Utilities\IpHelper;

JLoader::register('ActionlogsHelper', JPATH_ADMINISTRATOR . '/components/com_actionlogs/helpers/actionlogs.php');

/**
* Methods supporting a list of article records.
* Methods supporting a list of Actionlog records.
*
* @since 3.9.0
*/
Expand Down Expand Up @@ -42,7 +43,7 @@ public function addLog($messages, $messageLanguageKey, $context, $userId = null)

if ($params->get('ip_logging', 0))
{
$ip = JFactory::getApplication()->input->server->get('REMOTE_ADDR', null, 'raw');
$ip = IpHelper::getIp();

if (!filter_var($ip, FILTER_VALIDATE_IP))
{
Expand Down Expand Up @@ -100,9 +101,14 @@ protected function sendNotificationEmails($messages, $username, $context)
$params = ComponentHelper::getParams('com_actionlogs');
$showIpColumn = (bool) $params->get('ip_logging', 0);

$query->select($db->quoteName(array('email', 'params')))
->from($db->quoteName('#__users'))
->where($db->quoteName('params') . ' LIKE ' . $db->quote('%"logs_notification_option":1%'));
$query
->select($db->quoteName(array('u.email', 'l.extensions')))
->from($db->quoteName('#__users', 'u'))
->join(
'INNER',
$db->quoteName('#__action_logs_users', 'l') . ' ON ( ' . $db->quoteName('l.notify') . ' = 1 AND '
. $db->quoteName('l.user_id') . ' = ' . $db->quoteName('u.id') . ')'
);

$db->setQuery($query);

Expand All @@ -121,10 +127,9 @@ protected function sendNotificationEmails($messages, $username, $context)

foreach ($users as $user)
{
$userParams = json_decode($user->params, true);
$extensions = $userParams['logs_notification_extensions'];
$extensions = json_decode($user->extensions, true);

if (in_array(strtok($context, '.'), $extensions))
if ($extensions && in_array(strtok($context, '.'), $extensions))
{
$recipients[] = $user->email;
}
Expand Down
46 changes: 42 additions & 4 deletions administrator/components/com_actionlogs/models/actionlogs.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ protected function getListQuery()
$query = $db->getQuery(true)
->select('a.*, u.name')
->from('#__action_logs AS a')
->innerJoin('#__users AS u ON a.user_id = u.id');
->leftJoin('#__users AS u ON a.user_id = u.id');

// Get ordering
$fullorderCol = $this->state->get('list.fullordering', 'a.id DESC');
Expand Down Expand Up @@ -247,11 +247,51 @@ public function getLogsForItem($extension, $itemId)
/**
* Get logs data into JTable object
*
* @param integer[]|null $pks An optional array of log record IDs to load
*
* @return array All logs in the table
*
* @since 3.9.0
*/
public function getLogsData($pks = null)
{
$db = $this->getDbo();
$query = $this->getLogDataQuery($pks);

$db->setQuery($query);

return $db->loadObjectList();
}

/**
* Get logs data as a database iterator
*
* @param integer[]|null $pks An optional array of log record IDs to load
*
* @return JDatabaseIterator
*
* @since 3.9.0
*/
public function getLogDataAsIterator($pks = null)
{
$db = $this->getDbo();
$query = $this->getLogDataQuery($pks);

$db->setQuery($query);

return $db->getIterator();
}

/**
* Get the query for loading logs data
*
* @param integer[]|null $pks An optional array of log record IDs to load
*
* @return JDatabaseQuery
*
* @since 3.9.0
*/
private function getLogDataQuery($pks = null)
{
$db = $this->getDbo();
$query = $db->getQuery(true)
Expand All @@ -264,9 +304,7 @@ public function getLogsData($pks = null)
$query->where($db->quoteName('a.id') . ' IN (' . implode(',', ArrayHelper::toInteger($pks)) . ')');
}

$db->setQuery($query);

return $db->loadObjectList();
return $query;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
JLoader::register('ActionlogsHelper', JPATH_ADMINISTRATOR . '/components/com_actionlogs/helpers/actionlogs.php');

/**
* Field to load a list of all users that have logged actions
* Field to load a list of all extensions that have logged actions
*
* @since 3.9.0
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
JFormHelper::loadFieldClass('list');

/**
* Form Field to load a list of content authors
* Field to load a list of all users that have logged actions
*
* @since 3.9.0
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
defined('_JEXEC') or die;

use Joomla\CMS\Component\ComponentHelper;
use Joomla\Registry\Registry;
use Joomla\CMS\Plugin\PluginHelper;

JLoader::register('ActionlogsHelper', JPATH_ADMINISTRATOR . '/components/com_actionlogs/helpers/actionlogs.php');

/**
* View class for a list of logs.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
INSERT INTO `#__extensions` (`extension_id`, `package_id`, `name`, `type`, `element`, `folder`, `client_id`, `enabled`, `access`, `protected`, `manifest_cache`, `params`, `custom_data`, `system_data`, `checked_out`, `checked_out_time`, `ordering`, `state`) VALUES
(319, 0, 'mod_latestactions', 'module', 'mod_latestactions', '', 1, 0, 1, 0, '', '{}', '', '', 0, '1970-01-01 00:00:00', 0, 0);
(319, 0, 'mod_latestactions', 'module', 'mod_latestactions', '', 1, 1, 1, 0, '', '{}', '', '', 0, '1970-01-01 00:00:00', 0, 0);
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
INSERT INTO `#__extensions` (`extension_id`, `package_id`, `name`, `type`, `element`, `folder`, `client_id`, `enabled`, `access`, `protected`, `manifest_cache`, `params`, `custom_data`, `system_data`, `checked_out`, `checked_out_time`, `ordering`, `state`) VALUES
(320, 0, 'mod_privacy_dashboard', 'module', 'mod_privacy_dashboard', '', 1, 0, 1, 0, '', '{}', '', '', 0, '1970-01-01 00:00:00', 0, 0);
(320, 0, 'mod_privacy_dashboard', 'module', 'mod_privacy_dashboard', '', 1, 1, 1, 0, '', '{}', '', '', 0, '1970-01-01 00:00:00', 0, 0);
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
INSERT INTO `#__extensions` (`extension_id`, `package_id`, `name`, `type`, `element`, `folder`, `client_id`, `enabled`, `access`, `protected`, `manifest_cache`, `params`, `custom_data`, `system_data`, `checked_out`, `checked_out_time`, `ordering`, `state`) VALUES
(493, 0, 'plg_privacy_actionlogs', 'plugin', 'actionlogs', 'privacy', 0, 0, 1, 0, '', '{}', '', '', 0, '0000-00-00 00:00:00', 0, 0);
(493, 0, 'plg_privacy_actionlogs', 'plugin', 'actionlogs', 'privacy', 0, 1, 1, 0, '', '{}', '', '', 0, '0000-00-00 00:00:00', 0, 0);
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
CREATE TABLE IF NOT EXISTS `#__action_logs_users` (
`user_id` int(11) UNSIGNED NOT NULL,
`notify` tinyint(1) UNSIGNED NOT NULL,
`extensions` text NOT NULL,
PRIMARY KEY (`user_id`),
KEY `idx_notify` (`notify`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 DEFAULT COLLATE=utf8mb4_unicode_ci;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ALTER TABLE `#__action_logs` ADD INDEX `idx_user_id` (`user_id`);
ALTER TABLE `#__action_logs` ADD INDEX `idx_user_id_logdate` (`user_id`, `log_date`);
ALTER TABLE `#__action_logs` ADD INDEX `idx_user_id_extension` (`user_id`, `extension`);
ALTER TABLE `#__action_logs` ADD INDEX `idx_extension_item_id` (`extension`, `item_id`);
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ALTER TABLE `#__privacy_requests` DROP INDEX `idx_checkout`;
ALTER TABLE `#__privacy_requests` DROP COLUMN `checked_out`;
ALTER TABLE `#__privacy_requests` DROP COLUMN `checked_out_time`;

0 comments on commit 2da9d4c

Please sign in to comment.