eaudeweb/heavy-lifter

为您的 Drupal 项目提供的常用命令,助您快速上手


README

为本地 Drupal 开发承担重任。

安装

https://packagist.org.cn/packages/eaudeweb/heavy-lifter

Drupal 8

  • 使用 composer 安装 heavy-lifter: composer require eaudeweb/heavy-lifter

  • 执行 heavy-lifter 的配置脚本: ./vendor/bin/robo site:config

  • example.robo.yml 复制到 robo.yml,根据系统管理员提供的用户名和密码进行自定义

  • (可选) 您可以在 robo.yml 中为 heavy-lifter 的任何 robo 命令添加要排除的 drush 命令

示例

site:
    update:
         excluded_commands:
           - locale:check
           - yyy
  • (可选) 您可以在 robo.yml 中为 heavy-lifter 的任何 robo 命令添加额外的 drush 命令

示例

site:
    update:
         extra_commands:
           - locale:update
  • 执行 ./vendor/bin/robo sql:sync 以查看安装是否成功

Drupal 7

Drupal 7 上的安装指南与 Drupal 8 相同,只需注意以下几点

  • 并非所有可用的 robo 命令都适用于 Drupal 7 网站。(一些命令仅对 Drupal 8 网站可用,因此尚未在 Drupal 7 上实现/测试)

如何在项目中使用它

注意:您需要在项目的根目录中运行所有命令(即存储 web/ 文件夹的地方)。

  • example.robo.yml 复制到 robo.yml 并根据系统管理员提供的用户名和密码进行自定义

  • 获取数据库转储并导入: ./vendor/bin/robo sql:sync

  • 更新网站的配置和数据库: ./vendor/bin/robo site:update

  • 获取文件存档: ./vendor/bin/robo files:sync

  • 将文件目录的存档创建到指定的路径: /vendor/bin/robo files:dump [destination]

  • 启用开发模式: ./vendor/bin/robo site:develop

  • 从远程存储下载数据库转储,而不导入它: /vendor/bin/robo sql:download [destination]

自定义开发脚本

如果您想在 site:develop 命令的末尾运行自定义 drush 脚本,请将这些脚本添加到 PROJECT/etc/scripts/develop 文件夹中。

数据库匿名化

  1. 运行 composer require eaudeweb/gdpr-dump
  2. 在项目根目录(与 robo.yml 同一文件夹)中定义您的匿名化模式 schema.yml 文件
  3. 运行 ./vendor/bin/robo sql:dump --anonymize

ignored_values 下列出的行值将不会进行匿名化。

anonymize.schema.yml 示例

users_field_data:
  name:
    formatter: email
    exclude: # the rows that have these values will NOT be anonymized
      uid: [1, 76, 228, 81, 116, 117, 149, 393]
  telephone:
    formatter: phoneNumber
  mail:
    formatter: email
    unique: true
    exclude:
      uid: [1, 76, 228, 81, 116, 117, 149, 393]
    conditions_action: ignore
  pass:
    formatter: password
  preferred_admin_langcode:
    formatter: clear
table2:
  column1:
    formatter: randomText
    include: # only the rows that have these values will be anonymized
      name: ['Name to anonymize']
  rand_num
    formatter: randomNumber
    arguments: [6] # argument passed to the randomNumber() function from the Faker library, max 6 digits
taxonomy_term_field_revision:
  name:
    formatter: company
    include: # you can also use SELECT queries to define your list of included rows. The select query MUST only select ONE column
      tid: SELECT tid FROM taxonomy_term_field_data WHERE vid = "partners"
...

格式化类型

  • name - 生成一个名称
  • phoneNumber - 生成一个电话号码
  • username - 生成一个随机用户名
  • password - 生成一个随机密码
  • email - 生成一个随机电子邮件地址
  • date - 生成一个日期
  • longText - 生成一个句子
  • number - 生成一个数字
  • randomText - 生成一个句子
  • text - 生成一个段落
  • uri - 生成一个 URI
  • clear - 生成一个空字符串

有关可用的格式化程序的更多信息,请参阅 https://github.com/fzaninotto/Faker#formatters

Windows 环境的观察

  • 仅可用命令 sql:dump
  • robo 路径为 ./vendor/consolidation/robo/robo

多站点

对于多站点,在 robo.yml 中的 sites 下创建另一个密钥,并按照 sites:default 进行配置。

要在子站点上运行命令,使用 --site SITE 参数。

示例

robo.yml

sites:
  default:
    ...
  subsite:
    ...

./vendor/bin/robo sql:sync --site subsite