Skip to content

Commit

Permalink
remove bundle provider, introduce HealthState service, resolves #34
Browse files Browse the repository at this point in the history
  • Loading branch information
solverat committed Dec 16, 2021
1 parent 147f3ce commit a0eddbb
Show file tree
Hide file tree
Showing 34 changed files with 462 additions and 388 deletions.
27 changes: 18 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,26 @@
[![PhpStan](https://img.shields.io/github/workflow/status/dachcom-digital/pimcore-dynamic-search/PHP%20Stan/master?style=flat-square&logo=github&label=phpstan%20level%204)](https://github.com/dachcom-digital/pimcore-dynamic-search/actions?query=workflow%3A"PHP+Stan"+branch%3Amaster)

### Release Plan

| Release | Supported Pimcore Versions | Supported Symfony Versions | Release Date | Maintained | Branch |
|---------|-----------------------------------|----------------------------|--------------|----------------------------------|------------|
| **2.x** | `10.0` | `^5.2` | no release | Yes (Bugs, Features) | master |
| **1.x** | `6.6` - `6.9` | `^4.4` | 18.04.2021 | Yes (Bugs, Features if required) | [1.x](https://github.com/dachcom-digital/pimcore-dynamic-search/tree/1.x) |
| **2.x** | `10.0` | `^5.4` | no release | Yes (Bugs, Features) | master |
| **1.x** | `6.6` - `6.9` | `^4.4` | 18.04.2021 | No | [1.x](https://github.com/dachcom-digital/pimcore-dynamic-search/tree/1.x) |

## Introduction
The Dynamic Search Bundle allows you to redefine your search strategy. It's based on several data- and index providers.
The Dynamic Search Bundle allows you to redefine your search strategy.
It's based on several data- and index providers.

## Providers
There are several data- and index providers available:

### Data Provider
- [WebCrawler](https://github.com/dachcom-digital/pimcore-dynamic-search-data-provider-crawler) (Spider)
- [Trinity Data](https://github.com/dachcom-digital/pimcore-dynamic-search-data-provider-trinity) (Pimcore: Object, Asset, Document)
- [WebCrawler](https://github.com/dachcom-digital/pimcore-dynamic-search-data-provider-crawler) | Fetch data by crawling urls
- [Trinity Data](https://github.com/dachcom-digital/pimcore-dynamic-search-data-provider-trinity) | Fetch pimcore entities: object, asset, document

### Index Provider
- [Lucene Search](https://github.com/dachcom-digital/pimcore-dynamic-search-index-provider-lucene)
- [Elastic Search](https://github.com/dachcom-digital/pimcore-dynamic-search-index-provider-elasticsearch)
- _apisearch.io (coming soon)_
- [Lucene Search](https://github.com/dachcom-digital/pimcore-dynamic-search-index-provider-lucene) | Use the php lucene index. Not super-fast but comes without any dependencies but php
- [Elastic Search](https://github.com/dachcom-digital/pimcore-dynamic-search-index-provider-elasticsearch) | Index data with an elasticsearch instance.
- _apisearch.io_ | _coming soon_

### Installation

Expand All @@ -40,7 +43,13 @@ The Dynamic Search Bundle allows you to redefine your search strategy. It's base
## Upgrading
- Execute: `$ bin/console doctrine:migrations:migrate --prefix 'DynamicSearchBundle\Migrations'`

## Provider Installation
You need at least one data- and one index provider. They have to be installed separately.
Please check out install instruction of each provider (see list above).

## Further Information
![image](https://user-images.githubusercontent.com/700119/146414238-ad2964e6-e873-4607-a89b-bc2ec2e5b95c.png)

- [Example Setup](docs/0_ExampleSetup.md)
- Configuration
- Context Guard
Expand Down
3 changes: 2 additions & 1 deletion UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- PHP8 return type declarations added: you may have to adjust your extensions accordingly
- All Folders in `views` are lowercase/dashed now (`views/common`, `views/output-channel`, ...)
- `FieldTransformerInterface::configureOptions` return type changed to `void`
- Provider bundles registration process has changed: There not automatically registered. You need to this by yourself. [Example](https://github.com/dachcom-digital/pimcore-dynamic-search-data-provider-trinity#installation).
- Paginator changed:
- Removed Zend Paginator
- Use Paginator from `KnpPaginatorBundle` which is included in PX by default
Expand All @@ -27,7 +28,7 @@
--

### New Features
--
- Settings panel added.

***

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,5 @@

interface ConfigurationInterface
{
public const BUNDLE_PATH = PIMCORE_PRIVATE_VAR . '/bundles/DynamicSearchBundle';

public function get(string $slot): mixed;
}
38 changes: 34 additions & 4 deletions src/DynamicSearchBundle/Controller/Admin/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,48 @@

namespace DynamicSearchBundle\Controller\Admin;

use DynamicSearchBundle\Provider\Extension\ProviderBundleLocator;
use DynamicSearchBundle\Registry\HealthStateRegistryInterface;
use DynamicSearchBundle\State\HealthStateInterface;
use Pimcore\Bundle\AdminBundle\Controller\AdminController;
use Symfony\Component\HttpFoundation\JsonResponse;

class SettingsController extends AdminController
{
public function logAction(): JsonResponse
public function healStateAction(HealthStateRegistryInterface $healthStateRegistry): JsonResponse
{
return $this->json([]);
$stateLines = [];
foreach ($healthStateRegistry->all() as $healthStateService) {

$stateIcon = 'pimcore_icon_save';
if ($healthStateService->getState() === HealthStateInterface::STATE_WARNING) {
$stateIcon = 'pimcore_icon_info';
} elseif ($healthStateService->getState() === HealthStateInterface::STATE_ERROR) {
$stateIcon = 'pimcore_icon_cancel';
} elseif ($healthStateService->getState() === HealthStateInterface::STATE_SILENT) {
$stateIcon = null;
}

$stateLines[] = [
'module' => $healthStateService->getModuleName(),
'title' => $healthStateService->getTitle(),
'comment' => $healthStateService->getComment(),
'icon' => $stateIcon,
];

}

return $this->json([
'lines' => $stateLines
]);
}

public function stateAction(): JsonResponse
public function providerAction(ProviderBundleLocator $providerBundleLocator): JsonResponse
{
return $this->json([]);
$providerBundles = $providerBundleLocator->findProviderBundles();

return $this->json([
'provider' => $providerBundles
]);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace DynamicSearchBundle\DependencyInjection\Compiler;

use DynamicSearchBundle\Registry\HealthStateRegistry;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\Compiler\PriorityTaggedServiceTrait;
use Symfony\Component\DependencyInjection\ContainerBuilder;

final class HealthStatePass implements CompilerPassInterface
{
public const HEALTH_STATE_TAG = 'dynamic_search.health_state';

use PriorityTaggedServiceTrait;

public function process(ContainerBuilder $container): void
{
$definition = $container->getDefinition(HealthStateRegistry::class);
foreach ($this->findAndSortTaggedServices(self::HEALTH_STATE_TAG, $container) as $reference) {
$definition->addMethodCall('register', [$reference]);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
use DynamicSearchBundle\Factory\ContextDefinitionFactory;
use DynamicSearchBundle\Filter\Definition\FilterDefinitionBuilderInterface;
use DynamicSearchBundle\Guard\ContextGuardInterface;
use DynamicSearchBundle\Provider\Extension\ProviderConfig;
use Symfony\Component\Config\Resource\FileResource;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\ContainerBuilder;
Expand All @@ -30,7 +27,6 @@ public function load(array $configs, ContainerBuilder $container): void

$this->buildAutoconfiguration($container);
$this->setupConfiguration($container, $config);
$this->setupProviderBundles($container);
}

protected function buildAutoconfiguration(ContainerBuilder $container): void
Expand All @@ -57,18 +53,4 @@ protected function setupConfiguration(ContainerBuilder $container, array $config
$contextDefinitionFactory->addMethodCall('addContextConfig', [$contextName, $contextConfigNode]);
}
}

protected function setupProviderBundles(ContainerBuilder $container): void
{
$providerConfig = new ProviderConfig();

$providerConfigDefinition = new Definition();
$providerConfigDefinition->setClass(ProviderConfig::class);

$container->setDefinition(ProviderConfig::class, $providerConfigDefinition);

if ($providerConfig->configFileExists()) {
$container->addResource(new FileResource($providerConfig->locateConfigFile()));
}
}
}
22 changes: 7 additions & 15 deletions src/DynamicSearchBundle/DynamicSearchBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,18 @@
use DynamicSearchBundle\DependencyInjection\Compiler\ContextGuardPass;
use DynamicSearchBundle\DependencyInjection\Compiler\DataProviderPass;
use DynamicSearchBundle\DependencyInjection\Compiler\DefinitionBuilderPass;
use DynamicSearchBundle\DependencyInjection\Compiler\HealthStatePass;
use DynamicSearchBundle\DependencyInjection\Compiler\IndexPass;
use DynamicSearchBundle\DependencyInjection\Compiler\IndexProviderPass;
use DynamicSearchBundle\DependencyInjection\Compiler\OutputChannelPass;
use DynamicSearchBundle\DependencyInjection\Compiler\NormalizerPass;
use DynamicSearchBundle\DependencyInjection\Compiler\ResourceTransformerPass;
use DynamicSearchBundle\Provider\Extension\ProviderConfig;
use DynamicSearchBundle\Tool\Install;
use Pimcore\Extension\Bundle\AbstractPimcoreBundle;
use Pimcore\Extension\Bundle\Traits\PackageVersionTrait;
use Pimcore\HttpKernel\Bundle\DependentBundleInterface;
use Pimcore\HttpKernel\BundleCollection\BundleCollection;
use Symfony\Component\DependencyInjection\ContainerBuilder;

class DynamicSearchBundle extends AbstractPimcoreBundle implements DependentBundleInterface
class DynamicSearchBundle extends AbstractPimcoreBundle
{
use PackageVersionTrait;

Expand All @@ -36,16 +34,7 @@ public function build(ContainerBuilder $container): void
$container->addCompilerPass(new IndexPass());
$container->addCompilerPass(new OutputChannelPass());
$container->addCompilerPass(new ContextGuardPass());
}

public static function registerDependentBundles(BundleCollection $collection): void
{
$providerConfig = new ProviderConfig();
if ($providerConfig->configFileExists()) {
foreach ($providerConfig->getAvailableProviderBundles() as $providerBundle) {
$collection->addBundle(new $providerBundle());
}
}
$container->addCompilerPass(new HealthStatePass());
}

public function getInstaller(): Install
Expand All @@ -55,7 +44,10 @@ public function getInstaller(): Install

public function getJsPaths(): array
{
return [ ];
return [
'/bundles/dynamicsearch/js/backend/startup.js',
'/bundles/dynamicsearch/js/backend/settings.js',
];
}

public function getCssPaths(): array
Expand Down

This file was deleted.

25 changes: 0 additions & 25 deletions src/DynamicSearchBundle/Manager/ProviderBundleManager.php

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,26 @@
class ProviderBundleLocator implements ProviderBundleLocatorInterface
{
protected Composer\PackageInfo $composerPackageInfo;
protected array $availableBundles;

public function __construct(Composer\PackageInfo $composerPackageInfo)
public function __construct(Composer\PackageInfo $composerPackageInfo, array $availableBundles)
{
$this->composerPackageInfo = $composerPackageInfo;
$this->availableBundles = $availableBundles;
}

public function findProviderBundles(): array
{
$result = $this->findComposerBundles();
sort($result);
$data = [];
foreach ($this->findComposerBundles() as $bundleClass) {

return [
'dynamic_search_provider_bundles' => $result
];
$data[] = [
'path' => $bundleClass,
'active' => in_array($bundleClass, $this->availableBundles, true)
];
}

return $data;
}

/**
Expand Down
Loading

0 comments on commit a0eddbb

Please sign in to comment.