1 file.install file_update_1005()

Add the default file types and convert custom or modified file types from Drupal 7 file_entity.

File

core/modules/file/file.install, line 915
Install, update and uninstall functions for File module.

Code

function file_update_1005() {
  $default_file_types = array(
    'audio' => array(
      'type' => 'audio',
      'name' => 'Audio',
      'description' => 'An audio file is a sound recording.',
      'mimetypes' => array(
        'audio/*'
      ),
      'disabled' => FALSE,
      'storage' => 4,
      'module' => 'file'
    ),
    'document' => array(
      'type' => 'document',
      'name' => 'Document',
      'description' => 'A document file is written information.',
      'mimetypes' => array(
        'text/plain',
        // cspell:disable
        'application/msword',
        'application/vnd.ms-excel',
        'application/pdf',
        'application/vnd.ms-powerpoint',
        'application/vnd.oasis.opendocument.text',
        'application/vnd.oasis.opendocument.spreadsheet',
        'application/vnd.oasis.opendocument.presentation',
        'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
        'application/vnd.openxmlformats-officedocument.presentationml.presentation',
        'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
        // cspell:enable
      ),
      'disabled' => FALSE,
      'storage' => 4,
      'module' => 'file',
    ),
    'image' => array(
      'type' => 'image',
      'name' => 'Image',
      'description' => 'An image file is a still visual.',
      'mimetypes' => array(
        'image/*',
      ),
      'disabled' => FALSE,
      'storage' => 4,
      'module' => 'file',
    ),
    'video' => array(
      'type' => 'video',
      'name' => 'Video',
      'description' => 'A video file is a moving visual recording.',
      'mimetypes' => array(
        'video/*',
      ),
      'disabled' => FALSE,
      'storage' => 4,
      'module' => 'file',
    ),
  );
  foreach ($default_file_types as $machine => $type) {
    $config = config('file.type.' . $machine);
    if ($config->isNew()) {
      $config->setData($type);
      $config->save();
    }
  }

  // Check to see if there were file types in a D7 db.
  if (db_table_exists('file_type')) {
    $result = db_query("SELECT type, label, description, mimetypes FROM {file_type}")->fetchAll();
    foreach ($result as $record) {
      $mimetypes = unserialize($record->mimetypes);
      $storage = FILE_TYPE_STORAGE_NORMAL;

      if (file_type_load($record->type)) {
        $storage = FILE_TYPE_STORAGE_OVERRIDE;
      }

      $config = config('file.type.' . $record->type);
      $config->set('module', 'file');
      $config->set('type', $record->type);
      $config->set('name', $record->label);
      $config->set('description', $record->description);
      $config->set('mimetypes', $mimetypes);
      $config->set('storage', $storage);
      $config->save();
    }

    // Delete the file type table.
    db_drop_table('file_type');
  }
}