跳转到主要内容
首页

用户帐户菜单

  • 登录

主导航

  • 首页
  • 小公司运营
  • 网站建设
  • 创业杂谈
  • 兼职赚钱
  • 小微企业信息化
  • 手册教程
    • 《大伟哥的Drupal 8建站指南》
    • 《通过JohnChow.Com在网上赚钱》
  • 关于

面包屑

  • 首页
  • 使用Composer给Drupal打Patch补丁

使用Composer给Drupal打Patch补丁

By 大伟哥 | 2020-06-23,周二, 10:58

使用Composer可以方便地管理Drupal核心版本和模块版本的更新,那如果是已经有Drupal的补丁解决了你急需要解决的问题,而Drupal核心团队或者模块作者还没来得及或者压根不想把补丁打包进新的版本呢?使用Composer追求自动化的你一定不想在Composer每次更新版本之后,还要再次手动给Drupal打补丁。既然用了Composer,那就让Composer全部代劳吧,连补丁一块儿。

要想让Composer干好这活, 得给它额外安装个工具,叫composer-patches。安装很简单,在项目根目录里require一下就行了:

composer require cweagans/composer-patches

然后在项目的composer.json文件的extra部分,定义需要使用的补丁,格式如下:

"extra": {
    "enable-patching": true,
    "patches": {
        "drupal/core": {
            "patch1 information": "patch1 file path",
            "patch2 information": "patch2 file path"
        },
        "drupal/module_name": {
            "patch information": "patch file path"
        }
     },
}

其中,Drupal核心模块的补丁定义在drupal/core部分,其他模块的补丁定义在相关模块drupal/module_name部分,patch1 information可以填写补丁的相关信息和作用,patch file path是补丁文件的网址。

下面是一个给模块Menu token打补丁的示例:

        "patches":{
         "drupal/menu_token":{
            "get the right url path for a views page":"https://www.drupal.org/files/issues/2020-05-03/menu_token_2921178_27_route-resolved-links.patch"
               }
            },

保存好composer.json文件以后,需要再运行composer install命令来打上补丁:

composer install
Gathering patches for root package.
Removing package drupal/menu_token so that it can be re-installed and re-patched.
  - Removing drupal/menu_token (1.0.0-alpha3)
Deleting web/modules/contrib/menu_token - deleted
Loading composer repositories with package information
Installing dependencies (including require-dev) from lock file
Warning: The lock file is not up to date with the latest changes in composer.json. 
You may be getting outdated dependencies. It is recommended that you run 
`composer update` or `composer update <package name>`.
Package operations: 1 install, 0 updates, 0 removals
Gathering patches for root package.
Gathering patches for dependencies. This might take a minute.
  - Installing drupal/menu_token (1.0.0-alpha3): Loading from cache
  - Applying patches for drupal/menu_token
    https://www.drupal.org/files/issues/2020-05-03/menu_token_2921178_27_route-
resolved-links.patch (get the right url path for a views page)

Package container-interop/container-interop is abandoned, you should avoid using it. 
Use psr/container instead.
Generating autoload files
28 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
  * Homepage: https://www.drupal.org/project/drupal
  * Support:
    * docs: https://www.drupal.org/docs/user_guide/en/index.html
    * chat: https://www.drupal.org/node/314178

从上面的输出来看,composer先是卸载了已经安装的menu token模块,又重新安装它,然后再在新安装的模块上打上了补丁。

这时候清除Drupal的缓存以后再打开网站的相应页面,已经可以确定补丁生效了。但是还没完,我们需要再运行composer update --lock命令,来更新composer.lock文件:

composer update --lock
Gathering patches for root package.
Loading composer repositories with package information
Updating dependencies (including require-dev)
Nothing to install or update
Writing lock file
Generating autoload files
28 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
网站建设
  • 678 阅读
Drupal
Composer

Book traversal links for 使用Composer给Drupal打Patch补丁

  • ‹ 使用Composer接管以前手动安装的Drupal网站
  • 向上
  • Composer:PHP error: “The zip extension and unzip command are both missing, skipping.” ›

添加新评论

此字段内容将保密,不会被其他人看见。
关于文本格式
  • 不允许使用HTML标签。
CAPTCHA
1 + 14 =
计算出这道简单的算术题并键入答案。例如、1+3,就输入 4。
发布评论前,请通过下面的验证,以免被当作垃圾评论机器人屏蔽。

搜索

手册导航

  • 网站本地测试开发要尽量使用linux环境
  • Ubuntu Server 16.04安装LAMP网络服务器套件
  • 在测试机上配置Apache服务器下的第一个虚拟主机
  • 在测试服务器上安装第一个Drupal网站
  • Drupal 8/9安装及配置中文语言包
  • Ubuntu Server下启用Apache Rewrite模块
  • drupal 8小版本间升级详细说明
  • Drupal 8多站点实现:使用一套Drupal代码运行多个不同网站
  • Drupal 8网站迁移的步骤和注意事项
  • Drupal 8设置信任主机
  • 安装Drupal 8后除了首页外全是not found
  • Drupal 8解决5次输入密码暂时锁定帐号登录
  • 使用Drupal的SMTP模块发送邮件
  • Drupal怎么进行分类和创建栏目?
  • 使用composer安装Drupal及管理依赖(一)
    • 使用www-data用户运行Composer
    • 使用Composer的drupal/recommended-project默认模版下载Drupal核心文件
    • 使用Composer下载和安装Drupal的命令行工具Drush
    • 使用Composer接管以前手动安装的Drupal网站
    • 使用Composer给Drupal打Patch补丁
    • Composer:PHP error: “The zip extension and unzip command are both missing, skipping.”
    • Composer: Could not delete web/sites/default/default.settings.php
  • 新安装的Drupal 8默认能实现什么功能?
  • 给Drupal8/9网站添加基本页面
  • 让Drupal 8/9显示内容最近编辑时间
  • 给Drupal安装后台搜索服务xunsearch
  • Drupal 8/9 让某个字段仅对注册登录用户显示
  • Drupal Commerce 电子商务方案指南

沪ICP备17000093号-1

公安备案沪公网安备 31011402008254号

© 2016-2022 大伟哥博客版权所有