Open Data Catalog v2.0.0
DatabaseTable.php
Go to the documentation of this file.
1 <?php
2 
4 
5 use Drupal\Core\Database\Connection;
7 
12  private $identifier;
13 
22  public function __construct(Connection $connection, string $identifier) {
23  $this->identifier = $identifier;
24  $this->setOurSchema();
25  parent::__construct($connection);
26  }
27 
33  public function retrieve(string $id) {
34  $result = parent::retrieve($id);
35  return $result->data;
36  }
37 
43  protected function getTableName() {
44  return "harvest_{$this->identifier}";
45  }
46 
52  protected function prepareData(string $data, string $id = NULL): array {
53  return ["id" => $id, "data" => $data];
54  }
55 
61  protected function primaryKey() {
62  return "id";
63  }
64 
68  private function setOurSchema() {
69  $schema = [
70  'fields' => [
71  'id' => ['type' => 'varchar', 'not null' => TRUE, 'length' => 190],
72  'data' => ['type' => 'text', 'length' => 65535],
73  ],
74  'primary key' => ['id'],
75  ];
76 
77  $this->setSchema($schema);
78  }
79 
80 }
Drupal\dkan_common\Storage\AbstractDatabaseTable\$connection
$connection
Definition: AbstractDatabaseTable.php:20
Drupal\dkan_harvest\Storage\DatabaseTable
Definition: DatabaseTable.php:11
Drupal\dkan_harvest\Storage
Definition: DatabaseTable.php:3
Drupal\dkan_harvest\Storage\DatabaseTable\retrieve
retrieve(string $id)
Definition: DatabaseTable.php:33
Drupal\dkan_harvest\Storage\DatabaseTable\__construct
__construct(Connection $connection, string $identifier)
Definition: DatabaseTable.php:22
Drupal\dkan_common\Storage\AbstractDatabaseTable
Definition: AbstractDatabaseTable.php:16
Drupal\dkan_harvest\Storage\DatabaseTable\primaryKey
primaryKey()
Definition: DatabaseTable.php:61
Drupal\dkan_harvest\Storage\DatabaseTable\prepareData
prepareData(string $data, string $id=NULL)
Definition: DatabaseTable.php:52
Drupal\dkan_harvest\Storage\DatabaseTable\getTableName
getTableName()
Definition: DatabaseTable.php:43