You are here

trait DbUpdatesTrait in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/system/src/Tests/Update/DbUpdatesTrait.php \Drupal\system\Tests\Update\DbUpdatesTrait

Provides methods to conditionally enable db update functions and apply pending db updates through the Update UI.

This should be used only by classes extending \Drupal\simpletest\WebTestBase.

Hierarchy

2 files declare their use of DbUpdatesTrait
entity_test.install in core/modules/system/tests/modules/entity_test/entity_test.install
Install, update and uninstall functions for the entity_test module.
UpdateApiEntityDefinitionUpdateTest.php in core/modules/system/src/Tests/Entity/Update/UpdateApiEntityDefinitionUpdateTest.php
Contains \Drupal\system\Tests\Entity\Update\UpdateApiEntityDefinitionUpdateTest.

File

core/modules/system/src/Tests/Update/DbUpdatesTrait.php, line 19
Contains \Drupal\system\Tests\Update\DbUpdatesTrait.

Namespace

Drupal\system\Tests\Update
View source
trait DbUpdatesTrait {
  use StringTranslationTrait;

  /**
   * Enables db updates until the specified index.
   *
   * @param string $module
   *   The name of the module defining the update functions.
   * @param string $group
   *   A name identifying the group of update functions to enable.
   * @param $index
   *   The index of the last update function to run.
   */
  protected function enableUpdates($module, $group, $index) {
    $this->container
      ->get('state')
      ->set($module . '.db_updates.' . $group, $index);
  }

  /**
   * Applies any pending DB updates through the Update UI.
   */
  protected function applyUpdates() {
    $this
      ->drupalGet(Url::fromRoute('system.db_update'));
    $this
      ->clickLink($this
      ->t('Continue'));
    $this
      ->clickLink($this
      ->t('Apply pending updates'));
  }

  /**
   * Conditionally load Update API functions for the specified group.
   *
   * @param string $module
   *   The name of the module defining the update functions.
   * @param string $group
   *   A name identifying the group of update functions to enable.
   */
  public static function includeUpdates($module, $group) {
    if ($index = \Drupal::state()
      ->get($module . '.db_updates.' . $group)) {
      module_load_include('inc', $module, 'update/' . $group . '_' . $index);
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DbUpdatesTrait::applyUpdates protected function Applies any pending DB updates through the Update UI.
DbUpdatesTrait::enableUpdates protected function Enables db updates until the specified index.
DbUpdatesTrait::includeUpdates public static function Conditionally load Update API functions for the specified group.
StringTranslationTrait::$stringTranslation protected property The string translation service.
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.