Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.3] Deprecations: Changes we can make with 5.3 for the actionlog component (Backend) #44261

Open
wants to merge 18 commits into
base: 5.3-dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @package Joomla.Administrator
* @subpackage com_actionlogs
*
* @copyright (C) 2018 Open Source Matters, Inc. <https://www.joomla.org>
* @copyright 2018 Open Source Matters, Inc. <https://www.joomla.org>
rdeutz marked this conversation as resolved.
Show resolved Hide resolved
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

Expand All @@ -14,13 +14,13 @@
use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Date\Date;
use Joomla\CMS\Event\ActionLog\AfterLogExportEvent;
use Joomla\CMS\Input\Input;
use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\Controller\AdminController;
use Joomla\CMS\MVC\Factory\MVCFactoryInterface;
use Joomla\CMS\Router\Route;
use Joomla\Component\Actionlogs\Administrator\Helper\ActionlogsHelper;
use Joomla\Component\Actionlogs\Administrator\Model\ActionlogsModel;
use Joomla\Input\Input;
use Joomla\Utilities\ArrayHelper;

// phpcs:disable PSR1.Files.SideEffects
Expand All @@ -38,8 +38,8 @@ 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).
* 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
Expand Down Expand Up @@ -102,7 +102,8 @@ public function exportLogs()

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

$this->app->setHeader('Content-Type', 'application/csv', true)
$this->app
->setHeader('Content-Type', 'application/csv', true)
->setHeader('Content-Disposition', 'attachment; filename="' . $filename . '.csv"', true)
->setHeader('Cache-Control', 'must-revalidate', true)
->sendHeaders();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,12 @@ protected function getOptions()
->select($db->quoteName('u.id', 'value'))
->select($db->quoteName('u.username', 'text'))
->from($db->quoteName('#__users', 'u'))
->join('INNER', $db->quoteName('#__action_logs', 'c') . ' ON ' . $db->quoteName('c.user_id') . ' = ' . $db->quoteName('u.id'))
->join(
'INNER',
$db->quoteName('#__action_logs', 'c') . ' ON ' . $db->quoteName(
'c.user_id'
) . ' = ' . $db->quoteName('u.id')
)
->group($db->quoteName('u.id'))
->group($db->quoteName('u.username'))
->order($db->quoteName('u.username'));
Expand All @@ -70,7 +75,9 @@ protected function getOptions()
$db->setQuery($query);

// Return the result
if ($options = $db->loadObjectList()) {
$options = $db->loadObjectList();

if ($options) {
static::$options[$hash] = array_merge(static::$options[$hash], $options);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function __construct($form = null)
parent::__construct($form);

// Load the required language
$lang = Factory::getLanguage();
$lang = Factory::getApplication()->getLanguage();
$lang->load('com_actionlogs', JPATH_ADMINISTRATOR);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @package Joomla.Administrator
* @subpackage com_actionlogs
*
* @copyright (C) 2018 Open Source Matters, Inc. <https://www.joomla.org>
* @copyright 2018 Open Source Matters, Inc. <https://www.joomla.org>
rdeutz marked this conversation as resolved.
Show resolved Hide resolved
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

Expand All @@ -15,6 +15,7 @@
use Joomla\CMS\Language\Text;
use Joomla\CMS\Object\CMSObject;
use Joomla\CMS\Router\Route;
use Joomla\Database\DatabaseInterface;
use Joomla\Filesystem\Path;
use Joomla\String\StringHelper;

Expand Down Expand Up @@ -56,8 +57,8 @@ public static function getCsvData($data): \Generator
\sprintf(
'%s() requires an array or object implementing the Traversable interface, a %s was given.',
__METHOD__,
\is_object($data) ? \get_class($data) : \gettype($data)
)
\is_object($data) ? \get_class($data) : \gettype($data),
),
);
}

Expand All @@ -77,7 +78,9 @@ public static function getCsvData($data): \Generator
'extension' => self::escapeCsvFormula(Text::_($extension)),
'date' => (new Date($log->log_date, new \DateTimeZone('UTC')))->format('Y-m-d H:i:s T'),
'name' => self::escapeCsvFormula($log->name),
'ip_address' => self::escapeCsvFormula($log->ip_address === 'COM_ACTIONLOGS_DISABLED' ? $disabledText : $log->ip_address),
'ip_address' => self::escapeCsvFormula(
$log->ip_address === 'COM_ACTIONLOGS_DISABLED' ? $disabledText : $log->ip_address,
),
];
}
}
Expand All @@ -100,7 +103,7 @@ public static function loadTranslationFiles($extension)
return;
}

$lang = Factory::getLanguage();
$lang = Factory::getApplication()->getLanguage();
$source = '';

switch (substr($extension, 0, 3)) {
Expand Down Expand Up @@ -135,11 +138,11 @@ public static function loadTranslationFiles($extension)
}

$lang->load($extension, JPATH_ADMINISTRATOR)
|| $lang->load($extension, $source);
|| $lang->load($extension, $source);

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

$cache[$extension] = true;
Expand All @@ -152,7 +155,7 @@ public static function loadTranslationFiles($extension)
*
* @return mixed An object contains content type parameters, or null if not found
*
* @since 3.9.0
* @since 3.9.0
*
* @deprecated 4.3 will be removed in 6.0
* Use the action log config model instead
Expand Down Expand Up @@ -247,7 +250,13 @@ public static function getContentTypeLink($component, $contentType, $id, $urlVar
if (file_exists($file)) {
$prefix = ucfirst(str_replace('com_', '', $component));
$cName = $prefix . 'Helper';

/*
* @todo
* We want to have all classes as namespaces! We need to know the component namespace so we could
* check if NAMESPACE/getContentTypeLink is callable. Maybe we need to boot the component????
*
* Change can be made with 6.0?? Maybe we need a fallback.
*/
\JLoader::register($cName, $file);

if (class_exists($cName) && \is_callable([$cName, 'getContentTypeLink'])) {
Expand Down Expand Up @@ -280,11 +289,12 @@ public static function loadActionLogPluginsLanguage()
}
$loaded = true;

$lang = Factory::getLanguage();
$db = Factory::getDbo();
$lang = Factory::getApplication()->getLanguage();
$db = Factory::getContainer()->get(DatabaseInterface::class);

// Get all (both enabled and disabled) actionlog plugins
$query = $db->getQuery(true)
$query = $db
->getQuery(true)
->select(
$db->quoteName(
[
Expand All @@ -298,8 +308,8 @@ public static function loadActionLogPluginsLanguage()
'name',
'params',
'id',
]
)
],
),
)
->from($db->quoteName('#__extensions'))
->where($db->quoteName('type') . ' = ' . $db->quote('plugin'))
Expand Down Expand Up @@ -330,7 +340,7 @@ public static function loadActionLogPluginsLanguage()
}

$lang->load($extension, JPATH_ADMINISTRATOR)
|| $lang->load($extension, JPATH_PLUGINS . '/' . $type . '/' . $name);
|| $lang->load($extension, JPATH_PLUGINS . '/' . $type . '/' . $name);
}

// Load plg_system_actionlogs too
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @package Joomla.Administrator
* @subpackage com_actionlogs
*
* @copyright (C) 2018 Open Source Matters, Inc. <https://www.joomla.org>
* @copyright 2018 Open Source Matters, Inc. <https://www.joomla.org>
rdeutz marked this conversation as resolved.
Show resolved Hide resolved
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

Expand Down Expand Up @@ -46,12 +46,18 @@ public function __construct($config = [])
{
if (empty($config['filter_fields'])) {
$config['filter_fields'] = [
'a.id', 'id',
'a.extension', 'extension',
'a.user_id', 'user',
'a.message', 'message',
'a.log_date', 'log_date',
'a.ip_address', 'ip_address',
'a.id',
'id',
'a.extension',
rdeutz marked this conversation as resolved.
Show resolved Hide resolved
'extension',
'a.user_id',
'user',
'a.message',
'message',
'a.log_date',
'log_date',
'a.ip_address',
'ip_address',
'dateRange',
];
}
Expand Down Expand Up @@ -88,11 +94,15 @@ protected function populateState($ordering = 'a.id', $direction = 'desc')
protected function getListQuery()
{
$db = $this->getDatabase();
$query = $db->getQuery(true)
$query = $db
->getQuery(true)
->select('a.*')
->select($db->quoteName('u.name'))
->from($db->quoteName('#__action_logs', 'a'))
->join('LEFT', $db->quoteName('#__users', 'u') . ' ON ' . $db->quoteName('a.user_id') . ' = ' . $db->quoteName('u.id'));
->join(
'LEFT',
$db->quoteName('#__users', 'u') . ' ON ' . $db->quoteName('a.user_id') . ' = ' . $db->quoteName('u.id'),
);

// Get ordering
$fullorderCol = $this->state->get('list.fullordering', 'a.id DESC');
Expand All @@ -107,8 +117,9 @@ protected function getListQuery()

// Apply filter by user
if (!empty($user)) {
$user = (int) $user;
$query->where($db->quoteName('a.user_id') . ' = :userid')
$user = (int)$user;
rdeutz marked this conversation as resolved.
Show resolved Hide resolved
$query
->where($db->quoteName('a.user_id') . ' = :userid')
->bind(':userid', $user, ParameterType::INTEGER);
}

Expand All @@ -118,7 +129,8 @@ protected function getListQuery()
// Apply filter by extension
if (!empty($extension)) {
$extension .= '%';
$query->where($db->quoteName('a.extension') . ' LIKE :extension')
$query
->where($db->quoteName('a.extension') . ' LIKE :extension')
->bind(':extension', $extension);
}

Expand All @@ -134,7 +146,7 @@ protected function getListQuery()
$dStart = $date['dStart']->format('Y-m-d H:i:s');
$dNow = $date['dNow']->format('Y-m-d H:i:s');
$query->where(
$db->quoteName('a.log_date') . ' BETWEEN :dstart AND :dnow'
$db->quoteName('a.log_date') . ' BETWEEN :dstart AND :dnow',
);
$query->bind(':dstart', $dStart);
$query->bind(':dnow', $dNow);
Expand All @@ -146,16 +158,19 @@ protected function getListQuery()

if (!empty($search)) {
if (stripos($search, 'id:') === 0) {
$ids = (int) substr($search, 3);
$query->where($db->quoteName('a.id') . ' = :id')
$ids = (int)substr($search, 3);
$query
->where($db->quoteName('a.id') . ' = :id')
->bind(':id', $ids, ParameterType::INTEGER);
} elseif (stripos($search, 'item_id:') === 0) {
$ids = (int) substr($search, 8);
$query->where($db->quoteName('a.item_id') . ' = :itemid')
$ids = (int)substr($search, 8);
$query
->where($db->quoteName('a.item_id') . ' = :itemid')
->bind(':itemid', $ids, ParameterType::INTEGER);
} else {
$search = '%' . $search . '%';
$query->where($db->quoteName('a.message') . ' LIKE :message')
$query
->where($db->quoteName('a.message') . ' LIKE :message')
->bind(':message', $search);
}
}
Expand Down Expand Up @@ -230,13 +245,17 @@ private function buildDateRange($range)
*/
public function getLogsForItem($extension, $itemId)
{
$itemId = (int) $itemId;
$itemId = (int)$itemId;
$db = $this->getDatabase();
$query = $db->getQuery(true)
$query = $db
->getQuery(true)
->select('a.*')
->select($db->quoteName('u.name'))
->from($db->quoteName('#__action_logs', 'a'))
->join('INNER', $db->quoteName('#__users', 'u') . ' ON ' . $db->quoteName('a.user_id') . ' = ' . $db->quoteName('u.id'))
->join(
'INNER',
$db->quoteName('#__users', 'u') . ' ON ' . $db->quoteName('a.user_id') . ' = ' . $db->quoteName('u.id'),
)
->where($db->quoteName('a.extension') . ' = :extension')
->where($db->quoteName('a.item_id') . ' = :itemid')
->bind(':extension', $extension)
Expand Down Expand Up @@ -305,11 +324,15 @@ public function getLogDataAsIterator($pks = null)
private function getLogDataQuery($pks = null)
{
$db = $this->getDatabase();
$query = $db->getQuery(true)
$query = $db
->getQuery(true)
->select('a.*')
->select($db->quoteName('u.name'))
->from($db->quoteName('#__action_logs', 'a'))
->join('INNER', $db->quoteName('#__users', 'u') . ' ON ' . $db->quoteName('a.user_id') . ' = ' . $db->quoteName('u.id'));
->join(
'INNER',
$db->quoteName('#__users', 'u') . ' ON ' . $db->quoteName('a.user_id') . ' = ' . $db->quoteName('u.id'),
);

if (\is_array($pks) && \count($pks) > 0) {
$pks = ArrayHelper::toInteger($pks);
Expand All @@ -332,14 +355,16 @@ public function delete(&$pks)
{
$keys = ArrayHelper::toInteger($pks);
$db = $this->getDatabase();
$query = $db->getQuery(true)
$query = $db
->getQuery(true)
->delete($db->quoteName('#__action_logs'))
->whereIn($db->quoteName('id'), $keys);
$db->setQuery($query);

try {
$db->execute();
} catch (\RuntimeException $e) {
// @todo: 6.0
rdeutz marked this conversation as resolved.
Show resolved Hide resolved
$this->setError($e->getMessage());

return false;
Expand Down Expand Up @@ -384,7 +409,7 @@ public function getFilterForm($data = [], $loadData = true)
{
$form = parent::getFilterForm($data, $loadData);
$params = ComponentHelper::getParams('com_actionlogs');
$ipLogging = (bool) $params->get('ip_logging', 0);
$ipLogging = (bool)$params->get('ip_logging', 0);

// Add ip sort options to sort dropdown
if ($form && $ipLogging) {
Expand Down
Loading