Skip to content

[action logs] Add action log plugin library class#22389

Merged
mbabker merged 3 commits intojoomla:stagingfrom
Digital-Peak:j3/action/log
Oct 6, 2018
Merged

[action logs] Add action log plugin library class#22389
mbabker merged 3 commits intojoomla:stagingfrom
Digital-Peak:j3/action/log

Conversation

@laoneo
Copy link
Member

@laoneo laoneo commented Sep 26, 2018

Summary of Changes

As extension dev, I like to do as less repetitive work as possible. This pr adds a base class extension devs can use to log actions more convenient. For example a plugin can then look like:

JLoader::import('com_actionlogs.libraries.actionlogplugin', JPATH_ADMINISTRATOR . '/components');

class PlgActionlogFoo extends ActionLogPlugin
{
	public function onContentAfterSave($context, $item, $isNew)
	{
		if ($context != 'com_foo.bar')
		{
			return;
		}

		$message = array(
			'action'   => $isNew ? 'add' : 'update',
			'type'     => 'PLG_ACTIONLOG_FOO_TYPE_BAR',
			'id'       => $item->id,
			'title'    => $item->title,
			'itemlink' => 'index.php?option=com_foo&task=edit&id=' . $item->id
		);

		$this->addLog(array($message), 'PLG_ACTIONLOG_FOO_' . $message['action'], $context);
	}
}

Additionally it simplifies the default Joomla log plugin.

Testing Instructions

Save an article.

Expected result

An action log is created.

Actual result

An action log is created.

Documentation Changes Required

Document that a base class exists.

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

JLoader::import('com_actionlogs.libraries.actionlogplugin', JPATH_ADMINISTRATOR . '/components');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use JLoader::register() the same way that is done for the privacy plugins please.

$messages[$index] = $message;
}

/* @var ActionlogsModelActionlog $model */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be /** @var ... for IDEs to correctly pick up this inline doc block. Otherwise it's just seen as a "normal" comment.

Copy link
Member Author

@laoneo laoneo Sep 27, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In PHPStorm it works also with one *. But I will change it. There are more places to cleanup then.

@laoneo
Copy link
Member Author

laoneo commented Sep 27, 2018

Done the changes.

@ciar4n
Copy link
Contributor

ciar4n commented Oct 3, 2018

I have tested this item ✅ successfully on d48be2f

Action log created after save


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/22389.

@infograf768
Copy link
Member

I have tested this item ✅ successfully on d48be2f


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/22389.

@infograf768
Copy link
Member

RTC.


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/22389.

@joomla-cms-bot joomla-cms-bot added the RTC This Pull Request is Ready To Commit label Oct 4, 2018
@infograf768
Copy link
Member

Note:
The plugin uses the list() method which can be confusing depending on the php version.

@joomla-cms-bot joomla-cms-bot removed the RTC This Pull Request is Ready To Commit label Oct 6, 2018
@laoneo laoneo deleted the j3/action/log branch October 7, 2018 12:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants