Commit 579e0f7a authored by Elias Villiger's avatar Elias Villiger
Browse files

Extract tableId config changes from this branch

parent 1ee41d07
Pipeline #829 passed with stage
in 1 minute and 48 seconds
......@@ -234,7 +234,7 @@ abstract class AbstractBuildForm {
// element-update: with 'value'
$recordId = $this->store->getVar(SIP_RECORD_ID, STORE_SIP . STORE_ZERO);
$md5 = $this->buildRecordHashMd5($this->formSpec[F_TABLE_NAME], $recordId, $this->formSpec[F_TABLE_ID]);
$md5 = $this->buildRecordHashMd5($this->formSpec[F_TABLE_NAME], $recordId);
// Via 'element-update'
$json[][API_ELEMENT_UPDATE][DIRTY_RECORD_HASH_MD5][API_ELEMENT_ATTRIBUTE]['value'] = $md5;
......@@ -365,7 +365,7 @@ abstract class AbstractBuildForm {
public function buildInputRecordHashMd5() {
$recordId = $this->store->getVar(SIP_RECORD_ID, STORE_SIP . STORE_ZERO);
$md5 = $this->buildRecordHashMd5($this->formSpec[F_TABLE_NAME], $recordId, $this->formSpec[F_TABLE_ID]);
$md5 = $this->buildRecordHashMd5($this->formSpec[F_TABLE_NAME], $recordId);
$data = "<input id='" . DIRTY_RECORD_HASH_MD5 . "' name='" . DIRTY_RECORD_HASH_MD5 . "' type='hidden' value='$md5'>";
......@@ -378,18 +378,17 @@ abstract class AbstractBuildForm {
/**
* @param $tableName
* @param $recordId
* @param $tableId
*
* @return string
* @throws CodeException
* @throws DbException
* @throws UserFormException
*/
public function buildRecordHashMd5($tableName, $recordId, $tableId = F_TABLE_ID_DEFAULT) {
public function buildRecordHashMd5($tableName, $recordId) {
$record = array();
if ($recordId != 0) {
$record = $this->dbArray[$this->dbIndexData]->sql("SELECT * FROM $tableName WHERE $tableId=?", ROW_EXPECT_1, [$recordId], "Record to load not found.");
$record = $this->dbArray[$this->dbIndexData]->sql("SELECT * FROM $tableName WHERE id=?", ROW_EXPECT_1, [$recordId], "Record to load not found.");
}
return OnArray::getMd5($record);
......@@ -557,10 +556,9 @@ abstract class AbstractBuildForm {
$skip = [FE_SQL_UPDATE, FE_SQL_INSERT, FE_SQL_DELETE, FE_SQL_AFTER, FE_SQL_BEFORE, FE_PARAMETER, FE_FILL_STORE_VAR, FE_FILE_DOWNLOAD_BUTTON];
// get current data record
if ($recordId > 0 && $this->store->getVar($this->formSpec[F_TABLE_ID], STORE_RECORD) === false) {
if ($recordId > 0 && $this->store->getVar('id', STORE_RECORD) === false) {
$tableName = $this->formSpec[F_TABLE_NAME];
$tableId = $this->formSpec[F_TABLE_ID];
$row = $this->dbArray[$this->dbIndexData]->sql("SELECT * FROM $tableName WHERE $tableId = ?", ROW_EXPECT_1,
$row = $this->dbArray[$this->dbIndexData]->sql("SELECT * FROM $tableName WHERE id = ?", ROW_EXPECT_1,
array($recordId), "Form '" . $this->formSpec[F_NAME] . "' failed to load record '$recordId' from table '" .
$this->formSpec[F_TABLE_NAME] . "'.");
$this->store->setStore($row, STORE_RECORD);
......
......@@ -862,9 +862,6 @@ const F_TYPEAHEAD_LDAP_SEARCH = 'typeAheadLdapSearch';
const F_TYPEAHEAD_LDAP_SEARCH_PREFETCH = 'typeAheadLdapSearchPrefetch';
const F_TYPEAHEAD_LDAP_SEARCH_PER_TOKEN = 'typeAheadLdapSearchPerToken';
const F_TABLE_ID = 'tableId';
const F_TABLE_ID_DEFAULT = 'id';
const F_MODE = 'mode';
const F_MODE_READONLY = 'readonly';
const F_MODE_REQUIRED_OFF = 'requiredOff';
......
......@@ -381,8 +381,8 @@ class QuickFormQuery {
$this->store->createSipAfterFormLoad($formName);
}
if ($this->store->getVar($this->formSpec[F_TABLE_ID], STORE_BEFORE) === false) {
$this->fillStoreWithRecord($this->formSpec, $recordId, STORE_BEFORE);
if ($this->store->getVar('id', STORE_BEFORE) === false) {
$this->fillStoreWithRecord($this->formSpec[F_TABLE_NAME], $recordId, STORE_BEFORE);
}
// Check (and release) dirtyRecord.
......@@ -465,7 +465,7 @@ class QuickFormQuery {
$formAction->elements($recordId, $this->feSpecAction, FE_TYPE_BEFORE_INSERT . ',' . FE_TYPE_BEFORE_UPDATE . ',' . FE_TYPE_BEFORE_SAVE);
// If an old record exist: load it. Necessary to delete uploaded files which should be overwritten.
$this->fillStoreWithRecord($this->formSpec, $recordId, STORE_RECORD);
$this->fillStoreWithRecord($this->formSpec[F_TABLE_NAME], $recordId, STORE_RECORD);
// SAVE
$save = new Save($this->formSpec, $this->feSpecAction, $this->feSpecNative, $this->feSpecNativeRaw);
......@@ -476,7 +476,7 @@ class QuickFormQuery {
$rc = $save->process();
// Reload fresh saved record and fill STORE_RECORD with it.
$this->fillStoreWithRecord($this->formSpec, $rc, STORE_RECORD);
$this->fillStoreWithRecord($this->formSpec[F_TABLE_NAME], $rc, STORE_RECORD);
$save->processAllUploads($rc);
......@@ -484,7 +484,7 @@ class QuickFormQuery {
$status = $formAction->elements($rc, $this->feSpecAction, FE_TYPE_AFTER_INSERT . ',' . FE_TYPE_AFTER_UPDATE . ',' . FE_TYPE_AFTER_SAVE);
if ($status != ACTION_ELEMENT_NO_CHANGE) {
// Reload fresh saved record and fill STORE_RECORD with it.
$this->fillStoreWithRecord($this->formSpec, $rc, STORE_RECORD);
$this->fillStoreWithRecord($this->formSpec[F_TABLE_NAME], $rc, STORE_RECORD);
}
// Action: Paste
......@@ -802,7 +802,6 @@ class QuickFormQuery {
} else {
$form[F_DB_INDEX] = $this->eval->parse($form[F_DB_INDEX]);
}
$form[F_TABLE_ID] = $form[F_TABLE_ID] ?? F_TABLE_ID_DEFAULT;
// Some forms load/save the form data on extra defined databases.
if ($this->dbIndexData != $form[F_DB_INDEX]) {
......@@ -817,7 +816,7 @@ class QuickFormQuery {
// This is needed for filling templateGroup records with their default values
// and for evaluating variables in the Form title
$this->fillStoreWithRecord($form, $recordId, STORE_RECORD);
$this->fillStoreWithRecord($form[F_TABLE_NAME], $recordId, STORE_RECORD);
$formSpec = $this->eval->parseArray($form);
......@@ -1275,7 +1274,7 @@ class QuickFormQuery {
/**
* Load record $id from $table and saves them in $store
*
* @param array $formSpec tablename and table id column from where to load record with $recordId
* @param array $table tablename
* @param string $recordId record ID of current record
* @param string $store name of store where to save the record
*
......@@ -1283,11 +1282,9 @@ class QuickFormQuery {
* @throws DbException
* @throws UserFormException
*/
private function fillStoreWithRecord($formSpec, $recordId, $store = STORE_RECORD) {
$table = $formSpec[F_TABLE_NAME];
$tableId = $formSpec[F_TABLE_ID];
private function fillStoreWithRecord($table, $recordId, $store = STORE_RECORD) {
if ($recordId !== false && $recordId > 0) {
$record = $this->dbArray[$this->dbIndexData]->sql("SELECT * FROM $table WHERE $tableId = ?", ROW_EXPECT_1, [$recordId]);
$record = $this->dbArray[$this->dbIndexData]->sql("SELECT * FROM $table WHERE id = ?", ROW_EXPECT_1, [$recordId]);
$this->store->setStore($record, $store, true);
}
}
......
......@@ -229,7 +229,7 @@ class Save {
$rc = $this->insertRecord($this->formSpec[F_TABLE_NAME], $newValues);
} else {
$this->updateRecord($this->formSpec[F_TABLE_NAME], $newValues, $recordId, $this->formSpec[F_TABLE_ID]);
$this->updateRecord($this->formSpec[F_TABLE_NAME], $newValues, $recordId);
$rc = $recordId;
}
......@@ -287,14 +287,13 @@ class Save {
* @param string $tableName
* @param array $values
* @param int $recordId
* @param string $tableId
*
* @return bool|int false if $values is empty, else affectedrows
* @throws CodeException
* @throws DbException
* @throws UserFormException
*/
public function updateRecord($tableName, array $values, $recordId, $tableId = F_TABLE_ID_DEFAULT) {
public function updateRecord($tableName, array $values, $recordId) {
if (count($values) === 0)
return 0; // nothing to write, 0 rows affected
......@@ -310,7 +309,7 @@ class Save {
$sql .= '`' . $column . '` = ?, ';
}
$sql = substr($sql, 0, strlen($sql) - 2) . " WHERE $tableId = ?";
$sql = substr($sql, 0, strlen($sql) - 2) . " WHERE id = ?";
$values[] = $recordId;
$rc = $this->db->sql($sql, ROW_REGULAR, array_values($values));
......@@ -387,7 +386,7 @@ class Save {
// Only used in 'Simple Upload'
if (count($newValues) > 0) {
$this->updateRecord($this->formSpec[F_TABLE_NAME], $newValues, $recordId, $this->formSpec[F_TABLE_ID]);
$this->updateRecord($this->formSpec[F_TABLE_NAME], $newValues, $recordId);
}
}
......
......@@ -281,13 +281,13 @@ class Dirty {
*
* @return bool true if $recordHashMd5 is different from current record md5 hash.
*/
private function isRecordModified($tableName, $recordId, $recordHashMd5, &$rcMd5, $tableId = F_TABLE_ID_DEFAULT) {
private function isRecordModified($tableName, $recordId, $recordHashMd5, &$rcMd5) {
if ($recordHashMd5 == '') {
return false; // If there is no recordHashMd5, the check is not possible. Always return 'not modified' (=ok)
}
$record = $this->dbArray[$this->dbIndexData]->sql("SELECT * FROM $tableName WHERE $tableId=?", ROW_EXPECT_1, [$recordId], "Record to lock not found.");
$record = $this->dbArray[$this->dbIndexData]->sql("SELECT * FROM $tableName WHERE id=?", ROW_EXPECT_1, [$recordId], "Record to lock not found.");
$rcMd5 = OnArray::getMd5($record);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment