5 use Symfony\Component\Console\Helper\Table;
6 use Symfony\Component\Console\Output\ConsoleOutput;
8 use Drush\Commands\DrushCommands;
44 $this->harvestService = \Drupal::service(
'dkan_harvest.service');
45 $this->logger = \Drupal::service(
'dkan_harvest.logger_channel');
62 $this->harvestService->getAllHarvestIds()
64 (
new Table(
new ConsoleOutput()))->setHeaders([
'plan id'])->setRows($rows)->render();
72 public function register($harvest_plan) {
74 $plan = json_decode($harvest_plan);
75 $identifier = $this->harvestService
76 ->registerHarvest($plan);
77 $this->logger->notice(
"Successfully registered the {$identifier} harvest.");
79 catch (\Exception $e) {
80 $this->logger->error($e->getMessage());
81 $this->logger->debug($e->getTraceAsString());
92 if ($this->harvestService->deregisterHarvest($id)) {
93 $message =
"Successfully deregistered the {$id} harvest.";
96 catch (\Exception $e) {
97 $message = $e->getMessage();
100 (
new ConsoleOutput())->write($message . PHP_EOL);
114 public function run($id) {
115 $result = $this->harvestService
118 $this->renderResult($result);
131 $ids = $this->harvestService
132 ->getAllHarvestIds();;
134 foreach ($ids as $id) {
149 public function info($id, $run_id = NULL) {
151 if (!isset($run_id)) {
152 $runs = $this->harvestService
153 ->getAllHarvestRunInfo($id);
154 $table =
new Table(
new ConsoleOutput());
155 $table->setHeaders([
"{$id} runs"]);
156 foreach (array_keys($runs) as $run_id) {
157 $table->addRow([$run_id]);
162 $run = $this->harvestService
163 ->getHarvestRunInfo($id, $run_id);
164 $result = json_decode($run);
183 $result = $this->harvestService
184 ->revertHarvest($id);
186 (
new ConsoleOutput())->write(
"{$result} items reverted for the '{$id}' harvest plan." . PHP_EOL);