comparison openmindattribute/openmindattribute.install @ 0:124ef8f3b22d

initial
author Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
date Fri, 27 Mar 2015 19:21:42 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:124ef8f3b22d
1 <?php
2
3 /**
4 * @file
5 * Install file for the openmindattribute module.
6 */
7
8 /**
9 * Upgrade notes:
10 * Things we need to make sure work when upgrading from Drupal 6 to Drupal 7:
11 */
12
13 /**
14 * Implements hook_field_schema().
15 */
16 function openmindattribute_field_schema($field) {
17 return array(
18 'columns' => array(
19 'name' => array(
20 'type' => 'varchar',
21 // Maximum URLs length.
22 'length' => 2048,
23 'not null' => FALSE,
24 'sortable' => TRUE,
25 ),
26 'ov' => array(
27 'type' => 'text',
28 'not null' => FALSE,
29 'sortable' => TRUE,
30 ),
31 'nov' => array(
32 'type' => 'text',
33 'not null' => FALSE,
34 'sortable' => TRUE,
35 ),
36 'romanization' => array(
37 'type' => 'text',
38 'not null' => FALSE,
39 'sortable' => TRUE,
40 ),
41 ),
42 );
43 }
44
45 /**
46 * Implements hook_update_last_removed().
47 */
48 function openmindattribute_update_last_removed() {
49 return 6001;
50 }
51
52
53 //* add field romanization *//
54 function openmindattribute_update_7230(&$sandbox) {
55 $fields = field_info_fields();
56 foreach ($fields as $field_name => $field) {
57 dpm($field['type']);
58 dpm($field_name);
59 dpm("---");
60 if (($field['type'] == 'openmindattribute_fields' || $field['type'] == 'openmindattribute_field') && $field['storage']['type'] == 'field_sql_storage') {
61 $schema = openmindattribute_field_schema($field);
62
63 foreach ($field['storage']['details']['sql'] as $type => $table_info) {
64 foreach ($table_info as $table_name => $columns) {
65 try {
66
67 $column_name = _field_sql_storage_columnname($field_name, 'romanization');
68
69 dpm($field_name);
70 dpm($column_name);
71 db_add_field($table_name, $column_name, $schema['columns']['name']);
72 db_add_index($table_name, $column_name, array($column_name));
73 }
74 catch (Exception $e)
75 {
76 dpm("error");
77 dpm($table_name);
78 }
79 }
80 }
81 }
82 }
83 field_cache_clear();
84 }
85
86
87 /**
88 * Handles moving settings data from field_config.data to field_config_instance.data.
89 */
90 function openmindattribute_update_7010() {
91
92 // For each field that is a openmindattribute field, we need to copy the settings from the general field level down to the instance.
93 //$field_data = array();
94 $result = db_query("SELECT id, field_name, data FROM {field_config} WHERE module = 'openmindattribute' AND type = 'openmindattribute_field'");
95 foreach ($result as $field) {
96 $field_id = $field->id;
97 $name = $field->field_name;
98 $field_data = unserialize($field->data);
99
100 $instances = db_query("SELECT id, data FROM {field_config_instance} WHERE field_id = :field_id", array(':field_id' => $field_id));
101 foreach ($instances as $instance) {
102 // If this field has been updated already, we want to skip it.
103 $instance_data = unserialize($instance->data);
104 $update_instance = FALSE;
105 if (!isset($instance_data['settings']['title'])) {
106 foreach ($field_data['settings'] as $key => $value) {
107 if (!isset($instance_data['settings'][$key])) {
108 $instance_data['settings'][$key] = $value;
109 $update_instance = TRUE;
110 }
111 }
112 if ($update_instance) {
113 // update the database.
114 $num_updated = db_update('field_config_instance')
115 ->fields(array('data' => serialize($instance_data)))
116 ->condition('id', $instance->id)
117 ->execute();
118 }
119 }
120 }
121 }
122
123 return t("Instance settings have been set with the data from the field settings.");
124 }
125
126 /**
127 * Renames all displays from foobar to openmindattribute_foobar
128 */
129 function openmindattribute_update_7001() {
130 // Update the display type for each openmindattribute field type.
131 $result = db_query("SELECT id, field_name, data FROM {field_config} WHERE module = 'openmindattribute' AND type = 'openmindattribute_field'");
132 foreach ($result as $field) {
133 $field_id = $field->id;
134 $name = $field->field_name;
135 $field_data = unserialize($field->data);
136
137 $instances = db_query("SELECT id, data FROM {field_config_instance} WHERE field_id = :field_id", array(':field_id' => $field_id));
138 foreach ($instances as $instance) {
139 // If this field has been updated already, we want to skip it.
140 $instance_data = unserialize($instance->data);
141 $update_instance = FALSE;
142 foreach ($instance_data['display'] as $display_name => $display_data) {
143 if ($display_data['type'] && (0 !== strpos($display_data['type'], 'openmindattribute_'))) {
144 $instance_data['display'][$display_name]['type'] = 'openmindattribute_' . $display_data['type'];
145 $update_instance = TRUE;
146 }
147 }
148 if ($update_instance) {
149 db_update('field_config_instance')
150 ->fields(array('data' => serialize($instance_data)))
151 ->condition('id', $instance->id)
152 ->execute();
153 }
154 }
155 }
156 }