Skip to content

Commit

Permalink
[!!!][FEATURE] Add new Events for Indexing
Browse files Browse the repository at this point in the history
This change adds new PSR-14 events:

* `ApacheSolrForTypo3\Solr\Event\Indexing\BeforePageDocumentIsProcessedForIndexingEvent`
previously used with `$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['solr']['Indexer']['indexPageAddDocuments']`

* `ApacheSolrForTypo3\Solr\Event\Indexing\BeforeDocumentIsProcessedForIndexingEvent`
previously used with `$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['solr']['IndexQueueIndexer']['preAddModifyDocuments']`

* `ApacheSolrForTypo3\Solr\Event\Indexing\BeforeDocumentsAreIndexedEvent`
previously used with `$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['solr']['IndexQueueIndexer']['indexItemAddDocuments']`

This way, EXT:solr migrates to PSR-14 events and adds a more defined way to utilize the PHP API and to help extension authors to understand what is used in EXT:solr.

The hooks
* `$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['solr']['IndexQueueIndexer']['preAddModifyDocuments']`
* `$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['solr']['IndexQueueIndexer']['indexItemAddDocuments']`
* `$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['solr']['Indexer']['indexPageAddDocuments']`

are now removed in favor of the new events.

These interfaces related to the hooks are removed:
* `ApacheSolrForTypo3\Solr\IndexQueue\PageIndexerDocumentsModifier`
* `ApacheSolrForTypo3\Solr\IndexQueue\AdditionalIndexQueueItemIndexer`
* `ApacheSolrForTypo3\Solr\AdditionalPageIndexer`

Documentation is added, tests are adapted.

Relates: #3376, #3441
Fixes: #3437
  • Loading branch information
bmack authored Jun 2, 2023
1 parent 245e0db commit 57a36ba
Show file tree
Hide file tree
Showing 24 changed files with 535 additions and 521 deletions.
36 changes: 0 additions & 36 deletions Classes/AdditionalPageIndexer.php

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?php

declare(strict_types=1);

/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/

namespace ApacheSolrForTypo3\Solr\Event\Indexing;

use ApacheSolrForTypo3\Solr\IndexQueue\Item;
use ApacheSolrForTypo3\Solr\System\Solr\Document\Document;
use TYPO3\CMS\Core\Site\Entity\Site;
use TYPO3\CMS\Core\Site\Entity\SiteLanguage;

/**
* Allows third party extensions to provide additional documents which
* should be indexed for the current item.
*
* Previously used with
* $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['solr']['IndexQueueIndexer']['indexItemAddDocuments']
*/
class BeforeDocumentIsProcessedForIndexingEvent
{
/**
* @var Document[]
*/
private array $documents = [];

public function __construct(
private readonly Document $document,
private readonly Site $site,
private readonly SiteLanguage $siteLanguage,
private readonly Item $indexQueueItem
) {
$this->documents[] = $this->document;
}

public function getSite(): Site
{
return $this->site;
}

public function getSiteLanguage(): SiteLanguage
{
return $this->siteLanguage;
}

public function getIndexQueueItem(): Item
{
return $this->indexQueueItem;
}

public function getDocument(): Document
{
return $this->document;
}

/**
* @param Document[] $documents
*/
public function addDocuments(array $documents): void
{
$this->documents = array_merge($this->documents, $documents);
}

/**
* @return Document[]
*/
public function getDocuments(): array
{
return $this->documents;
}
}
78 changes: 78 additions & 0 deletions Classes/Event/Indexing/BeforeDocumentsAreIndexedEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php

declare(strict_types=1);

/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/

namespace ApacheSolrForTypo3\Solr\Event\Indexing;

use ApacheSolrForTypo3\Solr\IndexQueue\Item;
use ApacheSolrForTypo3\Solr\System\Solr\Document\Document;
use TYPO3\CMS\Core\Site\Entity\Site;
use TYPO3\CMS\Core\Site\Entity\SiteLanguage;

/**
* An event to manipulate documents right before they get added to the Solr index.
*
* Previously used with
* $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['solr']['IndexQueueIndexer']['preAddModifyDocuments']
*/
class BeforeDocumentsAreIndexedEvent
{
public function __construct(
private readonly Document $document,
private readonly Site $site,
private readonly SiteLanguage $siteLanguage,
private readonly Item $indexQueueItem,
/** @var Document[] */
private array $documents,
) {
}

public function getSite(): Site
{
return $this->site;
}

public function getSiteLanguage(): SiteLanguage
{
return $this->siteLanguage;
}

public function getIndexQueueItem(): Item
{
return $this->indexQueueItem;
}

public function getDocument(): Document
{
return $this->document;
}

/**
* @param Document[] $documents
*/
public function addDocuments(array $documents): void
{
$this->documents = array_merge($this->documents, $documents);
}

/**
* @return Document[]
*/
public function getDocuments(): array
{
return $this->documents;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?php

declare(strict_types=1);

/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/

namespace ApacheSolrForTypo3\Solr\Event\Indexing;

use ApacheSolrForTypo3\Solr\IndexQueue\Item;
use ApacheSolrForTypo3\Solr\System\Solr\Document\Document;
use TYPO3\CMS\Core\Site\Entity\Site;
use TYPO3\CMS\Core\Site\Entity\SiteLanguage;

/**
* Allows to add more documents to the Solr index.
*
* Previously used with
* $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['solr']['Indexer']['indexPageAddDocuments']
*/
class BeforePageDocumentIsProcessedForIndexingEvent
{
/**
* @var Document[]
*/
private array $documents = [];

public function __construct(
private readonly Document $document,
private readonly Site $site,
private readonly SiteLanguage $siteLanguage,
private readonly Item $indexQueueItem
) {
$this->documents[] = $this->document;
}

public function getSite(): Site
{
return $this->site;
}

public function getSiteLanguage(): SiteLanguage
{
return $this->siteLanguage;
}

public function getIndexQueueItem(): Item
{
return $this->indexQueueItem;
}

public function getDocument(): Document
{
return $this->document;
}

/**
* @param Document[] $documents
*/
public function addDocuments(array $documents): void
{
$this->documents = array_merge($this->documents, $documents);
}

/**
* @return Document[]
*/
public function getDocuments(): array
{
return $this->documents;
}
}
37 changes: 0 additions & 37 deletions Classes/IndexQueue/AdditionalIndexQueueItemIndexer.php

This file was deleted.

Loading

0 comments on commit 57a36ba

Please sign in to comment.