我認爲一個好的策略是使用安裝配置文件API。使用安裝配置文件API,您可以使用Drupal管理工具執行大部分操作。大多數核心形式只是在變量表中設置變量。爲了能夠明智地版本化您的非內容數據庫內容即配置使用更新功能是明智的。
在我的網站上,我們有模塊「ec」,除了它的ec.install文件包含更新功能, ec_update_6001()
您的主要安裝功能可以負責在您進行的任何新安裝中實際運行更新,以使您的模塊保持最新狀態。從我們的實際文件
function ec_install() {
$ret = array();
$num = 0;
while (1) {
$version = 6000 + $num;
$funcname = 'ec_update_' . $version;
if (function_exists($funcname)) {
$ret[] = $funcname();
$num++;
} else {
break;
}
}
return $ret;
}
樣本更新功能或兩個現在跟隨
// Create editor role and set permissions for comment module
function ec_update_6000() {
install_include(array('user'));
$editor_rid = install_add_role('editor');
install_add_permissions(DRUPAL_ANONYMOUS_RID, array('access comments'));
install_add_permissions(DRUPAL_AUTHENTICATED_RID, array('access comments', 'post comments', 'post comments without approval'));
install_add_permissions($editor_rid, array('administer comments', 'administer nodes'));
return array();
}
// Enable the pirc theme.
function ec_update_6001() {
install_include(array('system'));
// TODO: line below is not working due to a bug in Install Profile API. See http://drupal.org/node/316789.
install_enable_theme('pirc');
return array();
}
// Add the content types for article and mtblog
function ec_update_6002() {
install_include(array('node'));
$props = array(
'description' => 'Historical Movable Type blog entries',
);
install_create_content_type('mtblog', 'MT Blog entry', $props);
$props = array(
'description' => 'Article',
);
install_create_content_type('article', 'Article', $props);
return array();
}
實際上,這大多與數據庫和Drupal代碼解決了版本控制問題。我們廣泛使用它。它允許我們推廣新的代碼,這些代碼可以改變數據庫配置,而無需重新導入數據庫或進行實時更改。這也意味着我們可以正確測試版本而不用擔心隱藏的數據庫更改。
最後,cck和views支持這種方法。看到這段代碼片段
// Enable CCK modules, add CCK types for Articles in prep for first stage of migration,
// enable body for article, enable migration modules.
function ec_update_6023() {
$ret = array();
drupal_install_modules(array('content', 'content_copy', 'text', 'number', 'optionwidgets'));
install_include(array('content', 'content_copy'));
install_content_copy_import_from_file(drupal_get_path('module', 'ec') . '/' . 'article.type', 'article');
$sql = "UPDATE {node_type} SET body_label='Body', has_body=1
WHERE type = 'article'";
$ret[] = update_sql($sql);
return $ret;
}
嗯你能澄清一下嗎?你是否正在討論基本上某些模塊上的設置設置? – Owen 2008-11-12 03:19:15
真的很好的問題,謝謝。 – sepehr 2010-01-31 21:13:43