diff --git a/core/modules/media/media.install b/core/modules/media/media.install index d3386ea35a..ac7e78aa80 100644 --- a/core/modules/media/media.install +++ b/core/modules/media/media.install @@ -163,3 +163,22 @@ function media_update_8600() { ->set('oembed_providers_url', 'https://oembed.com/providers.json') ->save(TRUE); } + +/** +* Install missing icons. +*/ +function media_update_8601() { + $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); + + $files = file_scan_directory($source, '/.*\.(svg|png|jpg|jpeg|gif)$/'); + foreach ($files as $file) { + // When we run an update we don't want to copy the icons when they + // already exist. The icons could be replaced (by a contrib module or + // manually), so we don't want to replace the existing files. + if (!file_exists($destination . DIRECTORY_SEPARATOR . $file->filename)) { + file_unmanaged_copy($file->uri, $destination, FILE_EXISTS_ERROR); + } + } +}