function sharerich_update_7200 in Sharerich 7.3
Same name and namespace in other branches
- 7.2 sharerich.install \sharerich_update_7200()
Sharerich 2.x upgrade.
File
- ./
sharerich.install, line 181 - Install hooks for Sharerich project.
Code
function sharerich_update_7200() {
module_load_include('inc', 'ctools', 'includes/export');
// Install schema.
if (!db_table_exists('sharerich_sets')) {
drupal_install_schema('sharerich');
}
// Convert global sets into new ctools storage.
// Create a new object.
$imported = ctools_export_crud_new('sharerich_sets');
$imported->machinename = 'imported_set';
$imported->title = variable_get('sharerich_title', t('Share this'));
$imported->block = TRUE;
// Port legacy services.
foreach (variable_get('sharerich_services', array()) as $service_name => $value) {
$imported->services[$service_name]['enabled'] = $service_name === $value ? TRUE : FALSE;
$var_name = 'sharerich_custom_' . $service_name;
if ($content = variable_get($var_name, FALSE)) {
// Import legacy widgets and remove it.
variable_del($var_name);
}
else {
// Create new widgets.
$content = sharerich_get_service_content($service_name);
}
$imported->services[$service_name]['markup'] = $content;
$imported->services[$service_name]['weight'] = 0;
}
// Save configuration.
ctools_export_crud_save('sharerich_sets', $imported);
// Set default set for each content type that has Sharerich enabled.
foreach (node_type_get_types() as $node) {
if (variable_get('sharerich_node_' . $node->type, FALSE)) {
$config = field_bundle_settings('node', $node->type);
$display =& $config['extra_fields']['display']['sharerich'];
foreach ($display as $display_name => $item) {
$display[$display_name]['settings']['sharerich_sets'] = 'imported_set';
}
// Save extra field config.
field_bundle_settings('node', $node->type, $config);
}
}
// Remove old variables.
variable_del('sharerich_custom_0');
variable_del('sharerich_services');
variable_del('sharerich_title');
variable_del('sharerich_add_css');
variable_del('sharerich_add_js');
field_info_cache_clear();
}