Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -10,6 +10,7 @@

namespace Joomla\Component\Finder\Administrator\Controller;

use Joomla\CMS\Event\Finder\GarbageCollectionEvent;
use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\Controller\AdminController;
use Joomla\CMS\Plugin\PluginHelper;
Expand Down Expand Up @@ -53,9 +54,11 @@ public function optimise()
{
$this->checkToken();

$dispatcher = $this->getDispatcher();

// Optimise the index by first running the garbage collection
PluginHelper::importPlugin('finder');
$this->app->triggerEvent('onFinderGarbageCollection');
PluginHelper::importPlugin('finder', null, true, $dispatcher);
$dispatcher->dispatch('onFinderGarbageCollection', new GarbageCollectionEvent('onFinderGarbageCollection', []));

// Now run the optimisation method from the indexer
$indexer = new Indexer();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
namespace Joomla\Component\Finder\Administrator\Controller;

use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Event\Finder\BeforeIndexEvent;
use Joomla\CMS\Event\Finder\BuildIndexEvent;
use Joomla\CMS\Event\Finder\StartIndexEvent;
use Joomla\CMS\Factory;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Log\Log;
Expand Down Expand Up @@ -50,7 +53,8 @@ public function start()
return;
}

$params = ComponentHelper::getParams('com_finder');
$params = ComponentHelper::getParams('com_finder');
$dispatcher = $this->getDispatcher();

if ($params->get('enable_logging', '0')) {
$options['format'] = '{DATE}\t{TIME}\t{LEVEL}\t{CODE}\t{MESSAGE}';
Expand All @@ -75,7 +79,7 @@ public function start()
Indexer::resetState();

// Import the finder plugins.
PluginHelper::importPlugin('finder');
PluginHelper::importPlugin('finder', null, true, $dispatcher);

// Add the indexer language to \JS
Text::script('COM_FINDER_AN_ERROR_HAS_OCCURRED');
Expand All @@ -84,7 +88,7 @@ public function start()
// Start the indexer.
try {
// Trigger the onStartIndex event.
$this->app->triggerEvent('onStartIndex');
$dispatcher->dispatch('onStartIndex', new StartIndexEvent('onStartIndex', []));

// Get the indexer state.
$state = Indexer::getState();
Expand Down Expand Up @@ -120,7 +124,8 @@ public function batch()
return;
}

$params = ComponentHelper::getParams('com_finder');
$params = ComponentHelper::getParams('com_finder');
$dispatcher = $this->getDispatcher();

if ($params->get('enable_logging', '0')) {
$options['format'] = '{DATE}\t{TIME}\t{LEVEL}\t{CODE}\t{MESSAGE}';
Expand Down Expand Up @@ -154,7 +159,7 @@ public function batch()
Indexer::setState($state);

// Import the finder plugins.
PluginHelper::importPlugin('finder');
PluginHelper::importPlugin('finder', null, true, $dispatcher);

/*
* We are going to swap out the raw document object with an HTML document
Expand All @@ -175,10 +180,10 @@ public function batch()
// Start the indexer.
try {
// Trigger the onBeforeIndex event.
$this->app->triggerEvent('onBeforeIndex');
$dispatcher->dispatch('onBeforeIndex', new BeforeIndexEvent('onBeforeIndex', []));

// Trigger the onBuildIndex event.
$this->app->triggerEvent('onBuildIndex');
$dispatcher->dispatch('onBuildIndex', new BuildIndexEvent('onBuildIndex', []));

// Get the indexer state.
$state = Indexer::getState();
Expand Down Expand Up @@ -230,7 +235,7 @@ public function optimize()
ob_start();

// Import the finder plugins.
PluginHelper::importPlugin('finder');
PluginHelper::importPlugin('finder', null, true, $this->getDispatcher());

try {
// Optimize the index
Expand Down
4 changes: 4 additions & 0 deletions libraries/src/Event/CoreEventAware.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,10 @@ trait CoreEventAware
'onFinderAfterSave' => Finder\AfterSaveEvent::class,
'onFinderResult' => Finder\ResultEvent::class,
'onPrepareFinderContent' => Finder\PrepareContentEvent::class,
'onBeforeIndex' => Finder\BeforeIndexEvent::class,
'onBuildIndex' => Finder\BuildIndexEvent::class,
'onStartIndex' => Finder\StartIndexEvent::class,
'onFinderGarbageCollection' => Finder\GarbageCollectionEvent::class,
];

/**
Expand Down
6 changes: 3 additions & 3 deletions libraries/src/Event/Finder/AbstractFinderEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ public function __construct($name, array $arguments = [])
$arguments = $this->reshapeArguments($arguments, $this->legacyArgumentsOrder);
}

if (!\array_key_exists('subject', $arguments)) {
parent::__construct($name, $arguments);

if (!\array_key_exists('subject', $this->arguments)) {
throw new \BadMethodCallException("Argument 'subject' of event {$name} is required but has not been provided");
}

parent::__construct($name, $arguments);
}
}
27 changes: 27 additions & 0 deletions libraries/src/Event/Finder/BeforeIndexEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

/**
* Joomla! Content Management System
*
* @copyright (C) 2023 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

namespace Joomla\CMS\Event\Finder;

use Joomla\CMS\Event\AbstractImmutableEvent;

// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects

/**
* Class for Finder events.
* Example:
* new BeforeIndexEvent('onEventName', []);
*
* @since __DEPLOY_VERSION__
*/
class BeforeIndexEvent extends AbstractImmutableEvent implements FinderEventInterface
{
}
27 changes: 27 additions & 0 deletions libraries/src/Event/Finder/BuildIndexEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

/**
* Joomla! Content Management System
*
* @copyright (C) 2023 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

namespace Joomla\CMS\Event\Finder;

use Joomla\CMS\Event\AbstractImmutableEvent;

// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects

/**
* Class for Finder events.
* Example:
* new BuildIndexEvent('onEventName', []);
*
* @since __DEPLOY_VERSION__
*/
class BuildIndexEvent extends AbstractImmutableEvent implements FinderEventInterface
{
}
27 changes: 27 additions & 0 deletions libraries/src/Event/Finder/GarbageCollectionEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

/**
* Joomla! Content Management System
*
* @copyright (C) 2023 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

namespace Joomla\CMS\Event\Finder;

use Joomla\CMS\Event\AbstractImmutableEvent;

// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects

/**
* Class for Finder events.
* Example:
* new GarbageCollectionEvent('onEventName', []);
*
* @since __DEPLOY_VERSION__
*/
class GarbageCollectionEvent extends AbstractImmutableEvent implements FinderEventInterface
{
}
27 changes: 27 additions & 0 deletions libraries/src/Event/Finder/StartIndexEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

/**
* Joomla! Content Management System
*
* @copyright (C) 2023 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

namespace Joomla\CMS\Event\Finder;

use Joomla\CMS\Event\AbstractImmutableEvent;

// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects

/**
* Class for Finder events.
* Example:
* new StartIndexEvent('onEventName', []);
*
* @since __DEPLOY_VERSION__
*/
class StartIndexEvent extends AbstractImmutableEvent implements FinderEventInterface
{
}