Skip to content

Commit

Permalink
Datastore issues (#276)
Browse files Browse the repository at this point in the history
* Fix datastore's record_number issues
* Relax guzzle dependency
* Fix code style issues
  • Loading branch information
fmizzell authored and thierrydallacroce committed Dec 20, 2019
1 parent e7c6d7c commit 49148a8
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"getdkan/sae" : "^1.1.1",
"getdkan/sql-parser": "^1.1.2",
"getdkan/lunr.php": "^1.0.0",
"guzzlehttp/guzzle" : "6.3",
"guzzlehttp/guzzle" : "^6.3",
"ezyang/htmlpurifier" : "^4.11",
"ramsey/uuid" : "^3.8.0",
"oomphinc/composer-installers-extender": "~1.1"
Expand Down
13 changes: 10 additions & 3 deletions modules/custom/dkan_common/src/Storage/AbstractDatabaseTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,22 @@ public function retrieveAll(): array {
public function store($data, string $id = NULL): string {
$this->setTable();

$existing = $this->retrieve($id);
$existing = (isset($id)) ? $this->retrieve($id) : NULL;

$data = $this->prepareData($data, $id);

$returned_id = NULL;

if ($existing === NULL) {
$fields = $this->getNonSerialFields();

if (count($fields) != count($data)) {
throw new \Exception("The number of fields and data given do not match: fields - " .
json_encode($fields) . " data - " . json_encode($data));
}

$q = $this->connection->insert($this->getTableName());
$q->fields($this->getNonSerialFields());
$q->fields($fields);
$q->values($data);
$returned_id = $q->execute();
}
Expand All @@ -129,7 +136,7 @@ public function store($data, string $id = NULL): string {
/**
* Private.
*/
private function getNonSerialFields() {
protected function getNonSerialFields() {
$fields = [];
foreach ($this->schema['fields'] as $field => $info) {
if ($info['type'] != 'serial') {
Expand Down
12 changes: 12 additions & 0 deletions modules/custom/dkan_datastore/src/Storage/DatabaseTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,18 @@ protected function primaryKey() {
return "record_number";
}

/**
* Protected.
*/
protected function getNonSerialFields() {
$fields = parent::getNonSerialFields();
$index = array_search($this->primaryKey(), $fields);
if ($index !== FALSE) {
unset($fields[$index]);
}
return $fields;
}

/**
* Overriden.
*/
Expand Down

0 comments on commit 49148a8

Please sign in to comment.