5 use Consolidation\OutputFormatters\StructuredData\RowsOfFields;
6 use Consolidation\OutputFormatters\StructuredData\UnstructuredListData;
8 use Drush\Commands\DrushCommands;
15 class Drush extends DrushCommands {
35 $this->datastoreService = \Drupal::service(
'dkan_datastore.service');
36 $this->logger = \Drupal::service(
'dkan_datastore.logger_channel');
50 public function import($uuid, $deferred = FALSE) {
56 $this->datastoreService->import($uuid, $deferred);
58 catch (\Exception $e) {
59 $this->logger->error(
"We were not able to load the entity with uuid {$uuid}");
60 $this->logger->debug($e->getMessage());
81 public function list($options = [
86 $status = $options[
'status'];
87 $uuid_only = $options[
'uuid-only'];
89 $list = $this->datastoreService->list();
91 foreach ($list as $uuid => $item) {
92 $rows[] = $this->createRow($uuid, $item);
95 if (!empty($status)) {
96 $rows = array_filter($rows,
function ($row) use ($status) {
97 if ($row[
'fileFetcherStatus'] == $status || $row[
'importerStatus'] == $status) {
105 foreach ($rows as $index => $row) {
106 $rows[$index] = $row[
'uuid'];
108 return new UnstructuredListData($rows);
111 return new RowsOfFields($rows);
117 private function createRow($uuid, $item) {
120 'fileName' => $item->fileName,
121 'fileFetcherStatus' => $item->fileFetcherStatus,
122 'fileFetcherBytes' => \format_size($item->fileFetcherBytes) .
" ($item->fileFetcherPercentDone%)",
123 'importerStatus' => $item->importerStatus,
124 'importerBytes' => \format_size($item->importerBytes) .
" ($item->importerPercentDone%)",
140 $this->datastoreService->drop($uuid);
142 catch (\Exception $e) {
143 $this->logger->error(
"We were not able to load the entity with uuid {$uuid}");
144 $this->logger->debug($e->getMessage());