Skip to content
Snippets Groups Projects
Commit aa51520a authored by Sascha Grossenbacher's avatar Sascha Grossenbacher Committed by Sascha Grossenbacher
Browse files

Issue #3288711 by taniachque, Project Update Bot, Berdir: Automated Drupal 10 compatibility fixes

parent 302ad112
Branches
Tags 8.x-1.12
No related merge requests found
Showing
with 98 additions and 94 deletions
......@@ -4,7 +4,7 @@
"type": "drupal-module",
"license": "GPL-2.0",
"require": {
"drupal/core": "^8.7.7 || ^9"
"drupal/core": "^9.4 || ^10"
},
"require-dev": {
"drupal/simplenews": "~2.0",
......
......@@ -20,9 +20,9 @@
*/
Drupal.behaviors.tableFilterByText = {
attach: function (context, settings) {
var $input = $('input.table-filter-text').once('table-filter-text');
var $select_category = $('select.table-filter-select-category').once('table-filter-select-category');
var $select_sensor_type = $('select.table-filter-select-sensor-type').once('table-filter-select-sensor-type');
var $input = $(once('table-filter-text', 'input.table-filter-text'));
var $select_category = $(once('table-filter-select-category', 'select.table-filter-select-category'));
var $select_sensor_type = $(once('table-filter-select-sensor-type', 'select.table-filter-select-sensor-type');
var $table = $($input.attr('data-table'));
var $rows;
var $details;
......
......@@ -107,7 +107,7 @@ function monitoring_demo_install() {
$sensor_manager->enableSensor('monitoring_disappeared_sensors');
// Generate some image style derivative errors.
$file = file_save_data($random->name());
$file = \Drupal::service('file.repository')->writeData($random->name(), 'public://');
/** @var \Drupal\file\FileUsage\FileUsageInterface $usage */
$usage = \Drupal::service('file.usage');
foreach ($nodes as $node) {
......@@ -127,7 +127,7 @@ function monitoring_demo_install() {
]
);
}
$file = file_save_data($random->name());
$file = \Drupal::service('file.repository')->writeData($random->name(), 'public://');
\Drupal::logger('image')->notice('Source image at %source_image_path not found while trying to generate derivative image at %derivative_path.', [
'%source_image_path' => $file->getFileUri(),
'%derivative_path' => 'hash://styles/preview/5678.jpeg',
......
......@@ -16,22 +16,22 @@ class MonitoringDemoTest extends MonitoringTestBase {
*
* @var string[]
*/
public static $modules = ['monitoring_demo'];
protected static $modules = ['monitoring_demo'];
/**
* Asserts the demo instructions on the frontpage.
*/
public function testInstalled() {
$this->drupalGet('');
$this->assertText('Monitoring');
$this->assertText(t('Welcome to the Monitoring demo installation.'));
$this->assertLink(t('Monitoring sensors overview'));
$this->assertLink(t('Monitoring sensors settings'));
$this->assertText(t('Sensor example: "Installed modules"'));
$this->assertLink(t('Configure'));
$this->assertLink(t('Uninstall'), 0);
$this->assertLink(t('Uninstall'), 1);
$this->assertText(t('Drush integration - open up your console and type in # drush monitoring-sensor-config'));
$this->assertSession()->pageTextContains('Monitoring');
$this->assertSession()->pageTextContains(t('Welcome to the Monitoring demo installation.'));
$this->assertSession()->linkExists(t('Monitoring sensors overview'));
$this->assertSession()->linkExists(t('Monitoring sensors settings'));
$this->assertSession()->pageTextContains(t('Sensor example: "Installed modules"'));
$this->assertSession()->linkExists(t('Configure'));
$this->assertSession()->linkExists(t('Uninstall'), 0);
$this->assertSession()->linkExists(t('Uninstall'), 1);
$this->assertSession()->pageTextContains(t('Drush integration - open up your console and type in # drush monitoring-sensor-config'));
}
}
......@@ -30,7 +30,7 @@ class MonitoringMailKernelTest extends MonitoringUnitTestBase {
/**
* {@inheritdoc}
*/
protected function setUp() {
protected function setUp(): void {
parent::setUp();
$this->installSchema('dblog', ['watchdog']);
......
......@@ -40,7 +40,7 @@ class MultigraphServicesTest extends MonitoringTestBase {
/**
* {@inheritdoc}
*/
public function setUp() {
public function setUp(): void {
parent::setUp();
$this->servicesAccount = $this->drupalCreateUser([
......@@ -55,7 +55,7 @@ class MultigraphServicesTest extends MonitoringTestBase {
$this->drupalLogin($this->servicesAccount);
$response_data = $this->doJsonRequest('monitoring-multigraph');
$this->assertResponse(200);
$this->assertSession()->statusCodeEquals(200);
/** @var \Drupal\monitoring_multigraph\MultigraphInterface[] $multigraphs */
$multigraphs = \Drupal::entityTypeManager()
......@@ -64,28 +64,28 @@ class MultigraphServicesTest extends MonitoringTestBase {
// Test the list of multigraphs.
foreach ($multigraphs as $name => $multigraph) {
$this->assertEqual($response_data[$name]['id'], $multigraph->id());
$this->assertEqual($response_data[$name]['label'], $multigraph->label());
$this->assertEqual($response_data[$name]['description'], $multigraph->getDescription());
$this->assertEqual($response_data[$name]['sensors'], $multigraph->getSensorsRaw());
$this->assertEqual($response_data[$name]['uri'], Url::fromRoute('rest.monitoring-multigraph.GET' , ['id' => $multigraph->id(), '_format' => 'json'])->setAbsolute()->toString());
$this->assertEquals($response_data[$name]['id'], $multigraph->id());
$this->assertEquals($response_data[$name]['label'], $multigraph->label());
$this->assertEquals($response_data[$name]['description'], $multigraph->getDescription());
$this->assertEquals($response_data[$name]['sensors'], $multigraph->getSensorsRaw());
$this->assertEquals($response_data[$name]['uri'], Url::fromRoute('rest.monitoring-multigraph.GET' , ['id' => $multigraph->id(), '_format' => 'json'])->setAbsolute()->toString());
}
// Test response for non-existing multigraph.
$name = 'multigraph_that_does_not_exist';
$this->doJsonRequest('monitoring-multigraph/' . $name);
$this->assertResponse(404);
$this->assertSession()->statusCodeEquals(404);
// Test the predefined multigraph.
$name = 'watchdog_severe_entries';
$response_data = $this->doJsonRequest('monitoring-multigraph/' . $name);
$this->assertResponse(200);
$this->assertSession()->statusCodeEquals(200);
$multigraph = $multigraphs[$name];
$this->assertEqual($response_data['id'], $multigraph->id());
$this->assertEqual($response_data['label'], $multigraph->label());
$this->assertEqual($response_data['description'], $multigraph->getDescription());
$this->assertEqual($response_data['sensors'], $multigraph->getSensorsRaw());
$this->assertEqual($response_data['uri'], Url::fromRoute('rest.monitoring-multigraph.GET' , ['id' => $multigraph->id(), '_format' => 'json'])->setAbsolute()->toString());
$this->assertEquals($response_data['id'], $multigraph->id());
$this->assertEquals($response_data['label'], $multigraph->label());
$this->assertEquals($response_data['description'], $multigraph->getDescription());
$this->assertEquals($response_data['sensors'], $multigraph->getSensorsRaw());
$this->assertEquals($response_data['uri'], Url::fromRoute('rest.monitoring-multigraph.GET' , ['id' => $multigraph->id(), '_format' => 'json'])->setAbsolute()->toString());
}
}
......@@ -27,7 +27,7 @@ class MultigraphWebTest extends BrowserTestBase {
*
* @var string[]
*/
public static $modules = [
protected static $modules = [
'dblog',
'node',
'monitoring',
......@@ -66,27 +66,28 @@ class MultigraphWebTest extends BrowserTestBase {
'description' => $this->randomString(),
'sensor_add_select' => 'dblog_404',
];
$this->drupalPostForm('admin/config/system/monitoring/multigraphs/add', $values, t('Add sensor'));
$this->assertText(t('Sensor "Page not found errors" added. You have unsaved changes.'));
$this->drupalGet('admin/config/system/monitoring/multigraphs/add');
$this->submitForm($values, t('Add sensor'));
$this->assertSession()->pageTextContains(t('Sensor "Page not found errors" added. You have unsaved changes.'));
$this->drupalPostForm(NULL, [
$this->submitForm([
'sensor_add_select' => 'user_failed_logins',
], t('Add sensor'));
$this->assertText(t('Sensor "Failed user logins" added. You have unsaved changes.'));
$this->assertSession()->pageTextContains(t('Sensor "Failed user logins" added. You have unsaved changes.'));
$this->drupalPostForm(NULL, [
$this->submitForm([
'sensor_add_select' => 'user_successful_logins',
], t('Add sensor'));
$this->assertText(t('Sensor "Successful user logins" added. You have unsaved changes.'));
$this->assertSession()->pageTextContains(t('Sensor "Successful user logins" added. You have unsaved changes.'));
// And last but not least, change all sensor label values and save form.
$this->drupalPostForm(NULL, [
$this->submitForm([
'sensors[dblog_404][label]' => 'Page not found errors (test)',
'sensors[user_failed_logins][label]' => 'Failed user logins (test)',
'sensors[user_successful_logins][label]' => 'Successful user logins (test)',
], t('Save'));
$this->assertText(t('Multigraph settings saved.'));
$this->assertText('Page not found errors (test), Failed user logins (test), Successful user logins (test)');
$this->assertSession()->pageTextContains(t('Multigraph settings saved.'));
$this->assertSession()->pageTextContains('Page not found errors (test), Failed user logins (test), Successful user logins (test)');
}
/**
......@@ -98,13 +99,13 @@ class MultigraphWebTest extends BrowserTestBase {
// Go to multigraph overview and test editing pre-installed multigraph.
$this->drupalGet('admin/config/system/monitoring/multigraphs');
// Check label, description and sensors (before editing).
$this->assertText('Watchdog severe entries');
$this->assertText('Watchdog entries with severity Warning or higher');
$this->assertText('404, Alert, Critical, Emergency, Error');
$this->assertSession()->pageTextContains('Watchdog severe entries');
$this->assertSession()->pageTextContains('Watchdog entries with severity Warning or higher');
$this->assertSession()->pageTextContains('404, Alert, Critical, Emergency, Error');
// Edit.
$this->drupalGet('admin/config/system/monitoring/multigraphs/watchdog_severe_entries');
$this->assertText('Edit Multigraph');
$this->assertSession()->pageTextContains('Edit Multigraph');
// Change label, description and add a sensor.
$values = [
......@@ -112,30 +113,31 @@ class MultigraphWebTest extends BrowserTestBase {
'description' => 'Watchdog entries with severity Warning or higher (test)',
'sensor_add_select' => 'user_successful_logins',
];
$this->drupalPostForm(NULL, $values, t('Add sensor'));
$this->assertText('Sensor "Successful user logins" added. You have unsaved changes.');
$this->submitForm($values, t('Add sensor'));
$this->assertSession()->pageTextContains('Sensor "Successful user logins" added. You have unsaved changes.');
// Remove a sensor.
$this->getSession()->getPage()->pressButton('remove_dblog_404');
// (drupalPostAjaxForm() lets us target the button precisely.)
$this->assertText(t('Sensor "Page not found errors" removed. You have unsaved changes.'));
$this->drupalPostForm(NULL, [], t('Save'));
$this->assertSession()->pageTextContains(t('Sensor "Page not found errors" removed. You have unsaved changes.'));
$this->submitForm([], t('Save'));
$this->drupalGet('admin/config/system/monitoring/multigraphs/watchdog_severe_entries');
// Change weights and save form.
$this->drupalPostForm('admin/config/system/monitoring/multigraphs/watchdog_severe_entries', [
$this->submitForm([
'sensors[user_successful_logins][weight]' => -2,
'sensors[dblog_event_severity_error][weight]' => -1,
'sensors[dblog_event_severity_critical][weight]' => 0,
'sensors[dblog_event_severity_emergency][weight]' => 1,
'sensors[dblog_event_severity_alert][weight]' => 2,
], t('Save'));
$this->assertText(t('Multigraph settings saved.'));
$this->assertSession()->pageTextContains(t('Multigraph settings saved.'));
// Go back to multigraph overview and check changed values.
$this->drupalGet('admin/config/system/monitoring/multigraphs');
$this->assertText('Watchdog severe entries (test)');
$this->assertText('Watchdog entries with severity Warning or higher (test)');
$this->assertText('Successful user logins, Error, Critical, Emergency, Alert');
$this->assertSession()->pageTextContains('Watchdog severe entries (test)');
$this->assertSession()->pageTextContains('Watchdog entries with severity Warning or higher (test)');
$this->assertSession()->pageTextContains('Successful user logins, Error, Critical, Emergency, Alert');
}
/**
......@@ -145,16 +147,17 @@ class MultigraphWebTest extends BrowserTestBase {
// Go to multigraph overview and check for pre-installed multigraph.
$this->drupalGet('admin/config/system/monitoring/multigraphs');
// Check label and description (before deleting).
$this->assertText('Watchdog severe entries');
$this->assertText('Watchdog entries with severity Warning or higher');
$this->assertSession()->pageTextContains('Watchdog severe entries');
$this->assertSession()->pageTextContains('Watchdog entries with severity Warning or higher');
$this->drupalGet('admin/config/system/monitoring/multigraphs/watchdog_severe_entries/delete');
// Delete.
$this->drupalPostForm('admin/config/system/monitoring/multigraphs/watchdog_severe_entries/delete', [], t('Delete'));
$this->assertText('The Watchdog severe entries (test) multigraph has been deleted');
$this->submitForm([], t('Delete'));
$this->assertSession()->pageTextContains('The Watchdog severe entries (test) multigraph has been deleted');
// Go back to multigraph overview and check that multigraph is deleted.
$this->drupalGet('admin/config/system/monitoring/multigraphs');
$this->assertNoText('Watchdog severe entries');
$this->assertNoText('Watchdog entries with severity Warning or higher');
$this->assertSession()->pageTextNotContains('Watchdog severe entries');
$this->assertSession()->pageTextNotContains('Watchdog entries with severity Warning or higher');
}
}
......@@ -19,14 +19,14 @@ class MultigraphUnitTest extends UnitTestCase {
/**
* A mock entity manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface|\PHPUnit_Framework_MockObject_MockObject
* @var \Drupal\Core\Entity\EntityTypeManagerInterface|\PHPUnit\Framework\MockObject\MockObject
*/
protected $entityTypeManager;
/**
* {@inheritdoc}
*/
protected function setUp() {
protected function setUp(): void {
$this->entityTypeManager = $this->createMock(EntityTypeManagerInterface::class);
$container = new ContainerBuilder();
......@@ -78,7 +78,7 @@ class MultigraphUnitTest extends UnitTestCase {
* @param array $id
* An ID to set on the sensor.
*
* @return \Drupal\monitoring\Entity\SensorConfig|\PHPUnit_Framework_MockObject_MockObject
* @return \Drupal\monitoring\Entity\SensorConfig|\PHPUnit\Framework\MockObject\MockObject
* The mock sensor object.
*/
protected function getMockSensor($id) {
......
name: Monitoring Test
description: Monitoring base test module.
package: Monitoring
core_version_requirement: ^8.7.7 || ^9
core_version_requirement: ^9 || ^10
hidden: TRUE
type: module
......
<?php
use Drupal\monitoring\Entity\SensorConfig;
/**
* @file
* Monitoring API documentation.
......@@ -15,7 +16,7 @@
*
* @see \Drupal\monitoring\Controller\SensorList::content()
*/
function hook_monitoring_sensor_links_alter(&$links, \Drupal\monitoring\Entity\SensorConfig $sensor_config) {
function hook_monitoring_sensor_links_alter(&$links, SensorConfig $sensor_config) {
}
......
......@@ -2,7 +2,7 @@ name: Monitoring
type: module
description: Monitoring base.
package: Monitoring
core_version_requirement: ^8.7.7 || ^9
core_version_requirement: ^9.4 || ^10
configure: monitoring.settings
dependencies:
- drupal:views
......
......@@ -51,9 +51,9 @@ function monitoring_install() {
include_once DRUPAL_ROOT . '/core/includes/install.inc';
drupal_load_updates();
foreach (\Drupal::moduleHandler()->getImplementations('requirements') as $module) {
\Drupal::moduleHandler()->invokeAllWith('requirements', function (callable $hook, string $module) {
initialize_requirements_sensors($module);
}
});
}
/**
......@@ -81,7 +81,7 @@ function monitoring_event_severities() {
function monitoring_update_8101() {
// Only create if the sensor config does not exist yet.
if (!SensorConfig::load('temporary_files_usages')) {
$config_path = drupal_get_path('module', 'monitoring') . '/config/install/monitoring.sensor_config.temporary_files_usages.yml';
$config_path = \Drupal::service('extension.list.module')->getPath('monitoring') . '/config/install/monitoring.sensor_config.temporary_files_usages.yml';
$data = Yaml::decode(file_get_contents($config_path));
\Drupal::service('monitoring.sensor_manager')->clearCachedDefinitions();
SensorConfig::create($data)->trustData()->save();
......
......@@ -12,7 +12,7 @@
attach: function(context) {
// Check if there are any criticals, warnings or unknowns.
if (drupalSettings.monitoring_escalated_sensors > 0) {
$overview = $(context).find('.monitoring-overview-summary').once('monitoring-button');
$overview = $(once('monitoring-button', '.monitoring-overview-summary', context));
if ($overview.length) {
// Inject toggle link into DOM.
$('<a class="button button--primary button--small" href="#">' + Drupal.t('Show OK sensors') + '</a>')
......
......@@ -4,6 +4,10 @@ monitoring:
monitoring.css: {}
js:
monitoring.js: {}
dependencies:
- core/jquery
- core/drupal
- core/once
monitoring.sensor.overview:
js:
......@@ -11,4 +15,4 @@ monitoring.sensor.overview:
dependencies:
- core/jquery
- core/drupal
- core/jquery.once
- core/once
......@@ -54,18 +54,11 @@ function monitoring_sensor_config_by_categories($enabled = TRUE) {
/**
* Implements hook_modules_installed().
*/
function monitoring_modules_installed($modules) {
if (\Drupal::service('config.installer')->isSyncing()) {
// Don't create any config when syncing.
// @todo change to $is_syncing param after 8.9 is minimum per
// https://www.drupal.org/node/3098920
return;
}
function monitoring_modules_installed($modules, $is_syncing) {
// Update the installed modules.
foreach ($modules as $module) {
// Check for dependencies that are not initialized.
if(\Drupal::moduleHandler()->implementsHook($module, 'requirements') && !SensorConfig::load('core_requirements_' . $module)) {
if (\Drupal::moduleHandler()->hasImplementations('requirements', $module) && !SensorConfig::load('core_requirements_' . $module)) {
initialize_requirements_sensors($module);
}
}
......@@ -267,6 +260,7 @@ function monitoring_sensor_result_last($sensor_name) {
->sort('timestamp', 'DESC')
->sort('record_id', 'DESC')
->range(0, 1)
->accessCheck(TRUE)
->execute();
if (!empty($result)) {
......@@ -293,6 +287,7 @@ function monitoring_sensor_result_second_last($sensor_name) {
->sort('timestamp', 'DESC')
->sort('record_id', 'DESC')
->range(1, 1)
->accessCheck(TRUE)
->execute();
if (!empty($result)) {
......
......@@ -237,14 +237,14 @@ class CoreRequirementsSensorPlugin extends SensorPluginBase implements ExtendedI
* Thrown when the given module does not provide a requirements hook.
*/
protected function getRequirements($module) {
module_load_install($module);
\Drupal::moduleHandler()->loadInclude($module, 'install');
$function = $module . '_requirements';
if (!function_exists($function)) {
throw new \RuntimeException(new FormattableMarkup('Requirement function @function not found', array('@function' => $function)));
}
return (array)$function('runtime');
return (array) \Drupal::moduleHandler()->invoke($module, 'requirements', ['runtime']);
}
/**
......
......@@ -14,6 +14,7 @@ use Drupal\monitoring\SensorPlugin\DatabaseAggregatorSensorPluginBase;
use Drupal\Core\Entity\DependencyTrait;
use Drupal\Core\Entity\Query\Sql\Condition;
use Drupal\Core\Entity\Query\Sql\Tables;
use Drupal\TestTools\Extension\SchemaInspector;
/**
* Database aggregator able to query a single db table.
......@@ -385,14 +386,12 @@ class DatabaseAggregatorSensorPlugin extends DatabaseAggregatorSensorPluginBase
// There is no API to load a list of all tables, loop through all modules
// with a hook_schema() hook and try to find the table.
\Drupal::moduleHandler()->loadAllIncludes('install');
foreach (\Drupal::moduleHandler()->getImplementations('schema') as $module) {
$schema = drupal_get_module_schema($module, $this->sensorConfig->getSetting('table'));
if (isset($schema['module'])) {
$this->addDependency('module', $schema['module']);
break;
\Drupal::moduleHandler()->invokeAllWith('schema', function (callable $hook, string $module) {
$schema = SchemaInspector::getTablesSpecification(\Drupal::moduleHandler(), $module);
if (isset($schema[$this->sensorConfig->getSetting('table')])) {
$this->addDependency('module', $module);
}
}
});
return $this->dependencies;
}
......
......@@ -11,6 +11,7 @@ use Drupal\monitoring\Result\SensorResultInterface;
use Drupal\monitoring\SensorPlugin\SensorPluginBase;
use Drupal;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Extension\ModuleExtensionList;
/**
* Monitors installed modules.
......@@ -93,7 +94,7 @@ class EnabledModulesSensorPlugin extends SensorPluginBase {
// result for 1 hour.
$modules = \Drupal::service('extension.list.module')->getList();
uasort($modules, 'system_sort_modules_by_info_name');
uasort($modules, [ModuleExtensionList::class, 'sortByName']);
$visible_modules = array();
$visible_default_value = array();
......@@ -102,7 +103,7 @@ class EnabledModulesSensorPlugin extends SensorPluginBase {
foreach ($modules as $module => $module_data) {
// Skip profiles.
if (strpos(drupal_get_path('module', $module), 'profiles') === 0) {
if (strpos(\Drupal::service('extension.list.module')->getPath($module), 'profiles') === 0) {
continue;
}
// As we also include hidden modules, some might have no name at all,
......@@ -184,7 +185,7 @@ class EnabledModulesSensorPlugin extends SensorPluginBase {
$monitoring_installed_modules = array();
// Filter out install profile.
foreach (array_keys(Drupal::moduleHandler()->getModuleList()) as $module) {
$path_parts = explode('/', drupal_get_path('module', $module));
$path_parts = explode('/', \Drupal::service('extension.list.module')->getPath($module));
if ($path_parts[0] != 'profiles') {
$monitoring_installed_modules[$module] = $module;
}
......
......@@ -103,6 +103,7 @@ class ImageMissingStyleSensorPlugin extends WatchdogAggregatorSensorPlugin {
$results[$key]['file'] = $variables['%source_image_path'];
$results[$key]['count'] = $row['records_count'];
$file = \Drupal::entityQuery('file')
->accessCheck(TRUE)
->condition('uri', $variables['%source_image_path'])
->execute();
if (!empty($file)) {
......
......@@ -118,7 +118,7 @@ class TemporaryFilesUsagesSensorPlugin extends DatabaseAggregatorSensorPlugin {
if (!empty($types)) {
// Delete the last unnecessary comma.
array_pop($types);
$filename = Link::fromTextAndUrl($file->getFilename(), Url::fromUri(file_create_url($file->getFileUri())));
$filename = Link::fromTextAndUrl($file->getFilename(), \Drupal::service('file_url_generator')->generate($file->getFileUri()));
$status = Link::createFromRoute('Make permanent', 'monitoring.make_file_permanent', [
'monitoring_sensor_config' => $this->sensorConfig->id(),
'file' => $fid
......@@ -127,7 +127,7 @@ class TemporaryFilesUsagesSensorPlugin extends DatabaseAggregatorSensorPlugin {
$rows[] = [
'fid' => $fid,
'filename' => $filename,
'usages' => render($types),
'usages' => \Drupal::service('renderer')->render($types),
'status' => $status,
];
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment