Open Data Catalog v2.0.0
Commands.php
Go to the documentation of this file.
1 <?php
2 
4 
5 use Drush\Commands\DrushCommands;
6 use Symfony\Component\Console\Output\ConsoleOutput;
7 use Drupal\dkan_harvest\Drush\Helper;
8 
12 class Commands extends DrushCommands {
13  use Helper;
14 
20  public function create() {
21  $this->createDummyJson();
22  $harvester = $this->getHarvester("dummy");
23  $result = $harvester->harvest();
24  $this->renderResult($result);
25  print_r($result);
26  }
27 
33  public function remove() {
34  $harvester = $this->getHarvester("dummy");
35  $result = $harvester->revert();
36 
37  $count = $result;
38 
39  $output = new ConsoleOutput();
40  $output->write("{$count} items reverted for the 'dummy' harvest plan.");
41  }
42 
46  private function getHarvestPlan() {
47  $module_path = DRUPAL_ROOT . "/" . drupal_get_path('module', 'dkan_dummy_content');
48 
49  $plan_path = $module_path . "/harvest_plan.json";
50  $json = file_get_contents($plan_path);
51  $plan = json_decode($json);
52 
53  $plan->extract->uri = "file://" . $module_path . $plan->extract->uri;
54 
55  return $plan;
56  }
57 
61  private function createDummyJson() {
62  $dummy_template = DRUPAL_ROOT . "/" . drupal_get_path('module', 'dkan_dummy_content') . "/dummy.template.json";
63  $content = file_get_contents($dummy_template);
64  $new = $this->detokenize($content);
65  file_put_contents(DRUPAL_ROOT . "/" . drupal_get_path('module', 'dkan_dummy_content') . "/dummy.json", $new);
66  }
67 
71  private function detokenize($content) {
72  $absolute_module_path = DRUPAL_ROOT . "/" . drupal_get_path('module', 'dkan_dummy_content') . "/files";
73  return str_replace("<!*path*!>", $absolute_module_path, $content);
74  }
75 
76 }
Drupal\dkan_dummy_content\Drush\Commands\create
create()
Definition: Commands.php:20
Drupal\dkan_dummy_content\Drush\Commands
Definition: Commands.php:12
Drupal\dkan_dummy_content\Drush
Definition: Commands.php:3