file.install 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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'] = [
  11. 'description' => 'Track where a file is used.',
  12. 'fields' => [
  13. 'fid' => [
  14. 'description' => 'File ID.',
  15. 'type' => 'int',
  16. 'unsigned' => TRUE,
  17. 'not null' => TRUE,
  18. ],
  19. 'module' => [
  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' => [
  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' => [
  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' => [
  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' => ['fid', 'type', 'id', 'module'],
  49. 'indexes' => [
  50. 'type_id' => ['type', 'id'],
  51. 'fid_count' => ['fid', 'count'],
  52. 'fid_module' => ['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 = [];
  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) {
  94. $value = t('Not enabled');
  95. $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>.');
  96. }
  97. elseif ($implementation == 'apc') {
  98. $value = t('Enabled (<a href="http://php.net/manual/apcu.configuration.php#ini.apcu.rfc1867">APC RFC1867</a>)');
  99. $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.');
  100. }
  101. elseif ($implementation == 'uploadprogress') {
  102. $value = t('Enabled (<a href="http://pecl.php.net/package/uploadprogress">PECL uploadprogress</a>)');
  103. }
  104. $requirements['file_progress'] = [
  105. 'title' => t('Upload progress'),
  106. 'value' => $value,
  107. 'description' => $description,
  108. ];
  109. }
  110. return $requirements;
  111. }
  112. /**
  113. * Prevent unused files from being deleted.
  114. */
  115. function file_update_8300() {
  116. // Disable deletion of unused permanent files.
  117. \Drupal::configFactory()->getEditable('file.settings')
  118. ->set('make_unused_managed_files_temporary', FALSE)
  119. ->save();
  120. return t('Files that have no remaining usages are no longer deleted by default.');
  121. }