function userreference_update_6002 in Content Construction Kit (CCK) 6.2
Same name and namespace in other branches
- 6.3 modules/userreference/userreference.install \userreference_update_6002()
Convert 'referenceable_status' option from array to integer to match the change in the field settings form where the element has been changed from a checkboxes element (array) to a radios element (integer).
Reference: http://drupal.org/node/416134
File
- modules/
userreference/ userreference.install, line 123 - Implementation of hook_install().
Code
function userreference_update_6002() {
$ret = array();
drupal_load('module', 'content');
$result = db_query("SELECT field_name, global_settings FROM {" . content_field_tablename() . "} WHERE type = 'userreference'");
while ($userreference = db_fetch_object($result)) {
$global_settings = unserialize($userreference->global_settings);
if (isset($global_settings['referenceable_status']) && is_array($global_settings['referenceable_status'])) {
$referenceable_status = array_filter($global_settings['referenceable_status']);
$global_settings['referenceable_status'] = !empty($referenceable_status) ? 1 : '';
// We can't use update_sql() here because of curly braces in serialized
// array.
db_query("UPDATE {" . content_field_tablename() . "} SET global_settings = '%s' WHERE field_name = '%s'", serialize($global_settings), $userreference->field_name);
$ret[] = array(
'success' => TRUE,
'query' => t("The 'referenceable_status' option for %field has been fixed.", array(
'%field' => $userreference->field_name,
)),
);
}
}
// Rebuild content caches only if necessary.
if (!empty($ret)) {
content_clear_type_cache();
}
return $ret;
}