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