Skip to content
Snippets Groups Projects
Commit 0919c4e9 authored by Lucas Hedding's avatar Lucas Hedding Committed by Lucas Hedding
Browse files

Issue #2952581 by heddn, quietone: Handle missing source file

parent 2ab6db19
No related branches found
No related tags found
No related merge requests found
......@@ -3,6 +3,7 @@
namespace Drupal\migrate_source_csv\Plugin\migrate\source;
use Drupal\Component\Plugin\ConfigurablePluginInterface;
use Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException;
use Drupal\Component\Utility\NestedArray;
use Drupal\migrate\MigrateException;
use Drupal\migrate\Plugin\migrate\source\SourcePluginBase;
......@@ -85,6 +86,9 @@ class CSV extends SourcePluginBase implements ConfigurablePluginInterface {
* {@inheritdoc}
*/
public function initializeIterator() {
if (!file_exists($this->getConfiguration()['path'])) {
throw new InvalidPluginDefinitionException($this->getPluginId(), sprintf('File path (%s) does not exist.', $this->getConfiguration()['path']));
}
// File handler using header-rows-respecting extension of SPLFileObject.
$this->file = new $this->fileClass($this->getConfiguration()['path']);
return $this->setupFile();
......
......@@ -2,6 +2,7 @@
namespace Drupal\Tests\migrate_source_csv\Unit\Plugin\migrate\source;
use Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException;
use Drupal\migrate\Plugin\MigrationInterface;
use Drupal\migrate_source_csv\CSVFileObject;
use Drupal\migrate_source_csv\Plugin\migrate\source\CSV;
......@@ -338,6 +339,22 @@ class CSVUnitTest extends CSVUnitBase {
$this->assertArrayEquals($row, $current);
}
/**
* Tests malformed CSV file path.
*
* @covers ::initializeIterator
*/
public function testMalformedFilePath() {
$configuration = [
'path' => 'non-existent-path',
'keys' => ['id'],
];
$csv = new CSV($configuration, $this->pluginId, $this->pluginDefinition, $this->migration);
$this->setExpectedException(InvalidPluginDefinitionException::class, 'File path (non-existent-path) does not exist.');
$csv->initializeIterator();
}
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment