Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NYS-16492: public hearing updates not importing #218

Merged
merged 1 commit into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Openleg API Response plugin for a list of public hearing transcript updates.
*
* @OpenlegApiResponse(
* id = "public_hearing-update-token list",
* id = "hearing-update-token list",
* label = @Translation("Public Hearing Update List"),
* description = @Translation("Openleg API Response plugin")
* )
Expand All @@ -18,15 +18,15 @@ class PublicHearingUpdateList extends ResponseUpdate {
*/
public function listIds(): array {
return array_unique(
array_filter(
array_map(
function ($v) {
return $v->publicHearingId->id ?? '';
},
$this->items()
)
)
);
array_filter(
array_map(
function ($v) {
return $v->hearingId->id ?? '';
},
$this->items()
)
)
);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use Drupal\Core\State\State;
use Drupal\nys_openleg_api\ConditionalLogger;
use Drupal\nys_openleg_api\Plugin\OpenlegApi\Response\EmptyList;
use Drupal\nys_openleg_api\Plugin\OpenlegApi\Response\ResponseSearch;
use Drupal\nys_openleg_api\Plugin\OpenlegApi\Response\YearBasedSearchList;
use Drupal\nys_openleg_api\Request;
use Drupal\nys_openleg_api\Service\Api;
Expand Down Expand Up @@ -86,7 +85,7 @@ class OpenlegImport extends DrushCommands {
/**
* An importer to be used with this execution.
*
* @var ImporterInterface
* @var \Drupal\nys_openleg_imports\ImporterInterface
*/
protected ImporterInterface $importer;

Expand Down Expand Up @@ -178,16 +177,6 @@ protected function resolveOptions(array $options): array {
}
$options['ids'] = $list;

// This is here to trigger a sniffer error preventing a commit until this line and below is removed
/*
// Change any hyphens to slashes.
$options['ids'] = array_map(
function ($v) {
return str_replace('-', '/', $v);
},
array_filter(array_unique($list))
);
*/
return $options;
}

Expand Down Expand Up @@ -280,18 +269,21 @@ protected function doCleanup(ImportResult $result): void {
/**
* Wrapper to execute an import command.
*
* Note that the return is a shell success/fail in the context of drush.
* Non-zero returns indicate an error condition.
*
* @throws \Drush\Exceptions\CommandFailedException
*/
protected function execute(string $type, array $options, string $callback): int {
// Set up or die.
if (!$this->doSetup($type, $options)) {
return DRUSH_FRAMEWORK_ERROR;
return 1;
}

// Call the handler and send the result through clean up.
$this->doCleanup($this->$callback($options));

return DRUSH_SUCCESS;
return 0;
}

/**
Expand Down Expand Up @@ -322,11 +314,9 @@ protected function execute(string $type, array $options, string $callback): int
*
* @throws \Drush\Exceptions\CommandFailedException
*/
public function importUpdates(string $type, array $options = [
'from' => NULL,
'to' => NULL,
'force' => FALSE,
]
public function importUpdates(
string $type,
array $options = ['from' => NULL, 'to' => NULL, 'force' => FALSE],
): int {
return $this->execute($type, $options, 'doImportUpdate');
}
Expand All @@ -335,12 +325,12 @@ public function importUpdates(string $type, array $options = [
* Handler/callback to import updates.
*
* @param array $options
* The original drush command-line options.
* The original command-line options.
*
* @see importUpdates()
*/
protected function doImportUpdate(array $options): ImportResult {
// If no "to" time was passed, set the last run marker to the current time.
// Only set the last_run.updates marker if no `to` time was specified.
if (!($options['to'] ?? 0)) {
$this->setState('last_run.updates', time());
}
Expand Down Expand Up @@ -384,14 +374,15 @@ protected function doImportUpdate(array $options): ImportResult {
*
* @throws \Drush\Exceptions\CommandFailedException
*/
public function import(string $type, array $options = [
'ids' => [],
'session' => 0,
'limit' => 0,
'offset' => 1,
'force' => FALSE,
'log-level' => RfcLogLevel::NOTICE,
]
public function import(
string $type,
array $options = [
'ids' => [],
'session' => 0,
'limit' => 0,
'offset' => 1,
'force' => FALSE,
],
): int {
return $this->execute($type, $options, 'doImport');
}
Expand All @@ -400,7 +391,7 @@ public function import(string $type, array $options = [
* Handler/callback for a standard import.
*
* @param array $options
* The original drush command-line options.
* The original command-line options.
*
* @see import()
*/
Expand Down
Loading