Skip to content
Snippets Groups Projects
Unverified Commit 91dc8831 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3040746 by Berdir, amateescu, Sam152: Update functions that set owner...

Issue #3040746 by Berdir, amateescu, Sam152: Update functions that set owner entity key updates can fail on existing data with NULL values
parent f4420c5f
No related branches found
No related tags found
No related merge requests found
......@@ -5,6 +5,7 @@
* Install, uninstall and update hooks for Media module.
*/
use Drupal\Core\Entity\Sql\SqlEntityStorageInterface;
use Drupal\Core\File\Exception\FileException;
use Drupal\Core\File\FileSystemInterface;
use Drupal\Core\Url;
......@@ -180,6 +181,24 @@ function media_update_8600() {
function media_update_8700() {
$definition_update_manager = \Drupal::entityDefinitionUpdateManager();
$entity_type = $definition_update_manager->getEntityType('media');
$database = \Drupal::database();
if (\Drupal::entityTypeManager()->getStorage('media') instanceof SqlEntityStorageInterface) {
if ($database->schema()->tableExists($entity_type->getDataTable())) {
$database->update($entity_type->getDataTable())
->fields(['uid' => 0])
->isNull('uid')
->execute();
}
if ($database->schema()->tableExists($entity_type->getRevisionDataTable())) {
$database->update($entity_type->getRevisionDataTable())
->fields(['uid' => 0])
->isNull('uid')
->execute();
}
}
$keys = $entity_type->getKeys();
$keys['owner'] = 'uid';
$entity_type->set('entity_keys', $keys);
......
No preview for this file type
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment