123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175 |
- <?php
- /**
- * @file
- * Install, update and uninstall functions for File module.
- */
- use Drupal\Core\Entity\Entity\EntityViewDisplay;
- /**
- * Implements hook_schema().
- */
- function file_schema() {
- $schema['file_usage'] = [
- 'description' => 'Track where a file is used.',
- 'fields' => [
- 'fid' => [
- 'description' => 'File ID.',
- 'type' => 'int',
- 'unsigned' => TRUE,
- 'not null' => TRUE,
- ],
- 'module' => [
- 'description' => 'The name of the module that is using the file.',
- 'type' => 'varchar_ascii',
- 'length' => DRUPAL_EXTENSION_NAME_MAX_LENGTH,
- 'not null' => TRUE,
- 'default' => '',
- ],
- 'type' => [
- 'description' => 'The name of the object type in which the file is used.',
- 'type' => 'varchar_ascii',
- 'length' => 64,
- 'not null' => TRUE,
- 'default' => '',
- ],
- 'id' => [
- 'description' => 'The primary key of the object using the file.',
- 'type' => 'varchar_ascii',
- 'length' => 64,
- 'not null' => TRUE,
- 'default' => 0,
- ],
- 'count' => [
- 'description' => 'The number of times this file is used by this object.',
- 'type' => 'int',
- 'unsigned' => TRUE,
- 'not null' => TRUE,
- 'default' => 0,
- ],
- ],
- 'primary key' => ['fid', 'type', 'id', 'module'],
- 'indexes' => [
- 'type_id' => ['type', 'id'],
- 'fid_count' => ['fid', 'count'],
- 'fid_module' => ['fid', 'module'],
- ],
- ];
- return $schema;
- }
- /**
- * Implements hook_requirements().
- *
- * Display information about getting upload progress bars working.
- */
- function file_requirements($phase) {
- $requirements = [];
- // Check the server's ability to indicate upload progress.
- if ($phase == 'runtime') {
- $description = NULL;
- $implementation = file_progress_implementation();
- $server_software = \Drupal::request()->server->get('SERVER_SOFTWARE');
- // 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) {
- $value = t('Not enabled');
- $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.');
- }
- elseif ($fastcgi) {
- $value = t('Not enabled');
- $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.');
- }
- elseif (!$implementation) {
- $value = t('Not enabled');
- $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>.');
- }
- elseif ($implementation == 'uploadprogress') {
- $value = t('Enabled (<a href="http://pecl.php.net/package/uploadprogress">PECL uploadprogress</a>)');
- }
- $requirements['file_progress'] = [
- 'title' => t('Upload progress'),
- 'value' => $value,
- 'description' => $description,
- ];
- }
- return $requirements;
- }
- /**
- * Prevent unused files from being deleted.
- */
- function file_update_8300() {
- // Disable deletion of unused permanent files.
- \Drupal::configFactory()->getEditable('file.settings')
- ->set('make_unused_managed_files_temporary', FALSE)
- ->save();
- return t('Files that have no remaining usages are no longer deleted by default.');
- }
- /**
- * Add 'use_description_as_link_text' setting to file field formatters.
- */
- function file_update_8001() {
- $displays = EntityViewDisplay::loadMultiple();
- foreach ($displays as $display) {
- /** @var \Drupal\Core\Entity\Entity\EntityViewDisplay $display */
- $fields_settings = $display->get('content');
- $changed = FALSE;
- foreach ($fields_settings as $field_name => $settings) {
- if (!empty($settings['type'])) {
- switch ($settings['type']) {
- // The file_table formatter never displayed available descriptions
- // before, so we disable this option to ensure backward compatibility.
- case 'file_table':
- $fields_settings[$field_name]['settings']['use_description_as_link_text'] = FALSE;
- $changed = TRUE;
- break;
- // The file_default formatter always displayed available descriptions
- // before, so we enable this option to ensure backward compatibility.
- case 'file_default':
- $fields_settings[$field_name]['settings']['use_description_as_link_text'] = TRUE;
- $changed = TRUE;
- break;
- }
- }
- }
- if ($changed === TRUE) {
- $display->set('content', $fields_settings)->save();
- }
- }
- }
- /**
- * Set the 'owner' entity key and update the field.
- */
- function file_update_8700() {
- $definition_update_manager = \Drupal::entityDefinitionUpdateManager();
- $entity_type = $definition_update_manager->getEntityType('file');
- $keys = $entity_type->getKeys();
- $keys['owner'] = 'uid';
- $entity_type->set('entity_keys', $keys);
- $definition_update_manager->updateEntityType($entity_type);
- $definition_update_manager->updateFieldStorageDefinition($definition_update_manager->getFieldStorageDefinition('uid', 'file'));
- }
|