跳转到主要内容
首页

用户帐户菜单

  • 登录

主导航

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

面包屑

  • 首页
  • Drupal 清理卸载模块遗留的无效权限 Invalid permissions

Drupal 清理卸载模块遗留的无效权限 Invalid permissions

By 大伟哥 | 2023-07-28,周五, 09:16

从 Drupal 9 升级到 Drupal 10 有可能会碰到很多问题,大伟哥就碰到了这么一个情况,在运行 upgrade status 的时候,有一条错误提示是这样的:

Invalid permissions will trigger runtime exceptions in Drupal 10. Permissions should be defined in a permissions.yml file or a permission callback.
Permissions of user role: "注册用户": view own userpoints_default_points transaction 

这是因为在 Drupal 9.3 以后,所有的用户角色权限都要在permissions.yml文件或者permission callback, 其他的权限定义方法都被视为无效的了。这些无效的权限设置包括已那些已经卸载模块里没有删除干净的权限、依赖于已删除的配置(如内容类型)的权限以及来源不明的权限。在升级到 Drupal 9.3以后,保存含有无效的角色权限,会导致出错。在升级到 Drupal 10 之后会抛出运时时异常。

我这种情况,就是在删除了user points 模块之后,用户的权限设置数据没有随着模块一起删除,遗留下来的一个非法权限设定。

那怎么解决呢?

网上搜索到的思路,是先导出权限配置文件,删除掉相应的权限设置这后,再重新导入进来。

 www-data@debian12:~/html/canyinqiao.local$ ./vendor/drush/drush/drush config:export 
[notice] Differences of the active config to the export directory: 
+------------+---------------------------------------------------------------------+-----------+ 
| Collection | Config                                                              | Operation | 
+------------+---------------------------------------------------------------------+-----------+ 
|            | block_content.type.basic                                            | Create    | 
|            | book.settings                                                       | Create    | 
|            | block.block.claro_secondary_local_tasks                             | Create    | 
|            | block.block.claro_primary_local_tasks                               | Create    | 
|            | block.block.claro_page_title                                        | Create    | 
|            | block.block.claro_local_actions                                     | Create    | 
|            | claro.settings                                                      | Create    | 
|            | comment.settings                                                    | Create    | 
|            | comment.type.comment                                                | Create    |
 The .yml files in your export directory (sites/default/files/config_xDqcU2ISVOvS7G9eP0WCuvTo-sG8Uqj_PcEFGW6QB1DFdYbBj7YMr77UozF0dS_d4yLubl3a6w/sync) will be deleted and replaced with the active config. (yes/no) [yes]: 
> yes
 [success] Configuration successfully exported to sites/default/files/config_xDqcU2ISVOvS7G9eP0WCuvTo-sG8Uqj_PcEFGW6QB1DFdYbBj7YMr77UozF0dS_d4yLubl3a6w/sync. 
sites/default/files/config_xDqcU2ISVOvS7G9eP0WCuvTo-sG8Uqj_PcEFGW6QB1DFdYbBj7YMr77UozF0dS_d4yLubl3a6w/sync

在这个目录里找到vim user.role.authenticated.yml文件,打开它,会看到permissions里面有一项,就是没有清除干净的view own userpoints_default_points transaction。我们删除这一行,保存。然后再想导入回去试试看。

www-data@debian12:~/html/canyinqiao.local$ ./vendor/drush/drush/drush config:import --source=/var/www/html/canyinqiao.local/web/sites/default/files/config_xDqcU2ISVOvS7G9eP0WCuvTo-sG8Uqj_PcEFGW6QB1DFdYbBj7YMr77UozF0dS_d4yLubl3a6w/sync/
+------------+-------------------------+-----------+
| Collection | Config                  | Operation |
+------------+-------------------------+-----------+
|            | user.role.authenticated | Update    |
+------------+-------------------------+-----------+
Import the listed configuration changes? (yes/no) [yes]:
> yes
[notice] 正在同步配置:update user.role.authenticated。
[notice] 正在完成配置同步。
[success] The configuration was imported successfully.

 现在再回去查看 upgrade status 的时候,就找不到这方面的错误了。

大伟哥的网站里就只有这一条权限方面的问题影响升级到 Drupal 10. 如果你的非法权限有很多条需要清除,还可以使用drush 脚本的形式去解决,详细代码可以参考 Drupal 官网这篇文档:Permissions must exist

网站建设
  • 114 阅读
Drupal
Drush

添加新评论

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

搜索

沪ICP备17000093号-1

公安备案沪公网安备 31011402008254号

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