diff --git a/core/modules/rest/rest.install b/core/modules/rest/rest.install index 1bfa778..601206d 100644 --- a/core/modules/rest/rest.install +++ b/core/modules/rest/rest.install @@ -5,9 +5,6 @@ * Install, update and uninstall functions for the rest module. */ -use Drupal\rest\Entity\RestResourceConfig; -use Drupal\rest\RestResourceConfigInterface; - /** * Implements hook_requirements(). */ @@ -26,26 +23,17 @@ function rest_requirements($phase) { } /** - * @defgroup updates-8.1.x-to-8.2.x Updates from 8.1.x to 8.2.x + * @defgroup updates-8.1.x-to-8.2.x * @{ * Update functions from 8.1.x to 8.2.x. */ /** - * Install the REST config entity type and convert old settings-based config. - * - * @todo Automatically upgrade those REST resource config entities that have the same formats/auth mechanisms for all methods to "granular: resource" in https://www.drupal.org/node/2721595. + * Install the REST config entity type and fix old settings-based config. */ function rest_update_8201() { \Drupal::entityDefinitionUpdateManager()->installEntityType(\Drupal::entityTypeManager()->getDefinition('rest_resource_config')); - foreach (\Drupal::config('rest.settings')->get('resources') as $key => $resource) { - $resource = RestResourceConfig::create([ - 'id' => str_replace(':', '.', $key), - 'granularity' => RestResourceConfigInterface::METHOD_GRANULARITY, - 'configuration' => $resource, - ]); - $resource->save(); - } + \Drupal::state()->set('rest_update_8201_resources', \Drupal::config('rest.settings')->get('resources')); \Drupal::configFactory()->getEditable('rest.settings') ->clear('resources') ->save(); diff --git a/core/modules/rest/rest.post_update.php b/core/modules/rest/rest.post_update.php new file mode 100644 index 0000000..7068662 --- /dev/null +++ b/core/modules/rest/rest.post_update.php @@ -0,0 +1,39 @@ +get('rest_update_8201_resources', []); + foreach ($resources as $key => $resource) { + $resource = RestResourceConfig::create([ + 'id' => str_replace(':', '.', $key), + 'granularity' => RestResourceConfigInterface::METHOD_GRANULARITY, + 'configuration' => $resource, + ]); + $resource->save(); + } +} + +/** + * @} End of "addtogroup updates-8.1.x-to-8.2.x". + */ diff --git a/core/modules/rest/src/Tests/Update/RestConfigurationEntitiesUpdateTest.php b/core/modules/rest/src/Tests/Update/RestConfigurationEntitiesUpdateTest.php index 11f40c7..9100f16 100644 --- a/core/modules/rest/src/Tests/Update/RestConfigurationEntitiesUpdateTest.php +++ b/core/modules/rest/src/Tests/Update/RestConfigurationEntitiesUpdateTest.php @@ -57,6 +57,7 @@ public function testResourcesConvertedToConfigEntities() { $node_resource_config_entity = $resource_config_entities['entity.node']; $this->assertIdentical(RestResourceConfigInterface::METHOD_GRANULARITY, $node_resource_config_entity->get('granularity')); $this->assertIdentical($node_configuration, $node_resource_config_entity->get('configuration')); + $this->assertIdentical(['module' => ['basic_auth', 'node', 'serialization']], $node_resource_config_entity->getDependencies()); } } diff --git a/core/modules/rest/tests/fixtures/update/drupal-8.rest-rest_update_8201.php b/core/modules/rest/tests/fixtures/update/drupal-8.rest-rest_update_8201.php index f035e94..72a143b 100644 --- a/core/modules/rest/tests/fixtures/update/drupal-8.rest-rest_update_8201.php +++ b/core/modules/rest/tests/fixtures/update/drupal-8.rest-rest_update_8201.php @@ -22,6 +22,11 @@ 'name' => 'serialization', 'value' => 'i:8000;', ]) + ->fields([ + 'collection' => 'system.schema', + 'name' => 'basic_auth', + 'value' => 'i:8000;', + ]) ->execute(); // Update core.extension. @@ -32,6 +37,7 @@ ->execute() ->fetchField(); $extensions = unserialize($extensions); +$extensions['module']['basic_auth'] = 8000; $extensions['module']['rest'] = 8000; $extensions['module']['serialization'] = 8000; $connection->update('config') @@ -48,7 +54,7 @@ 'entity:node' => [ 'GET' => [ 'supported_formats' => ['json'], - 'supported_auth' => [], + 'supported_auth' => ['basic_auth'], ], ], ],