22185682504a566dfb3efab32e5023cde5a5c948
[yaffs-website] / web / core / modules / system / src / Tests / Update / DbUpdatesTrait.php
1 <?php
2
3 namespace Drupal\system\Tests\Update;
4
5 use Drupal\Core\StringTranslation\StringTranslationTrait;
6 use Drupal\Core\Url;
7
8 /**
9  * Provides methods to conditionally enable db update functions and apply
10  * pending db updates through the Update UI.
11  *
12  * This should be used only by classes extending \Drupal\simpletest\WebTestBase.
13  */
14 trait DbUpdatesTrait {
15
16   use StringTranslationTrait;
17
18   /**
19    * Enables db updates until the specified index.
20    *
21    * @param string $module
22    *   The name of the module defining the update functions.
23    * @param string $group
24    *   A name identifying the group of update functions to enable.
25    * @param $index
26    *   The index of the last update function to run.
27    */
28   protected function enableUpdates($module, $group, $index) {
29     $this->container->get('state')->set($module . '.db_updates.' . $group, $index);
30   }
31
32   /**
33    * Applies any pending DB updates through the Update UI.
34    */
35   protected function applyUpdates() {
36     $this->drupalGet(Url::fromRoute('system.db_update'));
37     $this->clickLink($this->t('Continue'));
38     $this->clickLink($this->t('Apply pending updates'));
39   }
40
41   /**
42    * Conditionally load Update API functions for the specified group.
43    *
44    * @param string $module
45    *   The name of the module defining the update functions.
46    * @param string $group
47    *   A name identifying the group of update functions to enable.
48    */
49   public static function includeUpdates($module, $group) {
50     if ($index = \Drupal::state()->get($module . '.db_updates.' . $group)) {
51       module_load_include('inc', $module, 'update/' . $group . '_' . $index);
52     }
53   }
54
55 }