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.1][com_actionlog] synch extension to log with email notification #38588

Merged
merged 24 commits into from Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -0,0 +1,74 @@
<?php

/**
* @package Joomla.Administrator
* @subpackage com_actionlogs
*
* @copyright (C) 2018 Open Source Matters, Inc. <https://www.joomla.org>
alikon marked this conversation as resolved.
Show resolved Hide resolved
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

namespace Joomla\Component\Actionlogs\Administrator\Field;

use Joomla\CMS\Application\ApplicationHelper;
use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Factory;
use Joomla\CMS\Form\Field\ListField;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Language\Text;
use Joomla\Component\Actionlogs\Administrator\Helper\ActionlogsHelper;
use Joomla\Database\ParameterType;

/**
* Field to load a list of all users that have logged actions
*
* @since __DEPLOY_VERSION__
*/
class UserlogtypeField extends ListField
{
/**
* The form field type.
*
* @var string
* @since __DEPLOY_VERSION__
*/
protected $type = 'UserLogType';

/**
* Method to get the field options.
*
* @return array The field option objects.
*
* @since __DEPLOY_VERSION__
*/
public function getOptions()
{
$db = $this->getDatabase();
$user = Factory::getApplication()->getIdentity();
$query = $db->getQuery(true)
->select($db->quoteName('extensions'))
->from($db->quoteName('#__action_logs_users'))
->where($db->quoteName('user_id') . ' = :userid')
->bind(':userid', $user->id, ParameterType::INTEGER);

$extensions = $db->setQuery($query)->loadColumn();
$params = ComponentHelper::getParams('com_actionlogs');
$globalExt = $params->get('loggable_extensions', []);
$userExt = substr($extensions[0], 2);
$userExt = substr($userExt,0 , -2);
alikon marked this conversation as resolved.
Show resolved Hide resolved
$userExt = explode('","', $userExt);
$common = array_merge($globalExt, array_intersect($globalExt, $userExt));

$options = [];

foreach ($common as $extension) {
ActionlogsHelper::loadTranslationFiles($extension);
$extensionName = Text::_($extension);
$options[ApplicationHelper::stringURLSafe($extensionName) . '_' . $extension] = HTMLHelper::_('select.option', $extension, $extensionName);
}

ksort($options);

return array_merge(parent::getOptions(), array_values($options));
}
}
65 changes: 65 additions & 0 deletions plugins/system/actionlogs/actionlogs.php
Expand Up @@ -10,6 +10,7 @@
defined('_JEXEC') or die;

use Joomla\CMS\Cache\Cache;
use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Factory;
use Joomla\CMS\Form\Form;
use Joomla\CMS\HTML\HTMLHelper;
Expand Down Expand Up @@ -546,4 +547,68 @@ public static function renderActionlogsExtensions($extensions)

return implode(', ', $extensions);
}

/**
* On Saving extensions logging method
* Method is called when an extension is being saved
*
* @param string $context The extension
* @param Table $table DataBase Table object
* @param boolean $isNew If the extension is new or not
*
* @return void
*
* @since __DEPLOY
alikon marked this conversation as resolved.
Show resolved Hide resolved
*/
public function onExtensionAfterSave($context, $table, $isNew): void
{
if ($table->name !== 'com_actionlogs')
richard67 marked this conversation as resolved.
Show resolved Hide resolved
{
return;
}

$params = ComponentHelper::getParams('com_actionlogs');
$globalExt = (array) $params->get('loggable_extensions', []);

$db = $this->db;

$query = $db->getQuery(true)
->select($db->quoteName(['user_id', 'notify', 'extensions']))
->from($db->quoteName('#__action_logs_users'));

try
{
$values = $db->setQuery($query)->loadObjectList();
}
catch (ExecutionFailureException $e)
{
return;
}

foreach ($values as $item)
{
$userExt = substr($item->extensions, 2);
$userExt = substr($userExt,0 , -2);
$user = explode('","', $userExt);
alikon marked this conversation as resolved.
Show resolved Hide resolved
$common = array_intersect($globalExt, $user);

$extension = '["' . implode('","', $common) . '"]';

$query->clear()
->update($db->quoteName('#__action_logs_users'))
->set($db->quoteName('extensions') . ' = :extension')
->where($db->quoteName('user_id') . ' = :userid')
->bind(':userid', $item->user_id, ParameterType::INTEGER)
->bind(':extension', $extension);

try
{
$db->setQuery($query)->execute();
}
catch (ExecutionFailureException $e)
{
// Do nothing.
}
}
}
}
2 changes: 1 addition & 1 deletion plugins/system/actionlogs/forms/actionlogs.xml
Expand Up @@ -16,7 +16,7 @@
</field>
<field
name="actionlogsExtensions"
type="logtype"
type="userlogtype"
label="PLG_SYSTEM_ACTIONLOGS_EXTENSIONS_NOTIFICATIONS"
multiple="true"
validate="options"
Expand Down