mirror of
https://github.com/silverstripe/silverstripe-fulltextsearch
synced 2024-10-22 12:05:29 +00:00
SS 4.0 - Update Database Captures to support Postgres & SQLite
This commit is contained in:
parent
6066af5841
commit
fcf9a4f888
@ -0,0 +1,21 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace SilverStripe\FullTextSearch\Captures;
|
||||||
|
|
||||||
|
use SilverStripe\PostgreSQL\PostgreSQLDatabase;
|
||||||
|
use SilverStripe\FullTextSearch\Search\Updaters\SearchUpdater;
|
||||||
|
|
||||||
|
if (!class_exists('PostgreSQLDatabase')) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
class SearchManipulateCapture_PostgreSQLDatabase extends PostgreSQLDatabase {
|
||||||
|
|
||||||
|
public $isManipulationCapture = true;
|
||||||
|
|
||||||
|
public function manipulate($manipulation) {
|
||||||
|
$res = parent::manipulate($manipulation);
|
||||||
|
SearchUpdater::handle_manipulation($manipulation);
|
||||||
|
return $res;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,21 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace SilverStripe\FullTextSearch\Captures;
|
||||||
|
|
||||||
|
use SilverStripe\SQLite\SQLite3Database;
|
||||||
|
use SilverStripe\FullTextSearch\Search\Updaters\SearchUpdater;
|
||||||
|
|
||||||
|
if (!class_exists('SQLite3Database')) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
class SearchManipulateCapture_SQLite3Database extends SQLite3Database {
|
||||||
|
|
||||||
|
public $isManipulationCapture = true;
|
||||||
|
|
||||||
|
public function manipulate($manipulation) {
|
||||||
|
$res = parent::manipulate($manipulation);
|
||||||
|
SearchUpdater::handle_manipulation($manipulation);
|
||||||
|
return $res;
|
||||||
|
}
|
||||||
|
}
|
@ -11,6 +11,7 @@ use SilverStripe\FullTextSearch\Search\SearchIntrospection;
|
|||||||
use SilverStripe\Core\Injector\Injector;
|
use SilverStripe\Core\Injector\Injector;
|
||||||
use SilverStripe\FullTextSearch\Search\Processors\SearchUpdateImmediateProcessor;
|
use SilverStripe\FullTextSearch\Search\Processors\SearchUpdateImmediateProcessor;
|
||||||
use SilverStripe\FullTextSearch\Captures\SearchManipulateCapture_MySQLDatabase;
|
use SilverStripe\FullTextSearch\Captures\SearchManipulateCapture_MySQLDatabase;
|
||||||
|
use ReflectionClass;
|
||||||
/**
|
/**
|
||||||
* This class is responsible for capturing changes to DataObjects and triggering index updates of the resulting dirty index
|
* This class is responsible for capturing changes to DataObjects and triggering index updates of the resulting dirty index
|
||||||
* items.
|
* items.
|
||||||
@ -38,17 +39,20 @@ class SearchUpdater extends Object
|
|||||||
return;
|
return;
|
||||||
} // If not yet set, or its already captured, just return
|
} // If not yet set, or its already captured, just return
|
||||||
|
|
||||||
|
$type = (new ReflectionClass($current))->getShortName();
|
||||||
|
$dbClass = 'SilverStripe\FullTextSearch\Captures\SearchManipulateCapture_' . $type;
|
||||||
|
|
||||||
|
// Check if Capture class exists.
|
||||||
|
if (!class_exists($dbClass)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$dbClass = SearchManipulateCapture_MySQLDatabase::class;
|
|
||||||
/** @var SS_Database $captured */
|
/** @var SS_Database $captured */
|
||||||
$captured = new $dbClass($databaseConfig);
|
$captured = new $dbClass($databaseConfig);
|
||||||
|
|
||||||
// Framework 3.2+ ORM needs some dependencies set
|
|
||||||
if (method_exists($captured, "setConnector")) {
|
|
||||||
$captured->setConnector($current->getConnector());
|
$captured->setConnector($current->getConnector());
|
||||||
$captured->setQueryBuilder($current->getQueryBuilder());
|
$captured->setQueryBuilder($current->getQueryBuilder());
|
||||||
$captured->setSchemaManager($current->getSchemaManager());
|
$captured->setSchemaManager($current->getSchemaManager());
|
||||||
}
|
|
||||||
|
|
||||||
// The connection might have had it's name changed (like if we're currently in a test)
|
// The connection might have had it's name changed (like if we're currently in a test)
|
||||||
$captured->selectDatabase($current->getSelectedDatabase());
|
$captured->selectDatabase($current->getSelectedDatabase());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user