From 111e723a82772ab4380b623f0b770e959d085cd2 Mon Sep 17 00:00:00 2001 From: Maxime Leclercq Date: Thu, 7 Jul 2022 13:46:31 +0200 Subject: [PATCH 1/2] fix: remove unused Indexer class --- src/Model/Document/Index/Indexer.php | 172 --------------------------- 1 file changed, 172 deletions(-) delete mode 100644 src/Model/Document/Index/Indexer.php diff --git a/src/Model/Document/Index/Indexer.php b/src/Model/Document/Index/Indexer.php deleted file mode 100644 index 58963949..00000000 --- a/src/Model/Document/Index/Indexer.php +++ /dev/null @@ -1,172 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE.txt - * file that was distributed with this source code. - */ - -declare(strict_types=1); - -namespace MonsieurBiz\SyliusSearchPlugin\Model\Document\Index; - -use Elastica\Document; -use Elastica\Exception\ResponseException; -use JoliCode\Elastically\Client; -use MonsieurBiz\SyliusSearchPlugin\Exception\MissingParamException; -use MonsieurBiz\SyliusSearchPlugin\Exception\ReadOnlyIndexException; -use MonsieurBiz\SyliusSearchPlugin\Model\Document\Result; -use MonsieurBiz\SyliusSearchPlugin\Model\Documentable\DocumentableInterface; -use MonsieurBiz\SyliusSearchPlugin\Provider\DocumentRepositoryProvider; -use Sylius\Component\Locale\Model\LocaleInterface; -use Sylius\Component\Resource\Repository\RepositoryInterface; -use Webmozart\Assert\Assert; - -class Indexer extends AbstractIndex -{ - /** - * @var DocumentRepositoryProvider - */ - protected $documentRepositoryProvider; - - /** @var RepositoryInterface */ - private $localeRepository; - - /** @var array */ - private $locales = []; - - /** - * PopulateCommand constructor. - */ - public function __construct( - Client $client, - DocumentRepositoryProvider $documentRepositoryProvider, - RepositoryInterface $localeRepository - ) { - parent::__construct($client); - $this->documentRepositoryProvider = $documentRepositoryProvider; - $this->localeRepository = $localeRepository; - } - - /** - * Retrieve all available locales. - */ - public function getLocales(): array - { - if (empty($this->locales)) { - $locales = $this->localeRepository->findAll(); - $this->locales = array_map( - function (LocaleInterface $locale) { - return $locale->getCode(); - }, - $locales - ); - } - - return $this->locales; - } - - /** - * Index all documents in all locales. - * - * @throws \Exception - */ - public function indexAll(): void - { - foreach ($this->getLocales() as $locale) { - $this->indexAllByLocale($locale); - } - } - - /** - * Index all document for a locale. - * - * @throws \Exception - */ - public function indexAllByLocale(string $locale): void - { - $indexName = $this->getIndexName($locale); - $newIndex = $this->getIndexBuilder()->createIndex($indexName); - - $repositories = $this->documentRepositoryProvider->getRepositories(); - foreach ($repositories as $repository) { - $documents = $repository->findAll(); - /** @var DocumentableInterface $document */ - foreach ($documents as $document) { - Assert::isInstanceOf($document, DocumentableInterface::class); - $convertToDocument = $document->convertToDocument($locale); - $this->getIndexer()->scheduleIndex($newIndex, new Document($convertToDocument->getUniqId(), $convertToDocument)); - } - } - - $this->getIndexBuilder()->markAsLive( - $newIndex, - $indexName - ); - - $this->getIndexer()->flush(); - - $this->getIndexer()->refresh($indexName); - - try { - $this->getIndexBuilder()->purgeOldIndices($indexName); - } catch (ResponseException $exception) { - throw new ReadOnlyIndexException($exception->getMessage()); - } - } - - /** - * Index a document for all locales. - * - * @throws \Exception - */ - public function indexOne(DocumentableInterface $subject): void - { - foreach ($this->getLocales() as $locale) { - $this->indexOneByLocale($subject->convertToDocument($locale), $locale); - $this->getIndexer()->flush(); - } - } - - /** - * Index a document for one locale. - * - * @throws MissingParamException - */ - public function indexOneByLocale(Result $document, string $locale): void - { - $this->getIndexer()->scheduleIndex( - $this->getClient()->getIndex($this->getIndexName($locale)), - new Document($document->getUniqId(), $document) - ); - } - - /** - * Remove a document for all locales. - * - * @throws \Exception - */ - public function removeOne(DocumentableInterface $subject): void - { - foreach ($this->getLocales() as $locale) { - $this->removeOneByLocale($subject->convertToDocument($locale), $locale); - $this->getIndexer()->flush(); - } - } - - /** - * Remove a document for all locales. - * - * @throws MissingParamException - */ - public function removeOneByLocale(Result $document, string $locale): void - { - $this->getIndexer()->scheduleDelete( - $this->getClient()->getIndex($this->getIndexName($locale)), - $document->getUniqId() - ); - } -} From 60ca3c076fe05431a4dfba0c1e8a589fbcdc4a52 Mon Sep 17 00:00:00 2001 From: Maxime Leclercq Date: Thu, 7 Jul 2022 13:48:33 +0200 Subject: [PATCH 2/2] fix: add allow plugins and update composer for CI --- .github/workflows/recipe.yaml | 5 +++-- .github/workflows/tests.yaml | 5 ++--- Makefile | 1 + 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/.github/workflows/recipe.yaml b/.github/workflows/recipe.yaml index 34938ccf..6e2bb39e 100644 --- a/.github/workflows/recipe.yaml +++ b/.github/workflows/recipe.yaml @@ -53,8 +53,8 @@ jobs: key: composer2-php:${{ matrix.php }}-sylius:${{ matrix.sylius }}-${{ github.sha }} restore-keys: composer2-php:${{ matrix.php }}-sylius:${{ matrix.sylius }}- - - name: Composer v2 - run: sudo composer self-update --2 + - name: Update composer + run: sudo composer self-update - name: Composer Github Auth run: composer config -g github-oauth.github.com ${{ github.token }} @@ -72,6 +72,7 @@ jobs: - name: Setup some requirements working-directory: ./sylius run: | + composer config --no-plugins allow-plugins true composer config repositories.plugin '{"type": "path", "url": "../plugin/"}' composer config extra.symfony.allow-contrib true composer config secure-http false diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index fc1829f6..57889c45 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -46,10 +46,9 @@ jobs: restore-keys: composer2-php:${{ matrix.php }}- - run: mkdir -p /home/runner/{.composer/cache,.config/composer} - if: steps.cache-composer.outputs.cache-hit != 'true' - - name: Composer v2 - run: sudo composer self-update --2 + - name: Update composer + run: sudo composer self-update - name: Composer Github Auth run: composer config -g github-oauth.github.com ${{ github.token }} diff --git a/Makefile b/Makefile index aed44abd..39060f3c 100644 --- a/Makefile +++ b/Makefile @@ -68,6 +68,7 @@ setup_application: (cd ${APP_DIR} && ${COMPOSER} config repositories.plugin '{"type": "path", "url": "../../"}') (cd ${APP_DIR} && ${COMPOSER} config extra.symfony.allow-contrib true) (cd ${APP_DIR} && ${COMPOSER} config minimum-stability dev) + (cd ${APP_DIR} && ${COMPOSER} config --no-plugins allow-plugins true) (cd ${APP_DIR} && ${COMPOSER} require --no-install --no-scripts --no-progress sylius/sylius="~${SYLIUS_VERSION}") # Make sure to install the required version of sylius because the sylius-standard has a soft constraint $(MAKE) ${APP_DIR}/.php-version ${APP_DIR}/php.ini (cd ${APP_DIR} && ${COMPOSER} install --no-interaction)