diff --git a/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php b/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php index 22238d4bf5..4dcd603f74 100644 --- a/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php +++ b/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php @@ -843,9 +843,16 @@ protected function doSaveFieldItems(ContentEntityInterface $entity, array $names if ($update) { $default_revision = $entity->isDefaultRevision(); if ($default_revision) { + // We must remove the serial field to prevent it from being included + // in the update statements assignment list. Updating a serial field + // is not allowed in SQL Server. + $record_array = (array) $record; + if (isset($record_array[$this->idKey])) { + unset($record_array[$this->idKey]); + } $this->database ->update($this->baseTable) - ->fields((array) $record) + ->fields($record_array) ->condition($this->idKey, $record->{$this->idKey}) ->execute(); } @@ -855,10 +862,17 @@ protected function doSaveFieldItems(ContentEntityInterface $entity, array $names } else { $record = $this->mapToStorageRecord($entity->getUntranslated(), $this->revisionTable); + // We must remove the serial field to prevent it from being included + // in the update statements assignment list. Updating a serial field + // is not allowed in SQL Server. + $record_array = (array) $record; + if (isset($record_array[$this->revisionKey])) { + unset($record_array[$this->revisionKey]); + } $entity->preSaveRevision($this, $record); $this->database ->update($this->revisionTable) - ->fields((array) $record) + ->fields($record_array) ->condition($this->revisionKey, $record->{$this->revisionKey}) ->execute(); } @@ -1088,9 +1102,16 @@ protected function saveRevision(ContentEntityInterface $entity) { } } else { + // Unset revisionKey column from updating. + // Prevents SQL Driver issue for updating Identity Column. + $record_array = (array) $record; + if (isset($record_array[$this->revisionKey])) { + unset($record_array[$this->revisionKey]); + } + $this->database ->update($this->revisionTable) - ->fields((array) $record) + ->fields($record_array) ->condition($this->revisionKey, $record->{$this->revisionKey}) ->execute(); } diff --git a/core/lib/Drupal/Core/Path/AliasStorage.php b/core/lib/Drupal/Core/Path/AliasStorage.php index a02bc3534d..b689848719 100644 --- a/core/lib/Drupal/Core/Path/AliasStorage.php +++ b/core/lib/Drupal/Core/Path/AliasStorage.php @@ -106,11 +106,11 @@ public function save($source, $alias, $langcode = LanguageInterface::LANGCODE_NO $this->catchException($e); $original = FALSE; } - $fields['pid'] = $pid; $query = $this->connection->update(static::TABLE) ->fields($fields) ->condition('pid', $pid); $pid = $query->execute(); + $fields['pid'] = $pid; $fields['original'] = $original; $operation = 'update'; }