file.install 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. /**
  3. * @file
  4. * Install, update and uninstall functions for File module.
  5. */
  6. /**
  7. * Implements hook_schema().
  8. */
  9. function file_schema() {
  10. $schema['file_usage'] = array(
  11. 'description' => 'Track where a file is used.',
  12. 'fields' => array(
  13. 'fid' => array(
  14. 'description' => 'File ID.',
  15. 'type' => 'int',
  16. 'unsigned' => TRUE,
  17. 'not null' => TRUE,
  18. ),
  19. 'module' => array(
  20. 'description' => 'The name of the module that is using the file.',
  21. 'type' => 'varchar_ascii',
  22. 'length' => DRUPAL_EXTENSION_NAME_MAX_LENGTH,
  23. 'not null' => TRUE,
  24. 'default' => '',
  25. ),
  26. 'type' => array(
  27. 'description' => 'The name of the object type in which the file is used.',
  28. 'type' => 'varchar_ascii',
  29. 'length' => 64,
  30. 'not null' => TRUE,
  31. 'default' => '',
  32. ),
  33. 'id' => array(
  34. 'description' => 'The primary key of the object using the file.',
  35. 'type' => 'varchar_ascii',
  36. 'length' => 64,
  37. 'not null' => TRUE,
  38. 'default' => 0,
  39. ),
  40. 'count' => array(
  41. 'description' => 'The number of times this file is used by this object.',
  42. 'type' => 'int',
  43. 'unsigned' => TRUE,
  44. 'not null' => TRUE,
  45. 'default' => 0,
  46. ),
  47. ),
  48. 'primary key' => array('fid', 'type', 'id', 'module'),
  49. 'indexes' => array(
  50. 'type_id' => array('type', 'id'),
  51. 'fid_count' => array('fid', 'count'),
  52. 'fid_module' => array('fid', 'module'),
  53. ),
  54. );
  55. return $schema;
  56. }
  57. /**
  58. * Implements hook_requirements().
  59. *
  60. * Display information about getting upload progress bars working.
  61. */
  62. function file_requirements($phase) {
  63. $requirements = array();
  64. // Check the server's ability to indicate upload progress.
  65. if ($phase == 'runtime') {
  66. $description = NULL;
  67. $implementation = file_progress_implementation();
  68. $server_software = \Drupal::request()->server->get('SERVER_SOFTWARE');
  69. // Test the web server identity.
  70. if (preg_match("/Nginx/i", $server_software)) {
  71. $is_nginx = TRUE;
  72. $is_apache = FALSE;
  73. $fastcgi = FALSE;
  74. }
  75. elseif (preg_match("/Apache/i", $server_software)) {
  76. $is_nginx = FALSE;
  77. $is_apache = TRUE;
  78. $fastcgi = strpos($server_software, 'mod_fastcgi') !== FALSE || strpos($server_software, 'mod_fcgi') !== FALSE;
  79. }
  80. else {
  81. $is_nginx = FALSE;
  82. $is_apache = FALSE;
  83. $fastcgi = FALSE;
  84. }
  85. if (!$is_apache && !$is_nginx) {
  86. $value = t('Not enabled');
  87. $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.');
  88. }
  89. elseif ($fastcgi) {
  90. $value = t('Not enabled');
  91. $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.');
  92. }
  93. elseif (!$implementation && extension_loaded('apcu')) {
  94. $value = t('Not enabled');
  95. $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="http://pecl.php.net/package/uploadprogress">PECL uploadprogress</a>, which supports more than one simultaneous upload.');
  96. }
  97. elseif (!$implementation) {
  98. $value = t('Not enabled');
  99. $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="http://pecl.php.net/package/uploadprogress">PECL uploadprogress library</a> (preferred) or to install <a href="http://php.net/apcu">APC</a>.');
  100. }
  101. elseif ($implementation == 'apc') {
  102. $value = t('Enabled (<a href="http://php.net/manual/apcu.configuration.php#ini.apcu.rfc1867">APC RFC1867</a>)');
  103. $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="http://pecl.php.net/package/uploadprogress">PECL uploadprogress library</a> if possible.');
  104. }
  105. elseif ($implementation == 'uploadprogress') {
  106. $value = t('Enabled (<a href="http://pecl.php.net/package/uploadprogress">PECL uploadprogress</a>)');
  107. }
  108. $requirements['file_progress'] = array(
  109. 'title' => t('Upload progress'),
  110. 'value' => $value,
  111. 'description' => $description,
  112. );
  113. }
  114. return $requirements;
  115. }