annotate core/modules/system/src/Tests/Update/DbUpdatesTrait.php @ 19:fa3358dc1485 tip

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents 4c8ae668cc8c
children
rev   line source
Chris@0 1 <?php
Chris@0 2
Chris@0 3 namespace Drupal\system\Tests\Update;
Chris@0 4
Chris@0 5 @trigger_error(__NAMESPACE__ . '\DbUpdatesTrait is deprecated in Drupal 8.4.0 and will be removed before Drupal 9.0.0. Use \Drupal\FunctionalTests\Update\DbUpdatesTrait instead. See https://www.drupal.org/node/2896640.', E_USER_DEPRECATED);
Chris@0 6
Chris@0 7 use Drupal\Core\StringTranslation\StringTranslationTrait;
Chris@0 8 use Drupal\Core\Url;
Chris@0 9
Chris@0 10 /**
Chris@0 11 * Provides methods to conditionally enable db update functions and apply
Chris@0 12 * pending db updates through the Update UI.
Chris@0 13 *
Chris@0 14 * This should be used only by classes extending \Drupal\simpletest\WebTestBase.
Chris@0 15 *
Chris@0 16 * @deprecated in Drupal 8.4.0 and will be removed before Drupal 9.0.0.
Chris@0 17 * Use \Drupal\FunctionalTests\Update\DbUpdatesTrait.
Chris@0 18 * @see https://www.drupal.org/node/2896640
Chris@0 19 */
Chris@0 20 trait DbUpdatesTrait {
Chris@0 21
Chris@0 22 use StringTranslationTrait;
Chris@0 23
Chris@0 24 /**
Chris@0 25 * Enables db updates until the specified index.
Chris@0 26 *
Chris@0 27 * @param string $module
Chris@0 28 * The name of the module defining the update functions.
Chris@0 29 * @param string $group
Chris@0 30 * A name identifying the group of update functions to enable.
Chris@0 31 * @param $index
Chris@0 32 * The index of the last update function to run.
Chris@0 33 */
Chris@0 34 protected function enableUpdates($module, $group, $index) {
Chris@0 35 $this->container->get('state')->set($module . '.db_updates.' . $group, $index);
Chris@0 36 }
Chris@0 37
Chris@0 38 /**
Chris@0 39 * Applies any pending DB updates through the Update UI.
Chris@0 40 */
Chris@0 41 protected function applyUpdates() {
Chris@0 42 $this->drupalGet(Url::fromRoute('system.db_update'));
Chris@0 43 $this->clickLink($this->t('Continue'));
Chris@0 44 $this->clickLink($this->t('Apply pending updates'));
Chris@0 45 }
Chris@0 46
Chris@0 47 /**
Chris@0 48 * Conditionally load Update API functions for the specified group.
Chris@0 49 *
Chris@0 50 * @param string $module
Chris@0 51 * The name of the module defining the update functions.
Chris@0 52 * @param string $group
Chris@0 53 * A name identifying the group of update functions to enable.
Chris@0 54 */
Chris@0 55 public static function includeUpdates($module, $group) {
Chris@0 56 if ($index = \Drupal::state()->get($module . '.db_updates.' . $group)) {
Chris@0 57 module_load_include('inc', $module, 'update/' . $group . '_' . $index);
Chris@0 58 }
Chris@0 59 }
Chris@0 60
Chris@0 61 }