Last active
August 29, 2015 13:55
-
-
Save cesarmiquel/8721638 to your computer and use it in GitHub Desktop.
Sample .install file which enables/disables modules, features, etc.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Update site to ... | |
* | |
* First comment is used when displaying updates to perform. Implementation of | |
* hook_update_N(). | |
*/ | |
function xxxx_update_700X() { | |
// List of modules to disable | |
$modules_to_disable = array( | |
'xmlsitemap_custom', | |
'xmlsitemap_node', | |
... | |
); | |
// List of modules to uninstall | |
$modules_to_uninstall = array( | |
'lightbox2', | |
.... | |
); | |
// List of modules enable | |
$modules_to_enable = array( | |
'auto_nodetitle', | |
'breadcrumb_config', | |
'captcha', | |
... | |
'jcarousel', | |
); | |
// List of features to revert | |
$features_to_revert = array( | |
'blogs' => array('views_view', 'variable'), | |
... | |
); | |
// List of blocks to disable | |
$blocks_to_disable = array( | |
array('views', 'similarterms-block'), | |
array('views', 'blog_list_tags-block_1'), | |
array('views', 'blog_related_content-block'), | |
... | |
); | |
// | |
// Start install / update process | |
// | |
// Drop unused / broken tables left by a broken install | |
db_drop_table('table1'); | |
db_drop_table('table2'); | |
// Blocks to disable. There might be a better way via an API. | |
foreach ($blocks_to_disable as $block) { | |
db_update('block') | |
->fields(array( | |
'status' => 0, | |
'region' => "-1", | |
)) | |
->condition('delta', $block[1]) | |
->condition('module', $block[0]) | |
->execute(); | |
} | |
// Move block around: change region of block to branding | |
db_update('block') | |
->fields(array('weight' => -35, 'region' => 'branding')) | |
->condition('bid', 126) | |
->execute(); | |
// Change block title | |
db_update('block') | |
->fields(array('title' => 'NEW TITLE')) | |
->condition('bid', BLOCK_ID) | |
->execute(); | |
// Add 'Goto Google link' link | |
$menu_item = array( | |
'menu_name' => 'main-menu', | |
'link_title' => 'Goto Google', | |
'link_path' => 'http://www.google.com', | |
'plid' => PARENT_MENU_LINK_ID, | |
'weight' => -30, | |
); | |
menu_link_save($menu_item); | |
// Revert certain features. | |
// See also: https://gist.github.com/becw/4121388 | |
features_revert($features_to_revert); | |
// Disable and uninstall certain modules. | |
module_disable($modules_to_disable + $modules_to_uninstall); | |
drupal_uninstall_modules($modules_to_uninstall); | |
// Enable other modules. | |
module_enable($modules_to_enable); | |
// revert all components of this feature | |
features_revert_module('my_feature_module'); | |
// remove a field instance from a field collection | |
// Data that is saved in the field will be removed on cron run and/or clear cache | |
$field_collection_instance = field_info_instance('field_collection_item', 'field_name', 'field_collection_name'); | |
field_delete_instance($field_collection_instance); | |
// remove a field instance from a node | |
// Data that is saved in the field will be removed on cron run and/or clear cache | |
$instance = field_info_instance('node', 'field_name', 'bundle'); | |
field_delete_instance($instance); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment