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