Problem/Motivation

Attempting to use the Migrate operation to migrate a search server using a searchstax user with multiple Accounts will throw an error if any of the Accounts does not have an App.

In MigrateServerForm.php on line 201 the form attempts to retrieve all Apps for a specified account name in order to build an options array. That calls getApps on line 206 of Api.php, which in turn calls sendApiRequest
$data = $this->sendApiRequest('GET', '/apps', ['account' => $account]);

Accounts with no Apps return an empty body as no Apps are available which triggers the conditional on line 580
if ($response->getStatusCode() !== 200 || !$data) {

That results in the following error message and a broken form:
Drupal\searchstax\Exception\SearchStaxException: HTTP 200 response from server: [] in Drupal\searchstax\Service\Api->sendApiRequest() (line 591 of /var/www/html/docroot/modules/contrib/searchstax/src/Service/Api.php).
 [] error message

Steps to reproduce

  • Install the searchstax and solr_to_searchstax_ss_migration modules on a site with an existing solr server.
  • Click Migrate under Operations next to the server
  • Provide searchstax credentials for a user that has access to an Account with no App
  • The logged in message should show in green, then the error in red

Proposed resolution

It seems that the empty body in the return is a valid response and shouldn't be treated as an error. I don't know where else the method is used so I don't want to change the return if there are assumptions that an empty response throws an error elsewhere. A possible first step would be to catch the exception and message an error but allow the form to continue building to see if other Accounts have Apps. something like the following

try {
  foreach ($this->searchStaxApi->getApps($account_name) as $app_id => $app) {
    ...
  }
}
catch (SearchStaxException $e) {
  if ($e->getCode() === 200 && !$e->getResponse()) {
    $this->messenger()->addError($this->t('%account_name has no Apps to select', ['%account_name' => $account_name]));
  }
  else {
    throw SearchStaxException::fromPrevious($e);
  }
}

That allows the form to be used and alerts the user to the Account that needs an App before it can be used.
No App for account error message with usable form

Issue fork searchstax-3545168

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

wolffereast created an issue. See original summary.

wolffereast’s picture

Adding an interim patch which fixes the form for now

drunken monkey made their first commit to this issue’s fork.

drunken monkey’s picture

Version: 1.7.1 » 1.x-dev
Status: Active » Needs review

Thanks a lot for reporting this problem! I can reproduce it in the latest dev version, too.
As you say, [] is definitely a valid response and we should treat it as such. I’m pretty sure just fixing the method in the Api class should be safe, I cannot imagine any code relying on this faulty behavior.
Unfortunately, your patch does not apply for me, but this merge request should implement a complete solution:

  • It fixes Api::sendApiRequest() to not treat a [] response as a failed request.
  • It adapts MigrateServerForm to display a helpful message when an account has no apps.
  • It adds test coverage for this new behavior.

Please give it a try and tell me whether this works for you.
And thanks again, in any case!

rajeshreeputra made their first commit to this issue’s fork.

drunken monkey’s picture

Does anyone still want to test or review this MR?

carolpettirossi’s picture

I couldn't apply the patch on 1.8.1

Downloading https://git.drupalcode.org/project/searchstax/-/merge_requests/53.diff
patch '-p1' --no-backup-if-mismatch -d 'docroot/modules/contrib/searchstax' < '/tmp/69091e69a04f7.patch'
Executing command (CWD): patch '-p1' --no-backup-if-mismatch -d 'docroot/modules/contrib/searchstax' < '/tmp/69091e69a04f7.patch'
patching file solr_to_searchstax_ss_migration/src/Form/MigrateServerForm.php

Hunk #4 FAILED at 301.
Hunk #5 succeeded at 318 (offset -3 lines).

1 out of 5 hunks FAILED -- saving rejects to file solr_to_searchstax_ss_migration/src/Form/MigrateServerForm.php.rej

patching file solr_to_searchstax_ss_migration/tests/data/lookup.json

Hunk #1 succeeded at 5 with fuzz 2.

patching file solr_to_searchstax_ss_migration/tests/data/requests/searchstax/get-apps-third-account.json

patching file solr_to_searchstax_ss_migration/tests/data/responses/searchstax/get-apps-third-account/body.json

patching file solr_to_searchstax_ss_migration/tests/data/responses/searchstax/get-apps-third-account/metadata.json

patching file solr_to_searchstax_ss_migration/tests/src/Functional/IntegrationTest.php

patching file src/Service/Api.php

Hunk #1 succeeded at 578 (offset 1 line).

patch '-p0' --no-backup-if-mismatch -d 'docroot/modules/contrib/searchstax' < '/tmp/69091e69a04f7.patch'
Executing command (CWD): patch '-p0' --no-backup-if-mismatch -d 'docroot/modules/contrib/searchstax' < '/tmp/69091e69a04f7.patch'
can't find file to patch at input line 5
Perhaps you used the wrong -p or --strip option?
The text leading up to this was:
--------------------------
|diff --git a/solr_to_searchstax_ss_migration/src/Form/MigrateServerForm.php b/solr_to_searchstax_ss_migration/src/Form/MigrateServerForm.php
|index a1b2ca11496f454ae2dfae3d9ac1c6f761ca23e8..61641eaa7c3eaf178fe861530f657893eaf82794 100644
|--- a/solr_to_searchstax_ss_migration/src/Form/MigrateServerForm.php
|+++ b/solr_to_searchstax_ss_migration/src/Form/MigrateServerForm.php
--------------------------
File to patch: 
Skip this patch? [y] 
Skipping patch.

5 out of 5 hunks ignored
can't find file to patch at input line 63
Perhaps you used the wrong -p or --strip option?
The text leading up to this was:
--------------------------
|diff --git a/solr_to_searchstax_ss_migration/tests/data/lookup.json b/solr_to_searchstax_ss_migration/tests/data/lookup.json
|index 276137637d388609d9e3462f6ee12a38755f17c5..5d628929c250f21f5d0dfd8f07a24a7472ed80b0 100644
|--- a/solr_to_searchstax_ss_migration/tests/data/lookup.json
|+++ b/solr_to_searchstax_ss_migration/tests/data/lookup.json
--------------------------
File to patch: 
Skip this patch? [y] 
Skipping patch.

1 out of 1 hunk ignored

patching file b/solr_to_searchstax_ss_migration/tests/data/requests/searchstax/get-apps-third-account.json

patching file b/solr_to_searchstax_ss_migration/tests/data/responses/searchstax/get-apps-third-account/body.json

patching file b/solr_to_searchstax_ss_migration/tests/data/responses/searchstax/get-apps-third-account/metadata.json

can't find file to patch at input line 104
Perhaps you used the wrong -p or --strip option?
The text leading up to this was:
--------------------------
|diff --git a/solr_to_searchstax_ss_migration/tests/src/Functional/IntegrationTest.php b/solr_to_searchstax_ss_migration/tests/src/Functional/IntegrationTest.php
|index 4f41cb9e0707e4f79f6ea614c1875cd93cfecc1f..5a82343f0db1bd530285e3e0f92562d6e4e119e2 100644
|--- a/solr_to_searchstax_ss_migration/tests/src/Functional/IntegrationTest.php
|+++ b/solr_to_searchstax_ss_migration/tests/src/Functional/IntegrationTest.php
--------------------------
File to patch: 
Skip this patch? [y] 
Skipping patch.

3 out of 3 hunks ignored

can't find file to patch at input line 151
Perhaps you used the wrong -p or --strip option?
The text leading up to this was:
--------------------------
|diff --git a/src/Service/Api.php b/src/Service/Api.php
|index e8d7794c6dd26888d614d94cfdb8bb8c8333a331..c43f892d7e0df8fdcbbe992bc60f494d844bdfdb 100644
|--- a/src/Service/Api.php
|+++ b/src/Service/Api.php
--------------------------
File to patch: 
Skip this patch? [y] 
Skipping patch.

1 out of 1 hunk ignored

patch '-p2' --no-backup-if-mismatch -d 'docroot/modules/contrib/searchstax' < '/tmp/69091e69a04f7.patch'
Executing command (CWD): patch '-p2' --no-backup-if-mismatch -d 'docroot/modules/contrib/searchstax' < '/tmp/69091e69a04f7.patch'
can't find file to patch at input line 5
Perhaps you used the wrong -p or --strip option?
The text leading up to this was:
--------------------------
|diff --git a/solr_to_searchstax_ss_migration/src/Form/MigrateServerForm.php b/solr_to_searchstax_ss_migration/src/Form/MigrateServerForm.php
|index a1b2ca11496f454ae2dfae3d9ac1c6f761ca23e8..61641eaa7c3eaf178fe861530f657893eaf82794 100644
|--- a/solr_to_searchstax_ss_migration/src/Form/MigrateServerForm.php
|+++ b/solr_to_searchstax_ss_migration/src/Form/MigrateServerForm.php
--------------------------
File to patch: 
Skip this patch? [y] 
Skipping patch.

5 out of 5 hunks ignored

can't find file to patch at input line 63
Perhaps you used the wrong -p or --strip option?
The text leading up to this was:
--------------------------
|diff --git a/solr_to_searchstax_ss_migration/tests/data/lookup.json b/solr_to_searchstax_ss_migration/tests/data/lookup.json
|index 276137637d388609d9e3462f6ee12a38755f17c5..5d628929c250f21f5d0dfd8f07a24a7472ed80b0 100644
|--- a/solr_to_searchstax_ss_migration/tests/data/lookup.json
|+++ b/solr_to_searchstax_ss_migration/tests/data/lookup.json
--------------------------
File to patch: 
Skip this patch? [y] 
Skipping patch.

1 out of 1 hunk ignored

patching file tests/data/requests/searchstax/get-apps-third-account.json

patching file tests/data/responses/searchstax/get-apps-third-account/body.json

patching file tests/data/responses/searchstax/get-apps-third-account/metadata.json

can't find file to patch at input line 104
Perhaps you used the wrong -p or --strip option?
The text leading up to this was:
--------------------------
|diff --git a/solr_to_searchstax_ss_migration/tests/src/Functional/IntegrationTest.php b/solr_to_searchstax_ss_migration/tests/src/Functional/IntegrationTest.php
|index 4f41cb9e0707e4f79f6ea614c1875cd93cfecc1f..5a82343f0db1bd530285e3e0f92562d6e4e119e2 100644
|--- a/solr_to_searchstax_ss_migration/tests/src/Functional/IntegrationTest.php
|+++ b/solr_to_searchstax_ss_migration/tests/src/Functional/IntegrationTest.php
--------------------------
File to patch: 
Skip this patch? [y] 
Skipping patch.

3 out of 3 hunks ignored
can't find file to patch at input line 151
Perhaps you used the wrong -p or --strip option?
The text leading up to this was:
--------------------------
|diff --git a/src/Service/Api.php b/src/Service/Api.php
|index e8d7794c6dd26888d614d94cfdb8bb8c8333a331..c43f892d7e0df8fdcbbe992bc60f494d844bdfdb 100644
|--- a/src/Service/Api.php
|+++ b/src/Service/Api.php
--------------------------
File to patch: 
Skip this patch? [y] 
Skipping patch.

1 out of 1 hunk ignored

patch '-p4' --no-backup-if-mismatch -d 'docroot/modules/contrib/searchstax' < '/tmp/69091e69a04f7.patch'
Executing command (CWD): patch '-p4' --no-backup-if-mismatch -d 'docroot/modules/contrib/searchstax' < '/tmp/69091e69a04f7.patch'
can't find file to patch at input line 5
Perhaps you used the wrong -p or --strip option?
The text leading up to this was:
--------------------------
|diff --git a/solr_to_searchstax_ss_migration/src/Form/MigrateServerForm.php b/solr_to_searchstax_ss_migration/src/Form/MigrateServerForm.php
|index a1b2ca11496f454ae2dfae3d9ac1c6f761ca23e8..61641eaa7c3eaf178fe861530f657893eaf82794 100644
|--- a/solr_to_searchstax_ss_migration/src/Form/MigrateServerForm.php
|+++ b/solr_to_searchstax_ss_migration/src/Form/MigrateServerForm.php
--------------------------
File to patch: 
Skip this patch? [y] 
Skipping patch.

5 out of 5 hunks ignored

can't find file to patch at input line 63
Perhaps you used the wrong -p or --strip option?
The text leading up to this was:
--------------------------
|diff --git a/solr_to_searchstax_ss_migration/tests/data/lookup.json b/solr_to_searchstax_ss_migration/tests/data/lookup.json
|index 276137637d388609d9e3462f6ee12a38755f17c5..5d628929c250f21f5d0dfd8f07a24a7472ed80b0 100644
|--- a/solr_to_searchstax_ss_migration/tests/data/lookup.json
|+++ b/solr_to_searchstax_ss_migration/tests/data/lookup.json
--------------------------
File to patch: 
Skip this patch? [y] 
Skipping patch.

1 out of 1 hunk ignored

patching file requests/searchstax/get-apps-third-account.json

patching file responses/searchstax/get-apps-third-account/body.json

patching file responses/searchstax/get-apps-third-account/metadata.json

can't find file to patch at input line 104
Perhaps you used the wrong -p or --strip option?
The text leading up to this was:
--------------------------
|diff --git a/solr_to_searchstax_ss_migration/tests/src/Functional/IntegrationTest.php b/solr_to_searchstax_ss_migration/tests/src/Functional/IntegrationTest.php
|index 4f41cb9e0707e4f79f6ea614c1875cd93cfecc1f..5a82343f0db1bd530285e3e0f92562d6e4e119e2 100644
|--- a/solr_to_searchstax_ss_migration/tests/src/Functional/IntegrationTest.php
|+++ b/solr_to_searchstax_ss_migration/tests/src/Functional/IntegrationTest.php
--------------------------
File to patch: 
Skip this patch? [y] 
Skipping patch.

3 out of 3 hunks ignored
can't find file to patch at input line 151
Perhaps you used the wrong -p or --strip option?
The text leading up to this was:
--------------------------

|diff --git a/src/Service/Api.php b/src/Service/Api.php
|index e8d7794c6dd26888d614d94cfdb8bb8c8333a331..c43f892d7e0df8fdcbbe992bc60f494d844bdfdb 100644
|--- a/src/Service/Api.php
|+++ b/src/Service/Api.php
--------------------------
File to patch: 
Skip this patch? [y] 
Skipping patch.

1 out of 1 hunk ignored

   Could not apply patch! Skipping. The error was: Cannot apply patch https://git.drupalcode.org/project/searchstax/-/merge_requests/53.diff
Downloading https://packages.drupal.org/8/downloads
[200] https://packages.drupal.org/8/downloads

In Patches.php line 331:
                                                                                                                                                 
  [Exception]                                                                                                                                    
  Cannot apply patch 3545168 - Accounts with no Apps break migrations (https://git.drupalcode.org/project/searchstax/-/merge_requests/53.diff)!  

carolpettirossi’s picture

Status: Needs review » Needs work
drunken monkey’s picture

Status: Needs work » Needs review

Thanks for reporting!
I rebased the MR, please try again.

sophie.sk’s picture

Status: Needs review » Reviewed & tested by the community
Related issues: +#3550829: Version Check fails when one of the Accounts doesn't have an App configured yet

Confirming that the updated patch applies cleanly against version 1.10.0, and resolves the issues I've spotted.

Namely, this resolves the issue #3550829: Version Check fails when one of the Accounts doesn't have an App configured yet - will post there too.

  • drunken monkey committed dccd7a69 on 1.x
    fix: #3545168 Fixed handling of accounts without apps.
    
    By: wolffereast...
drunken monkey’s picture

Status: Reviewed & tested by the community » Fixed
Related issues: -#3550829: Version Check fails when one of the Accounts doesn't have an App configured yet

Thanks a lot for your feedback, glad to hear this worked for you!
Merged. Thanks again, everyone!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

drunken monkey’s picture

Title: Accounts with no Apps break migrations » Accounts with no Apps lead to errors
Component: Solr Migration sub-module » General code

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.