diff core/modules/media/media.install @ 5:12f9dff5fda9 tip

Update to Drupal core 8.7.1
author Chris Cannam
date Thu, 09 May 2019 15:34:47 +0100
parents a9cd425dd02b
children
line wrap: on
line diff
--- a/core/modules/media/media.install	Thu Feb 28 13:11:55 2019 +0000
+++ b/core/modules/media/media.install	Thu May 09 15:34:47 2019 +0100
@@ -5,11 +5,14 @@
  * 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;
 use Drupal\media\MediaTypeInterface;
 use Drupal\media\Plugin\media\Source\OEmbedInterface;
+use Drupal\user\Entity\Role;
 use Drupal\user\RoleInterface;
-use Drupal\user\Entity\Role;
 
 /**
  * Implements hook_install().
@@ -17,7 +20,9 @@
 function media_install() {
   $source = drupal_get_path('module', 'media') . '/images/icons';
   $destination = \Drupal::config('media.settings')->get('icon_base_uri');
-  file_prepare_directory($destination, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);
+  /** @var \Drupal\Core\File\FileSystemInterface $file_system */
+  $file_system = \Drupal::service('file_system');
+  $file_system->prepareDirectory($destination, FileSystemInterface::CREATE_DIRECTORY | FileSystemInterface::MODIFY_PERMISSIONS);
 
   $files = file_scan_directory($source, '/.*\.(svg|png|jpg|jpeg|gif)$/');
   foreach ($files as $file) {
@@ -28,7 +33,13 @@
     // referenced somewhere else. Since showing an error that it was not
     // possible to copy the files is also confusing, we silently do nothing.
     if (!file_exists($destination . DIRECTORY_SEPARATOR . $file->filename)) {
-      file_unmanaged_copy($file->uri, $destination, FILE_EXISTS_ERROR);
+      try {
+        $file_system->copy($file->uri, $destination, FileSystemInterface::EXISTS_ERROR);
+      }
+      catch (FileException $e) {
+        // Ignore and continue.
+      }
+
     }
   }
 
@@ -46,7 +57,7 @@
   $requirements = [];
   if ($phase == 'install') {
     $destination = 'public://media-icons/generic';
-    file_prepare_directory($destination, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);
+    \Drupal::service('file_system')->prepareDirectory($destination, FileSystemInterface::CREATE_DIRECTORY | FileSystemInterface::MODIFY_PERMISSIONS);
     $is_writable = is_writable($destination);
     $is_directory = is_dir($destination);
     if (!$is_writable || !$is_directory) {
@@ -163,3 +174,34 @@
     ->set('oembed_providers_url', 'https://oembed.com/providers.json')
     ->save(TRUE);
 }
+
+/**
+ * Set the 'owner' entity key and update the field.
+ */
+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);
+  $definition_update_manager->updateEntityType($entity_type);
+  $definition_update_manager->updateFieldStorageDefinition($definition_update_manager->getFieldStorageDefinition('uid', 'media'));
+}