Skip to content
Snippets Groups Projects
Commit 7b581aa3 authored by Kunal Sachdev's avatar Kunal Sachdev Committed by Adam G-H
Browse files

Issue #3311534 by kunal.sachdev, phenaproxima, TravisCarden:...

Issue #3311534 by kunal.sachdev, phenaproxima, TravisCarden: package_manager_requirements() should check for the presence of the failure marker
parent 6f418d1f
No related branches found
No related tags found
No related merge requests found
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
* Contains install and update functions for Package Manager. * Contains install and update functions for Package Manager.
*/ */
use Drupal\package_manager\Exception\ApplyFailedException;
/** /**
* Implements hook_requirements(). * Implements hook_requirements().
*/ */
...@@ -25,5 +27,22 @@ function package_manager_requirements(string $phase) { ...@@ -25,5 +27,22 @@ function package_manager_requirements(string $phase) {
'severity' => REQUIREMENT_WARNING, 'severity' => REQUIREMENT_WARNING,
]; ];
} }
// If we're able to check for the presence of the failure marker at all, do it
// irrespective of the current run phase. If the failure marker is there, the
// site is in an indeterminate state and should be restored from backup ASAP.
$service_id = 'package_manager.failure_marker';
if (\Drupal::hasService($service_id)) {
try {
\Drupal::service($service_id)->assertNotExists();
}
catch (ApplyFailedException $exception) {
$requirements['package_manager_failure_marker'] = [
'title' => t('Failed update detected'),
'description' => $exception->getMessage(),
'severity' => REQUIREMENT_ERROR,
];
}
}
return $requirements; return $requirements;
} }
<?php
namespace Drupal\Tests\package_manager\Functional;
use Drupal\package_manager\Stage;
use Drupal\Tests\BrowserTestBase;
/**
* Tests that Package Manager's requirements check for the failure marker.
*
* @group package_manager
*/
class FailureMarkerRequirementTest extends BrowserTestBase {
/**
* {@inheritdoc}
*/
protected static $modules = [
'package_manager',
'package_manager_bypass',
];
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* Tests that error is shown if failure marker already exists.
*/
public function testFailureMarkerExists() {
$account = $this->drupalCreateUser([
'administer site configuration',
]);
$this->drupalLogin($account);
$this->container->get('package_manager.path_locator')
->setPaths($this->publicFilesDirectory, NULL, NULL, NULL);
$failure_marker = $this->container->get('package_manager.failure_marker');
$message = 'Package Manager is here to wreck your day.';
$failure_marker->write($this->createMock(Stage::class), $message);
$path = $failure_marker->getPath();
$this->assertFileExists($path);
$this->assertStringStartsWith($this->publicFilesDirectory, $path);
$this->drupalGet('/admin/reports/status');
$assert_session = $this->assertSession();
$assert_session->pageTextContains('Failed update detected');
$assert_session->pageTextContains($message);
}
}
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