Verified Commit 0f7d46f9 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3397575 by kim.pepper, sourabhjain, alexpott, longwave: Deprecate...

Issue #3397575 by kim.pepper, sourabhjain, alexpott, longwave: Deprecate file_progress_implementation() and replace with extension_loaded('uploadprogress')
parent de1a11ea
Loading
Loading
Loading
Loading
Loading
+17 −27
Original line number Diff line number Diff line
@@ -65,31 +65,28 @@ function file_schema() {
function file_requirements($phase) {
  $requirements = [];

  // Check the server's ability to indicate upload progress.
  if ($phase == 'runtime') {
    $description = NULL;
    $implementation = file_progress_implementation();
    // The environment variable might be missing. Fallback to an empty string to
    // prevent passing NULL to preg_match(), a few lines later.
  if ($phase != 'runtime') {
    return $requirements;
  }

  $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 = str_contains($server_software, 'mod_fastcgi') || str_contains($server_software, 'mod_fcgi');
  // Get the web server identity.
  $is_nginx = preg_match("/Nginx/i", $server_software);
  $is_apache = preg_match("/Apache/i", $server_software);
  $fastcgi = $is_apache && ((str_contains($server_software, 'mod_fastcgi') || str_contains($server_software, 'mod_fcgi')));

  // Check the uploadprogress extension is loaded.
  if (extension_loaded('uploadprogress')) {
    $value = t('Enabled (<a href="http://pecl.php.net/package/uploadprogress">PECL uploadprogress</a>)');
    $description = NULL;
  }
  else {
      $is_nginx = FALSE;
      $is_apache = FALSE;
      $fastcgi = FALSE;
    $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>.');
  }

  // Adjust the requirement depending on what the server supports.
  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.');
@@ -98,19 +95,12 @@ function file_requirements($phase) {
    $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;
}
+6 −0
Original line number Diff line number Diff line
@@ -723,8 +723,14 @@ function file_save_upload($form_field_name, $validators = [], $destination = FAL
 * @return string|false
 *   A string indicating which upload progress system is available. Either "apc"
 *   or "uploadprogress". If neither are available, returns FALSE.
 *
 * @deprecated in drupal:10.3.0 and is removed from drupal:11.0.0. Use
 *    extension_loaded('uploadprogress') instead.
 *
 * @see https://www.drupal.org/node/3397577
 */
function file_progress_implementation() {
  @trigger_error(__FUNCTION__ . '() is deprecated in drupal:10.3.0 and is removed from drupal:11.0.0. Use extension_loaded(\'uploadprogress\') instead. See https://www.drupal.org/node/3397577', E_USER_DEPRECATED);
  static $implementation;
  if (!isset($implementation)) {
    $implementation = FALSE;
+1 −2
Original line number Diff line number Diff line
@@ -27,8 +27,7 @@ public function progress($key) {
      'percentage' => -1,
    ];

    $implementation = file_progress_implementation();
    if ($implementation == 'uploadprogress') {
    if (extension_loaded('uploadprogress')) {
      $status = uploadprogress_get_info($key);
      if (isset($status['bytes_uploaded']) && !empty($status['bytes_total'])) {
        $progress['message'] = t('Uploading... (@current of @total)', [
+1 −3
Original line number Diff line number Diff line
@@ -276,10 +276,9 @@ public static function processManagedFile(&$element, FormStateInterface $form_st
    ];

    // Add progress bar support to the upload if possible.
    if ($element['#progress_indicator'] == 'bar' && $implementation = file_progress_implementation()) {
    if ($element['#progress_indicator'] == 'bar' && extension_loaded('uploadprogress')) {
      $upload_progress_key = mt_rand();

      if ($implementation == 'uploadprogress') {
      $element['UPLOAD_IDENTIFIER'] = [
        '#type' => 'hidden',
        '#value' => $upload_progress_key,
@@ -288,7 +287,6 @@ public static function processManagedFile(&$element, FormStateInterface $form_st
        // the form.
        '#weight' => -20,
      ];
      }

      // Add the upload progress callback.
      $element['upload_button']['#ajax']['progress']['url'] = Url::fromRoute('file.ajax_progress', ['key' => $upload_progress_key]);
+1 −1
Original line number Diff line number Diff line
@@ -72,7 +72,7 @@ public function settingsForm(array $form, FormStateInterface $form_state) {
      '#default_value' => $this->getSetting('progress_indicator'),
      '#description' => $this->t('The throbber display does not show the status of uploads but takes up less space. The progress bar is helpful for monitoring progress on large uploads.'),
      '#weight' => 16,
      '#access' => file_progress_implementation(),
      '#access' => extension_loaded('uploadprogress'),
    ];
    return $element;
  }
Loading