function _filter_features_update in Features 6
Helper function for updating/inserting formats.
1 call to _filter_features_update()
- filter_features_rebuild in includes/
features.filter.inc - Implementation of hook_features_rebuild().
File
- includes/
features.filter.inc, line 161
Code
function _filter_features_update($format) {
$format_id = db_result(db_query("SELECT format FROM {filter_formats} WHERE name = '%s'", $format['name']));
// Format the role IDs into something that can be inserted into the database.
// This is so painful. See filter.admin.inc line 218. : (
// We cannot use user_roles() here because it has the names translated.
$roles = _features_get_roles();
$format_rids = array();
foreach ($format['roles'] as $role_name) {
// Ensure that each role exists. If it does not, create it and store the rid.
if (!isset($roles[$role_name])) {
$record = array(
'name' => $role_name,
);
drupal_write_record('role', $record);
$roles[$role_name]['rid'] = $record['rid'];
$roles[$role_name]['perm'] = array();
}
// Retrieve the rid corresponding to each role and add it to the format's rids
if (isset($roles[$role_name])) {
$format_rids[] = $roles[$role_name]['rid'];
}
}
if ($format_id && $format_id == variable_get('filter_default_format', 1)) {
$format['roles'] = ',' . implode(',', array_keys(user_roles())) . ',';
}
else {
$format['roles'] = ',' . implode(',', $format_rids) . ',';
}
// Update or insert the format
if ($format_id) {
$format['format'] = $format_id;
drupal_write_record('filter_formats', $format, 'format');
}
else {
drupal_write_record('filter_formats', $format);
}
// Update the filters for the format
if ($format['format']) {
db_query("DELETE FROM {filters} WHERE format = %d", $format['format']);
foreach ($format['filters'] as $filter) {
$filter['format'] = $format['format'];
drupal_write_record('filters', $filter);
}
}
}