Verified Commit f290315a authored by godotislate's avatar godotislate
Browse files

fix: #3114887 Error responses are stored when using the Download migration process

By: codebymikey
By: slucero
By: mikelutz
By: benjifisher
By: xurizaemon
By: das-peter
By: alexpott
By: godotislate
(cherry picked from commit ae4815ac)
parent c748ee97
Loading
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -156,6 +156,12 @@ public function transform($value, MigrateExecutableInterface $migrate_executable
      $this->httpClient->get($source, $this->configuration['guzzle_options']);
    }
    catch (\Exception $e) {
      // Since the destination file stream was used as the sink for the Guzzle
      // request, invalid file content from the failed request may be stored in
      // a newly created file. Clean up the file if it exists since the request
      // failed.
      $this->fileSystem->delete($final_destination);

      throw new MigrateException("{$e->getMessage()} ($source)");
    }

+5 −1
Original line number Diff line number Diff line
@@ -34,13 +34,14 @@ class DownloadFunctionalTest extends BrowserTestBase {
   */
  public function testExceptionThrow(): void {
    $invalid_url = "{$this->baseUrl}/not-existent-404";
    $invalid_uri = "public://first.txt";
    $valid_url = "{$this->baseUrl}/core/misc/favicon.ico";

    $definition = [
      'source' => [
        'plugin' => 'embedded_data',
        'data_rows' => [
          ['url' => $invalid_url, 'uri' => 'public://first.txt'],
          ['url' => $invalid_url, 'uri' => $invalid_uri],
          ['url' => $valid_url, 'uri' => 'public://second.ico'],
        ],
        'ids' => [
@@ -86,6 +87,9 @@ public function testExceptionThrow(): void {
    $this->assertStringContainsString($invalid_url, $message->message);
    $this->assertEquals(MigrationInterface::MESSAGE_ERROR, $message->level);

    // Check that no file was created for the failed request.
    $this->assertFileDoesNotExist($invalid_uri);

    // Check that the second row was migrated successfully.
    $map_row = $id_map_plugin->getRowBySource(['url' => $valid_url]);
    $this->assertEquals(MigrateIdMapInterface::STATUS_IMPORTED, $map_row['source_row_status']);