Open Data Catalog v2.0.0
Helper.php
Go to the documentation of this file.
1 <?php
2 
4 
6 use Harvest\ETL\Factory;
7 use Harvest\Harvester;
8 use Harvest\ResultInterpreter;
9 use Symfony\Component\Console\Helper\Table;
10 use Symfony\Component\Console\Output\ConsoleOutput;
11 
17 trait Helper {
18 
22  private function getHarvester($id) {
23 
24  if (!method_exists($this, 'getHarvestPlan')) {
25  throw new \Exception("Drupal\dkan_harvest\Drush\Helper requires the host to implement the getHarvestPlan method.");
26  }
27 
28  return new Harvester(new Factory($this->getHarvestPlan($id),
29  $this->getStorage($id, "item"),
30  $this->getStorage($id, "hash")));
31  }
32 
36  private function getPlanStorage() {
37  $connection = \Drupal::service('database');
38  return new DatabaseTable($connection, "harvest_plans");
39  }
40 
44  private function getStorage($id, $type) {
45  $connection = \Drupal::service('database');
46  return new DatabaseTable($connection, "harvest_{$id}_{$type}");
47  }
48 
52  private function renderResult($result) {
53  $interpreter = new ResultInterpreter($result);
54 
55  $table = new Table(new ConsoleOutput());
56  $table->setHeaders(['processed', 'created', 'updated', 'errors']);
57  $table->addRow([
58  $interpreter->countProcessed(),
59  $interpreter->countCreated(),
60  $interpreter->countUpdated(),
61  $interpreter->countFailed(),
62  ]);
63  $table->render();
64  }
65 
66 }
Drupal\dkan_harvest\Storage\DatabaseTable
Definition: DatabaseTable.php:11
Drupal\dkan_harvest\Drush
Definition: Commands.php:3