Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Datastore issues #276

Merged
merged 3 commits into from
Dec 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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