23、Drupal 模块部署与更新全攻略

23、Drupal 模块部署与更新全攻略

Drupal 模块部署与更新全攻略

1. 模块卸载与准备交付

在模块卸载时,如果在安装阶段通过 Field 模块向数据库表中添加了附加字段,卸载钩子函数需要删除这些字段以清除所有相关信息。示例代码如下:

field_delete_field('field_weather_unit'); // Flush the cache to get rid of the user profile page entry drupal_flush_all_caches();

需要注意的是,如果使用 schema 钩子创建了表,卸载引擎会自动处理这些表的删除,无需手动操作。

在交付模块之前,需要将.install文件添加到.info文件中,让 Drupal 知晓该文件。以下是一个新的.info文件示例:

; $Id$ name = Weather information description = A block that shows current weather for a particular location. package = Cool stuff from Brian core = 7.x files[] = weather_info.module files[] = weather_info.inc files[] = weather_info.install files[] = tests/weather_inf