From e7420a584db71b45ad84ff02f0ed31e24ab5ce60 Mon Sep 17 00:00:00 2001 From: Raissa North Date: Wed, 14 Mar 2018 14:43:37 +1300 Subject: [PATCH 1/4] NEW Update to use proxied DB instead of self-proxied --- _config/database.yml | 34 +++---------------- composer.json | 3 +- .../SearchManipulateCapture_MySQLDatabase.php | 4 +++ ...chManipulateCapture_PostgreSQLDatabase.php | 4 +++ ...earchManipulateCapture_SQLite3Database.php | 4 +++ src/Search/Extensions/ProxyDBExtension.php | 19 +++++++++++ 6 files changed, 37 insertions(+), 31 deletions(-) create mode 100644 src/Search/Extensions/ProxyDBExtension.php diff --git a/_config/database.yml b/_config/database.yml index c81fb42..6eea6f0 100644 --- a/_config/database.yml +++ b/_config/database.yml @@ -1,32 +1,6 @@ --- -Name: fulltextsearchmysql -After: - - 'databaseconnectors' +Name: fulltextsearchproxydb --- -SilverStripe\Core\Injector\Injector: - MySQLDatabase: - class: SilverStripe\FullTextSearch\Search\Captures\SearchManipulateCapture_MySQLDatabase - MySQLPDODatabase: - class: SilverStripe\FullTextSearch\Search\Captures\SearchManipulateCapture_MySQLDatabase - ---- -Name: fulltextsearchpostgresql -After: - - 'postgresqlconnectors' ---- -SilverStripe\Core\Injector\Injector: - PostgrePDODatabase: - class: SilverStripe\FullTextSearch\Search\Captures\SearchManipulateCapture_PostgreSQLDatabase - PostgreSQLDatabase: - class: SilverStripe\FullTextSearch\Search\Captures\SearchManipulateCapture_PostgreSQLDatabase - ---- -Name: fulltextsearchsqlite -After: - - 'sqlite3connectors' ---- -SilverStripe\Core\Injector\Injector: - SQLite3PDODatabase: - class: SilverStripe\FullTextSearch\Search\Captures\SearchManipulateCapture_SQLite3Database - SQLite3Database: - class: SilverStripe\FullTextSearch\Search\Captures\SearchManipulateCapture_SQLite3Database +TractorCow\SilverStripeProxyDB\ProxyDBFactory: + extensions: + - SilverStripe\FullTextSearch\Search\Extensions\ProxyDBExtension diff --git a/composer.json b/composer.json index fb3bf2d..a84179c 100644 --- a/composer.json +++ b/composer.json @@ -24,7 +24,8 @@ "silverstripe/framework": "^4.0", "monolog/monolog": "~1.15", "ptcinc/solr-php-client": "^1.0", - "symfony/process": "^3.2" + "symfony/process": "^3.2", + "tractorcow/silverstripe-proxy-db" : "~0.1" }, "require-dev": { "silverstripe/cms": "^4.0", diff --git a/src/Search/Captures/SearchManipulateCapture_MySQLDatabase.php b/src/Search/Captures/SearchManipulateCapture_MySQLDatabase.php index dd78f8e..a336339 100644 --- a/src/Search/Captures/SearchManipulateCapture_MySQLDatabase.php +++ b/src/Search/Captures/SearchManipulateCapture_MySQLDatabase.php @@ -5,6 +5,10 @@ namespace SilverStripe\FullTextSearch\Search\Captures; use SilverStripe\ORM\Connect\MySQLDatabase; use SilverStripe\FullTextSearch\Search\Updaters\SearchUpdater; +/** + * @deprecated 3.1...4.0 Please use tractorcow/silverstripe-proxy-db to proxy the database connector instead + */ + class SearchManipulateCapture_MySQLDatabase extends MySQLDatabase { diff --git a/src/Search/Captures/SearchManipulateCapture_PostgreSQLDatabase.php b/src/Search/Captures/SearchManipulateCapture_PostgreSQLDatabase.php index 8d38854..c1c2d1c 100644 --- a/src/Search/Captures/SearchManipulateCapture_PostgreSQLDatabase.php +++ b/src/Search/Captures/SearchManipulateCapture_PostgreSQLDatabase.php @@ -9,6 +9,10 @@ if (!class_exists(PostgreSQLDatabase::class)) { return; } +/** + * @deprecated 3.1...4.0 Please use tractorcow/silverstripe-proxy-db to proxy the database connector instead + */ + class SearchManipulateCapture_PostgreSQLDatabase extends PostgreSQLDatabase { public $isManipulationCapture = true; diff --git a/src/Search/Captures/SearchManipulateCapture_SQLite3Database.php b/src/Search/Captures/SearchManipulateCapture_SQLite3Database.php index 9c1fcbf..88027f9 100644 --- a/src/Search/Captures/SearchManipulateCapture_SQLite3Database.php +++ b/src/Search/Captures/SearchManipulateCapture_SQLite3Database.php @@ -9,6 +9,10 @@ if (!class_exists(SQLite3Database::class)) { return; } +/** + * @deprecated 3.1...4.0 Please use tractorcow/silverstripe-proxy-db to proxy the database connector instead + */ + class SearchManipulateCapture_SQLite3Database extends SQLite3Database { diff --git a/src/Search/Extensions/ProxyDBExtension.php b/src/Search/Extensions/ProxyDBExtension.php new file mode 100644 index 0000000..50ecd91 --- /dev/null +++ b/src/Search/Extensions/ProxyDBExtension.php @@ -0,0 +1,19 @@ +addMethod('manipulate', function ($args, $next) { + $manipulation = $args[0]; + SearchUpdater::handle_manipulation($manipulation); + return $next(...$args); + }); + } +} From 08052436e837c29094d95995a020b96eb8507574 Mon Sep 17 00:00:00 2001 From: Raissa North Date: Thu, 15 Mar 2018 09:45:14 +1300 Subject: [PATCH 2/4] DOCS Add doc blocks for ProxyDBExtension --- src/Search/Extensions/ProxyDBExtension.php | 13 +++++++++++++ src/Search/Updaters/SearchUpdater.php | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/Search/Extensions/ProxyDBExtension.php b/src/Search/Extensions/ProxyDBExtension.php index 50ecd91..47bac8a 100644 --- a/src/Search/Extensions/ProxyDBExtension.php +++ b/src/Search/Extensions/ProxyDBExtension.php @@ -6,8 +6,21 @@ use SilverStripe\Core\Extension; use TractorCow\ClassProxy\Generators\ProxyGenerator; use SilverStripe\FullTextSearch\Search\Updaters\SearchUpdater; +/** + * Class ProxyDBExtension + * @package SilverStripe\FullTextSearch\Search\Extensions + * + * 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. + * + */ class ProxyDBExtension extends Extension { + /** + * @param ProxyGenerator $proxy + * + * Ensure the search index is kept up to date by monitoring SilverStripe database manipulations + */ public function updateProxy(ProxyGenerator &$proxy) { $proxy = $proxy->addMethod('manipulate', function ($args, $next) { diff --git a/src/Search/Updaters/SearchUpdater.php b/src/Search/Updaters/SearchUpdater.php index b6efabc..dbb24f0 100644 --- a/src/Search/Updaters/SearchUpdater.php +++ b/src/Search/Updaters/SearchUpdater.php @@ -42,7 +42,7 @@ class SearchUpdater public static $processor = null; /** - * Called by the SearchManiplateCapture database adapter with every manipulation made against the database. + * Called by the ProxyDBExtension database connector with every manipulation made against the database. * * Check every index to see what objects need re-inserting into what indexes to keep the index fresh, * but doesn't actually do it yet. From f416a648c7ebc62e0458d02e70cee9ba99a0d4d1 Mon Sep 17 00:00:00 2001 From: Raissa North Date: Thu, 15 Mar 2018 09:52:44 +1300 Subject: [PATCH 3/4] Update scrutinizer config --- .scrutinizer.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.scrutinizer.yml b/.scrutinizer.yml index de09355..051ef9a 100644 --- a/.scrutinizer.yml +++ b/.scrutinizer.yml @@ -1,5 +1,11 @@ inherit: true +build: + nodes: + analysis: + tests: + override: [php-scrutinizer-run] + checks: php: code_rating: true From f47f43324c0a14f1508845a901438248e42f0d7a Mon Sep 17 00:00:00 2001 From: Raissa North Date: Thu, 15 Mar 2018 10:36:31 +1300 Subject: [PATCH 4/4] Update doc blocks at class level --- src/Search/Extensions/ProxyDBExtension.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/Search/Extensions/ProxyDBExtension.php b/src/Search/Extensions/ProxyDBExtension.php index 47bac8a..f878b38 100644 --- a/src/Search/Extensions/ProxyDBExtension.php +++ b/src/Search/Extensions/ProxyDBExtension.php @@ -7,9 +7,6 @@ use TractorCow\ClassProxy\Generators\ProxyGenerator; use SilverStripe\FullTextSearch\Search\Updaters\SearchUpdater; /** - * Class ProxyDBExtension - * @package SilverStripe\FullTextSearch\Search\Extensions - * * 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. *