Commit 808098a2 authored by catch's avatar catch

Issue #2279395 by alexpott, mradcliffe, plach, bzrudi71: Fixed The PostgreSQL...

Issue #2279395 by alexpott, mradcliffe, plach, bzrudi71: Fixed The PostgreSQL backend does not handle NULL values for serial fields gracefully.
parent 5776d983
......@@ -1017,7 +1017,7 @@ protected function mapToStorageRecord(ContentEntityInterface $entity, $table_nam
// SQL database drivers.
// @see https://www.drupal.org/node/2279395
$value = drupal_schema_get_field_value($definition->getSchema()['columns'][$column_name], $value);
if (!(empty($value) && $this->getSchema()[$table_name]['fields'][$schema_name]['type'] == 'serial')) {
if (!(empty($value) && $this->isColumnSerial($table_name, $schema_name))) {
$record->$schema_name = $value;
}
}
......@@ -1026,6 +1026,36 @@ protected function mapToStorageRecord(ContentEntityInterface $entity, $table_nam
return $record;
}
/**
* Checks whether a field column should be treated as serial.
*
* @param $table_name
* The name of the table the field column belongs to.
* @param $schema_name
* The schema name of the field column.
*
* @return bool
* TRUE if the the column is serial, FALSE otherwise.
*
* @see \Drupal\Core\Entity\Schema\ContentEntitySchemaHandler::processBaseTable()
* @see \Drupal\Core\Entity\Schema\ContentEntitySchemaHandler::processRevisionTable()
*/
protected function isColumnSerial($table_name, $schema_name) {
$result = FALSE;
switch ($table_name) {
case $this->baseTable:
$result = $schema_name == $this->idKey;
break;
case $this->revisionTable:
$result = $schema_name == $this->revisionKey;
break;
}
return $result;
}
/**
* Maps from an entity object to the storage record of the field data.
*
......
......@@ -97,6 +97,14 @@ public function save(EntityInterface $entity) {
parent::save($entity);
}
/**
* {@inheritdoc}
*/
protected function isColumnSerial($table_name, $schema_name) {
// User storage does not use a serial column for the user id.
return $table_name == $this->revisionTable && $schema_name == $this->revisionKey;
}
/**
* {@inheritdoc}
*/
......
Markdown is supported
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