Skip to content
Snippets Groups Projects
Commit 2ef69298 authored by Rich Lott / Artful Robot's avatar Rich Lott / Artful Robot
Browse files

Fix bug that could result in inlays changing public_id

parent d4be4f6c
Branches
Tags
No related merge requests found
......@@ -15,4 +15,12 @@ class Create extends DAOCreateAction {
$this->updateBundle($result);
}
/**
*/
protected function validateValues() {
$records = [&$this->values];
$this->ensurePublicID($records);
// Return parent but I think it returns void anyway.
return parent::validateValues();
}
}
......@@ -15,5 +15,14 @@ class Save extends DAOSaveAction {
$this->updateBundle($result);
}
/**
* Loop the *fully populated* array in $this->values
* which contain new values applied over existing data with.
*/
protected function validateValues() {
$this->ensurePublicID($this->records);
// Return parent but I think it returns void anyway.
return parent::validateValues();
}
}
......@@ -16,22 +16,33 @@ trait WriteTrait {
protected $updateBundle = TRUE;
/**
* Override the formatWriteValues.
* Override the formatWriteValues. This is api input data only.
*
*/
public function formatWriteValues(&$record) {
// Check we have a unique id
if (empty($record['public_id']) || $record['public_id'] === 'new') {
$record['public_id'] = substr(sha1(uniqid()), 0, 12);
}
// Stringify the json.
if (is_array($record['config'])) {
$record['config'] = json_encode($record['config']);
}
parent::formatWriteValues($record);
}
/**
*
*/
protected function ensurePublicID(&$records) {
foreach ($records as &$record) {
// Check we have a unique id
if (empty($record['public_id']) || $record['public_id'] === 'new') {
if (empty($record['id'])) {
// Only do this if we're saving a new record.
$record['public_id'] = substr(sha1(uniqid()), 0, 12);
}
}
unset($record);
}
}
/**
* Rebuild the javascript for each result.
*
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment