- <?php
- * @file
- * Install, update and uninstall functions for the field module.
- */
-
- * Implements hook_schema().
- */
- function field_schema() {
- $schema['cache_field'] = backdrop_get_schema_unprocessed('system', 'cache');
- $schema['cache_field']['description'] = 'Cache table for the Field module to store already built field information.';
-
- return $schema;
- }
-
- * Convert fields to configuration files.
- */
- function field_update_1000() {
- if (db_table_exists('field_config')) {
-
-
-
- $result = db_query('SELECT * FROM {field_config} WHERE deleted = 0 AND active = 1');
- foreach ($result as $row) {
- $field = (array) $row;
- $field += unserialize($field['data']);
- $field['storage'] = array(
- 'type' => $field['storage_type'],
- 'module' => $field['storage_module'],
- 'active' => $field['storage_active'],
- 'settings' => array(),
- );
- unset($field['id']);
- unset($field['data']);
- unset($field['storage_type']);
- unset($field['storage_module']);
- unset($field['storage_active']);
- $config = config('field.field.' . $field['field_name']);
- $config->setData($field);
- $config->save();
- }
- db_drop_table('field_config');
- }
-
- if (db_table_exists('field_config_instance')) {
- $result = db_query('SELECT * FROM {field_config_instance} WHERE deleted = 0');
- foreach ($result as $row) {
- $instance = (array) $row;
- $instance += unserialize($instance['data']);
- unset($instance['id']);
- unset($instance['field_id']);
- unset($instance['data']);
- $config = config('field.instance.' . $instance['entity_type'] . '.' . $instance['bundle'] . '.' . $instance['field_name']);
- $config->setData($instance);
- $config->save();
- }
- }
-
-
- $result = db_query("SELECT * FROM {variable} WHERE name LIKE 'field_bundle_settings_%'");
- foreach ($result as $row) {
- $variable_name = $row->name;
- $data = unserialize($row->value);
- $name = str_replace('field_bundle_settings_', '', $variable_name);
- $entity_type = substr($name, 0, strpos($name, '__'));
- $bundle = substr($name, strpos($name, '__') + 2);
- $config = config('field.bundle.' . $entity_type . '.' . $bundle);
- $config->setData($data);
- $config->save();
- }
- db_query("DELETE FROM {variable} WHERE name LIKE 'field_bundle_settings_%'");
-
-
- config_set('system.core', 'field_purge_batch_size', update_variable_get('field_purge_batch_size', 200));
- }
-
- * Add missing entity type and bundle information to Field config files.
- */
- function field_update_1001() {
- $names = config_get_names_with_prefix('field.bundle.');
- foreach ($names as $name) {
- $config = config($name);
- list(, , $entity_type, $bundle) = explode('.', $name);
- $settings = $config->get();
- $data = array(
- 'entity_type' => $entity_type,
- 'bundle' => $bundle,
- ) + $settings;
- $config->setData($data);
- $config->save();
- }
- }
-
- * Grant the new "administer fields" permission to trusted users.
- */
- function field_update_1002() {
-
-
- $role_names = array();
- $permissions = array(
- 'administer site configuration',
- 'administer content types',
- 'administer users',
- );
- foreach ($permissions as $permission) {
- $role_names = array_merge($role_names, array_keys(user_roles(FALSE, $permission)));
- }
- $role_names = array_unique($role_names);
- foreach ($role_names as $role_name) {
- $role_config = config('user.role.' . $role_name);
- $permissions = array_unique(array_merge($role_config->get('permissions'), array('administer fields')));
- $role_config->set('permissions', $permissions);
- $role_config->save();
- }
- }
-
- * Uninstall the options_element contrib module, now part of core.
- */
- function field_update_1003() {
- $module = db_query("SELECT name FROM {system} WHERE name = 'options_element' AND type = 'module'")->fetchField();
- if ($module) {
- $path = backdrop_get_path('module', 'options_element');
- backdrop_set_message(t('The contributed module <em>Options Element</em> has been located at %path. The module has been disabled, since its functionality is now provided by Backdrop core. It is recommended that you remove this module from your site.', array('%path' => BACKDROP_ROOT . '/' . $path)), 'warning');
-
-
-
-
-
-
- db_query("DELETE FROM {system} WHERE name = 'options_element' AND type = 'module'");
- }
- else {
- return t('<em>Options Element</em> not found. Nothing to be done.');
- }
- }
-
- * Uninstall the field_formatter_settings contrib module, now part of core.
- */
- function field_update_1004() {
- $module = db_query("SELECT name FROM {system} WHERE name = 'field_formatter_settings' AND type = 'module'")->fetchField();
- if ($module) {
- $path = backdrop_get_path('module', 'field_formatter_settings');
- backdrop_set_message(t('The contributed module <em>Field Formatter Settings</em> has been located at %path. The module has been disabled, since its functionality is now provided by Backdrop core. It is recommended that you remove this module from your site.', array('%path' => BACKDROP_ROOT . '/' . $path)), 'warning');
-
-
-
-
-
-
-
- db_query("DELETE FROM {system} WHERE name = 'field_formatter_settings' AND type = 'module'");
- }
- else {
- return t('<em>Field Formatter Settings</em> not found. Nothing to be done.');
- }
- }