Skip to content

Commit 6cd2c18

Browse files
authored
Revert "Switch to simple built-in FileFetcher on import (#3881)" (#3893)
1 parent 9ffba22 commit 6cd2c18

File tree

19 files changed

+149
-330
lines changed

19 files changed

+149
-330
lines changed

composer.json

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"fmizzell/maquina": "^1.1.0",
1919
"getdkan/contracts": "^1.0.0",
2020
"getdkan/csv-parser": "^1.2.3",
21+
"getdkan/file-fetcher" : "^4.1.0",
2122
"getdkan/harvest": "^1.0.0",
2223
"getdkan/json-schema-provider": "^0.1.2",
2324
"getdkan/locker": "^1.1.0",

modules/common/common.services.yml

+5
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ services:
2424
factory: entity_type.manager:getStorage
2525
arguments: ['node']
2626

27+
dkan.common.file_fetcher:
28+
class: \Drupal\common\FileFetcher\Factory
29+
arguments:
30+
- '@dkan.common.job_store'
31+
2732
dkan.common.dataset_info:
2833
class: \Drupal\common\DatasetInfo
2934
calls:
+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
3+
namespace Drupal\common\FileFetcher;
4+
5+
use Contracts\FactoryInterface;
6+
use Drupal\common\Storage\JobStoreFactory;
7+
use FileFetcher\FileFetcher;
8+
9+
/**
10+
* File fetcher Factory.
11+
*/
12+
class Factory implements FactoryInterface {
13+
14+
/**
15+
* Job store factory service.
16+
*
17+
* @var \Drupal\common\Storage\JobStoreFactory
18+
*/
19+
private $factory;
20+
21+
/**
22+
* Default file fetcher config.
23+
*
24+
* @var array
25+
*/
26+
private $configDefault = [
27+
'keep_original_filename' => TRUE,
28+
];
29+
30+
/**
31+
* Constructor.
32+
*/
33+
public function __construct(JobStoreFactory $factory) {
34+
$this->factory = $factory;
35+
}
36+
37+
/**
38+
* Inherited.
39+
*
40+
* @inheritdoc
41+
*/
42+
public function getInstance(string $identifier, array $config = []) {
43+
$config = array_merge($this->configDefault, $config);
44+
return FileFetcher::get($identifier, $this->getFileFetcherJobStore(), $config);
45+
}
46+
47+
/**
48+
* Private.
49+
*/
50+
private function getFileFetcherJobStore() {
51+
/** @var \Drupal\common\Storage\JobStoreFactory $jobStoreFactory */
52+
$jobStoreFactory = $this->factory;
53+
return $jobStoreFactory->getInstance(FileFetcher::class);
54+
}
55+
56+
}

modules/common/tests/src/Traits/CleanUp.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace Drupal\Tests\common\Traits;
44

55
use Drupal\node\Entity\Node;
6-
use Drupal\datastore\Plugin\QueueWorker\FileFetcherJob;
6+
use FileFetcher\FileFetcher;
77

88
/**
99
*
@@ -50,7 +50,7 @@ private function removeAllFileFetchingJobs() {
5050
$jobStoreFactory = \Drupal::service('dkan.common.job_store');
5151

5252
/** @var \Drupal\common\Storage\JobStore $jobStore */
53-
$jobStore = $jobStoreFactory->getInstance(FileFetcherJob::class);
53+
$jobStore = $jobStoreFactory->getInstance(FileFetcher::class);
5454
foreach ($jobStore->retrieveAll() as $id) {
5555
$jobStore->remove($id);
5656
}

modules/common/tests/src/Unit/Storage/JobStoreTest.php

+9-9
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
use Drupal\Core\Database\Schema;
1010
use Drupal\Core\Database\StatementWrapper;
1111
use Drupal\common\Storage\JobStore;
12-
use Drupal\datastore\Plugin\QueueWorker\FileFetcherJob;
1312

1413
use Contracts\Mock\Storage\Memory;
14+
use FileFetcher\FileFetcher;
1515
use MockChain\Chain;
1616
use MockChain\Sequence;
1717
use PHPUnit\Framework\TestCase;
@@ -30,7 +30,7 @@ public function testConstruction() {
3030
->add(Connection::class, "schema", Schema::class)
3131
->add(Schema::class, "tableExists", FALSE);
3232

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

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

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

6666
/**
@@ -90,7 +90,7 @@ public function testRetrieveAll() {
9090
->add(Connection::class, 'query', StatementWrapper::class)
9191
->add(StatementWrapper::class, 'fetchAll', $sequence);
9292

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

@@ -127,7 +127,7 @@ public function testStore() {
127127
->add(StatementWrapper::class, 'fetchAll', $fieldInfo)
128128
->getMock();
129129

130-
$jobStore = new JobStore(FileFetcherJob::class, $connection);
130+
$jobStore = new JobStore(FileFetcher::class, $connection);
131131

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

154-
$jobStore = new JobStore(FileFetcherJob::class, $connection);
154+
$jobStore = new JobStore(FileFetcher::class, $connection);
155155

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

159159
/**
160160
* Private.
161161
*/
162162
private function getFileFetcher() {
163-
return FileFetcherJob::get("1", new Memory(), ["filePath" => "file://" . __DIR__ . "/../../data/countries.csv"]);
163+
return FileFetcher::get("1", new Memory(), ["filePath" => "file://" . __DIR__ . "/../../data/countries.csv"]);
164164
}
165165

166166
}

modules/datastore/datastore.services.yml

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ services:
1717
class: \Drupal\datastore\Service\ResourceLocalizer
1818
arguments:
1919
- '@dkan.metastore.resource_mapper'
20+
- '@dkan.common.file_fetcher'
2021
- '@dkan.common.drupal_files'
2122
- '@dkan.common.job_store'
2223

modules/datastore/src/Plugin/QueueWorker/FileFetcherJob.php

-165
This file was deleted.

modules/datastore/src/Service.php

+2-9
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace Drupal\datastore;
44

55
use Drupal\common\DataResource;
6-
use Drupal\datastore\Plugin\QueueWorker\FileFetcherJob;
76
use Drupal\common\Storage\JobStoreFactory;
87
use Procrastinator\Result;
98
use Symfony\Component\DependencyInjection\ContainerInterface;
@@ -13,6 +12,7 @@
1312
use Drupal\datastore\Service\ResourceLocalizer;
1413
use Drupal\datastore\Service\Factory\ImportFactoryInterface;
1514
use Drupal\datastore\Service\Info\ImportInfoList;
15+
use FileFetcher\FileFetcher;
1616

1717
/**
1818
* Main services for the datastore.
@@ -33,13 +33,6 @@ class Service implements ContainerInjectionInterface {
3333
*/
3434
private $importServiceFactory;
3535

36-
/**
37-
* Import info list service.
38-
*
39-
* @var \Drupal\datastore\Service\Info\ImportInfoList
40-
*/
41-
private ImportInfoList $importInfoList;
42-
4336
/**
4437
* Drupal queue.
4538
*
@@ -211,7 +204,7 @@ public function drop(string $identifier, ?string $version = NULL, bool $local_re
211204
if ($local_resource) {
212205
$this->resourceLocalizer->remove($identifier, $version);
213206
$this->jobStoreFactory
214-
->getInstance(FileFetcherJob::class)
207+
->getInstance(FileFetcher::class)
215208
->remove(substr(str_replace('__', '_', $resource_id), 0, -11));
216209
}
217210
}

modules/datastore/src/Service/Info/ImportInfo.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Drupal\common\Storage\JobStoreFactory;
77
use Drupal\datastore\Service\Factory\ImportFactoryInterface;
88
use Drupal\datastore\Service\ResourceLocalizer;
9+
use FileFetcher\FileFetcher;
910
use Procrastinator\Job\Job;
1011

1112
/**
@@ -37,7 +38,7 @@ class ImportInfo {
3738
/**
3839
* FileFetcher service.
3940
*
40-
* @var \Drupal\datastore\Plugin\QueueWorker\FileFetcherJob
41+
* @var \FileFetcher\FileFetcher
4142
*/
4243
private $fileFetcher;
4344

0 commit comments

Comments
 (0)