-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[4.2] Convert versionable plugin to services #37929
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
Merged
Merged
Changes from 3 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
a62287f
Convert versionable plugin to services
laoneo 3365a21
Update plugins/behaviour/versionable/src/Extension/Versionable.php
laoneo dd450fe
Merge branch '4.2-dev' into j4/plugins/versions
laoneo fb38b47
Update plugins/behaviour/versionable/src/Extension/Versionable.php
laoneo 4f0d4cd
Update plugins/behaviour/versionable/src/Extension/Versionable.php
laoneo 5af6eaa
language in manifest
laoneo 804666b
new line
laoneo b9dfed9
Merge branch '4.2-dev' into j4/plugins/versions
roland-d File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| <?php | ||
| /** | ||
| * @package Joomla.Plugin | ||
| * @subpackage Behaviour.versionable | ||
| * | ||
| * @copyright (C) 2022 Open Source Matters, Inc. <https://www.joomla.org> | ||
| * @license GNU General Public License version 2 or later; see LICENSE.txt | ||
| */ | ||
|
|
||
| defined('_JEXEC') or die; | ||
|
|
||
| use Joomla\CMS\Extension\PluginInterface; | ||
| use Joomla\CMS\Helper\CMSHelper; | ||
| use Joomla\CMS\Plugin\PluginHelper; | ||
| use Joomla\DI\Container; | ||
| use Joomla\DI\ServiceProviderInterface; | ||
| use Joomla\Event\DispatcherInterface; | ||
| use Joomla\Filter\InputFilter; | ||
| use Joomla\Plugin\Behaviour\Versionable\Extension\Versionable; | ||
|
|
||
| return new class implements ServiceProviderInterface | ||
| { | ||
| /** | ||
| * Registers the service provider with a DI container. | ||
| * | ||
| * @param Container $container The DI container. | ||
| * | ||
| * @return void | ||
| * | ||
| * @since __DEPLOY_VERSION__ | ||
| */ | ||
| public function register(Container $container) | ||
| { | ||
| $container->set( | ||
| PluginInterface::class, | ||
| function (Container $container) | ||
| { | ||
| $dispatcher = $container->get(DispatcherInterface::class); | ||
| $plugin = new Versionable( | ||
| $dispatcher, | ||
| (array) PluginHelper::getPlugin('behaviour', 'versionable'), | ||
| new InputFilter, | ||
| new CMSHelper | ||
| ); | ||
|
|
||
| return $plugin; | ||
| } | ||
| ); | ||
| } | ||
| }; |
169 changes: 169 additions & 0 deletions
169
plugins/behaviour/versionable/src/Extension/Versionable.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,169 @@ | ||
| <?php | ||
| /** | ||
| * @package Joomla.Plugin | ||
| * @subpackage Behaviour.versionable | ||
| * | ||
| * @copyright (C) 2016 Open Source Matters, Inc. <https://www.joomla.org> | ||
| * @license GNU General Public License version 2 or later; see LICENSE.txt | ||
| */ | ||
|
|
||
| namespace Joomla\Plugin\Behaviour\Versionable\Extension; | ||
|
|
||
| defined('_JEXEC') or die; | ||
|
|
||
| use Joomla\CMS\Application\CMSApplicationInterface; | ||
| use Joomla\CMS\Component\ComponentHelper; | ||
| use Joomla\CMS\Event\Table\AfterStoreEvent; | ||
| use Joomla\CMS\Event\Table\BeforeDeleteEvent; | ||
| use Joomla\CMS\Helper\CMSHelper; | ||
| use Joomla\CMS\Plugin\CMSPlugin; | ||
| use Joomla\CMS\Versioning\VersionableTableInterface; | ||
| use Joomla\CMS\Versioning\Versioning; | ||
| use Joomla\Event\DispatcherInterface; | ||
| use Joomla\Event\SubscriberInterface; | ||
| use Joomla\Filter\InputFilter; | ||
|
|
||
| /** | ||
| * Implements the Versionable behaviour which allows extensions to automatically support content history for their content items. | ||
| * | ||
| * This plugin supersedes JTableObserverContenthistory. | ||
| * | ||
| * @since 4.0.0 | ||
| */ | ||
| class Versionable extends CMSPlugin implements SubscriberInterface | ||
| { | ||
| /** | ||
| * Returns an array of events this subscriber will listen to. | ||
| * | ||
| * @return array | ||
| * | ||
| * @since __DEPLOY_VERSION__ | ||
| */ | ||
| public static function getSubscribedEvents(): array | ||
| { | ||
| return [ | ||
| 'onTableAfterStore' => 'onTableAfterStore', | ||
| 'onTableBeforeDelete' => 'onTableBeforeDelete', | ||
| ]; | ||
| } | ||
|
|
||
| /** | ||
| * The application object | ||
| * | ||
| * @var CMSApplicationInterface | ||
| * @since __DEPLOY_VERSION__ | ||
| */ | ||
| protected $app; | ||
|
|
||
| /** | ||
| * The input filter | ||
| * | ||
| * @var InputFilter | ||
| * @since __DEPLOY_VERSION__ | ||
| */ | ||
| private $filter; | ||
|
|
||
| /** | ||
| * The CMS helper | ||
| * | ||
| * @var CMSHelper | ||
| * @since __DEPLOY_VERSION__ | ||
| */ | ||
| private $helper; | ||
|
|
||
| /** | ||
| * Constructor. | ||
| * | ||
| * @param DispatcherInterface $dispatcher The dispatcher | ||
| * @param array $config An optional associative array of configuration settings | ||
| * @param InputFilter $filter The input filter | ||
| * @param CMSHelper $helper The CMS helper | ||
| * | ||
| * @since 4.0.0 | ||
| */ | ||
| public function __construct(DispatcherInterface $dispatcher, array $config, InputFilter $filter, CMSHelper $helper) | ||
| { | ||
| parent::__construct($dispatcher, $config); | ||
|
|
||
| $this->filter = $filter; | ||
| $this->helper = $helper; | ||
| } | ||
|
|
||
| /** | ||
| * Post-processor for $table->store($updateNulls) | ||
| * | ||
| * @param AfterStoreEvent $event The event to handle | ||
| * | ||
| * @return void | ||
| * | ||
| * @since 4.0.0 | ||
| */ | ||
| public function onTableAfterStore(AfterStoreEvent $event) | ||
| { | ||
| // Extract arguments | ||
| /** @var VersionableTableInterface $table */ | ||
| $table = $event['subject']; | ||
| $result = $event['result']; | ||
laoneo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| if (!$result) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| if (!(is_object($table) && $table instanceof VersionableTableInterface)) | ||
laoneo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { | ||
| return; | ||
| } | ||
|
|
||
| // Get the Tags helper and assign the parsed alias | ||
| $typeAlias = $table->getTypeAlias(); | ||
| $aliasParts = explode('.', $typeAlias); | ||
|
|
||
| if ($aliasParts[0] === '' || !ComponentHelper::getParams($aliasParts[0])->get('save_history', 0)) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| $id = $table->getId(); | ||
| $data = $this->helper->getDataObject($table); | ||
| $input = $this->app->input; | ||
| $jform = $input->get('jform', array(), 'array'); | ||
| $versionNote = ''; | ||
|
|
||
| if (isset($jform['version_note'])) | ||
| { | ||
| $versionNote = $this->filter->clean($jform['version_note'], 'string'); | ||
| } | ||
|
|
||
| Versioning::store($typeAlias, $id, $data, $versionNote); | ||
| } | ||
|
|
||
| /** | ||
| * Pre-processor for $table->delete($pk) | ||
| * | ||
| * @param BeforeDeleteEvent $event The event to handle | ||
| * | ||
| * @return void | ||
| * | ||
| * @since 4.0.0 | ||
| */ | ||
| public function onTableBeforeDelete(BeforeDeleteEvent $event) | ||
| { | ||
| // Extract arguments | ||
| /** @var VersionableTableInterface $table */ | ||
| $table = $event['subject']; | ||
|
|
||
| if (!(is_object($table) && $table instanceof VersionableTableInterface)) | ||
roland-d marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { | ||
| return; | ||
| } | ||
|
|
||
| $typeAlias = $table->getTypeAlias(); | ||
| $aliasParts = explode('.', $typeAlias); | ||
|
|
||
| if ($aliasParts[0] && ComponentHelper::getParams($aliasParts[0])->get('save_history', 0)) | ||
| { | ||
| Versioning::delete($typeAlias, $table->getId()); | ||
| } | ||
| } | ||
| } | ||
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.