Project

General

Profile

Paste
Download (2.11 KB) Statistics
| Branch: | Revision:

root / drupal7 / sites / all / modules / media / modules / media_migrate_file_types / media_migrate_file_types.module @ 2b3c8cc1

1
<?php
2

    
3
/**
4
 * @file
5
 * Primarily Drupal hooks.
6
 */
7

    
8
/*
9
 * Implements hook_system_info_alter()
10
 */
11
function media_migrate_file_types_system_info_alter(&$info, $file, $type) {
12
  if ($type == 'module' && $file->name == 'media_migrate_file_types') {
13
    $info['hidden'] = FALSE;
14
  }
15
}
16

    
17
/**
18
 * Implements hook_menu().
19
 */
20
function media_migrate_file_types_menu() {
21
  $items['admin/structure/file-types/upgrade'] = array(
22
    'title' => 'Upgrade types',
23
    'page callback' => 'drupal_get_form',
24
    'page arguments' => array('media_migrate_file_types_upgrade_file_types'),
25
    'access arguments' => array('administer file types'),
26
    'file' => 'includes/media_migrate_file_types.pages.inc',
27
    'type' => MENU_CALLBACK,
28
  );
29
  $items['admin/structure/file-types/upgrade/confirm'] = array(
30
    'title' => 'Upgrade types',
31
    'page callback' => 'drupal_get_form',
32
    'page arguments' => array('media_migrate_file_types_upgrade_file_types_confirm'),
33
    'access arguments' => array('administer file types'),
34
    'file' => 'includes/media_migrate_file_types.pages.inc',
35
    'type' => MENU_CALLBACK,
36
  );
37

    
38
  return $items;
39
}
40

    
41
/**
42
 * Implements hook_help().
43
 */
44
function media_migrate_file_types_help($path, $arg) {
45
  switch ($path) {
46
    case 'admin/structure/file-types':
47
      if (_media_migrate_file_types_get_migratable_file_types()) {
48
        drupal_set_message(t('There are disabled/deleted file types that can be migrated to their new alternatives. Visit <a href="!url">migration page</a> to get more information.', array('!url' => url('admin/structure/file-types/upgrade'))));
49
      }
50
      break;
51
  }
52
}
53

    
54
/**
55
 * Checks if there are any files that belong to disabled or deleted file
56
 * types.
57
 *
58
 * @return Array of file types (machine names) that are candidates for
59
 *   migration.
60
 */
61
function _media_migrate_file_types_get_migratable_file_types() {
62
  $query = db_select('file_managed', 'f')
63
    ->fields('f', array('type'))
64
    ->distinct();
65
  $types = $query->execute()->fetchCol();
66

    
67
  $enabled_types = array();
68
  foreach (file_type_get_enabled_types() as $type) {
69
    $enabled_types[] = $type->type;
70
  }
71

    
72
  return array_diff($types, $enabled_types);
73
}