5 use Consolidation\OutputFormatters\StructuredData\RowsOfFields;
6 use Consolidation\OutputFormatters\StructuredData\UnstructuredListData;
10 use Drush\Commands\DrushCommands;
17 class Drush extends DrushCommands {
38 private $resourceLocalizer;
50 $this->resourceLocalizer = $resourceLocalizer;
66 public function import($uuid, $deferred = FALSE) {
69 $this->datastoreService->import($uuid, $deferred);
71 catch (\Exception $e) {
72 $this->logger->error(
"We were not able to load the entity with uuid {$uuid}");
73 $this->logger->debug($e->getMessage());
96 public function list($options = [
101 $status = $options[
'status'];
102 $uuid_only = $options[
'uuid-only'];
104 $list = $this->datastoreService->list();
106 foreach ($list as $uuid => $item) {
107 $rows[] = $this->createRow($uuid, $item);
110 if (!empty($status)) {
111 $rows = array_filter($rows,
function ($row) use ($status) {
112 if ($row[
'fileFetcherStatus'] == $status || $row[
'importerStatus'] == $status) {
120 foreach ($rows as $index => $row) {
121 $rows[$index] = $row[
'uuid'];
123 return new UnstructuredListData($rows);
126 return new RowsOfFields($rows);
132 private function createRow($uuid, $item) {
135 'fileName' => $item->fileName,
136 'fileFetcherStatus' => $item->fileFetcherStatus,
137 'fileFetcherBytes' => \format_size($item->fileFetcherBytes) .
" ($item->fileFetcherPercentDone%)",
138 'importerStatus' => $item->importerStatus,
139 'importerBytes' => \format_size($item->importerBytes) .
" ($item->importerPercentDone%)",
155 $this->datastoreService->drop($uuid);
156 $this->logger->notice(
"Successfully dropped the datastore for {$uuid}");
158 catch (\Exception $e) {
159 $this->logger->error(
"Unable to find an entity with uuid {$uuid}");
160 $this->logger->debug($e->getMessage());
163 catch (\TypeError $e) {
167 $this->logger->error(
"Unexpected entity uuid.");
168 $this->logger->debug($e->getMessage());
172 $this->jobstorePrune($uuid);
181 foreach ($this->metastoreService->getAll(
'distribution') as $distribution) {
182 $uuid = $distribution->data->{
"%Ref:downloadURL"}[0]->data->identifier;