function field_permissions_install in Field Permissions 6
Same name and namespace in other branches
- 7 field_permissions.install \field_permissions_install()
Implementation of hook_install().
File
- ./
field_permissions.install, line 11 - Installation hooks for Field Permissions module.
Code
function field_permissions_install() {
$t = get_t();
// If Content Permissions module is enabled we need to enable permissions
// for all fields, as a method to upgrade from one module to another with
// the same exact options available.
$messages = array();
if (module_exists('content_permissions')) {
drupal_load('module', 'content');
$result = db_query('SELECT field_name, global_settings FROM {' . content_field_tablename() . '}');
while ($field = db_fetch_object($result)) {
$global_settings = unserialize($field->global_settings);
$global_settings['field_permissions'] = array(
'view' => 'view',
'edit' => 'edit',
);
$global_settings = serialize($global_settings);
// We cannot 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'", $global_settings, $field->field_name);
$messages[] = $t('Field permissions have been enabled for field %field-name.', array(
'%field-name' => $field->field_name,
));
}
}
drupal_set_message($t('Field Permissions module has been installed successfully.'));
if (!empty($messages)) {
content_clear_type_cache();
drupal_set_message($t('We have found that Content Permissions module (part of CCK) is installed, permissions have been enabled for all fields in your site. You can now uninstall Content Permissions module. Then you may want to enable and/or disable permissions for each field independently from the field settings form.'));
drupal_set_message(implode('<br />', $messages));
}
}