Created
January 26, 2009 10:40
-
-
Save hugowetterberg/52780 to your computer and use it in GitHub Desktop.
Example use of the _update_sql_with_param_support function
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
/** | |
* Update that changes the CCK field field_info_url | |
* from a text field to a link field without data loss | |
* | |
* @return void | |
*/ | |
function hook_update_1() { | |
$ret = array(); | |
// Global settings | |
$global_settings = array( | |
'attributes' => array( | |
'target' => '_blank', | |
'rel' => 'nofollow', | |
'class' => '', | |
), | |
'display' => array( | |
'url_cutoff' => '80', | |
), | |
'url' => 0, | |
'title' => 'optional', | |
'title_value' => '', | |
'enable_tokens' => 0, | |
); | |
// DB-columns | |
$db_columns = array( | |
'url' => array( | |
'type' => 'varchar', | |
'length' => 255, | |
'not null' => false, | |
'sortable' => true, | |
), | |
'title' => array( | |
'type' => 'varchar', | |
'length' => 255, | |
'not null' => false, | |
'sortable' => true, | |
), | |
'attributes' => array( | |
'type' => 'text', | |
'size' => 'medium', | |
'not null' => false, | |
), | |
); | |
// Change the schema for the field table | |
db_change_field($ret, 'content_field_info_url', 'field_info_url_value', 'field_info_url_url', $db_columns['url']); | |
db_add_field($ret, 'content_field_info_url', 'field_info_url_title', $db_columns['title']); | |
db_add_field($ret, 'content_field_info_url', 'field_info_url_attributes', $db_columns['attributes']); | |
// Update the field settings | |
$ret[] = _update_sql_with_param_support( | |
"UPDATE {content_node_field} SET | |
type='link', | |
global_settings='%s', | |
db_columns='%s' | |
WHERE field_name='field_info_url'", array( | |
':global' => serialize($global_settings), | |
':db' => serialize($db_columns), | |
)); | |
// Fill in Values that should have been set for normally | |
// created link fields | |
$ret[] = update_sql( | |
"UPDATE {content_field_info_url} | |
SET field_info_url_attributes='N;' | |
WHERE NOT field_info_url_url IS NULL"); | |
// Clear cck cache | |
cache_clear_all('*', 'cache_content', TRUE); | |
return $ret; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment