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
36 merge requests!8528Issue #3456871 by Tim Bozeman: Support NULL services,!8323Fix source code editing and in place front page site studio editing.,!6278Issue #3187770 by godotislate, smustgrave, catch, quietone: Views Rendered...,!3878Removed unused condition head title for views,!38582585169-10.1.x,!3818Issue #2140179: $entity->original gets stale between updates,!3742Issue #3328429: Create item list field formatter for displaying ordered and unordered lists,!3731Claro: role=button on status report items,!3668Resolve #3347842 "Deprecate the trusted",!3651Issue #3347736: Create new SDC component for Olivero (header-search),!3546refactored dialog.pcss file,!3531Issue #3336994: StringFormatter always displays links to entity even if the user in context does not have access,!3502Issue #3335308: Confusing behavior with FormState::setFormState and FormState::setMethod,!3452Issue #3332701: Refactor Claro's tablesort-indicator stylesheet,!3355Issue #3209129: Scrolling problems when adding a block via layout builder,!3226Issue #2987537: Custom menu link entity type should not declare "bundle" entity key,!3154Fixes #2987987 - CSRF token validation broken on routes with optional parameters.,!3147Issue #3328457: Replace most substr($a, $i) where $i is negative with str_ends_with(),!3146Issue #3328456: Replace substr($a, 0, $i) with str_starts_with(),!3133core/modules/system/css/components/hidden.module.css,!2964Issue #2865710 : Dependencies from only one instance of a widget are used in display modes,!2812Issue #3312049: [Followup] Fix Drupal.Commenting.FunctionComment.MissingReturnType returns for NULL,!2614Issue #2981326: Replace non-test usages of \Drupal::logger() with IoC injection,!2378Issue #2875033: Optimize joins and table selection in SQL entity query implementation,!2334Issue #3228209: Add hasRole() method to AccountInterface,!2062Issue #3246454: Add weekly granularity to views date sort,!1105Issue #3025039: New non translatable field on translatable content throws error,!1073issue #3191727: Focus states on mobile second level navigation items fixed,!10223132456: Fix issue where views instances are emptied before an ajax request is complete,!877Issue #2708101: Default value for link text is not saved,!844Resolve #3036010 "Updaters",!673Issue #3214208: FinishResponseSubscriber could create duplicate headers,!617Issue #3043725: Provide a Entity Handler for user cancelation,!579Issue #2230909: Simple decimals fail to pass validation,!560Move callback classRemove outside of the loop,!555Issue #3202493
Pipeline #64730 canceled
......@@ -65,53 +65,43 @@ 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.
$server_software = \Drupal::request()->server->get('SERVER_SOFTWARE', '');
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');
}
else {
$is_nginx = FALSE;
$is_apache = FALSE;
$fastcgi = FALSE;
}
// 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 {
$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>.');
}
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,
];
// 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.');
}
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.');
}
$requirements['file_progress'] = [
'title' => t('Upload progress'),
'value' => $value,
'description' => $description,
];
return $requirements;
}
......
......@@ -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;
......
......@@ -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)', [
......
......@@ -276,19 +276,17 @@ 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,
'#attributes' => ['class' => ['file-progress']],
// Uploadprogress extension requires this field to be at the top of
// the form.
'#weight' => -20,
];
}
$element['UPLOAD_IDENTIFIER'] = [
'#type' => 'hidden',
'#value' => $upload_progress_key,
'#attributes' => ['class' => ['file-progress']],
// Uploadprogress extension requires this field to be at the top of
// the form.
'#weight' => -20,
];
// Add the upload progress callback.
$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) {
'#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;
}
......
<?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:
count: 1
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\\.$#"
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