Skip to content

Commit

Permalink
Use literal identifier for FileFetcherJobStoreFactory (#4090)
Browse files Browse the repository at this point in the history
  • Loading branch information
paul-m committed Jan 11, 2024
1 parent e46711f commit a8c2f44
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 37 deletions.
7 changes: 6 additions & 1 deletion modules/common/common.services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,14 @@ services:
dkan.common.file_fetcher:
class: \Drupal\common\FileFetcher\FileFetcherFactory
arguments:
- '@dkan.common.job_store'
- '@dkan.common.filefetcher_job_store_factory'
- '@config.factory'

dkan.common.filefetcher_job_store_factory:
class: \Drupal\common\Storage\FileFetcherJobStoreFactory
arguments:
- '@database'

dkan.common.dataset_info:
class: \Drupal\common\DatasetInfo
calls:
Expand Down
14 changes: 7 additions & 7 deletions modules/common/src/FileFetcher/FileFetcherFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Drupal\common\FileFetcher;

use Contracts\FactoryInterface;
use Drupal\common\Storage\JobStoreFactory;
use Drupal\common\Storage\FileFetcherJobStoreFactory;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Config\ImmutableConfig;
use FileFetcher\FileFetcher;
Expand All @@ -14,11 +14,11 @@
class FileFetcherFactory implements FactoryInterface {

/**
* Job store factory service.
* File fetcher job store factory.
*
* @var \Drupal\common\Storage\JobStoreFactory
* @var \Drupal\common\Storage\FileFetcherJobStoreFactory
*/
private JobStoreFactory $jobStoreFactory;
private FileFetcherJobStoreFactory $fileFetcherJobStoreFactory;

/**
* The common.settings config.
Expand All @@ -39,8 +39,8 @@ class FileFetcherFactory implements FactoryInterface {
/**
* Constructor.
*/
public function __construct(JobStoreFactory $jobStoreFactory, ConfigFactoryInterface $configFactory) {
$this->jobStoreFactory = $jobStoreFactory;
public function __construct(FileFetcherJobStoreFactory $fileFetcherJobStoreFactory, ConfigFactoryInterface $configFactory) {
$this->fileFetcherJobStoreFactory = $fileFetcherJobStoreFactory;
$this->dkanConfig = $configFactory->get('common.settings');
}

Expand All @@ -50,7 +50,7 @@ public function __construct(JobStoreFactory $jobStoreFactory, ConfigFactoryInter
public function getInstance(string $identifier, array $config = []) {
return FileFetcher::get(
$identifier,
$this->jobStoreFactory->getInstance(FileFetcher::class),
$this->fileFetcherJobStoreFactory->getInstance(),
$this->getFileFetcherConfig($config)
);
}
Expand Down
17 changes: 17 additions & 0 deletions modules/common/src/Storage/FileFetcherJobStoreFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace Drupal\common\Storage;

/**
* Create a job store object for the import process.
*/
class FileFetcherJobStoreFactory extends AbstractJobStoreFactory {

/**
* {@inheritDoc}
*
* This string contains an ugly hash for historical reasons.
*/
protected string $tableName = 'jobstore_524493904_filefetcher';

}
11 changes: 5 additions & 6 deletions modules/common/tests/src/Traits/CleanUp.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,12 @@ private function removeAllMappedFiles() {
*
*/
private function removeAllFileFetchingJobs() {
/** @var \Drupal\common\Storage\JobStoreFactory $jobStoreFactory */
$jobStoreFactory = \Drupal::service('dkan.common.job_store');
/** @var \Drupal\common\Storage\FileFetcherJobStoreFactory $jobStoreFactory */
$jobStoreFactory = \Drupal::service('dkan.common.filefetcher_job_store_factory');

/** @var \Drupal\common\Storage\JobStore $jobStore */
$jobStore = $jobStoreFactory->getInstance(FileFetcher::class);
foreach ($jobStore->retrieveAll() as $id) {
$jobStore->remove($id);
$fileFetcherJob = $jobStoreFactory->getInstance();
foreach ($fileFetcherJob->retrieveAll() as $id) {
$fileFetcherJob->remove($id);
}
}

Expand Down
4 changes: 2 additions & 2 deletions modules/datastore/datastore.services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ services:
- '@dkan.metastore.resource_mapper'
- '@dkan.common.file_fetcher'
- '@dkan.common.drupal_files'
- '@dkan.common.job_store'
- '@dkan.common.filefetcher_job_store_factory'
- '@queue'

dkan.datastore.service.resource_processor_collector:
Expand Down Expand Up @@ -110,7 +110,7 @@ services:
dkan.datastore.import_info_list:
class: \Drupal\datastore\Service\Info\ImportInfoList
arguments:
- '@dkan.common.job_store'
- '@dkan.common.filefetcher_job_store_factory'
- '@dkan.datastore.import_info'

dkan.datastore.import_job_store_factory:
Expand Down
17 changes: 8 additions & 9 deletions modules/datastore/src/Service/Info/ImportInfoList.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

namespace Drupal\datastore\Service\Info;

use Drupal\common\Storage\JobStoreFactory;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use FileFetcher\FileFetcher;
use Drupal\common\Storage\FileFetcherJobStoreFactory;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
Expand All @@ -13,11 +12,11 @@
class ImportInfoList implements ContainerInjectionInterface {

/**
* A JobStore object.
* File fetcher job store factory.
*
* @var \Drupal\common\Storage\JobStoreFactory
* @var \Drupal\common\Storage\FileFetcherJobStoreFactory
*/
private $jobStoreFactory;
private FileFetcherJobStoreFactory $fileFetcherJobStoreFactory;

/**
* Datastore import job info.
Expand All @@ -33,16 +32,16 @@ class ImportInfoList implements ContainerInjectionInterface {
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('dkan.common.job_store'),
$container->get('dkan.common.filefetcher_job_store_factory'),
$container->get('dkan.datastore.import_info')
);
}

/**
* Constructor.
*/
public function __construct(JobStoreFactory $jobStoreFactory, ImportInfo $importInfo) {
$this->jobStoreFactory = $jobStoreFactory;
public function __construct(FileFetcherJobStoreFactory $fileFetcherJobStoreFactory, ImportInfo $importInfo) {
$this->fileFetcherJobStoreFactory = $fileFetcherJobStoreFactory;
$this->importInfo = $importInfo;
}

Expand All @@ -58,7 +57,7 @@ public function __construct(JobStoreFactory $jobStoreFactory, ImportInfo $import
public function buildList() {
$list = [];

$store = $this->jobStoreFactory->getInstance(FileFetcher::class);
$store = $this->fileFetcherJobStoreFactory->getInstance();

foreach ($store->retrieveAll() as $id) {
$pieces = explode('_', $id);
Expand Down
14 changes: 7 additions & 7 deletions modules/datastore/src/Service/ResourceLocalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
use Drupal\common\DataResource;
use Drupal\common\EventDispatcherTrait;
use Drupal\common\LoggerTrait;
use Drupal\common\Storage\JobStoreFactory;
use Drupal\common\UrlHostTokenResolver;
use Drupal\common\Util\DrupalFiles;
use Drupal\Core\File\FileSystemInterface;
use Drupal\Core\Queue\QueueFactory;
use Drupal\common\Storage\FileFetcherJobStoreFactory;
use Drupal\metastore\Exception\AlreadyRegistered;
use Drupal\metastore\ResourceMapper;
use FileFetcher\FileFetcher;
Expand Down Expand Up @@ -69,11 +69,11 @@ class ResourceLocalizer {
private DrupalFiles $drupalFiles;

/**
* Job store factory.
* File fetcher job store factory.
*
* @var \Drupal\common\Storage\JobStoreFactory
* @var \Drupal\common\Storage\FileFetcherJobStoreFactory
*/
private JobStoreFactory $jobStoreFactory;
private FileFetcherJobStoreFactory $fileFetcherJobStoreFactory;

/**
* Drupal queue.
Expand All @@ -89,13 +89,13 @@ public function __construct(
ResourceMapper $fileMapper,
FactoryInterface $fileFetcherFactory,
DrupalFiles $drupalFiles,
JobStoreFactory $jobStoreFactory,
FileFetcherJobStoreFactory $fileFetcherJobStoreFactory,
QueueFactory $queueFactory
) {
$this->resourceMapper = $fileMapper;
$this->fileFetcherFactory = $fileFetcherFactory;
$this->drupalFiles = $drupalFiles;
$this->jobStoreFactory = $jobStoreFactory;
$this->fileFetcherJobStoreFactory = $fileFetcherJobStoreFactory;
$this->queueFactory = $queueFactory;
}

Expand Down Expand Up @@ -242,7 +242,7 @@ public function remove($identifier, $version = NULL): void {
*/
private function removeJob($uuid) {
if ($uuid) {
$this->jobStoreFactory->getInstance(FileFetcher::class)->remove($uuid);
$this->fileFetcherJobStoreFactory->getInstance()->remove($uuid);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public function testLocalizerNotDone() {
$this->container->get('dkan.metastore.resource_mapper'),
$this->container->get('dkan.common.file_fetcher'),
$this->container->get('dkan.common.drupal_files'),
$this->container->get('dkan.common.job_store'),
$this->container->get('dkan.common.filefetcher_job_store_factory'),
$this->container->get('queue'),
])
->onlyMethods(['localizeTask'])
Expand Down Expand Up @@ -165,7 +165,7 @@ public function testNotRequeuedOnError() {
$this->container->get('dkan.metastore.resource_mapper'),
$this->container->get('dkan.common.file_fetcher'),
$this->container->get('dkan.common.drupal_files'),
$this->container->get('dkan.common.job_store'),
$this->container->get('dkan.common.filefetcher_job_store_factory'),
$this->container->get('queue'),
])
->onlyMethods(['localizeTask'])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Drupal\Tests\datastore\Kernel\Service\Info;

use Drupal\common\DataResource;
use Drupal\common\Storage\FileFetcherJobStoreFactory;
use Drupal\datastore\Plugin\QueueWorker\ImportJob;
use Drupal\common\Storage\JobStore;
use Drupal\common\Storage\JobStoreFactory;
Expand Down Expand Up @@ -63,10 +64,10 @@ public function test() {
->getMock();

$job_store_factory = (new Chain($this))
->add(JobStoreFactory::class, 'getInstance', $job_store)
->add(FileFetcherJobStoreFactory::class, 'getInstance', $job_store)
->getMock();

$this->container->set('dkan.common.job_store', $job_store_factory);
$this->container->set('dkan.common.filefetcher_job_store_factory', $job_store_factory);

// Build the list.
/** @var \Drupal\datastore\Service\Info\ImportInfoList $import_info_list */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Drupal\common\FileFetcher\DkanFileFetcher;
use Drupal\common\FileFetcher\FileFetcherFactory;
use Drupal\common\Storage\DatabaseTableInterface;
use Drupal\common\Storage\FileFetcherJobStoreFactory;
use Drupal\common\Storage\JobStoreFactory;
use Drupal\common\Util\DrupalFiles;
use Drupal\Core\DependencyInjection\Container;
Expand Down Expand Up @@ -138,7 +139,7 @@ private function getDrupalFilesChain() {
*/
private function getJobStoreFactoryChain() {
return (new Chain($this))
->add(JobStoreFactory::class, 'getInstance', DatabaseTableInterface::class)
->add(FileFetcherJobStoreFactory::class, 'getInstance', DatabaseTableInterface::class)
->add(DatabaseTableInterface::class, 'remove', NULL);
}

Expand Down

0 comments on commit a8c2f44

Please sign in to comment.