jfhovinne / updater
Drush命令,用于自动化Drupal实例的更新
Requires
- composer/installers: ~1.0
- danielstjules/stringy: ~3.1.0
Requires (Dev)
- drupal/coder: 8.2.8
- drush/drush: ^8.1||^9
- phpro/grumphp: ^0.14
- phpunit/phpunit: ^5.7||^6.5||^7.3
- squizlabs/php_codesniffer: ~2.9
This package is not auto-updated.
Last update: 2020-02-21 17:55:24 UTC
README
一个Drush命令,通过执行可用的"updaters"来更新网站实例。
updater是执行Drush update-website
命令期间执行的PHP函数。Drush命令会跟踪已执行的updater,因此它们不会在同一个Drupal实例上重复执行。
Updaters可以访问常用的Drupal API和其他Drush命令。
当您想测试和自动化您的更新和部署时,这很有用,例如在开发新功能之后,因为updater是简单的PHP脚本,可以被包含在您的功能分支中。
示例用法包括将网站置于维护模式、启用模块、创建分类术语、发布页面,并将网站重新上线。
代码轻量级,可以很好地集成到持续集成/持续部署工作流程中。它是现有Drupal更新/部署工具的替代品,因为它不需要创建模块,并且已经兼容Drupal 7和8。
drupal.org上的项目页面:Updater
安装
使用Composer(推荐)
从网站根目录
composer require jfhovinne/updater
如果您使用Drush 8,命令应该会自动注册。如果您使用Drush 9,可能需要将drush/contrib/updater
符号链接到modules/updater
,并执行drush en -y updater
以注册命令。
使用Drush 8
drush dl updater
cd /path/to/updater
composer install --no-dev
用法
drush update-website --path=/path/to/my/updaters
在上面的示例中,drush update-website
命令将在/path/to/my/updaters
目录中搜索updater。它将搜索以updater-
开头并以.php
结尾的文件,然后搜索具有相同名称的函数,并在末尾添加_update
。
文件名按字母顺序排序,因此updater-0001-test.php
将在updater-0002-another-test.php
之前被加载并执行。每个文件只有一个updater,但每个文件可以包含其他PHP函数。
默认的搜索updater路径是{DRUPAL_ROOT}/sites/all/drush/updaters
。
您还可以指向特定的updater文件,例如
drush update-website --path=/path/to/my/updaters/updater-0001-test.php
示例
如果文件/path/to/my/updaters/updater-0001-test.php
包含函数updater_0001_test_update
,则将执行此函数。
<?php function updater_0001_test_update() { // Create the webmaster role and assign it the 'administer nodes' permission drush_invoke_process('@self', 'role-create', array('webmaster')); drush_invoke_process('@self', 'role-add-perm', array('webmaster', 'administer nodes')); }
如果文件/path/to/my/updaters/updater-0002-another-test.php
包含函数updater_0002_another_test_update
,则将执行此函数。
<?php function updater_0002_another_test_update() { // Drupal 7 only // Put the site in maintenance mode, add terms to the Tags vocabulary // then disable the maintenance mode drush_invoke_process('@self', 'vset', array('maintenance_mode', '1')); $vocab = taxonomy_vocabulary_machine_name_load('tags'); $values = array( 'module', 'theme', 'distribution' ); foreach($values as $value) { $term = (object) array( 'name' => $value, 'vid' => $vocab->vid, ); taxonomy_term_save($term); } drush_invoke_process('@self', 'vset', array('maintenance_mode', '0')); }
如果您想测试updater而不将其设置为已执行,则更新函数应返回FALSE。
<?php function updater_0003_testing_update() { drush_invoke_process('@self', 'cset', array( 'system.site', 'page.front', '/node/1', )); return FALSE; }