Skip to content
Snippets Groups Projects
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
No related branches found
No related tags found
No related merge requests found
...@@ -65,53 +65,43 @@ function file_schema() { ...@@ -65,53 +65,43 @@ function file_schema() {
function file_requirements($phase) { function file_requirements($phase) {
$requirements = []; $requirements = [];
// Check the server's ability to indicate upload progress. if ($phase != 'runtime') {
if ($phase == 'runtime') { return $requirements;
$description = NULL; }
$implementation = file_progress_implementation();
// The environment variable might be missing. Fallback to an empty string to $server_software = \Drupal::request()->server->get('SERVER_SOFTWARE', '');
// prevent passing NULL to preg_match(), a few lines later.
$server_software = \Drupal::request()->server->get('SERVER_SOFTWARE', '');
// Test the web server identity. // Get the web server identity.
if (preg_match("/Nginx/i", $server_software)) { $is_nginx = preg_match("/Nginx/i", $server_software);
$is_nginx = TRUE; $is_apache = preg_match("/Apache/i", $server_software);
$is_apache = FALSE; $fastcgi = $is_apache && ((str_contains($server_software, 'mod_fastcgi') || str_contains($server_software, 'mod_fcgi')));
$fastcgi = FALSE;
} // Check the uploadprogress extension is loaded.
elseif (preg_match("/Apache/i", $server_software)) { if (extension_loaded('uploadprogress')) {
$is_nginx = FALSE; $value = t('Enabled (<a href="http://pecl.php.net/package/uploadprogress">PECL uploadprogress</a>)');
$is_apache = TRUE; $description = NULL;
$fastcgi = str_contains($server_software, 'mod_fastcgi') || str_contains($server_software, 'mod_fcgi'); }
} else {
else { $value = t('Not enabled');
$is_nginx = FALSE; $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>.');
$is_apache = FALSE; }
$fastcgi = FALSE;
}
if (!$is_apache && !$is_nginx) { // Adjust the requirement depending on what the server supports.
$value = t('Not enabled'); if (!$is_apache && !$is_nginx) {
$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.'); $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'); elseif ($fastcgi) {
$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.'); $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,
];
} }
$requirements['file_progress'] = [
'title' => t('Upload progress'),
'value' => $value,
'description' => $description,
];
return $requirements; return $requirements;
} }
......
...@@ -723,8 +723,14 @@ function file_save_upload($form_field_name, $validators = [], $destination = FAL ...@@ -723,8 +723,14 @@ function file_save_upload($form_field_name, $validators = [], $destination = FAL
* @return string|false * @return string|false
* A string indicating which upload progress system is available. Either "apc" * A string indicating which upload progress system is available. Either "apc"
* or "uploadprogress". If neither are available, returns FALSE. * 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() { 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; static $implementation;
if (!isset($implementation)) { if (!isset($implementation)) {
$implementation = FALSE; $implementation = FALSE;
......
...@@ -27,8 +27,7 @@ public function progress($key) { ...@@ -27,8 +27,7 @@ public function progress($key) {
'percentage' => -1, 'percentage' => -1,
]; ];
$implementation = file_progress_implementation(); if (extension_loaded('uploadprogress')) {
if ($implementation == 'uploadprogress') {
$status = uploadprogress_get_info($key); $status = uploadprogress_get_info($key);
if (isset($status['bytes_uploaded']) && !empty($status['bytes_total'])) { if (isset($status['bytes_uploaded']) && !empty($status['bytes_total'])) {
$progress['message'] = t('Uploading... (@current of @total)', [ $progress['message'] = t('Uploading... (@current of @total)', [
......
...@@ -276,19 +276,17 @@ public static function processManagedFile(&$element, FormStateInterface $form_st ...@@ -276,19 +276,17 @@ public static function processManagedFile(&$element, FormStateInterface $form_st
]; ];
// Add progress bar support to the upload if possible. // 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(); $upload_progress_key = mt_rand();
if ($implementation == 'uploadprogress') { $element['UPLOAD_IDENTIFIER'] = [
$element['UPLOAD_IDENTIFIER'] = [ '#type' => 'hidden',
'#type' => 'hidden', '#value' => $upload_progress_key,
'#value' => $upload_progress_key, '#attributes' => ['class' => ['file-progress']],
'#attributes' => ['class' => ['file-progress']], // Uploadprogress extension requires this field to be at the top of
// Uploadprogress extension requires this field to be at the top of // the form.
// the form. '#weight' => -20,
'#weight' => -20, ];
];
}
// Add the upload progress callback. // Add the upload progress callback.
$element['upload_button']['#ajax']['progress']['url'] = Url::fromRoute('file.ajax_progress', ['key' => $upload_progress_key]); $element['upload_button']['#ajax']['progress']['url'] = Url::fromRoute('file.ajax_progress', ['key' => $upload_progress_key]);
......
...@@ -72,7 +72,7 @@ public function settingsForm(array $form, FormStateInterface $form_state) { ...@@ -72,7 +72,7 @@ public function settingsForm(array $form, FormStateInterface $form_state) {
'#default_value' => $this->getSetting('progress_indicator'), '#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.'), '#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, '#weight' => 16,
'#access' => file_progress_implementation(), '#access' => extension_loaded('uploadprogress'),
]; ];
return $element; return $element;
} }
......
<?php
declare(strict_types=1);
namespace Drupal\Tests\file\Kernel;
use Drupal\KernelTests\KernelTestBase;
/**
* Tests file module deprecations.
*
* @group legacy
* @group file
*/
class LegacyFileModuleTest extends KernelTestBase {
/**
* {@inheritdoc}
*/
protected static $modules = ['file'];
/**
* @covers ::file_progress_implementation
*/
public function testFileProgressDeprecation() {
$this->expectDeprecation('file_progress_implementation() 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');
$this->assertFalse(\file_progress_implementation());
}
}
<?php
declare(strict_types=1);
namespace Drupal\Tests\file\Kernel;
use Drupal\KernelTests\KernelTestBase;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
/**
* Tests the file requirements.
*
* @group file
*/
class RequirementsTest extends KernelTestBase {
/**
* {@inheritdoc}
*/
protected static $modules = ['file'];
/**
* Tests the file upload requirements.
*/
public function testUploadRequirements(): void {
if (\extension_loaded('uploadprogress')) {
$this->markTestSkipped('We are testing only when the uploadprogress extension is not loaded.');
}
/** @var \Drupal\Core\Extension\ModuleHandlerInterface $moduleHandler */
$moduleHandler = $this->container->get('module_handler');
$moduleHandler->loadInclude('file', 'install');
// Test unspecified server software.
$this->setServerSoftware(NULL);
$requirements = \file_requirements('runtime');
$this->assertNotEmpty($requirements);
$this->assertEquals('Upload progress', (string) $requirements['file_progress']['title']);
$this->assertEquals('Not enabled', (string) $requirements['file_progress']['value']);
$this->assertEquals('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.', (string) $requirements['file_progress']['description']);
// Test Apache + mod_php.
$this->setServerSoftware('Apache mod_php');
$requirements = \file_requirements('runtime');
$this->assertNotEmpty($requirements);
$this->assertEquals('Not enabled', (string) $requirements['file_progress']['value']);
$this->assertEquals('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>.', (string) $requirements['file_progress']['description']);
// Test Apache + mod_fastcgi.
$this->setServerSoftware('Apache mod_fastcgi');
$requirements = \file_requirements('runtime');
$this->assertNotEmpty($requirements);
$this->assertEquals('Not enabled', (string) $requirements['file_progress']['value']);
$this->assertEquals('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.', (string) $requirements['file_progress']['description']);
// Test Nginx.
$this->setServerSoftware('Nginx');
$requirements = \file_requirements('runtime');
$this->assertNotEmpty($requirements);
$this->assertEquals('Not enabled', (string) $requirements['file_progress']['value']);
$this->assertEquals('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>.', (string) $requirements['file_progress']['description']);
}
/**
* Sets the server software attribute in the request.
*/
private function setServerSoftware(?string $software): void {
$request = new Request();
if (is_string($software)) {
$request->server->set('SERVER_SOFTWARE', $software);
}
$requestStack = new RequestStack();
$requestStack->push($request);
$this->container->set('request_stack', $requestStack);
}
}
...@@ -1446,11 +1446,6 @@ parameters: ...@@ -1446,11 +1446,6 @@ parameters:
count: 1 count: 1
path: modules/field_ui/src/Form/FieldStorageConfigEditForm.php path: modules/field_ui/src/Form/FieldStorageConfigEditForm.php
-
message: "#^Variable \\$value might not be defined\\.$#"
count: 1
path: modules/file/file.install
- -
message: "#^Variable \\$file_upload in empty\\(\\) always exists and is not falsy\\.$#" message: "#^Variable \\$file_upload in empty\\(\\) always exists and is not falsy\\.$#"
count: 1 count: 1
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment