file.install 4.68 KB
Newer Older
1 2 3 4 5 6 7
<?php

/**
 * @file
 * Install, update and uninstall functions for File module.
 */

8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
/**
 * Implements hook_schema().
 */
function file_schema() {
  $schema['file_usage'] = array(
    'description' => 'Track where a file is used.',
    'fields' => array(
      'fid' => array(
        'description' => 'File ID.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'module' => array(
        'description' => 'The name of the module that is using the file.',
23
        'type' => 'varchar_ascii',
24
        'length' => DRUPAL_EXTENSION_NAME_MAX_LENGTH,
25 26 27 28 29
        'not null' => TRUE,
        'default' => '',
      ),
      'type' => array(
        'description' => 'The name of the object type in which the file is used.',
30
        'type' => 'varchar_ascii',
31 32 33 34 35 36
        'length' => 64,
        'not null' => TRUE,
        'default' => '',
      ),
      'id' => array(
        'description' => 'The primary key of the object using the file.',
37
        'type' => 'varchar_ascii',
38
        'length' => 64,
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
        'not null' => TRUE,
        'default' => 0,
      ),
      'count' => array(
        'description' => 'The number of times this file is used by this object.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
    ),
    'primary key' => array('fid', 'type', 'id', 'module'),
    'indexes' => array(
      'type_id' => array('type', 'id'),
      'fid_count' => array('fid', 'count'),
      'fid_module' => array('fid', 'module'),
    ),
  );
  return $schema;
}

60
/**
61
 * Implements hook_requirements().
62 63 64 65 66 67 68 69
 *
 * Display information about getting upload progress bars working.
 */
function file_requirements($phase) {
  $requirements = array();

  // Check the server's ability to indicate upload progress.
  if ($phase == 'runtime') {
70
    $description = NULL;
71
    $implementation = file_progress_implementation();
72
    $server_software = \Drupal::request()->server->get('SERVER_SOFTWARE');
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91

    // Test the web server identity.
    if (preg_match("/Nginx/i", $server_software)) {
      $is_nginx = TRUE;
      $is_apache = FALSE;
      $fastcgi = FALSE;
    }
    elseif (preg_match("/Apache/i", $server_software)) {
      $is_nginx = FALSE;
      $is_apache = TRUE;
      $fastcgi = strpos($server_software, 'mod_fastcgi') !== FALSE || strpos($server_software, 'mod_fcgi') !== FALSE;
    }
    else {
      $is_nginx = FALSE;
      $is_apache = FALSE;
      $fastcgi = FALSE;
    }

    if (!$is_apache && !$is_nginx) {
92
      $value = t('Not enabled');
93
      $description = t('Your server is not capable of displaying file upload progress. File upload progress requires an Apache server running PHP with mod_php or Nginx with PHP-FPM.');
94 95 96
    }
    elseif ($fastcgi) {
      $value = t('Not enabled');
97
      $description = t('Your server is not capable of displaying file upload progress. File upload progress requires PHP be run with mod_php or PHP-FPM and not as FastCGI.');
98 99 100
    }
    elseif (!$implementation && extension_loaded('apc')) {
      $value = t('Not enabled');
101
      $description = t('Your server is capable of displaying file upload progress through APC, but it is not enabled. Add <code>apc.rfc1867 = 1</code> to your php.ini configuration. Alternatively, it is recommended to use <a href="@url">PECL uploadprogress</a>, which supports more than one simultaneous upload.', array('@url' => 'http://pecl.php.net/package/uploadprogress'));
102 103 104
    }
    elseif (!$implementation) {
      $value = t('Not enabled');
105
      $description = t('Your server is capable of displaying file upload progress, but does not have the required libraries. It is recommended to install the <a href="@uploadprogress_url">PECL uploadprogress library</a> (preferred) or to install <a href="@apc_url">APC</a>.', array('@uploadprogress_url' => 'http://pecl.php.net/package/uploadprogress', '@apc_url' => 'http://php.net/apc'));
106 107
    }
    elseif ($implementation == 'apc') {
108 109
      $value = t('Enabled (<a href="@url">APC RFC1867</a>)', array('@url' => 'http://php.net/manual/apc.configuration.php#ini.apc.rfc1867'));
      $description = t('Your server is capable of displaying file upload progress using APC RFC1867. Note that only one upload at a time is supported. It is recommended to use the <a href="@url">PECL uploadprogress library</a> if possible.', array('@url' => 'http://pecl.php.net/package/uploadprogress'));
110 111
    }
    elseif ($implementation == 'uploadprogress') {
112
      $value = t('Enabled (<a href="@url">PECL uploadprogress</a>)', array('@url' => 'http://pecl.php.net/package/uploadprogress'));
113 114 115 116 117 118 119 120 121 122
    }
    $requirements['file_progress'] = array(
      'title' => t('Upload progress'),
      'value' => $value,
      'description' => $description,
    );
  }

  return $requirements;
}