file.install 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <?php
  2. /**
  3. * @file
  4. * Install, update and uninstall functions for File module.
  5. */
  6. /**
  7. * Implements hook_field_schema().
  8. */
  9. function file_field_schema($field) {
  10. return array(
  11. 'columns' => array(
  12. 'fid' => array(
  13. 'description' => 'The {file_managed}.fid being referenced in this field.',
  14. 'type' => 'int',
  15. 'not null' => FALSE,
  16. 'unsigned' => TRUE,
  17. ),
  18. 'display' => array(
  19. 'description' => 'Flag to control whether this file should be displayed when viewing content.',
  20. 'type' => 'int',
  21. 'size' => 'tiny',
  22. 'unsigned' => TRUE,
  23. 'not null' => TRUE,
  24. 'default' => 1,
  25. ),
  26. 'description' => array(
  27. 'description' => 'A description of the file.',
  28. 'type' => 'text',
  29. 'not null' => FALSE,
  30. ),
  31. ),
  32. 'indexes' => array(
  33. 'fid' => array('fid'),
  34. ),
  35. 'foreign keys' => array(
  36. 'fid' => array(
  37. 'table' => 'file_managed',
  38. 'columns' => array('fid' => 'fid'),
  39. ),
  40. ),
  41. );
  42. }
  43. /**
  44. * Implements hook_requirements().
  45. *
  46. * Display information about getting upload progress bars working.
  47. */
  48. function file_requirements($phase) {
  49. $requirements = array();
  50. // Check the server's ability to indicate upload progress.
  51. if ($phase == 'runtime') {
  52. $description = NULL;
  53. $implementation = file_progress_implementation();
  54. // Test the web server identity.
  55. $server_software = $_SERVER['SERVER_SOFTWARE'];
  56. if (preg_match("/Nginx/i", $server_software)) {
  57. $is_nginx = TRUE;
  58. $is_apache = FALSE;
  59. $fastcgi = FALSE;
  60. }
  61. elseif (preg_match("/Apache/i", $server_software)) {
  62. $is_nginx = FALSE;
  63. $is_apache = TRUE;
  64. $fastcgi = strpos($server_software, 'mod_fastcgi') !== FALSE || strpos($server_software, 'mod_fcgi') !== FALSE;
  65. }
  66. else {
  67. $is_nginx = FALSE;
  68. $is_apache = FALSE;
  69. $fastcgi = FALSE;
  70. }
  71. if (!$is_apache && !$is_nginx) {
  72. $value = t('Not enabled');
  73. $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.');
  74. $severity = REQUIREMENT_INFO;
  75. }
  76. elseif ($fastcgi) {
  77. $value = t('Not enabled');
  78. $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.');
  79. $severity = REQUIREMENT_INFO;
  80. }
  81. elseif (!$implementation && extension_loaded('apc')) {
  82. $value = t('Not enabled');
  83. $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.');
  84. $severity = REQUIREMENT_INFO;
  85. }
  86. elseif (!$implementation) {
  87. $value = t('Not enabled');
  88. $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://us2.php.net/apc">APC</a>.');
  89. $severity = REQUIREMENT_INFO;
  90. }
  91. elseif ($implementation == 'apc') {
  92. $value = t('Enabled (<a href="http://php.net/manual/en/apc.configuration.php#ini.apc.rfc1867">APC RFC1867</a>)');
  93. $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.');
  94. $severity = REQUIREMENT_OK;
  95. }
  96. elseif ($implementation == 'uploadprogress') {
  97. $value = t('Enabled (<a href="http://pecl.php.net/package/uploadprogress">PECL uploadprogress</a>)');
  98. $severity = REQUIREMENT_OK;
  99. }
  100. $requirements['file_progress'] = array(
  101. 'title' => t('Upload progress'),
  102. 'value' => $value,
  103. 'severity' => $severity,
  104. 'description' => $description,
  105. );
  106. }
  107. return $requirements;
  108. }