Skip to content
Snippets Groups Projects

Issue #3271144: Ensure new, changed or deleted service definitions are in the correct state after an update

Merged Issue #3271144: Ensure new, changed or deleted service definitions are in the correct state after an update
All threads resolved!
All threads resolved!
2 files
+ 12
46
Compare changes
  • Side-by-side
  • Inline
Files
2
@@ -45,27 +45,6 @@ class SystemChangeRecorder implements EventSubscriberInterface {
@@ -45,27 +45,6 @@ class SystemChangeRecorder implements EventSubscriberInterface {
*/
*/
private $permissionHandler;
private $permissionHandler;
/**
* A generic service which is different before and after the update.
*
* @var \stdClass
*/
private $existingService;
/**
* A generic service which was added in the newly updated module.
*
* @var \stdClass
*/
private $addedService;
/**
* A generic service which was deleted from the newly updated module.
*
* @var \stdClass
*/
private $deletedService;
/**
/**
* Constructs a SystemChangeRecorder object.
* Constructs a SystemChangeRecorder object.
*
*
@@ -77,23 +56,12 @@ class SystemChangeRecorder implements EventSubscriberInterface {
@@ -77,23 +56,12 @@ class SystemChangeRecorder implements EventSubscriberInterface {
* The router service.
* The router service.
* @param \Drupal\user\PermissionHandlerInterface $permission_handler
* @param \Drupal\user\PermissionHandlerInterface $permission_handler
* The permission handler service.
* The permission handler service.
* @param \stdClass $existing_service
* A generic service which will be different after the update.
* @param \stdClass|null $added_service
* A generic service which was added in the newly updated module, or NULL
* if it is not defined.
* @param \stdClass|null $deleted_service
* A generic service which was deleted from the newly updated module, or
* NULL if it is not defined.
*/
*/
public function __construct(PathLocator $path_locator, StateInterface $state, RouterInterface $router, PermissionHandlerInterface $permission_handler, \stdClass $existing_service, ?\stdClass $added_service, ?\stdClass $deleted_service) {
public function __construct(PathLocator $path_locator, StateInterface $state, RouterInterface $router, PermissionHandlerInterface $permission_handler) {
$this->pathLocator = $path_locator;
$this->pathLocator = $path_locator;
$this->state = $state;
$this->state = $state;
$this->router = $router;
$this->router = $router;
$this->permissionHandler = $permission_handler;
$this->permissionHandler = $permission_handler;
$this->existingService = $existing_service;
$this->addedService = $added_service;
$this->deletedService = $deleted_service;
}
}
/**
/**
@@ -129,22 +97,27 @@ class SystemChangeRecorder implements EventSubscriberInterface {
@@ -129,22 +97,27 @@ class SystemChangeRecorder implements EventSubscriberInterface {
// Check if a permission added in the updated module is available.
// Check if a permission added in the updated module is available.
$results['new permission exists'] = array_key_exists('added permission', $permissions) ? 'exists' : 'not exists';
$results['new permission exists'] = array_key_exists('added permission', $permissions) ? 'exists' : 'not exists';
// Check if changes to an existing service are picked up.
// Check if changes to an existing service are picked up. The service itself
$results['value of existing service'] = $this->existingService->value;
// is defined in updated_module, which is not, and should not be, a hard
 
// dependency of package_manager_test_api. So, we use ::hasService() to
 
// prevent an exception if updated_module is not installed.
 
if (\Drupal::hasService('updated_module.existing_service')) {
 
$results['value of existing service'] = \Drupal::service('updated_module.existing_service')->value;
 
}
// Check if a service removed from the updated module is available.
// Check if a service removed from the updated module is available.
if ($this->deletedService) {
if (\Drupal::service('updated_module.deleted_service')) {
$results['deleted service exists'] = 'exists';
$results['deleted service exists'] = 'exists';
$results['value of deleted service'] = $this->deletedService->value;
$results['value of deleted service'] = \Drupal::service('updated_module.deleted_service')->value;
}
}
else {
else {
$results['deleted service exists'] = 'not exists';
$results['deleted service exists'] = 'not exists';
}
}
// Check if a service added in the updated module is available.
// Check if a service added in the updated module is available.
if ($this->addedService) {
if (\Drupal::hasService('updated_module.added_service')) {
$results['new service exists'] = 'exists';
$results['new service exists'] = 'exists';
$results['value of added service'] = $this->addedService->value;
$results['value of added service'] = \Drupal::service('updated_module.added_service')->value;
}
}
else {
else {
$results['new service exists'] = 'not exists';
$results['new service exists'] = 'not exists';
Loading