2018-03-14 02:43:37 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace SilverStripe\FullTextSearch\Search\Extensions;
|
|
|
|
|
|
|
|
use SilverStripe\Core\Extension;
|
|
|
|
use TractorCow\ClassProxy\Generators\ProxyGenerator;
|
|
|
|
use SilverStripe\FullTextSearch\Search\Updaters\SearchUpdater;
|
|
|
|
|
2018-03-14 21:45:14 +01:00
|
|
|
/**
|
|
|
|
* This database connector proxy will allow {@link SearchUpdater::handle_manipulation} to monitor database schema
|
|
|
|
* changes that may need to be propagated through to search indexes.
|
|
|
|
*
|
|
|
|
*/
|
2018-03-14 02:43:37 +01:00
|
|
|
class ProxyDBExtension extends Extension
|
|
|
|
{
|
2018-03-14 21:45:14 +01:00
|
|
|
/**
|
|
|
|
* @param ProxyGenerator $proxy
|
|
|
|
*
|
|
|
|
* Ensure the search index is kept up to date by monitoring SilverStripe database manipulations
|
|
|
|
*/
|
2018-03-14 02:43:37 +01:00
|
|
|
public function updateProxy(ProxyGenerator &$proxy)
|
|
|
|
{
|
|
|
|
$proxy = $proxy->addMethod('manipulate', function ($args, $next) {
|
|
|
|
$manipulation = $args[0];
|
|
|
|
SearchUpdater::handle_manipulation($manipulation);
|
|
|
|
return $next(...$args);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|