Skip to content

Commit

Permalink
Revert "Switch to simple built-in FileFetcher on import (#3881)"
Browse files Browse the repository at this point in the history
This reverts commit edd187c.
  • Loading branch information
dafeder committed Dec 21, 2022
1 parent 9ffba22 commit cbdd870
Show file tree
Hide file tree
Showing 20 changed files with 150 additions and 331 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"fmizzell/maquina": "^1.1.0",
"getdkan/contracts": "^1.0.0",
"getdkan/csv-parser": "^1.2.3",
"getdkan/file-fetcher" : "^4.1.0",
"getdkan/harvest": "^1.0.0",
"getdkan/json-schema-provider": "^0.1.2",
"getdkan/locker": "^1.1.0",
Expand Down
5 changes: 5 additions & 0 deletions modules/common/common.services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ services:
factory: entity_type.manager:getStorage
arguments: ['node']

dkan.common.file_fetcher:
class: \Drupal\common\FileFetcher\Factory
arguments:
- '@dkan.common.job_store'

dkan.common.dataset_info:
class: \Drupal\common\DatasetInfo
calls:
Expand Down
56 changes: 56 additions & 0 deletions modules/common/src/FileFetcher/Factory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

namespace Drupal\common\FileFetcher;

use Contracts\FactoryInterface;
use Drupal\common\Storage\JobStoreFactory;
use FileFetcher\FileFetcher;

/**
* File fetcher Factory.
*/
class Factory implements FactoryInterface {

/**
* Job store factory service.
*
* @var \Drupal\common\Storage\JobStoreFactory
*/
private $factory;

/**
* Default file fetcher config.
*
* @var array
*/
private $configDefault = [
'keep_original_filename' => TRUE,
];

/**
* Constructor.
*/
public function __construct(JobStoreFactory $factory) {
$this->factory = $factory;
}

/**
* Inherited.
*
* @inheritdoc
*/
public function getInstance(string $identifier, array $config = []) {
$config = array_merge($this->configDefault, $config);
return FileFetcher::get($identifier, $this->getFileFetcherJobStore(), $config);
}

/**
* Private.
*/
private function getFileFetcherJobStore() {
/** @var \Drupal\common\Storage\JobStoreFactory $jobStoreFactory */
$jobStoreFactory = $this->factory;
return $jobStoreFactory->getInstance(FileFetcher::class);
}

}
4 changes: 2 additions & 2 deletions modules/common/tests/src/Traits/CleanUp.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Drupal\Tests\common\Traits;

use Drupal\node\Entity\Node;
use Drupal\datastore\Plugin\QueueWorker\FileFetcherJob;
use FileFetcher\FileFetcher;

/**
*
Expand Down Expand Up @@ -50,7 +50,7 @@ private function removeAllFileFetchingJobs() {
$jobStoreFactory = \Drupal::service('dkan.common.job_store');

/** @var \Drupal\common\Storage\JobStore $jobStore */
$jobStore = $jobStoreFactory->getInstance(FileFetcherJob::class);
$jobStore = $jobStoreFactory->getInstance(FileFetcher::class);
foreach ($jobStore->retrieveAll() as $id) {
$jobStore->remove($id);
}
Expand Down
18 changes: 9 additions & 9 deletions modules/common/tests/src/Unit/Storage/JobStoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
use Drupal\Core\Database\Schema;
use Drupal\Core\Database\StatementWrapper;
use Drupal\common\Storage\JobStore;
use Drupal\datastore\Plugin\QueueWorker\FileFetcherJob;

use Contracts\Mock\Storage\Memory;
use FileFetcher\FileFetcher;
use MockChain\Chain;
use MockChain\Sequence;
use PHPUnit\Framework\TestCase;
Expand All @@ -30,7 +30,7 @@ public function testConstruction() {
->add(Connection::class, "schema", Schema::class)
->add(Schema::class, "tableExists", FALSE);

$jobStore = new JobStore(FileFetcherJob::class, $chain->getMock());
$jobStore = new JobStore(FileFetcher::class, $chain->getMock());
$this->assertTrue(is_object($jobStore));
}

Expand Down Expand Up @@ -59,8 +59,8 @@ public function testRetrieve() {
->add(Connection::class, 'query', StatementWrapper::class)
->add(StatementWrapper::class, 'fetchAll', $fieldInfo);

$jobStore = new JobStore(FileFetcherJob::class, $chain->getMock());
$this->assertEquals($job_data, $jobStore->retrieve("1", FileFetcherJob::class));
$jobStore = new JobStore(FileFetcher::class, $chain->getMock());
$this->assertEquals($job_data, $jobStore->retrieve("1", FileFetcher::class));
}

/**
Expand Down Expand Up @@ -90,7 +90,7 @@ public function testRetrieveAll() {
->add(Connection::class, 'query', StatementWrapper::class)
->add(StatementWrapper::class, 'fetchAll', $sequence);

$jobStore = new JobStore(FileFetcherJob::class, $chain->getMock());
$jobStore = new JobStore(FileFetcher::class, $chain->getMock());
$this->assertTrue(is_array($jobStore->retrieveAll()));
}

Expand Down Expand Up @@ -127,7 +127,7 @@ public function testStore() {
->add(StatementWrapper::class, 'fetchAll', $fieldInfo)
->getMock();

$jobStore = new JobStore(FileFetcherJob::class, $connection);
$jobStore = new JobStore(FileFetcher::class, $connection);

$this->assertEquals("1", $jobStore->store(json_encode($jobObject), "1"));
}
Expand All @@ -151,16 +151,16 @@ public function testRemove() {
->add(StatementWrapper::class, 'fetchAll', $fieldInfo)
->getMock();

$jobStore = new JobStore(FileFetcherJob::class, $connection);
$jobStore = new JobStore(FileFetcher::class, $connection);

$this->assertEquals("", $jobStore->remove("1", FileFetcherJob::class));
$this->assertEquals("", $jobStore->remove("1", FileFetcher::class));
}

/**
* Private.
*/
private function getFileFetcher() {
return FileFetcherJob::get("1", new Memory(), ["filePath" => "file://" . __DIR__ . "/../../data/countries.csv"]);
return FileFetcher::get("1", new Memory(), ["filePath" => "file://" . __DIR__ . "/../../data/countries.csv"]);
}

}
1 change: 1 addition & 0 deletions modules/datastore/datastore.services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ services:
class: \Drupal\datastore\Service\ResourceLocalizer
arguments:
- '@dkan.metastore.resource_mapper'
- '@dkan.common.file_fetcher'
- '@dkan.common.drupal_files'
- '@dkan.common.job_store'

Expand Down
165 changes: 0 additions & 165 deletions modules/datastore/src/Plugin/QueueWorker/FileFetcherJob.php

This file was deleted.

2 changes: 1 addition & 1 deletion modules/datastore/src/Plugin/QueueWorker/ImportJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ protected function setStorageSchema(array $header) {
* Verify headers are unique.
*
* @param array $header
* List of strings.
* List of strings
*
* @throws \Exception
*/
Expand Down
11 changes: 2 additions & 9 deletions modules/datastore/src/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Drupal\datastore;

use Drupal\common\DataResource;
use Drupal\datastore\Plugin\QueueWorker\FileFetcherJob;
use Drupal\common\Storage\JobStoreFactory;
use Procrastinator\Result;
use Symfony\Component\DependencyInjection\ContainerInterface;
Expand All @@ -13,6 +12,7 @@
use Drupal\datastore\Service\ResourceLocalizer;
use Drupal\datastore\Service\Factory\ImportFactoryInterface;
use Drupal\datastore\Service\Info\ImportInfoList;
use FileFetcher\FileFetcher;

/**
* Main services for the datastore.
Expand All @@ -33,13 +33,6 @@ class Service implements ContainerInjectionInterface {
*/
private $importServiceFactory;

/**
* Import info list service.
*
* @var \Drupal\datastore\Service\Info\ImportInfoList
*/
private ImportInfoList $importInfoList;

/**
* Drupal queue.
*
Expand Down Expand Up @@ -211,7 +204,7 @@ public function drop(string $identifier, ?string $version = NULL, bool $local_re
if ($local_resource) {
$this->resourceLocalizer->remove($identifier, $version);
$this->jobStoreFactory
->getInstance(FileFetcherJob::class)
->getInstance(FileFetcher::class)
->remove(substr(str_replace('__', '_', $resource_id), 0, -11));
}
}
Expand Down
Loading

0 comments on commit cbdd870

Please sign in to comment.