From aa4f644d395b82a1f5ef1fa9b866577ab995e014 Mon Sep 17 00:00:00 2001 From: Greg Anderson Date: Thu, 5 Sep 2024 12:35:30 -0700 Subject: [PATCH 01/42] Update CODEOWNERS for new team names (#183) Auto merge PR #183 in search_api_pantheon --- CODEOWNERS | 1 + 1 file changed, 1 insertion(+) create mode 100644 CODEOWNERS diff --git a/CODEOWNERS b/CODEOWNERS new file mode 100644 index 00000000..632c6150 --- /dev/null +++ b/CODEOWNERS @@ -0,0 +1 @@ +* @pantheon-systems/site-experience From e879586c4f6a80bfde49dd3daa025ac3e5f30a5e Mon Sep 17 00:00:00 2001 From: Brian Weaver Date: Tue, 10 Sep 2024 16:25:32 -0400 Subject: [PATCH 02/42] Add or update catalog-info.yml --- catalog-info.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 catalog-info.yml diff --git a/catalog-info.yml b/catalog-info.yml new file mode 100644 index 00000000..b1795c74 --- /dev/null +++ b/catalog-info.yml @@ -0,0 +1,12 @@ +--- +apiVersion: backstage.io/v1alpha1 +kind: Component +metadata: + name: search_api_pantheon + description: Auto-generated catalog info for pantheon-systems/search_api_pantheon + annotations: + backstage.io/techdocs-ref: dir:docs/ +spec: + type: library + lifecycle: mature + owner: site From 0e2b0fe45ac28aaa44b700bdc25be21b0cd7b704 Mon Sep 17 00:00:00 2001 From: Kevin Porras Date: Fri, 8 Nov 2024 15:06:16 -0600 Subject: [PATCH 03/42] First attempt to reload core during post schema. --- src/Services/Endpoint.php | 16 ++++++++++++ src/Services/SchemaPoster.php | 47 +++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) diff --git a/src/Services/Endpoint.php b/src/Services/Endpoint.php index 7b9cf98f..91bd1ed9 100644 --- a/src/Services/Endpoint.php +++ b/src/Services/Endpoint.php @@ -198,6 +198,22 @@ public function getSchemaUploadUri(): string { ); } + /** + * Get URL in pantheon environment to upload schema files. + * + * @return string + * URL of envrionment. + */ + public function getReloadUri(): string { + return vsprintf( + '%s/%s', + [ + $this->getCoreBaseUri(), + 'reload', + ] + ); + } + /** * Get the path for Schema Uploads. * diff --git a/src/Services/SchemaPoster.php b/src/Services/SchemaPoster.php index fac2c2f6..3b0487aa 100644 --- a/src/Services/SchemaPoster.php +++ b/src/Services/SchemaPoster.php @@ -19,6 +19,7 @@ use Psr\Log\LoggerInterface; use Drupal\Core\Logger\LoggerChannelFactoryInterface; use Drupal\Core\Entity\EntityTypeManagerInterface; +use Drupal\search_api_pantheon\Exceptions\PantheonSearchApiException; /** * Posting schema for Pantheon-specific solr driver. @@ -105,9 +106,55 @@ public function postSchema(string $server_id, $files = []): array { throw new \Exception('Cannot post schema to environment url.'); } + $status_code = $response->getStatusCode(); + $this->logger->info('Status code: ' . $status_code); + if ($status_code >= 200 && $status_code < 300) { + // @TODO Maybe we need to capture exception here?? + // Call reload on the server. + $this->reloadServer(); + } + $this->logger->info('After server reload?'); + return $this->processResponse($response); } + protected function reloadServer(): void { + // Schema upload URL. + $uri = new Uri( + $this->getClient() + ->getEndpoint() + ->getReloadUri() + ); + + $this->logger->debug('Reload url: ' . (string) $uri); + + // Send the request. + $request = new Request( + 'POST', + $uri, + [ + 'Accept' => 'application/json', + 'Content-Type' => 'application/json', + ] + ); + $response = $this->getClient()->sendRequest($request); + + $status_code = $response->getStatusCode(); + if ($status_code >= 200 && $status_code < 300) { + $this->logger->info('Server reloaded: {status_code} {reason}', [ + 'status_code' => $response->getStatusCode(), + 'reason' => $response->getReasonPhrase(), + ]); + } + else { + $this->logger->error('Server not reloaded: {status_code} {reason}', [ + 'status_code' => $response->getStatusCode(), + 'reason' => $response->getReasonPhrase(), + ]); + throw new PantheonSearchApiException('Server not reloaded.'); + } + } + /** * Process response and return message to be shown to user. * From 2e324de9b19545b6e81be008e22c7f0a048b8d79 Mon Sep 17 00:00:00 2001 From: Phil Tyler Date: Tue, 12 Nov 2024 10:58:38 -0800 Subject: [PATCH 04/42] WIP --- .envrc.dist | 1 + .gitignore | 2 ++ phpunit.xml | 1 + src/Plugin/SolrConnector/PantheonSolrConnector.php | 1 + src/Services/Endpoint.php | 14 ++++++++++++-- tests/Unit/EndpointServiceTest.php | 13 +++++++++++++ tests/Unit/GuzzleClassTest.php | 4 +++- 7 files changed, 33 insertions(+), 3 deletions(-) diff --git a/.envrc.dist b/.envrc.dist index b18f4442..a0031c90 100644 --- a/.envrc.dist +++ b/.envrc.dist @@ -9,3 +9,4 @@ export PANTHEON_INDEX_PORT=8983 export PANTHEON_INDEX_PATH=/solr export PANTHEON_INDEX_CORE=${SOLR_CORE} export PANTHEON_INDEX_SCHEME=http +export PANTHEON_INDEX_RELOAD_PATH=${SOLR_RELOAD_PATH} diff --git a/.gitignore b/.gitignore index 5b0d6ba4..b580ef1d 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,5 @@ .idea .DS_Store docs/Badge.confluence + +.envrc \ No newline at end of file diff --git a/phpunit.xml b/phpunit.xml index 5184585e..b0e49b9c 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -11,6 +11,7 @@ + diff --git a/src/Plugin/SolrConnector/PantheonSolrConnector.php b/src/Plugin/SolrConnector/PantheonSolrConnector.php index c2ce5ea2..3bb421bb 100644 --- a/src/Plugin/SolrConnector/PantheonSolrConnector.php +++ b/src/Plugin/SolrConnector/PantheonSolrConnector.php @@ -129,6 +129,7 @@ public static function getPlatformConfig() { 'path' => getenv('PANTHEON_INDEX_PATH'), 'core' => getenv('PANTHEON_INDEX_CORE'), 'schema' => getenv('PANTHEON_INDEX_SCHEMA'), + 'reload_path' => getenv('PANTHEON_INDEX_RELOAD_PATH') ]; } diff --git a/src/Services/Endpoint.php b/src/Services/Endpoint.php index 91bd1ed9..cb1d001d 100644 --- a/src/Services/Endpoint.php +++ b/src/Services/Endpoint.php @@ -199,7 +199,7 @@ public function getSchemaUploadUri(): string { } /** - * Get URL in pantheon environment to upload schema files. + * Get URL in pantheon environment to POST reload requests. * * @return string * URL of envrionment. @@ -209,11 +209,21 @@ public function getReloadUri(): string { '%s/%s', [ $this->getCoreBaseUri(), - 'reload', + $this->getReloadPath(), ] ); } + /** + * Get the path for Schema Reloads + * + * @return string + * The path for schema reloads + **/ + public function getReloadPath(): string { + return $this->options['reload_path']; + } + /** * Get the path for Schema Uploads. * diff --git a/tests/Unit/EndpointServiceTest.php b/tests/Unit/EndpointServiceTest.php index a37d8dd2..4c3958d2 100644 --- a/tests/Unit/EndpointServiceTest.php +++ b/tests/Unit/EndpointServiceTest.php @@ -28,6 +28,7 @@ public function testURIGeneration() { 'schema' => '/schema-path', 'collection' => NULL, 'leader' => FALSE, + 'reload_path' => "/reload-path", ]); $this->assertEquals('/core-name', $ep->getCore()); @@ -43,6 +44,18 @@ public function testURIGeneration() { 'one://two:1234/server-path/schema-path', $ep->getSchemaUploadUri() ); + $this->assertEquals( + 'one://two:1234/server-path/schema-path', + $ep->getSchemaUploadUri() + ); + $this->assertEquals( + 'one://two:1234/server-path/schema-path/reload-path', + $ep->getReloadUri() + ); } + public function testReloadPath() { + $ep = new Endpoint(["reload_path"=>"/reload"]); + $this->assertEquals("/reload", $ep->getReloadPath()); + } } diff --git a/tests/Unit/GuzzleClassTest.php b/tests/Unit/GuzzleClassTest.php index d873e0d8..ea851c2c 100644 --- a/tests/Unit/GuzzleClassTest.php +++ b/tests/Unit/GuzzleClassTest.php @@ -18,7 +18,9 @@ * @package \Drupal\search_api_pantheon */ class GuzzleClassTest extends TestCase { - + + protected $loggerFactory; + /** * {@inheritdoc} */ From 23a7e202f2517c2e10e5f346185872e9c4d1b195 Mon Sep 17 00:00:00 2001 From: Phil Tyler Date: Tue, 12 Nov 2024 11:17:30 -0800 Subject: [PATCH 05/42] fixup & lint --- .../SolrConnector/PantheonSolrConnector.php | 2 +- src/Services/Endpoint.php | 4 ++-- src/Services/SchemaPoster.php | 19 ++++++++----------- tests/Unit/EndpointServiceTest.php | 5 +++-- tests/Unit/GuzzleClassTest.php | 4 ++-- 5 files changed, 16 insertions(+), 18 deletions(-) diff --git a/src/Plugin/SolrConnector/PantheonSolrConnector.php b/src/Plugin/SolrConnector/PantheonSolrConnector.php index 3bb421bb..f2a4740c 100644 --- a/src/Plugin/SolrConnector/PantheonSolrConnector.php +++ b/src/Plugin/SolrConnector/PantheonSolrConnector.php @@ -129,7 +129,7 @@ public static function getPlatformConfig() { 'path' => getenv('PANTHEON_INDEX_PATH'), 'core' => getenv('PANTHEON_INDEX_CORE'), 'schema' => getenv('PANTHEON_INDEX_SCHEMA'), - 'reload_path' => getenv('PANTHEON_INDEX_RELOAD_PATH') + 'reload_path' => getenv('PANTHEON_INDEX_RELOAD_PATH'), ]; } diff --git a/src/Services/Endpoint.php b/src/Services/Endpoint.php index cb1d001d..8b50afd7 100644 --- a/src/Services/Endpoint.php +++ b/src/Services/Endpoint.php @@ -215,8 +215,8 @@ public function getReloadUri(): string { } /** - * Get the path for Schema Reloads - * + * Get the path for Schema Reloads. + * * @return string * The path for schema reloads **/ diff --git a/src/Services/SchemaPoster.php b/src/Services/SchemaPoster.php index 3b0487aa..49eaa41d 100644 --- a/src/Services/SchemaPoster.php +++ b/src/Services/SchemaPoster.php @@ -140,19 +140,16 @@ protected function reloadServer(): void { $response = $this->getClient()->sendRequest($request); $status_code = $response->getStatusCode(); + $status_logger_content = [ + 'status_code' => $response->getStatusCode(), + 'reason' => $response->getReasonPhrase(), + ]; if ($status_code >= 200 && $status_code < 300) { - $this->logger->info('Server reloaded: {status_code} {reason}', [ - 'status_code' => $response->getStatusCode(), - 'reason' => $response->getReasonPhrase(), - ]); - } - else { - $this->logger->error('Server not reloaded: {status_code} {reason}', [ - 'status_code' => $response->getStatusCode(), - 'reason' => $response->getReasonPhrase(), - ]); - throw new PantheonSearchApiException('Server not reloaded.'); + $this->logger->info('Server reloaded: {status_code} {reason}', $status_logger_content); + return; } + $this->logger->error('Server not reloaded: {status_code} {reason}', $status_logger_content); + throw new PantheonSearchApiException('Server not reloaded.'); } /** diff --git a/tests/Unit/EndpointServiceTest.php b/tests/Unit/EndpointServiceTest.php index 4c3958d2..07c23911 100644 --- a/tests/Unit/EndpointServiceTest.php +++ b/tests/Unit/EndpointServiceTest.php @@ -55,7 +55,8 @@ public function testURIGeneration() { } public function testReloadPath() { - $ep = new Endpoint(["reload_path"=>"/reload"]); - $this->assertEquals("/reload", $ep->getReloadPath()); + $ep = new Endpoint(["reload_path" => "/reload"]); + $this->assertEquals("/reload", $ep->getReloadPath()); } + } diff --git a/tests/Unit/GuzzleClassTest.php b/tests/Unit/GuzzleClassTest.php index ea851c2c..1e08b746 100644 --- a/tests/Unit/GuzzleClassTest.php +++ b/tests/Unit/GuzzleClassTest.php @@ -18,9 +18,9 @@ * @package \Drupal\search_api_pantheon */ class GuzzleClassTest extends TestCase { - + protected $loggerFactory; - + /** * {@inheritdoc} */ From fd2778cf91ec8ed97057fc90c0495c5be044def2 Mon Sep 17 00:00:00 2001 From: Phil Tyler Date: Tue, 12 Nov 2024 11:18:24 -0800 Subject: [PATCH 06/42] lint --- src/Services/Endpoint.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Services/Endpoint.php b/src/Services/Endpoint.php index 8b50afd7..e3d47be9 100644 --- a/src/Services/Endpoint.php +++ b/src/Services/Endpoint.php @@ -219,7 +219,7 @@ public function getReloadUri(): string { * * @return string * The path for schema reloads - **/ + */ public function getReloadPath(): string { return $this->options['reload_path']; } From 21b9cfe9a4fe2523ff8a84df44f660d7e93fc735 Mon Sep 17 00:00:00 2001 From: Phil Tyler Date: Tue, 12 Nov 2024 11:20:22 -0800 Subject: [PATCH 07/42] fixup --- src/Services/SchemaPoster.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Services/SchemaPoster.php b/src/Services/SchemaPoster.php index 49eaa41d..76b7b8d8 100644 --- a/src/Services/SchemaPoster.php +++ b/src/Services/SchemaPoster.php @@ -140,15 +140,15 @@ protected function reloadServer(): void { $response = $this->getClient()->sendRequest($request); $status_code = $response->getStatusCode(); - $status_logger_content = [ - 'status_code' => $response->getStatusCode(), + $reload_logger_content = [ + 'status_code' => $status_code, 'reason' => $response->getReasonPhrase(), ]; if ($status_code >= 200 && $status_code < 300) { - $this->logger->info('Server reloaded: {status_code} {reason}', $status_logger_content); + $this->logger->info('Server reloaded: {status_code} {reason}', $reload_logger_content); return; } - $this->logger->error('Server not reloaded: {status_code} {reason}', $status_logger_content); + $this->logger->error('Server not reloaded: {status_code} {reason}', $reload_logger_content); throw new PantheonSearchApiException('Server not reloaded.'); } From 5d42df65da6a57d3e5b5c7b9b857c4b3a30eb4ab Mon Sep 17 00:00:00 2001 From: Phil Tyler Date: Tue, 12 Nov 2024 11:35:20 -0800 Subject: [PATCH 08/42] Add reload path to diagnose debugging --- src/Commands/Diagnose.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Commands/Diagnose.php b/src/Commands/Diagnose.php index 066f24fa..1ec37214 100644 --- a/src/Commands/Diagnose.php +++ b/src/Commands/Diagnose.php @@ -119,6 +119,9 @@ public function diagnose() { $this->logger->notice('Index PATH Value: {var}', [ 'var' => $this->endpoint->getPath(), ]); + $this->logger->notice('Index RELOAD_PATH Value: {var}', [ + 'var' => $this->endpoint->getReloadPath(), + ]); $this->logger->notice('Testing bare Connection...'); $response = $this->pingSolrHost(); $this->logger->notice('Ping Received Response? {var}', [ From f9bbd8bc5e9d753290eeae1bc30accfc95ea4b75 Mon Sep 17 00:00:00 2001 From: Phil Tyler Date: Tue, 12 Nov 2024 13:08:27 -0800 Subject: [PATCH 09/42] adjust path --- src/Services/Endpoint.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Services/Endpoint.php b/src/Services/Endpoint.php index e3d47be9..7a5f93a8 100644 --- a/src/Services/Endpoint.php +++ b/src/Services/Endpoint.php @@ -206,9 +206,12 @@ public function getSchemaUploadUri(): string { */ public function getReloadUri(): string { return vsprintf( - '%s/%s', + '%s://%s:%d/%s%s', [ - $this->getCoreBaseUri(), + $this->getScheme(), + $this->getHost(), + $this->getPort(), + $this->getPath(), $this->getReloadPath(), ] ); From 2ebc484cb806e85a04f194ccbfea6bc8df54b62e Mon Sep 17 00:00:00 2001 From: Phil Tyler Date: Tue, 12 Nov 2024 13:31:15 -0800 Subject: [PATCH 10/42] test adjust --- tests/Unit/EndpointServiceTest.php | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/tests/Unit/EndpointServiceTest.php b/tests/Unit/EndpointServiceTest.php index 07c23911..e2bc35ab 100644 --- a/tests/Unit/EndpointServiceTest.php +++ b/tests/Unit/EndpointServiceTest.php @@ -3,6 +3,7 @@ namespace Drupal\search_api_pantheon\tests\Unit; use Drupal\search_api_pantheon\Services\Endpoint; +use Drupal\Core\Entity\EntityTypeManagerInterface; use PHPUnit\Framework\TestCase; /** @@ -12,6 +13,23 @@ */ class EndpointServiceTest extends TestCase { + protected $entityTypeManager; + + protected function setUp(): void { + parent::setUp(); + + // Mock the EntityTypeManagerInterface. + $this->entityTypeManager = $this->createMock(EntityTypeManagerInterface::class); + + // Define any specific behavior for methods you expect to call. + // For example, if you are loading storage for a particular entity type: + // $storageMock = $this->createMock(EntityStorageInterface::class); + // $this->entityTypeManager + // ->method('getStorage') + // ->with('search_api_server') + // ->willReturn($storageMock); + } + /** * Test the endpoint class's ability to generate correct URL's. * @@ -29,7 +47,7 @@ public function testURIGeneration() { 'collection' => NULL, 'leader' => FALSE, 'reload_path' => "/reload-path", - ]); + ], $this->entityTypeManager); $this->assertEquals('/core-name', $ep->getCore()); $this->assertEquals('server-path', $ep->getPath()); @@ -49,13 +67,13 @@ public function testURIGeneration() { $ep->getSchemaUploadUri() ); $this->assertEquals( - 'one://two:1234/server-path/schema-path/reload-path', + 'one://two:1234/server-path/reload-path', $ep->getReloadUri() ); } public function testReloadPath() { - $ep = new Endpoint(["reload_path" => "/reload"]); + $ep = new Endpoint(["reload_path" => "/reload"], $this->entityTypeManager); $this->assertEquals("/reload", $ep->getReloadPath()); } From 36552ec4346ef7e4946ebec255535612e9f3a06e Mon Sep 17 00:00:00 2001 From: Phil Tyler Date: Tue, 12 Nov 2024 13:35:32 -0800 Subject: [PATCH 11/42] back out partial test fix --- tests/Unit/EndpointServiceTest.php | 21 ++------------------- 1 file changed, 2 insertions(+), 19 deletions(-) diff --git a/tests/Unit/EndpointServiceTest.php b/tests/Unit/EndpointServiceTest.php index e2bc35ab..c711bd46 100644 --- a/tests/Unit/EndpointServiceTest.php +++ b/tests/Unit/EndpointServiceTest.php @@ -13,23 +13,6 @@ */ class EndpointServiceTest extends TestCase { - protected $entityTypeManager; - - protected function setUp(): void { - parent::setUp(); - - // Mock the EntityTypeManagerInterface. - $this->entityTypeManager = $this->createMock(EntityTypeManagerInterface::class); - - // Define any specific behavior for methods you expect to call. - // For example, if you are loading storage for a particular entity type: - // $storageMock = $this->createMock(EntityStorageInterface::class); - // $this->entityTypeManager - // ->method('getStorage') - // ->with('search_api_server') - // ->willReturn($storageMock); - } - /** * Test the endpoint class's ability to generate correct URL's. * @@ -47,7 +30,7 @@ public function testURIGeneration() { 'collection' => NULL, 'leader' => FALSE, 'reload_path' => "/reload-path", - ], $this->entityTypeManager); + ]); $this->assertEquals('/core-name', $ep->getCore()); $this->assertEquals('server-path', $ep->getPath()); @@ -73,7 +56,7 @@ public function testURIGeneration() { } public function testReloadPath() { - $ep = new Endpoint(["reload_path" => "/reload"], $this->entityTypeManager); + $ep = new Endpoint(["reload_path" => "/reload"]); $this->assertEquals("/reload", $ep->getReloadPath()); } From ada254e1de1fb43c493c47d2447df5e800018b4d Mon Sep 17 00:00:00 2001 From: Brian Weaver Date: Tue, 12 Nov 2024 16:53:17 -0500 Subject: [PATCH 12/42] Add new reload drush command --- src/Commands/Reload.php | 136 ++++++++++++++++++++++++++++++++++ src/Services/SchemaPoster.php | 2 +- 2 files changed, 137 insertions(+), 1 deletion(-) create mode 100644 src/Commands/Reload.php diff --git a/src/Commands/Reload.php b/src/Commands/Reload.php new file mode 100644 index 00000000..9bf85913 --- /dev/null +++ b/src/Commands/Reload.php @@ -0,0 +1,136 @@ +logger = $loggerChannelFactory->get('SearchAPIPantheon Drush'); + $this->pantheonGuzzle = $pantheonGuzzle; + $this->schemaPoster = $schemaPoster; + } + + /** + * Search_api_pantheon:reloadSchema + * + * @usage search-api-pantheon:reloadSchema + * Reload the latest schema + * + * @command search-api-pantheon:reloadSchema + * + */ + public function reloadSchema() { + try { + $this->schemaPoster->reloadServer(); + } + catch (\Exception $e) { + $this->logger->error((string) $e); + } + } + + /** + * Search_api_pantheon:postSchema. + * + * @usage search-api-pantheon:postSchema [server_id] [path] + * Post the latest schema to the given Server. + * Default server ID = pantheon_solr8. + * Default path = empty (build files using search_api_solr mechanism). + * + * @command search-api-pantheon:postSchema + * + * @param $server_id + * Server id to post schema for. + * @param $path + * Path to schema files (Leave empty to use default schema). + * + * @aliases sapps + */ + public function postSchema(?string $server_id = NULL, ?string $path = NULL) { + if (!$server_id) { + $server_id = PantheonSolrConnector::getDefaultEndpoint(); + } + try { + $files = []; + if ($path) { + if (!is_dir($path)) { + throw new \Exception("Path '$path' is not a directory."); + } + $finder = new Finder(); + // Only work with direct children. + $finder->depth('== 0'); + $finder->files()->in($path); + if (!$finder->hasResults()) { + throw new \Exception("Path '$path' does not contain any files."); + } + foreach ($finder as $file) { + $files[$file->getfilename()] = $file->getContents(); + } + } + + $this->schemaPoster->postSchema($server_id, $files); + } + catch (\Exception $e) { + $this->logger->error((string) $e); + } + } + + /** + * View a Schema File. + * + * @param string $filename + * Filename to retrieve. + * + * @command search-api-pantheon:view-schema + * @aliases sapvs + * @usage sapvs schema.xml + * @usage search-api-pantheon:view-schema elevate.xml + * + * @throws \Exception + * @throws \Psr\Http\Client\ClientExceptionInterface + */ + public function viewSchema(string $filename = 'schema.xml') { + $currentSchema = $this->schemaPoster->viewSchema($filename); + $this->logger->notice($currentSchema); + } + +} diff --git a/src/Services/SchemaPoster.php b/src/Services/SchemaPoster.php index 76b7b8d8..545964ba 100644 --- a/src/Services/SchemaPoster.php +++ b/src/Services/SchemaPoster.php @@ -118,7 +118,7 @@ public function postSchema(string $server_id, $files = []): array { return $this->processResponse($response); } - protected function reloadServer(): void { + public function reloadServer(): void { // Schema upload URL. $uri = new Uri( $this->getClient() From 12320c00dd30c4b8afe790c62bbd8614b9c57757 Mon Sep 17 00:00:00 2001 From: Brian Weaver Date: Tue, 12 Nov 2024 16:55:03 -0500 Subject: [PATCH 13/42] Remove extra copypasta methods --- src/Commands/Reload.php | 67 ----------------------------------------- 1 file changed, 67 deletions(-) diff --git a/src/Commands/Reload.php b/src/Commands/Reload.php index 9bf85913..294ac2c2 100644 --- a/src/Commands/Reload.php +++ b/src/Commands/Reload.php @@ -67,70 +67,3 @@ public function reloadSchema() { $this->logger->error((string) $e); } } - - /** - * Search_api_pantheon:postSchema. - * - * @usage search-api-pantheon:postSchema [server_id] [path] - * Post the latest schema to the given Server. - * Default server ID = pantheon_solr8. - * Default path = empty (build files using search_api_solr mechanism). - * - * @command search-api-pantheon:postSchema - * - * @param $server_id - * Server id to post schema for. - * @param $path - * Path to schema files (Leave empty to use default schema). - * - * @aliases sapps - */ - public function postSchema(?string $server_id = NULL, ?string $path = NULL) { - if (!$server_id) { - $server_id = PantheonSolrConnector::getDefaultEndpoint(); - } - try { - $files = []; - if ($path) { - if (!is_dir($path)) { - throw new \Exception("Path '$path' is not a directory."); - } - $finder = new Finder(); - // Only work with direct children. - $finder->depth('== 0'); - $finder->files()->in($path); - if (!$finder->hasResults()) { - throw new \Exception("Path '$path' does not contain any files."); - } - foreach ($finder as $file) { - $files[$file->getfilename()] = $file->getContents(); - } - } - - $this->schemaPoster->postSchema($server_id, $files); - } - catch (\Exception $e) { - $this->logger->error((string) $e); - } - } - - /** - * View a Schema File. - * - * @param string $filename - * Filename to retrieve. - * - * @command search-api-pantheon:view-schema - * @aliases sapvs - * @usage sapvs schema.xml - * @usage search-api-pantheon:view-schema elevate.xml - * - * @throws \Exception - * @throws \Psr\Http\Client\ClientExceptionInterface - */ - public function viewSchema(string $filename = 'schema.xml') { - $currentSchema = $this->schemaPoster->viewSchema($filename); - $this->logger->notice($currentSchema); - } - -} From eb252e7b1787e4dc9a0906f114a86b5c04a8e5d1 Mon Sep 17 00:00:00 2001 From: Brian Weaver Date: Tue, 12 Nov 2024 16:56:51 -0500 Subject: [PATCH 14/42] Missing close brace --- src/Commands/Reload.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Commands/Reload.php b/src/Commands/Reload.php index 294ac2c2..4016fc4a 100644 --- a/src/Commands/Reload.php +++ b/src/Commands/Reload.php @@ -67,3 +67,4 @@ public function reloadSchema() { $this->logger->error((string) $e); } } +} From 0c8ed65b705123ec9d7e60b537837e21ba32a3be Mon Sep 17 00:00:00 2001 From: Phil Tyler Date: Tue, 12 Nov 2024 14:02:15 -0800 Subject: [PATCH 15/42] fixup --- src/Commands/Reload.php | 8 +++----- tests/Unit/EndpointServiceTest.php | 1 - 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/Commands/Reload.php b/src/Commands/Reload.php index 4016fc4a..9b42b482 100644 --- a/src/Commands/Reload.php +++ b/src/Commands/Reload.php @@ -4,16 +4,14 @@ use Drupal\Core\Logger\LoggerChannelFactoryInterface; use Drupal\Core\Logger\LoggerChannelTrait; -use Drupal\search_api_pantheon\Plugin\SolrConnector\PantheonSolrConnector; use Drupal\search_api_pantheon\Services\PantheonGuzzle; use Drupal\search_api_pantheon\Services\SchemaPoster; use Drush\Commands\DrushCommands; -use Symfony\Component\Finder\Finder; /** * Drush Search Api Pantheon Schema Commands. */ -class Schema extends DrushCommands { +class Reload extends DrushCommands { use LoggerChannelTrait; /** @@ -51,13 +49,12 @@ public function __construct( } /** - * Search_api_pantheon:reloadSchema + * Search_api_pantheon:reloadSchema. * * @usage search-api-pantheon:reloadSchema * Reload the latest schema * * @command search-api-pantheon:reloadSchema - * */ public function reloadSchema() { try { @@ -67,4 +64,5 @@ public function reloadSchema() { $this->logger->error((string) $e); } } + } diff --git a/tests/Unit/EndpointServiceTest.php b/tests/Unit/EndpointServiceTest.php index c711bd46..d37cf123 100644 --- a/tests/Unit/EndpointServiceTest.php +++ b/tests/Unit/EndpointServiceTest.php @@ -3,7 +3,6 @@ namespace Drupal\search_api_pantheon\tests\Unit; use Drupal\search_api_pantheon\Services\Endpoint; -use Drupal\Core\Entity\EntityTypeManagerInterface; use PHPUnit\Framework\TestCase; /** From 97684a7545cfb1384b387e1eb70ff5d696053aeb Mon Sep 17 00:00:00 2001 From: Phil Tyler Date: Tue, 12 Nov 2024 14:03:22 -0800 Subject: [PATCH 16/42] Update tests/Unit/EndpointServiceTest.php --- tests/Unit/EndpointServiceTest.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tests/Unit/EndpointServiceTest.php b/tests/Unit/EndpointServiceTest.php index d37cf123..8792fda1 100644 --- a/tests/Unit/EndpointServiceTest.php +++ b/tests/Unit/EndpointServiceTest.php @@ -44,10 +44,6 @@ public function testURIGeneration() { 'one://two:1234/server-path/schema-path', $ep->getSchemaUploadUri() ); - $this->assertEquals( - 'one://two:1234/server-path/schema-path', - $ep->getSchemaUploadUri() - ); $this->assertEquals( 'one://two:1234/server-path/reload-path', $ep->getReloadUri() From 9caa03f6be932acee2ae1b351d6d595ae46dab85 Mon Sep 17 00:00:00 2001 From: Phil Tyler Date: Tue, 12 Nov 2024 14:14:58 -0800 Subject: [PATCH 17/42] update services yml --- drush.services.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drush.services.yml b/drush.services.yml index 57fe20ed..f455f08f 100644 --- a/drush.services.yml +++ b/drush.services.yml @@ -19,3 +19,8 @@ services: arguments: [ "@logger.factory", "@search_api_pantheon.pantheon_guzzle", "@search_api_pantheon.endpoint", "@search_api_pantheon.solarium_client" ] tags: - { name: drush.command } +search_api_pantheon.drush_reload: + class: \Drupal\search_api_pantheon\Commands\Reload + arguments: [ "@logger.factory", "@search_api_pantheon.pantheon_guzzle", "@search_api_pantheon.schema_poster" ] + tags: + - { name: drush.command } \ No newline at end of file From 55948c711bf61d73e63c1fc5a06ca4b3cd4bfc2f Mon Sep 17 00:00:00 2001 From: Phil Tyler Date: Tue, 12 Nov 2024 14:20:30 -0800 Subject: [PATCH 18/42] whitespace --- drush.services.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drush.services.yml b/drush.services.yml index f455f08f..96d3a8d0 100644 --- a/drush.services.yml +++ b/drush.services.yml @@ -19,7 +19,7 @@ services: arguments: [ "@logger.factory", "@search_api_pantheon.pantheon_guzzle", "@search_api_pantheon.endpoint", "@search_api_pantheon.solarium_client" ] tags: - { name: drush.command } -search_api_pantheon.drush_reload: + search_api_pantheon.drush_reload: class: \Drupal\search_api_pantheon\Commands\Reload arguments: [ "@logger.factory", "@search_api_pantheon.pantheon_guzzle", "@search_api_pantheon.schema_poster" ] tags: From 89fd4bc96031f32d09eb488b73d6059363d06efa Mon Sep 17 00:00:00 2001 From: Phil Tyler Date: Tue, 12 Nov 2024 14:33:48 -0800 Subject: [PATCH 19/42] lintfix --- drush.services.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drush.services.yml b/drush.services.yml index 96d3a8d0..2be3d265 100644 --- a/drush.services.yml +++ b/drush.services.yml @@ -23,4 +23,4 @@ services: class: \Drupal\search_api_pantheon\Commands\Reload arguments: [ "@logger.factory", "@search_api_pantheon.pantheon_guzzle", "@search_api_pantheon.schema_poster" ] tags: - - { name: drush.command } \ No newline at end of file + - { name: drush.command } From a6b1488d37ab362b543b0439a343c656cace9c14 Mon Sep 17 00:00:00 2001 From: Tom Stovall Date: Tue, 12 Nov 2024 15:31:09 -0800 Subject: [PATCH 20/42] toms hasily coded slapdash core reload. --- .../SolrConnector/PantheonSolrConnector.php | 40 +++++++++++-------- src/Services/SchemaPoster.php | 5 +++ 2 files changed, 28 insertions(+), 17 deletions(-) diff --git a/src/Plugin/SolrConnector/PantheonSolrConnector.php b/src/Plugin/SolrConnector/PantheonSolrConnector.php index f2a4740c..9765057a 100644 --- a/src/Plugin/SolrConnector/PantheonSolrConnector.php +++ b/src/Plugin/SolrConnector/PantheonSolrConnector.php @@ -64,6 +64,13 @@ class PantheonSolrConnector extends SolrConnectorPluginBase implements */ protected $messenger; + /** + * The container. + * + * @var \Symfony\Component\DependencyInjection\ContainerInterface + */ + protected ContainerInterface $container; + /** * Class constructor. */ @@ -72,19 +79,17 @@ public function __construct( $plugin_id, array $plugin_definition, LoggerChannelFactoryInterface $logger_factory, - PantheonGuzzle $pantheon_guzzle, - PantheonSolariumClient $solarium_client, - DateFormatterInterface $date_formatter, - MessengerInterface $messenger + ContainerInterface $container, ) { parent::__construct($configuration, $plugin_id, $plugin_definition); - $this->pantheonGuzzle = $pantheon_guzzle; - $this->solariumClient = $solarium_client; - $this->dateFormatter = $date_formatter; - $this->messenger = $messenger; - $this->setLogger($logger_factory->get('PantheonSearch')); + $this->pantheonGuzzle = $container->get('search_api_pantheon.pantheon_guzzle'); + $this->solariumClient = $container->get('search_api_pantheon.solarium_client'); + $this->dateFormatter = $container->get('date.formatter'); + $this->messenger = $container->get('messenger'); + $this->setLogger($container->get('logger.factory')->get('PantheonSearch')); $this->configuration['core'] = self::getPlatformConfig()['core']; $this->configuration['schema'] = self::getPlatformConfig()['schema']; + $this->container = $container; $this->connect(); } @@ -107,11 +112,7 @@ public static function create( $configuration, $plugin_id, $plugin_definition, - $container->get('logger.factory'), - $container->get('search_api_pantheon.pantheon_guzzle'), - $container->get('search_api_pantheon.solarium_client'), - $container->get('date.formatter'), - $container->get('messenger') + $container, ); } @@ -406,9 +407,14 @@ public function getEndpoint($key = 'search_api_solr') { * Success or Failure. */ public function reloadCore() { - $this->logger->notice( - $this->t('Reload Core action for Pantheon Solr is automatic when Schema is updated.') - ); + $sp = $this->container->get('search_api_pantheon.schema_poster'); + if (!$sp instanceof SchemaPoster) { + throw new \RuntimeException('Unable to instantiate Schema Poster.'); + } + // Get the server id + $server_id = $this->getServerInfo()['server_id']; + $sp->postSchema($server_id); + $sp->reloadCore(); return TRUE; } diff --git a/src/Services/SchemaPoster.php b/src/Services/SchemaPoster.php index 545964ba..a2cc840a 100644 --- a/src/Services/SchemaPoster.php +++ b/src/Services/SchemaPoster.php @@ -118,6 +118,11 @@ public function postSchema(string $server_id, $files = []): array { return $this->processResponse($response); } + /** + * Reload the server after schema upload. + * + * @throws \Drupal\search_api_pantheon\Exceptions\PantheonSearchApiException + */ public function reloadServer(): void { // Schema upload URL. $uri = new Uri( From 12cab2c407aa0ee4a1f30663290fbeb03f62d41b Mon Sep 17 00:00:00 2001 From: Phil Tyler Date: Tue, 12 Nov 2024 16:03:21 -0800 Subject: [PATCH 21/42] phpcbf --- src/Plugin/SolrConnector/PantheonSolrConnector.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Plugin/SolrConnector/PantheonSolrConnector.php b/src/Plugin/SolrConnector/PantheonSolrConnector.php index 9765057a..0aedd855 100644 --- a/src/Plugin/SolrConnector/PantheonSolrConnector.php +++ b/src/Plugin/SolrConnector/PantheonSolrConnector.php @@ -15,7 +15,6 @@ use Drupal\search_api_pantheon\Services\SolariumClient as PantheonSolariumClient; use Drupal\Core\Logger\LoggerChannelFactoryInterface; use Drupal\Core\Datetime\DateFormatterInterface; -use Drupal\Core\Messenger\MessengerInterface; /** * Pantheon Solr connector. From 7debd4b73c3336471eb965aa128269835d8b113c Mon Sep 17 00:00:00 2001 From: Tom Stovall Date: Tue, 12 Nov 2024 16:35:05 -0800 Subject: [PATCH 22/42] linting --- .../SolrConnector/PantheonSolrConnector.php | 178 +++++++++--------- 1 file changed, 87 insertions(+), 91 deletions(-) diff --git a/src/Plugin/SolrConnector/PantheonSolrConnector.php b/src/Plugin/SolrConnector/PantheonSolrConnector.php index 0aedd855..f5ec5939 100644 --- a/src/Plugin/SolrConnector/PantheonSolrConnector.php +++ b/src/Plugin/SolrConnector/PantheonSolrConnector.php @@ -13,7 +13,6 @@ use Symfony\Component\DependencyInjection\ContainerInterface; use Drupal\search_api_pantheon\Services\PantheonGuzzle; use Drupal\search_api_pantheon\Services\SolariumClient as PantheonSolariumClient; -use Drupal\Core\Logger\LoggerChannelFactoryInterface; use Drupal\Core\Datetime\DateFormatterInterface; /** @@ -74,11 +73,10 @@ class PantheonSolrConnector extends SolrConnectorPluginBase implements * Class constructor. */ public function __construct( - array $configuration, - $plugin_id, - array $plugin_definition, - LoggerChannelFactoryInterface $logger_factory, - ContainerInterface $container, + array $configuration, + $plugin_id, + array $plugin_definition, + ContainerInterface $container, ) { parent::__construct($configuration, $plugin_id, $plugin_definition); $this->pantheonGuzzle = $container->get('search_api_pantheon.pantheon_guzzle'); @@ -102,17 +100,17 @@ public function __construct( * @throws \Exception */ public static function create( - ContainerInterface $container, - array $configuration, - $plugin_id, - $plugin_definition - ) { + ContainerInterface $container, + array $configuration, + $plugin_id, + $plugin_definition + ) { return new static( - $configuration, - $plugin_id, - $plugin_definition, - $container, - ); + $configuration, + $plugin_id, + $plugin_definition, + $container, + ); } /** @@ -171,9 +169,9 @@ public function defaultConfiguration() { * Form render array. */ public function buildConfigurationForm( - array $form, - FormStateInterface $form_state - ) { + array $form, + FormStateInterface $form_state + ) { $form = parent::buildConfigurationForm($form, $form_state); $fields = [ @@ -209,9 +207,9 @@ function ($field_name) use ($fields) { * Form state object. */ public function validateConfigurationForm( - array &$form, - FormStateInterface $form_state - ) { + array &$form, + FormStateInterface $form_state + ) { } /** @@ -223,9 +221,9 @@ public function validateConfigurationForm( * Form state object. */ public function submitConfigurationForm( - array &$form, - FormStateInterface $form_state - ) { + array &$form, + FormStateInterface $form_state + ) { $configuration = array_merge($this->defaultConfiguration(), $form_state->getValues()); $this->setConfiguration($configuration); @@ -294,16 +292,16 @@ public function getStatsSummary() { } $summary = [ - '@pending_docs' => '', - '@autocommit_time_seconds' => '', - '@autocommit_time' => '', - '@deletes_by_id' => '', - '@deletes_by_query' => '', - '@deletes_total' => '', - '@schema_version' => '', - '@core_name' => '', - '@index_size' => '', - ]; + '@pending_docs' => '', + '@autocommit_time_seconds' => '', + '@autocommit_time' => '', + '@deletes_by_id' => '', + '@deletes_by_query' => '', + '@deletes_total' => '', + '@schema_version' => '', + '@core_name' => '', + '@index_size' => '', + ]; if (empty($stats) || empty($indexStats)) { return $summary; @@ -312,33 +310,33 @@ public function getStatsSummary() { $max_time = -1; $update_handler_stats = $stats['UPDATE']['updateHandler']['stats'] ?? -1; $summary['@pending_docs'] = - (int) $update_handler_stats['UPDATE.updateHandler.docsPending'] ?? -1; + (int) $update_handler_stats['UPDATE.updateHandler.docsPending'] ?? -1; if ( - isset( - $update_handler_stats['UPDATE.updateHandler.softAutoCommitMaxTime'] - ) - ) { + isset( + $update_handler_stats['UPDATE.updateHandler.softAutoCommitMaxTime'] + ) + ) { $max_time = - (int) $update_handler_stats['UPDATE.updateHandler.softAutoCommitMaxTime']; + (int) $update_handler_stats['UPDATE.updateHandler.softAutoCommitMaxTime']; } $summary['@deletes_by_id'] = - (int) $update_handler_stats['UPDATE.updateHandler.deletesById'] ?? -1; + (int) $update_handler_stats['UPDATE.updateHandler.deletesById'] ?? -1; $summary['@deletes_by_query'] = - (int) $update_handler_stats['UPDATE.updateHandler.deletesByQuery'] ?? -1; + (int) $update_handler_stats['UPDATE.updateHandler.deletesByQuery'] ?? -1; $summary['@core_name'] = - $stats['CORE']['core']['class'] ?? - $this->t('No information available.'); + $stats['CORE']['core']['class'] ?? + $this->t('No information available.'); $summary['@index_size'] = - $indexStats['numDocs'] ?? $this->t('No information available.'); + $indexStats['numDocs'] ?? $this->t('No information available.'); $summary['@autocommit_time_seconds'] = $max_time / 1000; $summary['@autocommit_time'] = $this->dateFormatter ->formatInterval($max_time / 1000); $summary['@deletes_total'] = - ( - intval($summary['@deletes_by_id'] ?? 0) - + intval($summary['@deletes_by_query'] ?? 0) - ) ?? -1; + ( + intval($summary['@deletes_by_id'] ?? 0) + + intval($summary['@deletes_by_query'] ?? 0) + ) ?? -1; $summary['@schema_version'] = $this->getSchemaVersionString(TRUE); return $summary; } @@ -347,9 +345,9 @@ public function getStatsSummary() { * {@inheritdoc} */ public function useTimeout( - string $timeout = self::QUERY_TIMEOUT, - ?Endpoint $endpoint = NULL - ) { + string $timeout = self::QUERY_TIMEOUT, + ?Endpoint $endpoint = NULL + ) { } /** @@ -361,25 +359,25 @@ public function viewSettings() { $view_settings = []; $view_settings[] = [ - 'label' => $this->t('Pantheon Sitename'), - 'info' => $this->getEndpoint()->getCore(), - ]; + 'label' => $this->t('Pantheon Sitename'), + 'info' => $this->getEndpoint()->getCore(), + ]; $view_settings[] = [ - 'label' => $this->t('Pantheon Environment'), - 'info' => getenv('PANTHEON_ENVIRONMENT'), - ]; + 'label' => $this->t('Pantheon Environment'), + 'info' => getenv('PANTHEON_ENVIRONMENT'), + ]; $view_settings[] = [ - 'label' => $this->t('Schema Version'), - 'info' => $this->getSchemaVersion(TRUE), - ]; + 'label' => $this->t('Schema Version'), + 'info' => $this->getSchemaVersion(TRUE), + ]; $core_info = $this->getCoreInfo(TRUE); foreach ($core_info['core'] as $key => $value) { if (is_string($value)) { $view_settings[] = [ - 'label' => ucwords($key), - 'info' => $value, - ]; + 'label' => ucwords($key), + 'info' => $value, + ]; } } @@ -410,10 +408,8 @@ public function reloadCore() { if (!$sp instanceof SchemaPoster) { throw new \RuntimeException('Unable to instantiate Schema Poster.'); } - // Get the server id - $server_id = $this->getServerInfo()['server_id']; - $sp->postSchema($server_id); $sp->reloadCore(); + $this->logger->info('Core reloaded.'); return TRUE; } @@ -468,29 +464,29 @@ protected function createClient(array &$configuration) { */ protected function getStatsQuery(string $handler) { return json_decode( - $this->pantheonGuzzle - ->get( - $handler, - [ - 'query' => - [ - 'stats' => 'true', - 'wt' => 'json', - 'accept' => 'application/json', - 'contenttype' => 'application/json', - 'json.nl' => 'flat', - ], - 'headers' => - [ - 'Content-Type' => 'application/json', - 'Accept' => 'application/json', - ], - ] - ) - ->getBody(), - TRUE, - JSON_THROW_ON_ERROR - ); + $this->pantheonGuzzle + ->get( + $handler, + [ + 'query' => + [ + 'stats' => 'true', + 'wt' => 'json', + 'accept' => 'application/json', + 'contenttype' => 'application/json', + 'json.nl' => 'flat', + ], + 'headers' => + [ + 'Content-Type' => 'application/json', + 'Accept' => 'application/json', + ], + ] + ) + ->getBody(), + TRUE, + JSON_THROW_ON_ERROR + ); } } From 6782f08e4080429fcd976fea03a7f1d93c81c343 Mon Sep 17 00:00:00 2001 From: Tom Stovall <119924+stovak@users.noreply.github.com> Date: Tue, 12 Nov 2024 16:41:36 -0800 Subject: [PATCH 23/42] Update .gitignore Co-authored-by: Phil Tyler --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index b580ef1d..6baa65bf 100644 --- a/.gitignore +++ b/.gitignore @@ -9,4 +9,4 @@ .DS_Store docs/Badge.confluence -.envrc \ No newline at end of file +.envrc From e829f7c16724d7d0b317125b1fa35650a3a34e37 Mon Sep 17 00:00:00 2001 From: Phil Tyler Date: Tue, 12 Nov 2024 19:35:21 -0800 Subject: [PATCH 24/42] Reload server, not reload core --- src/Plugin/SolrConnector/PantheonSolrConnector.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Plugin/SolrConnector/PantheonSolrConnector.php b/src/Plugin/SolrConnector/PantheonSolrConnector.php index f5ec5939..8d263452 100644 --- a/src/Plugin/SolrConnector/PantheonSolrConnector.php +++ b/src/Plugin/SolrConnector/PantheonSolrConnector.php @@ -408,7 +408,7 @@ public function reloadCore() { if (!$sp instanceof SchemaPoster) { throw new \RuntimeException('Unable to instantiate Schema Poster.'); } - $sp->reloadCore(); + $sp->reloadServer(); $this->logger->info('Core reloaded.'); return TRUE; } From 41de0217501c47ddf08621a694d1883095189b0b Mon Sep 17 00:00:00 2001 From: Phil Tyler Date: Tue, 12 Nov 2024 21:37:51 -0800 Subject: [PATCH 25/42] Revert "toms hasily coded slapdash core reload." This reverts commit a6b1488d37ab362b543b0439a343c656cace9c14. --- .../SolrConnector/PantheonSolrConnector.php | 209 +++++++++--------- src/Services/SchemaPoster.php | 5 - 2 files changed, 104 insertions(+), 110 deletions(-) diff --git a/src/Plugin/SolrConnector/PantheonSolrConnector.php b/src/Plugin/SolrConnector/PantheonSolrConnector.php index 8d263452..f2a4740c 100644 --- a/src/Plugin/SolrConnector/PantheonSolrConnector.php +++ b/src/Plugin/SolrConnector/PantheonSolrConnector.php @@ -13,7 +13,9 @@ use Symfony\Component\DependencyInjection\ContainerInterface; use Drupal\search_api_pantheon\Services\PantheonGuzzle; use Drupal\search_api_pantheon\Services\SolariumClient as PantheonSolariumClient; +use Drupal\Core\Logger\LoggerChannelFactoryInterface; use Drupal\Core\Datetime\DateFormatterInterface; +use Drupal\Core\Messenger\MessengerInterface; /** * Pantheon Solr connector. @@ -62,31 +64,27 @@ class PantheonSolrConnector extends SolrConnectorPluginBase implements */ protected $messenger; - /** - * The container. - * - * @var \Symfony\Component\DependencyInjection\ContainerInterface - */ - protected ContainerInterface $container; - /** * Class constructor. */ public function __construct( - array $configuration, - $plugin_id, - array $plugin_definition, - ContainerInterface $container, + array $configuration, + $plugin_id, + array $plugin_definition, + LoggerChannelFactoryInterface $logger_factory, + PantheonGuzzle $pantheon_guzzle, + PantheonSolariumClient $solarium_client, + DateFormatterInterface $date_formatter, + MessengerInterface $messenger ) { parent::__construct($configuration, $plugin_id, $plugin_definition); - $this->pantheonGuzzle = $container->get('search_api_pantheon.pantheon_guzzle'); - $this->solariumClient = $container->get('search_api_pantheon.solarium_client'); - $this->dateFormatter = $container->get('date.formatter'); - $this->messenger = $container->get('messenger'); - $this->setLogger($container->get('logger.factory')->get('PantheonSearch')); + $this->pantheonGuzzle = $pantheon_guzzle; + $this->solariumClient = $solarium_client; + $this->dateFormatter = $date_formatter; + $this->messenger = $messenger; + $this->setLogger($logger_factory->get('PantheonSearch')); $this->configuration['core'] = self::getPlatformConfig()['core']; $this->configuration['schema'] = self::getPlatformConfig()['schema']; - $this->container = $container; $this->connect(); } @@ -100,17 +98,21 @@ public function __construct( * @throws \Exception */ public static function create( - ContainerInterface $container, - array $configuration, - $plugin_id, - $plugin_definition - ) { + ContainerInterface $container, + array $configuration, + $plugin_id, + $plugin_definition + ) { return new static( - $configuration, - $plugin_id, - $plugin_definition, - $container, - ); + $configuration, + $plugin_id, + $plugin_definition, + $container->get('logger.factory'), + $container->get('search_api_pantheon.pantheon_guzzle'), + $container->get('search_api_pantheon.solarium_client'), + $container->get('date.formatter'), + $container->get('messenger') + ); } /** @@ -169,9 +171,9 @@ public function defaultConfiguration() { * Form render array. */ public function buildConfigurationForm( - array $form, - FormStateInterface $form_state - ) { + array $form, + FormStateInterface $form_state + ) { $form = parent::buildConfigurationForm($form, $form_state); $fields = [ @@ -207,9 +209,9 @@ function ($field_name) use ($fields) { * Form state object. */ public function validateConfigurationForm( - array &$form, - FormStateInterface $form_state - ) { + array &$form, + FormStateInterface $form_state + ) { } /** @@ -221,9 +223,9 @@ public function validateConfigurationForm( * Form state object. */ public function submitConfigurationForm( - array &$form, - FormStateInterface $form_state - ) { + array &$form, + FormStateInterface $form_state + ) { $configuration = array_merge($this->defaultConfiguration(), $form_state->getValues()); $this->setConfiguration($configuration); @@ -292,16 +294,16 @@ public function getStatsSummary() { } $summary = [ - '@pending_docs' => '', - '@autocommit_time_seconds' => '', - '@autocommit_time' => '', - '@deletes_by_id' => '', - '@deletes_by_query' => '', - '@deletes_total' => '', - '@schema_version' => '', - '@core_name' => '', - '@index_size' => '', - ]; + '@pending_docs' => '', + '@autocommit_time_seconds' => '', + '@autocommit_time' => '', + '@deletes_by_id' => '', + '@deletes_by_query' => '', + '@deletes_total' => '', + '@schema_version' => '', + '@core_name' => '', + '@index_size' => '', + ]; if (empty($stats) || empty($indexStats)) { return $summary; @@ -310,33 +312,33 @@ public function getStatsSummary() { $max_time = -1; $update_handler_stats = $stats['UPDATE']['updateHandler']['stats'] ?? -1; $summary['@pending_docs'] = - (int) $update_handler_stats['UPDATE.updateHandler.docsPending'] ?? -1; + (int) $update_handler_stats['UPDATE.updateHandler.docsPending'] ?? -1; if ( - isset( - $update_handler_stats['UPDATE.updateHandler.softAutoCommitMaxTime'] - ) - ) { + isset( + $update_handler_stats['UPDATE.updateHandler.softAutoCommitMaxTime'] + ) + ) { $max_time = - (int) $update_handler_stats['UPDATE.updateHandler.softAutoCommitMaxTime']; + (int) $update_handler_stats['UPDATE.updateHandler.softAutoCommitMaxTime']; } $summary['@deletes_by_id'] = - (int) $update_handler_stats['UPDATE.updateHandler.deletesById'] ?? -1; + (int) $update_handler_stats['UPDATE.updateHandler.deletesById'] ?? -1; $summary['@deletes_by_query'] = - (int) $update_handler_stats['UPDATE.updateHandler.deletesByQuery'] ?? -1; + (int) $update_handler_stats['UPDATE.updateHandler.deletesByQuery'] ?? -1; $summary['@core_name'] = - $stats['CORE']['core']['class'] ?? - $this->t('No information available.'); + $stats['CORE']['core']['class'] ?? + $this->t('No information available.'); $summary['@index_size'] = - $indexStats['numDocs'] ?? $this->t('No information available.'); + $indexStats['numDocs'] ?? $this->t('No information available.'); $summary['@autocommit_time_seconds'] = $max_time / 1000; $summary['@autocommit_time'] = $this->dateFormatter ->formatInterval($max_time / 1000); $summary['@deletes_total'] = - ( - intval($summary['@deletes_by_id'] ?? 0) - + intval($summary['@deletes_by_query'] ?? 0) - ) ?? -1; + ( + intval($summary['@deletes_by_id'] ?? 0) + + intval($summary['@deletes_by_query'] ?? 0) + ) ?? -1; $summary['@schema_version'] = $this->getSchemaVersionString(TRUE); return $summary; } @@ -345,9 +347,9 @@ public function getStatsSummary() { * {@inheritdoc} */ public function useTimeout( - string $timeout = self::QUERY_TIMEOUT, - ?Endpoint $endpoint = NULL - ) { + string $timeout = self::QUERY_TIMEOUT, + ?Endpoint $endpoint = NULL + ) { } /** @@ -359,25 +361,25 @@ public function viewSettings() { $view_settings = []; $view_settings[] = [ - 'label' => $this->t('Pantheon Sitename'), - 'info' => $this->getEndpoint()->getCore(), - ]; + 'label' => $this->t('Pantheon Sitename'), + 'info' => $this->getEndpoint()->getCore(), + ]; $view_settings[] = [ - 'label' => $this->t('Pantheon Environment'), - 'info' => getenv('PANTHEON_ENVIRONMENT'), - ]; + 'label' => $this->t('Pantheon Environment'), + 'info' => getenv('PANTHEON_ENVIRONMENT'), + ]; $view_settings[] = [ - 'label' => $this->t('Schema Version'), - 'info' => $this->getSchemaVersion(TRUE), - ]; + 'label' => $this->t('Schema Version'), + 'info' => $this->getSchemaVersion(TRUE), + ]; $core_info = $this->getCoreInfo(TRUE); foreach ($core_info['core'] as $key => $value) { if (is_string($value)) { $view_settings[] = [ - 'label' => ucwords($key), - 'info' => $value, - ]; + 'label' => ucwords($key), + 'info' => $value, + ]; } } @@ -404,12 +406,9 @@ public function getEndpoint($key = 'search_api_solr') { * Success or Failure. */ public function reloadCore() { - $sp = $this->container->get('search_api_pantheon.schema_poster'); - if (!$sp instanceof SchemaPoster) { - throw new \RuntimeException('Unable to instantiate Schema Poster.'); - } - $sp->reloadServer(); - $this->logger->info('Core reloaded.'); + $this->logger->notice( + $this->t('Reload Core action for Pantheon Solr is automatic when Schema is updated.') + ); return TRUE; } @@ -464,29 +463,29 @@ protected function createClient(array &$configuration) { */ protected function getStatsQuery(string $handler) { return json_decode( - $this->pantheonGuzzle - ->get( - $handler, - [ - 'query' => - [ - 'stats' => 'true', - 'wt' => 'json', - 'accept' => 'application/json', - 'contenttype' => 'application/json', - 'json.nl' => 'flat', - ], - 'headers' => - [ - 'Content-Type' => 'application/json', - 'Accept' => 'application/json', - ], - ] - ) - ->getBody(), - TRUE, - JSON_THROW_ON_ERROR - ); + $this->pantheonGuzzle + ->get( + $handler, + [ + 'query' => + [ + 'stats' => 'true', + 'wt' => 'json', + 'accept' => 'application/json', + 'contenttype' => 'application/json', + 'json.nl' => 'flat', + ], + 'headers' => + [ + 'Content-Type' => 'application/json', + 'Accept' => 'application/json', + ], + ] + ) + ->getBody(), + TRUE, + JSON_THROW_ON_ERROR + ); } } diff --git a/src/Services/SchemaPoster.php b/src/Services/SchemaPoster.php index a2cc840a..545964ba 100644 --- a/src/Services/SchemaPoster.php +++ b/src/Services/SchemaPoster.php @@ -118,11 +118,6 @@ public function postSchema(string $server_id, $files = []): array { return $this->processResponse($response); } - /** - * Reload the server after schema upload. - * - * @throws \Drupal\search_api_pantheon\Exceptions\PantheonSearchApiException - */ public function reloadServer(): void { // Schema upload URL. $uri = new Uri( From c1ba15190a434e94e24ca3bc6bfe4ea2892bca9c Mon Sep 17 00:00:00 2001 From: Phil Tyler Date: Tue, 12 Nov 2024 21:38:30 -0800 Subject: [PATCH 26/42] restore docblock --- src/Services/SchemaPoster.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Services/SchemaPoster.php b/src/Services/SchemaPoster.php index 545964ba..a2cc840a 100644 --- a/src/Services/SchemaPoster.php +++ b/src/Services/SchemaPoster.php @@ -118,6 +118,11 @@ public function postSchema(string $server_id, $files = []): array { return $this->processResponse($response); } + /** + * Reload the server after schema upload. + * + * @throws \Drupal\search_api_pantheon\Exceptions\PantheonSearchApiException + */ public function reloadServer(): void { // Schema upload URL. $uri = new Uri( From 9031e509fbc2dfed50d2b7dd2554573b6380907c Mon Sep 17 00:00:00 2001 From: Phil Tyler Date: Tue, 12 Nov 2024 21:38:42 -0800 Subject: [PATCH 27/42] restore line ending fix --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 6baa65bf..b580ef1d 100644 --- a/.gitignore +++ b/.gitignore @@ -9,4 +9,4 @@ .DS_Store docs/Badge.confluence -.envrc +.envrc \ No newline at end of file From 54ae001d7bd8cf0c7c78ddfc871c8567a42a2cce Mon Sep 17 00:00:00 2001 From: Phil Tyler Date: Wed, 13 Nov 2024 09:50:12 -0800 Subject: [PATCH 28/42] Reapply "toms hasily coded slapdash core reload." This reverts commit 41de0217501c47ddf08621a694d1883095189b0b. --- .gitignore | 2 +- .../SolrConnector/PantheonSolrConnector.php | 209 +++++++++--------- 2 files changed, 106 insertions(+), 105 deletions(-) diff --git a/.gitignore b/.gitignore index b580ef1d..6baa65bf 100644 --- a/.gitignore +++ b/.gitignore @@ -9,4 +9,4 @@ .DS_Store docs/Badge.confluence -.envrc \ No newline at end of file +.envrc diff --git a/src/Plugin/SolrConnector/PantheonSolrConnector.php b/src/Plugin/SolrConnector/PantheonSolrConnector.php index f2a4740c..8d263452 100644 --- a/src/Plugin/SolrConnector/PantheonSolrConnector.php +++ b/src/Plugin/SolrConnector/PantheonSolrConnector.php @@ -13,9 +13,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface; use Drupal\search_api_pantheon\Services\PantheonGuzzle; use Drupal\search_api_pantheon\Services\SolariumClient as PantheonSolariumClient; -use Drupal\Core\Logger\LoggerChannelFactoryInterface; use Drupal\Core\Datetime\DateFormatterInterface; -use Drupal\Core\Messenger\MessengerInterface; /** * Pantheon Solr connector. @@ -64,27 +62,31 @@ class PantheonSolrConnector extends SolrConnectorPluginBase implements */ protected $messenger; + /** + * The container. + * + * @var \Symfony\Component\DependencyInjection\ContainerInterface + */ + protected ContainerInterface $container; + /** * Class constructor. */ public function __construct( - array $configuration, - $plugin_id, - array $plugin_definition, - LoggerChannelFactoryInterface $logger_factory, - PantheonGuzzle $pantheon_guzzle, - PantheonSolariumClient $solarium_client, - DateFormatterInterface $date_formatter, - MessengerInterface $messenger + array $configuration, + $plugin_id, + array $plugin_definition, + ContainerInterface $container, ) { parent::__construct($configuration, $plugin_id, $plugin_definition); - $this->pantheonGuzzle = $pantheon_guzzle; - $this->solariumClient = $solarium_client; - $this->dateFormatter = $date_formatter; - $this->messenger = $messenger; - $this->setLogger($logger_factory->get('PantheonSearch')); + $this->pantheonGuzzle = $container->get('search_api_pantheon.pantheon_guzzle'); + $this->solariumClient = $container->get('search_api_pantheon.solarium_client'); + $this->dateFormatter = $container->get('date.formatter'); + $this->messenger = $container->get('messenger'); + $this->setLogger($container->get('logger.factory')->get('PantheonSearch')); $this->configuration['core'] = self::getPlatformConfig()['core']; $this->configuration['schema'] = self::getPlatformConfig()['schema']; + $this->container = $container; $this->connect(); } @@ -98,21 +100,17 @@ public function __construct( * @throws \Exception */ public static function create( - ContainerInterface $container, - array $configuration, - $plugin_id, - $plugin_definition - ) { + ContainerInterface $container, + array $configuration, + $plugin_id, + $plugin_definition + ) { return new static( - $configuration, - $plugin_id, - $plugin_definition, - $container->get('logger.factory'), - $container->get('search_api_pantheon.pantheon_guzzle'), - $container->get('search_api_pantheon.solarium_client'), - $container->get('date.formatter'), - $container->get('messenger') - ); + $configuration, + $plugin_id, + $plugin_definition, + $container, + ); } /** @@ -171,9 +169,9 @@ public function defaultConfiguration() { * Form render array. */ public function buildConfigurationForm( - array $form, - FormStateInterface $form_state - ) { + array $form, + FormStateInterface $form_state + ) { $form = parent::buildConfigurationForm($form, $form_state); $fields = [ @@ -209,9 +207,9 @@ function ($field_name) use ($fields) { * Form state object. */ public function validateConfigurationForm( - array &$form, - FormStateInterface $form_state - ) { + array &$form, + FormStateInterface $form_state + ) { } /** @@ -223,9 +221,9 @@ public function validateConfigurationForm( * Form state object. */ public function submitConfigurationForm( - array &$form, - FormStateInterface $form_state - ) { + array &$form, + FormStateInterface $form_state + ) { $configuration = array_merge($this->defaultConfiguration(), $form_state->getValues()); $this->setConfiguration($configuration); @@ -294,16 +292,16 @@ public function getStatsSummary() { } $summary = [ - '@pending_docs' => '', - '@autocommit_time_seconds' => '', - '@autocommit_time' => '', - '@deletes_by_id' => '', - '@deletes_by_query' => '', - '@deletes_total' => '', - '@schema_version' => '', - '@core_name' => '', - '@index_size' => '', - ]; + '@pending_docs' => '', + '@autocommit_time_seconds' => '', + '@autocommit_time' => '', + '@deletes_by_id' => '', + '@deletes_by_query' => '', + '@deletes_total' => '', + '@schema_version' => '', + '@core_name' => '', + '@index_size' => '', + ]; if (empty($stats) || empty($indexStats)) { return $summary; @@ -312,33 +310,33 @@ public function getStatsSummary() { $max_time = -1; $update_handler_stats = $stats['UPDATE']['updateHandler']['stats'] ?? -1; $summary['@pending_docs'] = - (int) $update_handler_stats['UPDATE.updateHandler.docsPending'] ?? -1; + (int) $update_handler_stats['UPDATE.updateHandler.docsPending'] ?? -1; if ( - isset( - $update_handler_stats['UPDATE.updateHandler.softAutoCommitMaxTime'] - ) - ) { + isset( + $update_handler_stats['UPDATE.updateHandler.softAutoCommitMaxTime'] + ) + ) { $max_time = - (int) $update_handler_stats['UPDATE.updateHandler.softAutoCommitMaxTime']; + (int) $update_handler_stats['UPDATE.updateHandler.softAutoCommitMaxTime']; } $summary['@deletes_by_id'] = - (int) $update_handler_stats['UPDATE.updateHandler.deletesById'] ?? -1; + (int) $update_handler_stats['UPDATE.updateHandler.deletesById'] ?? -1; $summary['@deletes_by_query'] = - (int) $update_handler_stats['UPDATE.updateHandler.deletesByQuery'] ?? -1; + (int) $update_handler_stats['UPDATE.updateHandler.deletesByQuery'] ?? -1; $summary['@core_name'] = - $stats['CORE']['core']['class'] ?? - $this->t('No information available.'); + $stats['CORE']['core']['class'] ?? + $this->t('No information available.'); $summary['@index_size'] = - $indexStats['numDocs'] ?? $this->t('No information available.'); + $indexStats['numDocs'] ?? $this->t('No information available.'); $summary['@autocommit_time_seconds'] = $max_time / 1000; $summary['@autocommit_time'] = $this->dateFormatter ->formatInterval($max_time / 1000); $summary['@deletes_total'] = - ( - intval($summary['@deletes_by_id'] ?? 0) - + intval($summary['@deletes_by_query'] ?? 0) - ) ?? -1; + ( + intval($summary['@deletes_by_id'] ?? 0) + + intval($summary['@deletes_by_query'] ?? 0) + ) ?? -1; $summary['@schema_version'] = $this->getSchemaVersionString(TRUE); return $summary; } @@ -347,9 +345,9 @@ public function getStatsSummary() { * {@inheritdoc} */ public function useTimeout( - string $timeout = self::QUERY_TIMEOUT, - ?Endpoint $endpoint = NULL - ) { + string $timeout = self::QUERY_TIMEOUT, + ?Endpoint $endpoint = NULL + ) { } /** @@ -361,25 +359,25 @@ public function viewSettings() { $view_settings = []; $view_settings[] = [ - 'label' => $this->t('Pantheon Sitename'), - 'info' => $this->getEndpoint()->getCore(), - ]; + 'label' => $this->t('Pantheon Sitename'), + 'info' => $this->getEndpoint()->getCore(), + ]; $view_settings[] = [ - 'label' => $this->t('Pantheon Environment'), - 'info' => getenv('PANTHEON_ENVIRONMENT'), - ]; + 'label' => $this->t('Pantheon Environment'), + 'info' => getenv('PANTHEON_ENVIRONMENT'), + ]; $view_settings[] = [ - 'label' => $this->t('Schema Version'), - 'info' => $this->getSchemaVersion(TRUE), - ]; + 'label' => $this->t('Schema Version'), + 'info' => $this->getSchemaVersion(TRUE), + ]; $core_info = $this->getCoreInfo(TRUE); foreach ($core_info['core'] as $key => $value) { if (is_string($value)) { $view_settings[] = [ - 'label' => ucwords($key), - 'info' => $value, - ]; + 'label' => ucwords($key), + 'info' => $value, + ]; } } @@ -406,9 +404,12 @@ public function getEndpoint($key = 'search_api_solr') { * Success or Failure. */ public function reloadCore() { - $this->logger->notice( - $this->t('Reload Core action for Pantheon Solr is automatic when Schema is updated.') - ); + $sp = $this->container->get('search_api_pantheon.schema_poster'); + if (!$sp instanceof SchemaPoster) { + throw new \RuntimeException('Unable to instantiate Schema Poster.'); + } + $sp->reloadServer(); + $this->logger->info('Core reloaded.'); return TRUE; } @@ -463,29 +464,29 @@ protected function createClient(array &$configuration) { */ protected function getStatsQuery(string $handler) { return json_decode( - $this->pantheonGuzzle - ->get( - $handler, - [ - 'query' => - [ - 'stats' => 'true', - 'wt' => 'json', - 'accept' => 'application/json', - 'contenttype' => 'application/json', - 'json.nl' => 'flat', - ], - 'headers' => - [ - 'Content-Type' => 'application/json', - 'Accept' => 'application/json', - ], - ] - ) - ->getBody(), - TRUE, - JSON_THROW_ON_ERROR - ); + $this->pantheonGuzzle + ->get( + $handler, + [ + 'query' => + [ + 'stats' => 'true', + 'wt' => 'json', + 'accept' => 'application/json', + 'contenttype' => 'application/json', + 'json.nl' => 'flat', + ], + 'headers' => + [ + 'Content-Type' => 'application/json', + 'Accept' => 'application/json', + ], + ] + ) + ->getBody(), + TRUE, + JSON_THROW_ON_ERROR + ); } } From 14717424b9f58529e1532ffe71b730b9f02d91ac Mon Sep 17 00:00:00 2001 From: Phil Tyler Date: Wed, 13 Nov 2024 11:22:23 -0800 Subject: [PATCH 29/42] new robo drush tests --- RoboFile.php | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/RoboFile.php b/RoboFile.php index bc25bcf2..66b5440b 100644 --- a/RoboFile.php +++ b/RoboFile.php @@ -117,6 +117,10 @@ public function testFull(int $drupal_version = 9, string $site_name = NULL) { // Test creating Solr index. $this->testSolrIndexCreate($site_name, 'dev'); + // Test running the reload + $this->testPantheonSolrReload($site_name, 'dev'); + $this->testSolrReload($site_name, 'dev'); + // Test select query. $this->testSolrSelect($site_name, 'dev'); @@ -802,9 +806,41 @@ public function testSolrIndexCreate(string $site_name, string $env = 'dev') { if (!$result->wasSuccessful()) { exit(1); } + } + public function testPantheonSolrReload(string $site_name, string $env = 'dev') { + $result = $this->taskExec( static::$TERMINUS_EXE ) + ->args( + 'drush', + "$site_name.$env", + '--', + 'search-api-pantheon:reloadSchema', + ) + ->run(); + if (!$result->wasSuccessful()) { + exit(1); + } } + public function testSolrReload(string $site_name, string $env = 'dev') { + $result = $this->taskExec( static::$TERMINUS_EXE ) + ->args( + 'drush', + "$site_name.$env", + '--', + 'search-api-solr:reload', + 'pantheon_solr8' + ) + ->run(); + if (!$result->wasSuccessful()) { + exit(1); + } + } + + + + + /** * Use search-api-pantheon:select command to ensure both Drupal index and the actual Solr index have the same amount of items. * From abbb048268657ce35a94aa305f10e4542c53f509 Mon Sep 17 00:00:00 2001 From: Tom Stovall Date: Wed, 13 Nov 2024 12:19:24 -0800 Subject: [PATCH 30/42] Moving reload to it's own service --- search_api_pantheon.services.yml | 3 + .../SolrConnector/PantheonSolrConnector.php | 7 +- src/Services/PantheonGuzzle.php | 10 ++- src/Services/Reload.php | 83 +++++++++++++++++++ src/Services/SchemaPoster.php | 33 +------- 5 files changed, 99 insertions(+), 37 deletions(-) create mode 100644 src/Services/Reload.php diff --git a/search_api_pantheon.services.yml b/search_api_pantheon.services.yml index f20aa923..59e0c3bf 100755 --- a/search_api_pantheon.services.yml +++ b/search_api_pantheon.services.yml @@ -15,3 +15,6 @@ services: class: Drupal\search_api_pantheon\EventSubscriber\SearchApiPantheonSolrConfigFilesAlter tags: - { name: event_subscriber } + search_api_pantheon.reload: + class: Drupal\search_api_pantheon\Services\Reload + arguments: ['@logger.factory', '@search_api_pantheon.pantheon_guzzle'] \ No newline at end of file diff --git a/src/Plugin/SolrConnector/PantheonSolrConnector.php b/src/Plugin/SolrConnector/PantheonSolrConnector.php index 8d263452..7596f219 100644 --- a/src/Plugin/SolrConnector/PantheonSolrConnector.php +++ b/src/Plugin/SolrConnector/PantheonSolrConnector.php @@ -79,13 +79,12 @@ public function __construct( ContainerInterface $container, ) { parent::__construct($configuration, $plugin_id, $plugin_definition); + $this->configuration = array_merge($configuration, self::getPlatformConfig()); $this->pantheonGuzzle = $container->get('search_api_pantheon.pantheon_guzzle'); $this->solariumClient = $container->get('search_api_pantheon.solarium_client'); $this->dateFormatter = $container->get('date.formatter'); $this->messenger = $container->get('messenger'); $this->setLogger($container->get('logger.factory')->get('PantheonSearch')); - $this->configuration['core'] = self::getPlatformConfig()['core']; - $this->configuration['schema'] = self::getPlatformConfig()['schema']; $this->container = $container; $this->connect(); } @@ -406,9 +405,9 @@ public function getEndpoint($key = 'search_api_solr') { public function reloadCore() { $sp = $this->container->get('search_api_pantheon.schema_poster'); if (!$sp instanceof SchemaPoster) { - throw new \RuntimeException('Unable to instantiate Schema Poster.'); + $sp = \Drupal::getContainer()->get('search_api_pantheon.schema_poster'); } - $sp->reloadServer(); + $sp->reloadCore(); $this->logger->info('Core reloaded.'); return TRUE; } diff --git a/src/Services/PantheonGuzzle.php b/src/Services/PantheonGuzzle.php index 89ff0cf0..55e9b256 100644 --- a/src/Services/PantheonGuzzle.php +++ b/src/Services/PantheonGuzzle.php @@ -73,8 +73,14 @@ public function __construct(Endpoint $endpoint, LoggerChannelFactoryInterface $l $config['cert'] = $cert; } parent::__construct($config); - $this->endpoint = $endpoint; - $this->logger = $logger_factory->get('PantheonGuzzle'); + if (!$endpoint instanceof Endpoint) { + throw new \InvalidArgumentException('Endpoint must be an instance of Endpoint'); + } + $this->setEndpoint($endpoint); + if ($logger_factory instanceof LoggerChannelFactoryInterface) { + $this->setLogger($logger_factory->get('PantheonGuzzle')); + } + $this->setLogger($logger_factory->get('PantheonGuzzle')); } /** diff --git a/src/Services/Reload.php b/src/Services/Reload.php new file mode 100644 index 00000000..5fdf58f5 --- /dev/null +++ b/src/Services/Reload.php @@ -0,0 +1,83 @@ +logger_factory = $logger_factory; + $this->client = $client; + } + + + /** + * Reload the server after schema upload. + * + * @throws \Drupal\search_api_pantheon\Exceptions\PantheonSearchApiException + */ + public function reloadServer(): void { + // Schema upload URL. + $uri = new Uri( + $this->getClient() + ->getEndpoint() + ->getReloadUri() + ); + + $this->logger->debug('Reload url: ' . (string) $uri); + + // Send the request. + $request = new Request( + 'POST', + $uri, + [ + 'Accept' => 'application/json', + 'Content-Type' => 'application/json', + ] + ); + $response = $this->getClient()->sendRequest($request); + + $status_code = $response->getStatusCode(); + $reload_logger_content = [ + 'status_code' => $status_code, + 'reason' => $response->getReasonPhrase(), + ]; + if ($status_code >= 200 && $status_code < 300) { + $this->logger->info('Server reloaded: {status_code} {reason}', $reload_logger_content); + return; + } + $this->logger->error('Server not reloaded: {status_code} {reason}', $reload_logger_content); + throw new PantheonSearchApiException('Server not reloaded.'); + } + + +} diff --git a/src/Services/SchemaPoster.php b/src/Services/SchemaPoster.php index a2cc840a..ec87a8e8 100644 --- a/src/Services/SchemaPoster.php +++ b/src/Services/SchemaPoster.php @@ -124,37 +124,8 @@ public function postSchema(string $server_id, $files = []): array { * @throws \Drupal\search_api_pantheon\Exceptions\PantheonSearchApiException */ public function reloadServer(): void { - // Schema upload URL. - $uri = new Uri( - $this->getClient() - ->getEndpoint() - ->getReloadUri() - ); - - $this->logger->debug('Reload url: ' . (string) $uri); - - // Send the request. - $request = new Request( - 'POST', - $uri, - [ - 'Accept' => 'application/json', - 'Content-Type' => 'application/json', - ] - ); - $response = $this->getClient()->sendRequest($request); - - $status_code = $response->getStatusCode(); - $reload_logger_content = [ - 'status_code' => $status_code, - 'reason' => $response->getReasonPhrase(), - ]; - if ($status_code >= 200 && $status_code < 300) { - $this->logger->info('Server reloaded: {status_code} {reason}', $reload_logger_content); - return; - } - $this->logger->error('Server not reloaded: {status_code} {reason}', $reload_logger_content); - throw new PantheonSearchApiException('Server not reloaded.'); + $reload = new Reload($this->logger, $this->client); + $reload->reloadServer(); } /** From b1e21d8318bc5000b1ac0dd983c2d0c7ccad6213 Mon Sep 17 00:00:00 2001 From: Phil Tyler Date: Wed, 13 Nov 2024 12:58:22 -0800 Subject: [PATCH 31/42] Attempt Drush call reload directly instead of through SchemaPoster --- drush.services.yml | 2 +- src/Commands/{Reload.php => SchemaReload.php} | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) rename src/Commands/{Reload.php => SchemaReload.php} (79%) diff --git a/drush.services.yml b/drush.services.yml index 2be3d265..c3dd2bff 100644 --- a/drush.services.yml +++ b/drush.services.yml @@ -20,7 +20,7 @@ services: tags: - { name: drush.command } search_api_pantheon.drush_reload: - class: \Drupal\search_api_pantheon\Commands\Reload + class: \Drupal\search_api_pantheon\Commands\SchemaReload arguments: [ "@logger.factory", "@search_api_pantheon.pantheon_guzzle", "@search_api_pantheon.schema_poster" ] tags: - { name: drush.command } diff --git a/src/Commands/Reload.php b/src/Commands/SchemaReload.php similarity index 79% rename from src/Commands/Reload.php rename to src/Commands/SchemaReload.php index 9b42b482..3105664d 100644 --- a/src/Commands/Reload.php +++ b/src/Commands/SchemaReload.php @@ -5,13 +5,13 @@ use Drupal\Core\Logger\LoggerChannelFactoryInterface; use Drupal\Core\Logger\LoggerChannelTrait; use Drupal\search_api_pantheon\Services\PantheonGuzzle; -use Drupal\search_api_pantheon\Services\SchemaPoster; +use Drupal\search_api_pantheon\Services\Reload; use Drush\Commands\DrushCommands; /** * Drush Search Api Pantheon Schema Commands. */ -class Reload extends DrushCommands { +class SchemaReload extends DrushCommands { use LoggerChannelTrait; /** @@ -24,9 +24,9 @@ class Reload extends DrushCommands { /** * Configured pantheon-solr-specific schema poster class. * - * @var \Drupal\search_api_pantheon\Services\SchemaPoster + * @var \Drupal\search_api_pantheon\Services\Reload */ - private SchemaPoster $schemaPoster; + private Reload $reload; /** * Class constructor. @@ -35,17 +35,17 @@ class Reload extends DrushCommands { * Injected by container. * @param \Drupal\search_api_pantheon\Services\PantheonGuzzle $pantheonGuzzle * Injected by container. - * @param \Drupal\search_api_pantheon\Services\SchemaPoster $schemaPoster + * @param \Drupal\search_api_pantheon\Services\Reload $reload * Injected by Container. */ public function __construct( LoggerChannelFactoryInterface $loggerChannelFactory, PantheonGuzzle $pantheonGuzzle, - SchemaPoster $schemaPoster + Reload $reload ) { $this->logger = $loggerChannelFactory->get('SearchAPIPantheon Drush'); $this->pantheonGuzzle = $pantheonGuzzle; - $this->schemaPoster = $schemaPoster; + $this->reload = $reload; } /** @@ -58,7 +58,7 @@ public function __construct( */ public function reloadSchema() { try { - $this->schemaPoster->reloadServer(); + $this->reload->reloadServer(); } catch (\Exception $e) { $this->logger->error((string) $e); From 0e0449f13d553a920edfc16f4d4586ffcdf16a8b Mon Sep 17 00:00:00 2001 From: Phil Tyler Date: Wed, 13 Nov 2024 13:00:21 -0800 Subject: [PATCH 32/42] lint --- search_api_pantheon.services.yml | 2 +- src/Services/Reload.php | 112 +++++++++++++++---------------- src/Services/SchemaPoster.php | 1 - 3 files changed, 55 insertions(+), 60 deletions(-) diff --git a/search_api_pantheon.services.yml b/search_api_pantheon.services.yml index 59e0c3bf..8c5a19f1 100755 --- a/search_api_pantheon.services.yml +++ b/search_api_pantheon.services.yml @@ -17,4 +17,4 @@ services: - { name: event_subscriber } search_api_pantheon.reload: class: Drupal\search_api_pantheon\Services\Reload - arguments: ['@logger.factory', '@search_api_pantheon.pantheon_guzzle'] \ No newline at end of file + arguments: ['@logger.factory', '@search_api_pantheon.pantheon_guzzle'] diff --git a/src/Services/Reload.php b/src/Services/Reload.php index 5fdf58f5..62174440 100644 --- a/src/Services/Reload.php +++ b/src/Services/Reload.php @@ -2,82 +2,78 @@ namespace Drupal\search_api_pantheon\Services; - use Drupal\Core\Logger\LoggerChannelFactoryInterface; use Drupal\search_api_pantheon\Exceptions\PantheonSearchApiException; use GuzzleHttp\Psr7\Request; use GuzzleHttp\Psr7\Uri; use Psr\Log\LoggerAwareInterface; use Psr\Log\LoggerAwareTrait; -use Drupal\search_api_pantheon\Services\PantheonGuzzle; class Reload implements LoggerAwareInterface { - use LoggerAwareTrait; + use LoggerAwareTrait; - /** - * @var \Drupal\search_api_pantheon\Services\Reload - */ - protected $configuration; - /** - * @var \Drupal\search_api_pantheon\Services\Reload - */ - protected $logger_factory; + /** + * @var \Drupal\search_api_pantheon\Services\Reload + */ + protected $configuration; + /** + * @var \Drupal\search_api_pantheon\Services\Reload + */ + protected $logger_factory; - /** - * @var \Drupal\search_api_pantheon\Services\PantheonGuzzle - */ - protected PantheonGuzzle $client; + /** + * @var \Drupal\search_api_pantheon\Services\PantheonGuzzle + */ + protected PantheonGuzzle $client; - /** - * Class Constructor. - */ - public function __construct( + /** + * Class Constructor. + */ + public function __construct( LoggerChannelFactoryInterface $logger_factory, PantheonGuzzle $client, ) { - $this->logger_factory = $logger_factory; - $this->client = $client; - } + $this->logger_factory = $logger_factory; + $this->client = $client; + } + /** + * Reload the server after schema upload. + * + * @throws \Drupal\search_api_pantheon\Exceptions\PantheonSearchApiException + */ + public function reloadServer(): void { + // Schema upload URL. + $uri = new Uri( + $this->getClient() + ->getEndpoint() + ->getReloadUri() + ); - /** - * Reload the server after schema upload. - * - * @throws \Drupal\search_api_pantheon\Exceptions\PantheonSearchApiException - */ - public function reloadServer(): void { - // Schema upload URL. - $uri = new Uri( - $this->getClient() - ->getEndpoint() - ->getReloadUri() - ); + $this->logger->debug('Reload url: ' . (string) $uri); - $this->logger->debug('Reload url: ' . (string) $uri); + // Send the request. + $request = new Request( + 'POST', + $uri, + [ + 'Accept' => 'application/json', + 'Content-Type' => 'application/json', + ] + ); + $response = $this->getClient()->sendRequest($request); - // Send the request. - $request = new Request( - 'POST', - $uri, - [ - 'Accept' => 'application/json', - 'Content-Type' => 'application/json', - ] - ); - $response = $this->getClient()->sendRequest($request); - - $status_code = $response->getStatusCode(); - $reload_logger_content = [ - 'status_code' => $status_code, - 'reason' => $response->getReasonPhrase(), - ]; - if ($status_code >= 200 && $status_code < 300) { - $this->logger->info('Server reloaded: {status_code} {reason}', $reload_logger_content); - return; - } - $this->logger->error('Server not reloaded: {status_code} {reason}', $reload_logger_content); - throw new PantheonSearchApiException('Server not reloaded.'); + $status_code = $response->getStatusCode(); + $reload_logger_content = [ + 'status_code' => $status_code, + 'reason' => $response->getReasonPhrase(), + ]; + if ($status_code >= 200 && $status_code < 300) { + $this->logger->info('Server reloaded: {status_code} {reason}', $reload_logger_content); + return; } - + $this->logger->error('Server not reloaded: {status_code} {reason}', $reload_logger_content); + throw new PantheonSearchApiException('Server not reloaded.'); + } } diff --git a/src/Services/SchemaPoster.php b/src/Services/SchemaPoster.php index ec87a8e8..6ffe6f05 100644 --- a/src/Services/SchemaPoster.php +++ b/src/Services/SchemaPoster.php @@ -19,7 +19,6 @@ use Psr\Log\LoggerInterface; use Drupal\Core\Logger\LoggerChannelFactoryInterface; use Drupal\Core\Entity\EntityTypeManagerInterface; -use Drupal\search_api_pantheon\Exceptions\PantheonSearchApiException; /** * Posting schema for Pantheon-specific solr driver. From 2331ef25e3ab3bebf60a2e9aab284e9d51a36293 Mon Sep 17 00:00:00 2001 From: Tom Stovall Date: Wed, 13 Nov 2024 13:09:13 -0800 Subject: [PATCH 33/42] Fixing logger factory --- src/Services/SchemaPoster.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Services/SchemaPoster.php b/src/Services/SchemaPoster.php index 6ffe6f05..477bb9ac 100644 --- a/src/Services/SchemaPoster.php +++ b/src/Services/SchemaPoster.php @@ -58,6 +58,8 @@ class SchemaPoster implements LoggerAwareInterface { */ protected $moduleExtensionList; + protected LoggerChannelFactoryInterface $loggerFactory; + /** * Class Constructor. */ @@ -68,6 +70,7 @@ public function __construct( ModuleExtensionList $module_extension_list ) { $this->logger = $logger_factory->get('PantheonSearch'); + $this->loggerFactory = $logger_factory; $this->client = $client; $this->entityTypeManager = $entity_type_manager; $this->moduleExtensionList = $module_extension_list; @@ -123,7 +126,7 @@ public function postSchema(string $server_id, $files = []): array { * @throws \Drupal\search_api_pantheon\Exceptions\PantheonSearchApiException */ public function reloadServer(): void { - $reload = new Reload($this->logger, $this->client); + $reload = new Reload($this->loggerFactory, $this->client); $reload->reloadServer(); } From 03d8932290e6a38518640d25e252431a40bbb966 Mon Sep 17 00:00:00 2001 From: Phil Tyler Date: Wed, 13 Nov 2024 13:08:12 -0800 Subject: [PATCH 34/42] Add success output to Drush Schema Reload --- src/Commands/SchemaReload.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Commands/SchemaReload.php b/src/Commands/SchemaReload.php index 3105664d..6c59c0cc 100644 --- a/src/Commands/SchemaReload.php +++ b/src/Commands/SchemaReload.php @@ -62,7 +62,9 @@ public function reloadSchema() { } catch (\Exception $e) { $this->logger->error((string) $e); + return; } + $this->logger->notice("Schema Reloaded."); } } From 083de1e6a1ef47397b10d2189e57feb1ebed18f3 Mon Sep 17 00:00:00 2001 From: Phil Tyler Date: Wed, 13 Nov 2024 13:15:17 -0800 Subject: [PATCH 35/42] Revert "Attempt Drush call reload directly instead of through SchemaPoster" This reverts commit b1e21d8318bc5000b1ac0dd983c2d0c7ccad6213. --- drush.services.yml | 2 +- src/Commands/{SchemaReload.php => Reload.php} | 18 ++++++++---------- 2 files changed, 9 insertions(+), 11 deletions(-) rename src/Commands/{SchemaReload.php => Reload.php} (79%) diff --git a/drush.services.yml b/drush.services.yml index c3dd2bff..2be3d265 100644 --- a/drush.services.yml +++ b/drush.services.yml @@ -20,7 +20,7 @@ services: tags: - { name: drush.command } search_api_pantheon.drush_reload: - class: \Drupal\search_api_pantheon\Commands\SchemaReload + class: \Drupal\search_api_pantheon\Commands\Reload arguments: [ "@logger.factory", "@search_api_pantheon.pantheon_guzzle", "@search_api_pantheon.schema_poster" ] tags: - { name: drush.command } diff --git a/src/Commands/SchemaReload.php b/src/Commands/Reload.php similarity index 79% rename from src/Commands/SchemaReload.php rename to src/Commands/Reload.php index 6c59c0cc..9b42b482 100644 --- a/src/Commands/SchemaReload.php +++ b/src/Commands/Reload.php @@ -5,13 +5,13 @@ use Drupal\Core\Logger\LoggerChannelFactoryInterface; use Drupal\Core\Logger\LoggerChannelTrait; use Drupal\search_api_pantheon\Services\PantheonGuzzle; -use Drupal\search_api_pantheon\Services\Reload; +use Drupal\search_api_pantheon\Services\SchemaPoster; use Drush\Commands\DrushCommands; /** * Drush Search Api Pantheon Schema Commands. */ -class SchemaReload extends DrushCommands { +class Reload extends DrushCommands { use LoggerChannelTrait; /** @@ -24,9 +24,9 @@ class SchemaReload extends DrushCommands { /** * Configured pantheon-solr-specific schema poster class. * - * @var \Drupal\search_api_pantheon\Services\Reload + * @var \Drupal\search_api_pantheon\Services\SchemaPoster */ - private Reload $reload; + private SchemaPoster $schemaPoster; /** * Class constructor. @@ -35,17 +35,17 @@ class SchemaReload extends DrushCommands { * Injected by container. * @param \Drupal\search_api_pantheon\Services\PantheonGuzzle $pantheonGuzzle * Injected by container. - * @param \Drupal\search_api_pantheon\Services\Reload $reload + * @param \Drupal\search_api_pantheon\Services\SchemaPoster $schemaPoster * Injected by Container. */ public function __construct( LoggerChannelFactoryInterface $loggerChannelFactory, PantheonGuzzle $pantheonGuzzle, - Reload $reload + SchemaPoster $schemaPoster ) { $this->logger = $loggerChannelFactory->get('SearchAPIPantheon Drush'); $this->pantheonGuzzle = $pantheonGuzzle; - $this->reload = $reload; + $this->schemaPoster = $schemaPoster; } /** @@ -58,13 +58,11 @@ public function __construct( */ public function reloadSchema() { try { - $this->reload->reloadServer(); + $this->schemaPoster->reloadServer(); } catch (\Exception $e) { $this->logger->error((string) $e); - return; } - $this->logger->notice("Schema Reloaded."); } } From 7c209c8234ad363891c07b4c9263e2ca4d7eeaa8 Mon Sep 17 00:00:00 2001 From: Phil Tyler Date: Wed, 13 Nov 2024 13:26:54 -0800 Subject: [PATCH 36/42] solr admin module --- RoboFile.php | 1 + 1 file changed, 1 insertion(+) diff --git a/RoboFile.php b/RoboFile.php index 66b5440b..1fc32bba 100644 --- a/RoboFile.php +++ b/RoboFile.php @@ -577,6 +577,7 @@ public function testModuleEnable(string $site_name, string $env = 'dev') { '--yes', 'search_api_pantheon', 'search_api_pantheon_admin', + 'search_api_solr_admin' ) ->run(); $this->taskExec(static::$TERMINUS_EXE) From 4ecb15599ea4f4d7e89be8b1ba6ebd603e2e9b9d Mon Sep 17 00:00:00 2001 From: Tom Stovall Date: Wed, 13 Nov 2024 13:59:03 -0800 Subject: [PATCH 37/42] changes to solr connector --- .../SolrConnector/PantheonSolrConnector.php | 15 +++++---------- src/Services/Reload.php | 12 ++++++++---- src/Services/SchemaPoster.php | 5 +++-- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/Plugin/SolrConnector/PantheonSolrConnector.php b/src/Plugin/SolrConnector/PantheonSolrConnector.php index 7596f219..522f1ecd 100644 --- a/src/Plugin/SolrConnector/PantheonSolrConnector.php +++ b/src/Plugin/SolrConnector/PantheonSolrConnector.php @@ -14,6 +14,7 @@ use Drupal\search_api_pantheon\Services\PantheonGuzzle; use Drupal\search_api_pantheon\Services\SolariumClient as PantheonSolariumClient; use Drupal\Core\Datetime\DateFormatterInterface; +use Drupal\search_api_pantheon\Services\Reload; /** * Pantheon Solr connector. @@ -78,8 +79,7 @@ public function __construct( array $plugin_definition, ContainerInterface $container, ) { - parent::__construct($configuration, $plugin_id, $plugin_definition); - $this->configuration = array_merge($configuration, self::getPlatformConfig()); + parent::__construct(array_merge($configuration, self::getPlatformConfig()), $plugin_id, $plugin_definition); $this->pantheonGuzzle = $container->get('search_api_pantheon.pantheon_guzzle'); $this->solariumClient = $container->get('search_api_pantheon.solarium_client'); $this->dateFormatter = $container->get('date.formatter'); @@ -402,14 +402,9 @@ public function getEndpoint($key = 'search_api_solr') { * @return bool * Success or Failure. */ - public function reloadCore() { - $sp = $this->container->get('search_api_pantheon.schema_poster'); - if (!$sp instanceof SchemaPoster) { - $sp = \Drupal::getContainer()->get('search_api_pantheon.schema_poster'); - } - $sp->reloadCore(); - $this->logger->info('Core reloaded.'); - return TRUE; + public function reloadCore(): bool { + $rl = new Reload($this->container->get("logger.factory"), $this->pantheonGuzzle); + return $rl->reloadServer(); } /** diff --git a/src/Services/Reload.php b/src/Services/Reload.php index 62174440..cccbe87c 100644 --- a/src/Services/Reload.php +++ b/src/Services/Reload.php @@ -33,7 +33,7 @@ public function __construct( LoggerChannelFactoryInterface $logger_factory, PantheonGuzzle $client, ) { - $this->logger_factory = $logger_factory; + $this->setLogger($logger_factory->get('reload_service')); $this->client = $client; } @@ -42,7 +42,7 @@ public function __construct( * * @throws \Drupal\search_api_pantheon\Exceptions\PantheonSearchApiException */ - public function reloadServer(): void { + public function reloadServer(): bool { // Schema upload URL. $uri = new Uri( $this->getClient() @@ -70,10 +70,14 @@ public function reloadServer(): void { ]; if ($status_code >= 200 && $status_code < 300) { $this->logger->info('Server reloaded: {status_code} {reason}', $reload_logger_content); - return; + return true; } $this->logger->error('Server not reloaded: {status_code} {reason}', $reload_logger_content); - throw new PantheonSearchApiException('Server not reloaded.'); + return false; + } + + public function getClient(): PantheonGuzzle { + return $this->client; } } diff --git a/src/Services/SchemaPoster.php b/src/Services/SchemaPoster.php index 477bb9ac..f1e25d47 100644 --- a/src/Services/SchemaPoster.php +++ b/src/Services/SchemaPoster.php @@ -124,10 +124,11 @@ public function postSchema(string $server_id, $files = []): array { * Reload the server after schema upload. * * @throws \Drupal\search_api_pantheon\Exceptions\PantheonSearchApiException + * @return bool */ - public function reloadServer(): void { + public function reloadServer(): bool { $reload = new Reload($this->loggerFactory, $this->client); - $reload->reloadServer(); + return $reload->reloadServer(); } /** From c4383b0b34a8c31ae8bb6ad475f7e30ce95462d4 Mon Sep 17 00:00:00 2001 From: Phil Tyler Date: Wed, 13 Nov 2024 14:49:13 -0800 Subject: [PATCH 38/42] phpcs --- src/Services/Reload.php | 5 ++--- src/Services/SchemaPoster.php | 1 + 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Services/Reload.php b/src/Services/Reload.php index cccbe87c..4de21a26 100644 --- a/src/Services/Reload.php +++ b/src/Services/Reload.php @@ -3,7 +3,6 @@ namespace Drupal\search_api_pantheon\Services; use Drupal\Core\Logger\LoggerChannelFactoryInterface; -use Drupal\search_api_pantheon\Exceptions\PantheonSearchApiException; use GuzzleHttp\Psr7\Request; use GuzzleHttp\Psr7\Uri; use Psr\Log\LoggerAwareInterface; @@ -70,10 +69,10 @@ public function reloadServer(): bool { ]; if ($status_code >= 200 && $status_code < 300) { $this->logger->info('Server reloaded: {status_code} {reason}', $reload_logger_content); - return true; + return TRUE; } $this->logger->error('Server not reloaded: {status_code} {reason}', $reload_logger_content); - return false; + return FALSE; } public function getClient(): PantheonGuzzle { diff --git a/src/Services/SchemaPoster.php b/src/Services/SchemaPoster.php index f1e25d47..c8c45d22 100644 --- a/src/Services/SchemaPoster.php +++ b/src/Services/SchemaPoster.php @@ -124,6 +124,7 @@ public function postSchema(string $server_id, $files = []): array { * Reload the server after schema upload. * * @throws \Drupal\search_api_pantheon\Exceptions\PantheonSearchApiException + * * @return bool */ public function reloadServer(): bool { From 1714e95d198aca2ab307df6f147043b95e1122c2 Mon Sep 17 00:00:00 2001 From: Phil Tyler Date: Wed, 13 Nov 2024 15:51:39 -0800 Subject: [PATCH 39/42] back out solr connector --- .../SolrConnector/PantheonSolrConnector.php | 214 +++++++++--------- 1 file changed, 109 insertions(+), 105 deletions(-) diff --git a/src/Plugin/SolrConnector/PantheonSolrConnector.php b/src/Plugin/SolrConnector/PantheonSolrConnector.php index 522f1ecd..c2ce5ea2 100644 --- a/src/Plugin/SolrConnector/PantheonSolrConnector.php +++ b/src/Plugin/SolrConnector/PantheonSolrConnector.php @@ -13,8 +13,9 @@ use Symfony\Component\DependencyInjection\ContainerInterface; use Drupal\search_api_pantheon\Services\PantheonGuzzle; use Drupal\search_api_pantheon\Services\SolariumClient as PantheonSolariumClient; +use Drupal\Core\Logger\LoggerChannelFactoryInterface; use Drupal\Core\Datetime\DateFormatterInterface; -use Drupal\search_api_pantheon\Services\Reload; +use Drupal\Core\Messenger\MessengerInterface; /** * Pantheon Solr connector. @@ -63,29 +64,27 @@ class PantheonSolrConnector extends SolrConnectorPluginBase implements */ protected $messenger; - /** - * The container. - * - * @var \Symfony\Component\DependencyInjection\ContainerInterface - */ - protected ContainerInterface $container; - /** * Class constructor. */ public function __construct( - array $configuration, - $plugin_id, - array $plugin_definition, - ContainerInterface $container, + array $configuration, + $plugin_id, + array $plugin_definition, + LoggerChannelFactoryInterface $logger_factory, + PantheonGuzzle $pantheon_guzzle, + PantheonSolariumClient $solarium_client, + DateFormatterInterface $date_formatter, + MessengerInterface $messenger ) { - parent::__construct(array_merge($configuration, self::getPlatformConfig()), $plugin_id, $plugin_definition); - $this->pantheonGuzzle = $container->get('search_api_pantheon.pantheon_guzzle'); - $this->solariumClient = $container->get('search_api_pantheon.solarium_client'); - $this->dateFormatter = $container->get('date.formatter'); - $this->messenger = $container->get('messenger'); - $this->setLogger($container->get('logger.factory')->get('PantheonSearch')); - $this->container = $container; + parent::__construct($configuration, $plugin_id, $plugin_definition); + $this->pantheonGuzzle = $pantheon_guzzle; + $this->solariumClient = $solarium_client; + $this->dateFormatter = $date_formatter; + $this->messenger = $messenger; + $this->setLogger($logger_factory->get('PantheonSearch')); + $this->configuration['core'] = self::getPlatformConfig()['core']; + $this->configuration['schema'] = self::getPlatformConfig()['schema']; $this->connect(); } @@ -99,17 +98,21 @@ public function __construct( * @throws \Exception */ public static function create( - ContainerInterface $container, - array $configuration, - $plugin_id, - $plugin_definition - ) { + ContainerInterface $container, + array $configuration, + $plugin_id, + $plugin_definition + ) { return new static( - $configuration, - $plugin_id, - $plugin_definition, - $container, - ); + $configuration, + $plugin_id, + $plugin_definition, + $container->get('logger.factory'), + $container->get('search_api_pantheon.pantheon_guzzle'), + $container->get('search_api_pantheon.solarium_client'), + $container->get('date.formatter'), + $container->get('messenger') + ); } /** @@ -126,7 +129,6 @@ public static function getPlatformConfig() { 'path' => getenv('PANTHEON_INDEX_PATH'), 'core' => getenv('PANTHEON_INDEX_CORE'), 'schema' => getenv('PANTHEON_INDEX_SCHEMA'), - 'reload_path' => getenv('PANTHEON_INDEX_RELOAD_PATH'), ]; } @@ -168,9 +170,9 @@ public function defaultConfiguration() { * Form render array. */ public function buildConfigurationForm( - array $form, - FormStateInterface $form_state - ) { + array $form, + FormStateInterface $form_state + ) { $form = parent::buildConfigurationForm($form, $form_state); $fields = [ @@ -206,9 +208,9 @@ function ($field_name) use ($fields) { * Form state object. */ public function validateConfigurationForm( - array &$form, - FormStateInterface $form_state - ) { + array &$form, + FormStateInterface $form_state + ) { } /** @@ -220,9 +222,9 @@ public function validateConfigurationForm( * Form state object. */ public function submitConfigurationForm( - array &$form, - FormStateInterface $form_state - ) { + array &$form, + FormStateInterface $form_state + ) { $configuration = array_merge($this->defaultConfiguration(), $form_state->getValues()); $this->setConfiguration($configuration); @@ -291,16 +293,16 @@ public function getStatsSummary() { } $summary = [ - '@pending_docs' => '', - '@autocommit_time_seconds' => '', - '@autocommit_time' => '', - '@deletes_by_id' => '', - '@deletes_by_query' => '', - '@deletes_total' => '', - '@schema_version' => '', - '@core_name' => '', - '@index_size' => '', - ]; + '@pending_docs' => '', + '@autocommit_time_seconds' => '', + '@autocommit_time' => '', + '@deletes_by_id' => '', + '@deletes_by_query' => '', + '@deletes_total' => '', + '@schema_version' => '', + '@core_name' => '', + '@index_size' => '', + ]; if (empty($stats) || empty($indexStats)) { return $summary; @@ -309,33 +311,33 @@ public function getStatsSummary() { $max_time = -1; $update_handler_stats = $stats['UPDATE']['updateHandler']['stats'] ?? -1; $summary['@pending_docs'] = - (int) $update_handler_stats['UPDATE.updateHandler.docsPending'] ?? -1; + (int) $update_handler_stats['UPDATE.updateHandler.docsPending'] ?? -1; if ( - isset( - $update_handler_stats['UPDATE.updateHandler.softAutoCommitMaxTime'] - ) - ) { + isset( + $update_handler_stats['UPDATE.updateHandler.softAutoCommitMaxTime'] + ) + ) { $max_time = - (int) $update_handler_stats['UPDATE.updateHandler.softAutoCommitMaxTime']; + (int) $update_handler_stats['UPDATE.updateHandler.softAutoCommitMaxTime']; } $summary['@deletes_by_id'] = - (int) $update_handler_stats['UPDATE.updateHandler.deletesById'] ?? -1; + (int) $update_handler_stats['UPDATE.updateHandler.deletesById'] ?? -1; $summary['@deletes_by_query'] = - (int) $update_handler_stats['UPDATE.updateHandler.deletesByQuery'] ?? -1; + (int) $update_handler_stats['UPDATE.updateHandler.deletesByQuery'] ?? -1; $summary['@core_name'] = - $stats['CORE']['core']['class'] ?? - $this->t('No information available.'); + $stats['CORE']['core']['class'] ?? + $this->t('No information available.'); $summary['@index_size'] = - $indexStats['numDocs'] ?? $this->t('No information available.'); + $indexStats['numDocs'] ?? $this->t('No information available.'); $summary['@autocommit_time_seconds'] = $max_time / 1000; $summary['@autocommit_time'] = $this->dateFormatter ->formatInterval($max_time / 1000); $summary['@deletes_total'] = - ( - intval($summary['@deletes_by_id'] ?? 0) - + intval($summary['@deletes_by_query'] ?? 0) - ) ?? -1; + ( + intval($summary['@deletes_by_id'] ?? 0) + + intval($summary['@deletes_by_query'] ?? 0) + ) ?? -1; $summary['@schema_version'] = $this->getSchemaVersionString(TRUE); return $summary; } @@ -344,9 +346,9 @@ public function getStatsSummary() { * {@inheritdoc} */ public function useTimeout( - string $timeout = self::QUERY_TIMEOUT, - ?Endpoint $endpoint = NULL - ) { + string $timeout = self::QUERY_TIMEOUT, + ?Endpoint $endpoint = NULL + ) { } /** @@ -358,25 +360,25 @@ public function viewSettings() { $view_settings = []; $view_settings[] = [ - 'label' => $this->t('Pantheon Sitename'), - 'info' => $this->getEndpoint()->getCore(), - ]; + 'label' => $this->t('Pantheon Sitename'), + 'info' => $this->getEndpoint()->getCore(), + ]; $view_settings[] = [ - 'label' => $this->t('Pantheon Environment'), - 'info' => getenv('PANTHEON_ENVIRONMENT'), - ]; + 'label' => $this->t('Pantheon Environment'), + 'info' => getenv('PANTHEON_ENVIRONMENT'), + ]; $view_settings[] = [ - 'label' => $this->t('Schema Version'), - 'info' => $this->getSchemaVersion(TRUE), - ]; + 'label' => $this->t('Schema Version'), + 'info' => $this->getSchemaVersion(TRUE), + ]; $core_info = $this->getCoreInfo(TRUE); foreach ($core_info['core'] as $key => $value) { if (is_string($value)) { $view_settings[] = [ - 'label' => ucwords($key), - 'info' => $value, - ]; + 'label' => ucwords($key), + 'info' => $value, + ]; } } @@ -402,9 +404,11 @@ public function getEndpoint($key = 'search_api_solr') { * @return bool * Success or Failure. */ - public function reloadCore(): bool { - $rl = new Reload($this->container->get("logger.factory"), $this->pantheonGuzzle); - return $rl->reloadServer(); + public function reloadCore() { + $this->logger->notice( + $this->t('Reload Core action for Pantheon Solr is automatic when Schema is updated.') + ); + return TRUE; } /** @@ -458,29 +462,29 @@ protected function createClient(array &$configuration) { */ protected function getStatsQuery(string $handler) { return json_decode( - $this->pantheonGuzzle - ->get( - $handler, - [ - 'query' => - [ - 'stats' => 'true', - 'wt' => 'json', - 'accept' => 'application/json', - 'contenttype' => 'application/json', - 'json.nl' => 'flat', - ], - 'headers' => - [ - 'Content-Type' => 'application/json', - 'Accept' => 'application/json', - ], - ] - ) - ->getBody(), - TRUE, - JSON_THROW_ON_ERROR - ); + $this->pantheonGuzzle + ->get( + $handler, + [ + 'query' => + [ + 'stats' => 'true', + 'wt' => 'json', + 'accept' => 'application/json', + 'contenttype' => 'application/json', + 'json.nl' => 'flat', + ], + 'headers' => + [ + 'Content-Type' => 'application/json', + 'Accept' => 'application/json', + ], + ] + ) + ->getBody(), + TRUE, + JSON_THROW_ON_ERROR + ); } } From 2d032c352b7fa2d9fe0074e29db17688d4bc2c3f Mon Sep 17 00:00:00 2001 From: Phil Tyler Date: Wed, 13 Nov 2024 16:03:20 -0800 Subject: [PATCH 40/42] Revert "back out solr connector" This reverts commit 1714e95d198aca2ab307df6f147043b95e1122c2. --- .../SolrConnector/PantheonSolrConnector.php | 214 +++++++++--------- 1 file changed, 105 insertions(+), 109 deletions(-) diff --git a/src/Plugin/SolrConnector/PantheonSolrConnector.php b/src/Plugin/SolrConnector/PantheonSolrConnector.php index c2ce5ea2..522f1ecd 100644 --- a/src/Plugin/SolrConnector/PantheonSolrConnector.php +++ b/src/Plugin/SolrConnector/PantheonSolrConnector.php @@ -13,9 +13,8 @@ use Symfony\Component\DependencyInjection\ContainerInterface; use Drupal\search_api_pantheon\Services\PantheonGuzzle; use Drupal\search_api_pantheon\Services\SolariumClient as PantheonSolariumClient; -use Drupal\Core\Logger\LoggerChannelFactoryInterface; use Drupal\Core\Datetime\DateFormatterInterface; -use Drupal\Core\Messenger\MessengerInterface; +use Drupal\search_api_pantheon\Services\Reload; /** * Pantheon Solr connector. @@ -64,27 +63,29 @@ class PantheonSolrConnector extends SolrConnectorPluginBase implements */ protected $messenger; + /** + * The container. + * + * @var \Symfony\Component\DependencyInjection\ContainerInterface + */ + protected ContainerInterface $container; + /** * Class constructor. */ public function __construct( - array $configuration, - $plugin_id, - array $plugin_definition, - LoggerChannelFactoryInterface $logger_factory, - PantheonGuzzle $pantheon_guzzle, - PantheonSolariumClient $solarium_client, - DateFormatterInterface $date_formatter, - MessengerInterface $messenger + array $configuration, + $plugin_id, + array $plugin_definition, + ContainerInterface $container, ) { - parent::__construct($configuration, $plugin_id, $plugin_definition); - $this->pantheonGuzzle = $pantheon_guzzle; - $this->solariumClient = $solarium_client; - $this->dateFormatter = $date_formatter; - $this->messenger = $messenger; - $this->setLogger($logger_factory->get('PantheonSearch')); - $this->configuration['core'] = self::getPlatformConfig()['core']; - $this->configuration['schema'] = self::getPlatformConfig()['schema']; + parent::__construct(array_merge($configuration, self::getPlatformConfig()), $plugin_id, $plugin_definition); + $this->pantheonGuzzle = $container->get('search_api_pantheon.pantheon_guzzle'); + $this->solariumClient = $container->get('search_api_pantheon.solarium_client'); + $this->dateFormatter = $container->get('date.formatter'); + $this->messenger = $container->get('messenger'); + $this->setLogger($container->get('logger.factory')->get('PantheonSearch')); + $this->container = $container; $this->connect(); } @@ -98,21 +99,17 @@ public function __construct( * @throws \Exception */ public static function create( - ContainerInterface $container, - array $configuration, - $plugin_id, - $plugin_definition - ) { + ContainerInterface $container, + array $configuration, + $plugin_id, + $plugin_definition + ) { return new static( - $configuration, - $plugin_id, - $plugin_definition, - $container->get('logger.factory'), - $container->get('search_api_pantheon.pantheon_guzzle'), - $container->get('search_api_pantheon.solarium_client'), - $container->get('date.formatter'), - $container->get('messenger') - ); + $configuration, + $plugin_id, + $plugin_definition, + $container, + ); } /** @@ -129,6 +126,7 @@ public static function getPlatformConfig() { 'path' => getenv('PANTHEON_INDEX_PATH'), 'core' => getenv('PANTHEON_INDEX_CORE'), 'schema' => getenv('PANTHEON_INDEX_SCHEMA'), + 'reload_path' => getenv('PANTHEON_INDEX_RELOAD_PATH'), ]; } @@ -170,9 +168,9 @@ public function defaultConfiguration() { * Form render array. */ public function buildConfigurationForm( - array $form, - FormStateInterface $form_state - ) { + array $form, + FormStateInterface $form_state + ) { $form = parent::buildConfigurationForm($form, $form_state); $fields = [ @@ -208,9 +206,9 @@ function ($field_name) use ($fields) { * Form state object. */ public function validateConfigurationForm( - array &$form, - FormStateInterface $form_state - ) { + array &$form, + FormStateInterface $form_state + ) { } /** @@ -222,9 +220,9 @@ public function validateConfigurationForm( * Form state object. */ public function submitConfigurationForm( - array &$form, - FormStateInterface $form_state - ) { + array &$form, + FormStateInterface $form_state + ) { $configuration = array_merge($this->defaultConfiguration(), $form_state->getValues()); $this->setConfiguration($configuration); @@ -293,16 +291,16 @@ public function getStatsSummary() { } $summary = [ - '@pending_docs' => '', - '@autocommit_time_seconds' => '', - '@autocommit_time' => '', - '@deletes_by_id' => '', - '@deletes_by_query' => '', - '@deletes_total' => '', - '@schema_version' => '', - '@core_name' => '', - '@index_size' => '', - ]; + '@pending_docs' => '', + '@autocommit_time_seconds' => '', + '@autocommit_time' => '', + '@deletes_by_id' => '', + '@deletes_by_query' => '', + '@deletes_total' => '', + '@schema_version' => '', + '@core_name' => '', + '@index_size' => '', + ]; if (empty($stats) || empty($indexStats)) { return $summary; @@ -311,33 +309,33 @@ public function getStatsSummary() { $max_time = -1; $update_handler_stats = $stats['UPDATE']['updateHandler']['stats'] ?? -1; $summary['@pending_docs'] = - (int) $update_handler_stats['UPDATE.updateHandler.docsPending'] ?? -1; + (int) $update_handler_stats['UPDATE.updateHandler.docsPending'] ?? -1; if ( - isset( - $update_handler_stats['UPDATE.updateHandler.softAutoCommitMaxTime'] - ) - ) { + isset( + $update_handler_stats['UPDATE.updateHandler.softAutoCommitMaxTime'] + ) + ) { $max_time = - (int) $update_handler_stats['UPDATE.updateHandler.softAutoCommitMaxTime']; + (int) $update_handler_stats['UPDATE.updateHandler.softAutoCommitMaxTime']; } $summary['@deletes_by_id'] = - (int) $update_handler_stats['UPDATE.updateHandler.deletesById'] ?? -1; + (int) $update_handler_stats['UPDATE.updateHandler.deletesById'] ?? -1; $summary['@deletes_by_query'] = - (int) $update_handler_stats['UPDATE.updateHandler.deletesByQuery'] ?? -1; + (int) $update_handler_stats['UPDATE.updateHandler.deletesByQuery'] ?? -1; $summary['@core_name'] = - $stats['CORE']['core']['class'] ?? - $this->t('No information available.'); + $stats['CORE']['core']['class'] ?? + $this->t('No information available.'); $summary['@index_size'] = - $indexStats['numDocs'] ?? $this->t('No information available.'); + $indexStats['numDocs'] ?? $this->t('No information available.'); $summary['@autocommit_time_seconds'] = $max_time / 1000; $summary['@autocommit_time'] = $this->dateFormatter ->formatInterval($max_time / 1000); $summary['@deletes_total'] = - ( - intval($summary['@deletes_by_id'] ?? 0) - + intval($summary['@deletes_by_query'] ?? 0) - ) ?? -1; + ( + intval($summary['@deletes_by_id'] ?? 0) + + intval($summary['@deletes_by_query'] ?? 0) + ) ?? -1; $summary['@schema_version'] = $this->getSchemaVersionString(TRUE); return $summary; } @@ -346,9 +344,9 @@ public function getStatsSummary() { * {@inheritdoc} */ public function useTimeout( - string $timeout = self::QUERY_TIMEOUT, - ?Endpoint $endpoint = NULL - ) { + string $timeout = self::QUERY_TIMEOUT, + ?Endpoint $endpoint = NULL + ) { } /** @@ -360,25 +358,25 @@ public function viewSettings() { $view_settings = []; $view_settings[] = [ - 'label' => $this->t('Pantheon Sitename'), - 'info' => $this->getEndpoint()->getCore(), - ]; + 'label' => $this->t('Pantheon Sitename'), + 'info' => $this->getEndpoint()->getCore(), + ]; $view_settings[] = [ - 'label' => $this->t('Pantheon Environment'), - 'info' => getenv('PANTHEON_ENVIRONMENT'), - ]; + 'label' => $this->t('Pantheon Environment'), + 'info' => getenv('PANTHEON_ENVIRONMENT'), + ]; $view_settings[] = [ - 'label' => $this->t('Schema Version'), - 'info' => $this->getSchemaVersion(TRUE), - ]; + 'label' => $this->t('Schema Version'), + 'info' => $this->getSchemaVersion(TRUE), + ]; $core_info = $this->getCoreInfo(TRUE); foreach ($core_info['core'] as $key => $value) { if (is_string($value)) { $view_settings[] = [ - 'label' => ucwords($key), - 'info' => $value, - ]; + 'label' => ucwords($key), + 'info' => $value, + ]; } } @@ -404,11 +402,9 @@ public function getEndpoint($key = 'search_api_solr') { * @return bool * Success or Failure. */ - public function reloadCore() { - $this->logger->notice( - $this->t('Reload Core action for Pantheon Solr is automatic when Schema is updated.') - ); - return TRUE; + public function reloadCore(): bool { + $rl = new Reload($this->container->get("logger.factory"), $this->pantheonGuzzle); + return $rl->reloadServer(); } /** @@ -462,29 +458,29 @@ protected function createClient(array &$configuration) { */ protected function getStatsQuery(string $handler) { return json_decode( - $this->pantheonGuzzle - ->get( - $handler, - [ - 'query' => - [ - 'stats' => 'true', - 'wt' => 'json', - 'accept' => 'application/json', - 'contenttype' => 'application/json', - 'json.nl' => 'flat', - ], - 'headers' => - [ - 'Content-Type' => 'application/json', - 'Accept' => 'application/json', - ], - ] - ) - ->getBody(), - TRUE, - JSON_THROW_ON_ERROR - ); + $this->pantheonGuzzle + ->get( + $handler, + [ + 'query' => + [ + 'stats' => 'true', + 'wt' => 'json', + 'accept' => 'application/json', + 'contenttype' => 'application/json', + 'json.nl' => 'flat', + ], + 'headers' => + [ + 'Content-Type' => 'application/json', + 'Accept' => 'application/json', + ], + ] + ) + ->getBody(), + TRUE, + JSON_THROW_ON_ERROR + ); } } From 02fa0d04b95625f48777af28de176b76029bcd96 Mon Sep 17 00:00:00 2001 From: Phil Tyler Date: Wed, 13 Nov 2024 16:12:24 -0800 Subject: [PATCH 41/42] Reapply "back out solr connector" This reverts commit 2d032c352b7fa2d9fe0074e29db17688d4bc2c3f. --- .../SolrConnector/PantheonSolrConnector.php | 214 +++++++++--------- 1 file changed, 109 insertions(+), 105 deletions(-) diff --git a/src/Plugin/SolrConnector/PantheonSolrConnector.php b/src/Plugin/SolrConnector/PantheonSolrConnector.php index 522f1ecd..c2ce5ea2 100644 --- a/src/Plugin/SolrConnector/PantheonSolrConnector.php +++ b/src/Plugin/SolrConnector/PantheonSolrConnector.php @@ -13,8 +13,9 @@ use Symfony\Component\DependencyInjection\ContainerInterface; use Drupal\search_api_pantheon\Services\PantheonGuzzle; use Drupal\search_api_pantheon\Services\SolariumClient as PantheonSolariumClient; +use Drupal\Core\Logger\LoggerChannelFactoryInterface; use Drupal\Core\Datetime\DateFormatterInterface; -use Drupal\search_api_pantheon\Services\Reload; +use Drupal\Core\Messenger\MessengerInterface; /** * Pantheon Solr connector. @@ -63,29 +64,27 @@ class PantheonSolrConnector extends SolrConnectorPluginBase implements */ protected $messenger; - /** - * The container. - * - * @var \Symfony\Component\DependencyInjection\ContainerInterface - */ - protected ContainerInterface $container; - /** * Class constructor. */ public function __construct( - array $configuration, - $plugin_id, - array $plugin_definition, - ContainerInterface $container, + array $configuration, + $plugin_id, + array $plugin_definition, + LoggerChannelFactoryInterface $logger_factory, + PantheonGuzzle $pantheon_guzzle, + PantheonSolariumClient $solarium_client, + DateFormatterInterface $date_formatter, + MessengerInterface $messenger ) { - parent::__construct(array_merge($configuration, self::getPlatformConfig()), $plugin_id, $plugin_definition); - $this->pantheonGuzzle = $container->get('search_api_pantheon.pantheon_guzzle'); - $this->solariumClient = $container->get('search_api_pantheon.solarium_client'); - $this->dateFormatter = $container->get('date.formatter'); - $this->messenger = $container->get('messenger'); - $this->setLogger($container->get('logger.factory')->get('PantheonSearch')); - $this->container = $container; + parent::__construct($configuration, $plugin_id, $plugin_definition); + $this->pantheonGuzzle = $pantheon_guzzle; + $this->solariumClient = $solarium_client; + $this->dateFormatter = $date_formatter; + $this->messenger = $messenger; + $this->setLogger($logger_factory->get('PantheonSearch')); + $this->configuration['core'] = self::getPlatformConfig()['core']; + $this->configuration['schema'] = self::getPlatformConfig()['schema']; $this->connect(); } @@ -99,17 +98,21 @@ public function __construct( * @throws \Exception */ public static function create( - ContainerInterface $container, - array $configuration, - $plugin_id, - $plugin_definition - ) { + ContainerInterface $container, + array $configuration, + $plugin_id, + $plugin_definition + ) { return new static( - $configuration, - $plugin_id, - $plugin_definition, - $container, - ); + $configuration, + $plugin_id, + $plugin_definition, + $container->get('logger.factory'), + $container->get('search_api_pantheon.pantheon_guzzle'), + $container->get('search_api_pantheon.solarium_client'), + $container->get('date.formatter'), + $container->get('messenger') + ); } /** @@ -126,7 +129,6 @@ public static function getPlatformConfig() { 'path' => getenv('PANTHEON_INDEX_PATH'), 'core' => getenv('PANTHEON_INDEX_CORE'), 'schema' => getenv('PANTHEON_INDEX_SCHEMA'), - 'reload_path' => getenv('PANTHEON_INDEX_RELOAD_PATH'), ]; } @@ -168,9 +170,9 @@ public function defaultConfiguration() { * Form render array. */ public function buildConfigurationForm( - array $form, - FormStateInterface $form_state - ) { + array $form, + FormStateInterface $form_state + ) { $form = parent::buildConfigurationForm($form, $form_state); $fields = [ @@ -206,9 +208,9 @@ function ($field_name) use ($fields) { * Form state object. */ public function validateConfigurationForm( - array &$form, - FormStateInterface $form_state - ) { + array &$form, + FormStateInterface $form_state + ) { } /** @@ -220,9 +222,9 @@ public function validateConfigurationForm( * Form state object. */ public function submitConfigurationForm( - array &$form, - FormStateInterface $form_state - ) { + array &$form, + FormStateInterface $form_state + ) { $configuration = array_merge($this->defaultConfiguration(), $form_state->getValues()); $this->setConfiguration($configuration); @@ -291,16 +293,16 @@ public function getStatsSummary() { } $summary = [ - '@pending_docs' => '', - '@autocommit_time_seconds' => '', - '@autocommit_time' => '', - '@deletes_by_id' => '', - '@deletes_by_query' => '', - '@deletes_total' => '', - '@schema_version' => '', - '@core_name' => '', - '@index_size' => '', - ]; + '@pending_docs' => '', + '@autocommit_time_seconds' => '', + '@autocommit_time' => '', + '@deletes_by_id' => '', + '@deletes_by_query' => '', + '@deletes_total' => '', + '@schema_version' => '', + '@core_name' => '', + '@index_size' => '', + ]; if (empty($stats) || empty($indexStats)) { return $summary; @@ -309,33 +311,33 @@ public function getStatsSummary() { $max_time = -1; $update_handler_stats = $stats['UPDATE']['updateHandler']['stats'] ?? -1; $summary['@pending_docs'] = - (int) $update_handler_stats['UPDATE.updateHandler.docsPending'] ?? -1; + (int) $update_handler_stats['UPDATE.updateHandler.docsPending'] ?? -1; if ( - isset( - $update_handler_stats['UPDATE.updateHandler.softAutoCommitMaxTime'] - ) - ) { + isset( + $update_handler_stats['UPDATE.updateHandler.softAutoCommitMaxTime'] + ) + ) { $max_time = - (int) $update_handler_stats['UPDATE.updateHandler.softAutoCommitMaxTime']; + (int) $update_handler_stats['UPDATE.updateHandler.softAutoCommitMaxTime']; } $summary['@deletes_by_id'] = - (int) $update_handler_stats['UPDATE.updateHandler.deletesById'] ?? -1; + (int) $update_handler_stats['UPDATE.updateHandler.deletesById'] ?? -1; $summary['@deletes_by_query'] = - (int) $update_handler_stats['UPDATE.updateHandler.deletesByQuery'] ?? -1; + (int) $update_handler_stats['UPDATE.updateHandler.deletesByQuery'] ?? -1; $summary['@core_name'] = - $stats['CORE']['core']['class'] ?? - $this->t('No information available.'); + $stats['CORE']['core']['class'] ?? + $this->t('No information available.'); $summary['@index_size'] = - $indexStats['numDocs'] ?? $this->t('No information available.'); + $indexStats['numDocs'] ?? $this->t('No information available.'); $summary['@autocommit_time_seconds'] = $max_time / 1000; $summary['@autocommit_time'] = $this->dateFormatter ->formatInterval($max_time / 1000); $summary['@deletes_total'] = - ( - intval($summary['@deletes_by_id'] ?? 0) - + intval($summary['@deletes_by_query'] ?? 0) - ) ?? -1; + ( + intval($summary['@deletes_by_id'] ?? 0) + + intval($summary['@deletes_by_query'] ?? 0) + ) ?? -1; $summary['@schema_version'] = $this->getSchemaVersionString(TRUE); return $summary; } @@ -344,9 +346,9 @@ public function getStatsSummary() { * {@inheritdoc} */ public function useTimeout( - string $timeout = self::QUERY_TIMEOUT, - ?Endpoint $endpoint = NULL - ) { + string $timeout = self::QUERY_TIMEOUT, + ?Endpoint $endpoint = NULL + ) { } /** @@ -358,25 +360,25 @@ public function viewSettings() { $view_settings = []; $view_settings[] = [ - 'label' => $this->t('Pantheon Sitename'), - 'info' => $this->getEndpoint()->getCore(), - ]; + 'label' => $this->t('Pantheon Sitename'), + 'info' => $this->getEndpoint()->getCore(), + ]; $view_settings[] = [ - 'label' => $this->t('Pantheon Environment'), - 'info' => getenv('PANTHEON_ENVIRONMENT'), - ]; + 'label' => $this->t('Pantheon Environment'), + 'info' => getenv('PANTHEON_ENVIRONMENT'), + ]; $view_settings[] = [ - 'label' => $this->t('Schema Version'), - 'info' => $this->getSchemaVersion(TRUE), - ]; + 'label' => $this->t('Schema Version'), + 'info' => $this->getSchemaVersion(TRUE), + ]; $core_info = $this->getCoreInfo(TRUE); foreach ($core_info['core'] as $key => $value) { if (is_string($value)) { $view_settings[] = [ - 'label' => ucwords($key), - 'info' => $value, - ]; + 'label' => ucwords($key), + 'info' => $value, + ]; } } @@ -402,9 +404,11 @@ public function getEndpoint($key = 'search_api_solr') { * @return bool * Success or Failure. */ - public function reloadCore(): bool { - $rl = new Reload($this->container->get("logger.factory"), $this->pantheonGuzzle); - return $rl->reloadServer(); + public function reloadCore() { + $this->logger->notice( + $this->t('Reload Core action for Pantheon Solr is automatic when Schema is updated.') + ); + return TRUE; } /** @@ -458,29 +462,29 @@ protected function createClient(array &$configuration) { */ protected function getStatsQuery(string $handler) { return json_decode( - $this->pantheonGuzzle - ->get( - $handler, - [ - 'query' => - [ - 'stats' => 'true', - 'wt' => 'json', - 'accept' => 'application/json', - 'contenttype' => 'application/json', - 'json.nl' => 'flat', - ], - 'headers' => - [ - 'Content-Type' => 'application/json', - 'Accept' => 'application/json', - ], - ] - ) - ->getBody(), - TRUE, - JSON_THROW_ON_ERROR - ); + $this->pantheonGuzzle + ->get( + $handler, + [ + 'query' => + [ + 'stats' => 'true', + 'wt' => 'json', + 'accept' => 'application/json', + 'contenttype' => 'application/json', + 'json.nl' => 'flat', + ], + 'headers' => + [ + 'Content-Type' => 'application/json', + 'Accept' => 'application/json', + ], + ] + ) + ->getBody(), + TRUE, + JSON_THROW_ON_ERROR + ); } } From f89aa7cbf90bbc5fe6c149237ea630a2978994aa Mon Sep 17 00:00:00 2001 From: Phil Tyler Date: Wed, 13 Nov 2024 16:12:51 -0800 Subject: [PATCH 42/42] restore reload_path --- src/Plugin/SolrConnector/PantheonSolrConnector.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Plugin/SolrConnector/PantheonSolrConnector.php b/src/Plugin/SolrConnector/PantheonSolrConnector.php index c2ce5ea2..f2a4740c 100644 --- a/src/Plugin/SolrConnector/PantheonSolrConnector.php +++ b/src/Plugin/SolrConnector/PantheonSolrConnector.php @@ -129,6 +129,7 @@ public static function getPlatformConfig() { 'path' => getenv('PANTHEON_INDEX_PATH'), 'core' => getenv('PANTHEON_INDEX_CORE'), 'schema' => getenv('PANTHEON_INDEX_SCHEMA'), + 'reload_path' => getenv('PANTHEON_INDEX_RELOAD_PATH'), ]; }