Skip to content
Snippets Groups Projects
Commit 6551edcd authored by Michael Lee's avatar Michael Lee
Browse files

Upgrading drupal/redirect (1.8.0 => 1.9.0)

parent dab7810a
No related branches found
No related tags found
No related merge requests found
Showing
with 189 additions and 58 deletions
......@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "79b624198d865a053166b2726115450d",
"content-hash": "f19197ca5cc0ce7fff2fcfd34c47562b",
"packages": [
{
"name": "alchemy/zippy",
......@@ -6444,17 +6444,17 @@
},
{
"name": "drupal/redirect",
"version": "1.8.0",
"version": "1.9.0",
"source": {
"type": "git",
"url": "https://git.drupalcode.org/project/redirect.git",
"reference": "8.x-1.8"
"reference": "8.x-1.9"
},
"dist": {
"type": "zip",
"url": "https://ftp.drupal.org/files/projects/redirect-8.x-1.8.zip",
"reference": "8.x-1.8",
"shasum": "a7a440423434472ff7115ae69df01553f763f839"
"url": "https://ftp.drupal.org/files/projects/redirect-8.x-1.9.zip",
"reference": "8.x-1.9",
"shasum": "2987de20f509e9f7cec8a0f81d3a6774f9b0ba3e"
},
"require": {
"drupal/core": "^9.2 || ^10"
......@@ -6462,8 +6462,8 @@
"type": "drupal-module",
"extra": {
"drupal": {
"version": "8.x-1.8",
"datestamp": "1661806955",
"version": "8.x-1.9",
"datestamp": "1693393506",
"security-coverage": {
"status": "covered",
"message": "Covered by Drupal's security advisory policy"
......
......@@ -6707,18 +6707,18 @@
},
{
"name": "drupal/redirect",
"version": "1.8.0",
"version_normalized": "1.8.0.0",
"version": "1.9.0",
"version_normalized": "1.9.0.0",
"source": {
"type": "git",
"url": "https://git.drupalcode.org/project/redirect.git",
"reference": "8.x-1.8"
"reference": "8.x-1.9"
},
"dist": {
"type": "zip",
"url": "https://ftp.drupal.org/files/projects/redirect-8.x-1.8.zip",
"reference": "8.x-1.8",
"shasum": "a7a440423434472ff7115ae69df01553f763f839"
"url": "https://ftp.drupal.org/files/projects/redirect-8.x-1.9.zip",
"reference": "8.x-1.9",
"shasum": "2987de20f509e9f7cec8a0f81d3a6774f9b0ba3e"
},
"require": {
"drupal/core": "^9.2 || ^10"
......@@ -6726,8 +6726,8 @@
"type": "drupal-module",
"extra": {
"drupal": {
"version": "8.x-1.8",
"datestamp": "1661806955",
"version": "8.x-1.9",
"datestamp": "1693393506",
"security-coverage": {
"status": "covered",
"message": "Covered by Drupal's security advisory policy"
......@@ -6748,6 +6748,10 @@
"name": "Dave Reid",
"homepage": "https://www.drupal.org/user/53892"
},
{
"name": "Kristen Pol",
"homepage": "https://www.drupal.org/user/8389"
},
{
"name": "pifagor",
"homepage": "https://www.drupal.org/user/2375692"
......
......@@ -3,7 +3,7 @@
'name' => 'osu-asc-webservices/d8-upstream',
'pretty_version' => 'dev-master',
'version' => 'dev-master',
'reference' => 'c451a15e8ca5597c0bf0cbe81e0fefa4756dd511',
'reference' => 'dab7810abd7812786f78216afa53bddff99ecfd8',
'type' => 'project',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
......@@ -1076,9 +1076,9 @@
'dev_requirement' => false,
),
'drupal/redirect' => array(
'pretty_version' => '1.8.0',
'version' => '1.8.0.0',
'reference' => '8.x-1.8',
'pretty_version' => '1.9.0',
'version' => '1.9.0.0',
'reference' => '8.x-1.9',
'type' => 'drupal-module',
'install_path' => __DIR__ . '/../../web/modules/redirect',
'aliases' => array(),
......@@ -1531,7 +1531,7 @@
'osu-asc-webservices/d8-upstream' => array(
'pretty_version' => 'dev-master',
'version' => 'dev-master',
'reference' => 'c451a15e8ca5597c0bf0cbe81e0fefa4756dd511',
'reference' => 'dab7810abd7812786f78216afa53bddff99ecfd8',
'type' => 'project',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
......
......@@ -38,7 +38,7 @@ display:
type: basic
options:
submit_button: Filter
reset_button: false
reset_button: true
reset_button_label: Reset
exposed_sorts_label: 'Sort by'
expose_sort_order: true
......
......@@ -8,7 +8,7 @@ dependencies:
- redirect:redirect
- drupal:views
# Information added by Drupal.org packaging script on 2022-08-29
version: '8.x-1.8'
# Information added by Drupal.org packaging script on 2023-08-30
version: '8.x-1.9'
project: 'redirect'
datestamp: 1661806957
datestamp: 1693393511
......@@ -6,6 +6,7 @@
*/
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\Url;
use Drupal\redirect\Entity\Redirect;
......@@ -69,6 +70,12 @@ function redirect_404_form_redirect_settings_form_alter(&$form, FormStateInterfa
]),
];
$form['clear_ignored'] = [
'#type' => 'checkbox',
'#title' => t('Clear ignored 404 log entries when saving this form'),
'#default_value' => FALSE,
];
$form['suppress_404'] = [
'#type' => 'checkbox',
'#title' => t("Suppress 'page not found' log messages"),
......@@ -100,6 +107,13 @@ function redirect_404_logging_settings_submit($form, FormStateInterface $form_st
->set('pages', $pages)
->set('suppress_404', $form_state->getValue('suppress_404'))
->save();
// Remove the filtered out items.
/** @var \Drupal\redirect_404\RedirectNotFoundStorageInterface; $redirect_storage */
$redirect_storage = \Drupal::service('redirect.not_found_storage');
foreach ($ignore_pages as $ignore_page) {
$redirect_storage->resolveLogRequest(trim($ignore_page));
}
}
/**
......@@ -109,6 +123,10 @@ function redirect_404_redirect_presave(Redirect $redirect) {
$path = $redirect->getSourcePathWithQuery();
$langcode = $redirect->get('language')->value;
if ($langcode == LanguageInterface::LANGCODE_NOT_SPECIFIED) {
$langcode = NULL;
}
// Mark a potentially existing log entry for this path as resolved.
\Drupal::service('redirect.not_found_storage')->resolveLogRequest($path, $langcode);
}
......
ignore 404 requests:
title: 'Ignore 404 requests'
description: 'This allows users without the Administer redirect settings to ignore specific 404 requests, without the ability to customize the 404 exclude patterns.'
......@@ -11,5 +11,5 @@ redirect_404.ignore_404:
defaults:
_controller: '\Drupal\redirect_404\Controller\Fix404IgnoreController::ignorePath'
requirements:
_permission: 'administer redirect settings'
_permission: 'administer redirect settings+ignore 404 requests'
_csrf_token: 'TRUE'
......@@ -60,26 +60,41 @@ public static function create(ContainerInterface $container) {
* @return \Symfony\Component\HttpFoundation\RedirectResponse
*/
public function ignorePath(Request $request) {
$ignored_paths = $this->config('redirect_404.settings')->get('pages');
$editable = $this->configuration->getEditable('redirect_404.settings');
$existing_config_raw = $editable->get('pages');
$path = $request->query->get('path');
$langcode = $request->query->get('langcode');
if (empty($ignored_paths) || !strpos($path, $ignored_paths)) {
$this->redirectStorage->resolveLogRequest($path, $langcode);
if (empty($existing_config_raw) || !empty($path) || !strpos($path, $existing_config_raw)) {
$this->redirectStorage->resolveLogRequest($path);
$this->messenger()->addMessage($this->t('Resolved the path %path in the database. Please check the ignored list and save the settings.', [
'%path' => $path,
]));
}
// Users without 'administer redirect settings' and 'ignore 4040 request'
// permission can also ignore pages.
if (!$this->currentUser()->hasPermission('administer redirect settings') && $this->currentUser()->hasPermission('ignore 404 requests')) {
$existing_config_raw .= $path . "\n";
$editable->set('pages', $existing_config_raw);
$editable->save();
$options = [
'query' => [
'ignore' => $path,
'destination' => Url::fromRoute('redirect_404.fix_404')->getInternalPath(),
],
];
$response = $this->redirect('redirect_404.fix_404');
$this->messenger()->addMessage($this->t('Resolved the path %path in the database.', [
'%path' => $path,
]));
}
else {
$options = [
'query' => [
'ignore' => $path,
'destination' => Url::fromRoute('redirect_404.fix_404')->getInternalPath(),
],
];
$response = $this->redirect('redirect.settings', [], $options);
$this->messenger()->addMessage($this->t('Resolved the path %path in the database. Please check the ignored list and save the settings.', [
'%path' => $path,
]));
}
return $this->redirect('redirect.settings', [], $options);
return $response;
}
}
}
......@@ -105,11 +105,11 @@ public function onKernelException(ExceptionEvent $event) {
$path = $this->currentPath->getPath();
// Ignore paths specified in the redirect settings.
if ($pages = mb_strtolower($this->config->get('pages'))) {
if ($pages = $this->config->get('pages')) {
// Do not trim a trailing slash if that is the complete path.
$path_to_match = $path === '/' ? $path : rtrim($path, '/');
if ($this->pathMatcher->matchPath(mb_strtolower($path_to_match), $pages)) {
if ($this->pathMatcher->matchPath(mb_strtolower($path_to_match), mb_strtolower($pages))) {
return;
}
}
......
......@@ -33,6 +33,13 @@ class Redirect404Operations extends FieldPluginBase {
*/
protected $renderer;
/**
* The current user.
*
* @var \Drupal\Core\Session\AccountInterface
*/
protected $currentUser;
/**
* Constructor for the redirect operations view field.
*
......@@ -95,7 +102,7 @@ public function render(ResultRow $values) {
'url' => Url::fromRoute('redirect.add', [], $query),
];
if ($this->currentUser->hasPermission('administer redirect settings')) {
if ($this->currentUser->hasPermission('administer redirect settings') || $this->currentUser->hasPermission('ignore 404 requests')) {
$links['ignore'] = [
'title' => $this->t('Ignore'),
'url' => Url::fromRoute('redirect_404.ignore_404', [
......
......@@ -18,14 +18,14 @@ interface RedirectNotFoundStorageInterface {
public function logRequest($path, $langcode);
/**
* Marks a 404 request log as resolved.
* Marks a 404 request log as resolved (supports wildcards).
*
* @param string $path
* The path of the current request.
* @param string $langcode
* The ID of the language code.
* (optional) The ID of the language code.
*/
public function resolveLogRequest($path, $langcode);
public function resolveLogRequest($path, $langcode = NULL);
/**
* Returns the 404 request data.
......
......@@ -4,7 +4,6 @@
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\DependencyInjection\DependencySerializationTrait;
use Drupal\Core\Logger\LoggerChannelFactory;
use Drupal\Core\Logger\LoggerChannelFactoryInterface;
use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;
......
......@@ -80,12 +80,17 @@ public function logRequest($path, $langcode) {
/**
* {@inheritdoc}
*/
public function resolveLogRequest($path, $langcode) {
$this->database->update('redirect_404')
public function resolveLogRequest($path, $langcode = NULL) {
$path = str_replace('*', '%', $path);
$update = $this->database->update('redirect_404')
->fields(['resolved' => 1])
->condition('path', $path)
->condition('langcode', $langcode)
->execute();
->condition('path', $path, 'LIKE');
if ($langcode) {
$update->condition('langcode', $langcode);
}
$update->execute();
}
/**
......
......@@ -191,6 +191,82 @@ public function testIgnorePages() {
$this->getSession()->getPage()->pressButton('Save configuration');
$this->drupalGet('admin/config/search/redirect/settings');
$this->assertSession()->fieldValueEquals('ignore_pages', "/node/*\n/term/*\n/llama_page");
// Test clearing of ignored pages.
$this->drupalGet('vicuna_page');
$this->drupalGet('vicuna_page/subpage');
$this->drupalGet('prefix/vicuna_page/subpage');
$this->drupalGet('alpaca_page');
$this->drupalGet('admin/config/search/redirect/404');
$this->assertSession()->pageTextContains('vicuna_page');
$this->assertSession()->pageTextContains('alpaca_page');
$this->drupalGet('admin/config/search/redirect/settings');
$edit = [
'ignore_pages' => '*vicuna*',
'clear_ignored' => TRUE,
];
$this->submitForm($edit, 'Save configuration');
$this->drupalGet('admin/config/search/redirect/404');
$this->assertSession()->pageTextNotContains('vicuna');
$this->drupalGet('prefix/jaguar_page/subpage');
$this->drupalGet('prefix/tucan_page/subpage');
$this->drupalGet('admin/config/search/redirect/404');
$this->assertSession()->pageTextContains('jaguar_page');
$this->assertSession()->pageTextContains('tucan_page');
$this->drupalGet('admin/config/search/redirect/settings');
$edit = [
'ignore_pages' => '*/tucan_page/*',
'clear_ignored' => TRUE,
];
$this->submitForm($edit, 'Save configuration');
$this->drupalGet('admin/config/search/redirect/404');
$this->assertSession()->pageTextContains('jaguar_page');
$this->assertSession()->pageTextNotContains('tucan_page');
}
/**
* Tests the redirect ignore pages for users without the 'administer redirect
* settings' permission.
*/
public function testIgnorePagesNonAdmin() {
// Create a node.
$node = $this->drupalCreateNode(['type' => 'page']);
$this->container->get('config.factory')
->getEditable('redirect_404.settings')
->set('pages', "/brian\n/flying/circus\n/meaning/of/*\n")
->save();
// Create a non admin user.
$user = $this->drupalCreateUser([
'administer redirects',
'ignore 404 requests',
'access content',
'bypass node access',
'create url aliases',
'administer url aliases',
]);
$this->drupalLogin($user);
// Visit non existing pages.
$this->drupalGet('node/' . $node->id() . '/foobar');
// Go to the "fix 404" page and check there is a 404 entry.
$this->drupalGet('admin/config/search/redirect/404');
$this->assertSession()->pageTextContains('node/' . $node->id() . '/foobar');
// Add this 404 entry to the 'ignore path' list, assert it works properly.
$this->clickLink('Ignore');
$this->assertSession()->addressEquals('admin/config/search/redirect/404');
// Check the message.
$this->assertSession()->pageTextContains('Resolved the path /node/' . $node->id() . '/foobar in the database.');
// This removes the message.
$this->drupalGet('admin/config/search/redirect/404');
$this->assertSession()->pageTextNotContains('node/' . $node->id() . '/foobar');
$config = $this->container->get('config.factory')
->get('redirect_404.settings')
->get('pages');
$this->assertStringContainsString('node/' . $node->id() . '/foobar', $config);
}
/**
......
......@@ -2,7 +2,6 @@
namespace Drupal\Tests\redirect_404\Functional;
use Drupal\Component\Render\FormattableMarkup;
use Drupal\Tests\BrowserTestBase;
/**
......
......@@ -7,7 +7,7 @@ configure: redirect_domain.domain_list
dependencies:
- redirect:redirect
# Information added by Drupal.org packaging script on 2022-08-29
version: '8.x-1.8'
# Information added by Drupal.org packaging script on 2023-08-30
version: '8.x-1.9'
project: 'redirect'
datestamp: 1661806957
datestamp: 1693393511
redirect_domain.domain_list:
title: 'Domain redirects'
parent: redirect.list
route_name: redirect_domain.domain_list
description: 'Configure domain redirects.'
menu_name: admin
......@@ -5,7 +5,6 @@
* Generate callbacks for the redirect module.
*/
use Drupal\Component\Utility\Random;
use Drupal\devel_generate\DevelGenerateBase;
use Drupal\node\NodeInterface;
use Drupal\redirect\Entity\Redirect;
......
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