diff options
Diffstat (limited to 'core/modules/jsonapi')
3 files changed, 105 insertions, 3 deletions
diff --git a/core/modules/jsonapi/jsonapi.install b/core/modules/jsonapi/jsonapi.install index 36bc4f021105..a1ada646df33 100644 --- a/core/modules/jsonapi/jsonapi.install +++ b/core/modules/jsonapi/jsonapi.install @@ -77,8 +77,11 @@ function jsonapi_requirements($phase) { } /** - * Implements hook_update_last_removed(). + * Enable BC: default the new read-only mode to "off" on existing sites. */ -function jsonapi_update_last_removed() { - return 8701; +function jsonapi_update_8701() { + $config_factory = \Drupal::configFactory(); + $jsonapi_settings = $config_factory->getEditable('jsonapi.settings'); + $jsonapi_settings->set('read_only', FALSE) + ->save(TRUE); } diff --git a/core/modules/jsonapi/tests/fixtures/update/drupal-8.jsonapi-jsonapi_update_8701.php b/core/modules/jsonapi/tests/fixtures/update/drupal-8.jsonapi-jsonapi_update_8701.php new file mode 100644 index 000000000000..783c57b9c10e --- /dev/null +++ b/core/modules/jsonapi/tests/fixtures/update/drupal-8.jsonapi-jsonapi_update_8701.php @@ -0,0 +1,49 @@ +<?php + +/** + * @file + * Contains database additions for testing jsonapi_update_8701()'s update path. + * + * @depends core/modules/system/tests/fixtures/update/drupal-8.bare.standard.php.gz + */ + +use Drupal\Core\Database\Database; + +$connection = Database::getConnection(); + +// Set the schema version. +$connection->insert('key_value') + ->fields([ + 'collection', + 'name', + 'value', + ]) + ->values([ + 'collection' => 'system.schema', + 'name' => 'serialization', + 'value' => 'i:8401;', + ]) + ->values([ + 'collection' => 'system.schema', + 'name' => 'jsonapi', + 'value' => 'i:8000;', + ]) + ->execute(); + +// Update core.extension. +$extensions = $connection->select('config') + ->fields('config', ['data']) + ->condition('collection', '') + ->condition('name', 'core.extension') + ->execute() + ->fetchField(); +$extensions = unserialize($extensions); +$extensions['module']['serialization'] = 0; +$extensions['module']['jsonapi'] = 0; +$connection->update('config') + ->fields([ + 'data' => serialize($extensions), + ]) + ->condition('collection', '') + ->condition('name', 'core.extension') + ->execute(); diff --git a/core/modules/jsonapi/tests/src/Functional/Update/ReadOnlyModeUpdateTest.php b/core/modules/jsonapi/tests/src/Functional/Update/ReadOnlyModeUpdateTest.php new file mode 100644 index 000000000000..dabc0df37e7d --- /dev/null +++ b/core/modules/jsonapi/tests/src/Functional/Update/ReadOnlyModeUpdateTest.php @@ -0,0 +1,50 @@ +<?php + +namespace Drupal\Tests\jsonapi\Functional\Update; + +use Drupal\FunctionalTests\Update\UpdatePathTestBase; + +/** + * Tests that existing sites have the new read-only mode to "off". + * + * @see jsonapi_update_8701() + * @see https://www.drupal.org/project/jsonapi/issues/3039568 + * + * @group jsonapi + * @group Update + * @group legacy + */ +class ReadOnlyModeUpdateTest extends UpdatePathTestBase { + + /** + * {@inheritdoc} + */ + protected static $modules = ['jsonapi']; + + /** + * {@inheritdoc} + */ + public function setDatabaseDumpFiles() { + $this->databaseDumpFiles = [ + DRUPAL_ROOT . '/core/modules/system/tests/fixtures/update/drupal-8.bare.standard.php.gz', + __DIR__ . '/../../../fixtures/update/drupal-8.jsonapi-jsonapi_update_8701.php', + ]; + } + + /** + * Tests jsonapi_update_8701(). + */ + public function testBcReadOnlyModeSettingAdded() { + // Make sure we have the expected values before the update. + $jsonapi_settings = $this->config('jsonapi.settings'); + $this->assertFalse(array_key_exists('read_only', $jsonapi_settings->getRawData())); + + $this->runUpdates(); + + // Make sure we have the expected values after the update. + $jsonapi_settings = $this->config('jsonapi.settings'); + $this->assertTrue(array_key_exists('read_only', $jsonapi_settings->getRawData())); + $this->assertFalse($jsonapi_settings->get('read_only')); + } + +} |