Newer
Older
* Implementation of hook_install().
*/
Yves Chedemois
committed
drupal_load('module', 'content');
Karen Stevenson
committed
content_notify('install', 'userreference');
}
/**
* Implementation of hook_uninstall().
*/
function userreference_uninstall() {
Yves Chedemois
committed
drupal_load('module', 'content');
Karen Stevenson
committed
content_notify('uninstall', 'userreference');
Karen Stevenson
committed
/**
* Implementation of hook_enable().
*
* Notify content module when this module is enabled.
*/
function userreference_enable() {
Yves Chedemois
committed
drupal_load('module', 'content');
Karen Stevenson
committed
content_notify('enable', 'userreference');
}
/**
* Implementation of hook_disable().
*
* Notify content module when this module is disabled.
*/
function userreference_disable() {
Yves Chedemois
committed
drupal_load('module', 'content');
Karen Stevenson
committed
content_notify('disable', 'userreference');
}
function userreference_update_last_removed() {
return 4;
Jonathan Chaffer
committed
}
Karen Stevenson
committed
* Placeholder update to set newly installed versions to the latest update number.
Karen Stevenson
committed
function userreference_update_6000() {
Yves Chedemois
committed
if ($abort = content_check_update('userreference')) {
return $abort;
Yves Chedemois
committed
}
Yves Chedemois
committed
$ret = array();
Marc Ferran (aka Markus)
committed
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
}
/**
* Create an index by user reference column for all fields.
*/
function userreference_update_6001(&$sandbox) {
include_once('./'. drupal_get_path('module', 'content') .'/content.install');
drupal_load('module', 'content');
$ret = array();
if (!isset($sandbox['progress'])) {
if ($abort = content_check_update('userreference')) {
return $abort;
}
// Get the latest cache values and schema.
content_clear_type_cache(TRUE, TRUE);
$types = content_types_install();
if (empty($types)) {
return $ret;
}
$sandbox['fields'] = array();
foreach ($types as $type_name => $fields) {
foreach ($fields as $field) {
if ($field['type'] == 'userreference') {
$sandbox['fields'][] = $field;
}
}
}
if (empty($sandbox['fields'])) {
return $ret;
}
$sandbox['progress'] = 0;
$sandbox['visited'] = array();
}
$field = $sandbox['fields'][$sandbox['progress']];
// We only want to process a field once -- if we hit it a second time,
// that means it's its own table and it should have already been updated.
if (!in_array($field['field_name'], $sandbox['visited'])) {
$db_info = content_database_info($field);
$table = $db_info['table'];
$attributes = $db_info['columns']['uid'];
$column = $attributes['column'];
if (!content_db_index_exists($table, $column)) {
db_add_index($ret, $table, $column, array($column));
}
$sandbox['visited'][] = $field['field_name'];
}
$sandbox['progress']++;
$ret['#finished'] = $sandbox['progress'] / count($sandbox['fields']);
return $ret;
}
Marc Ferran (aka Markus)
committed
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/**
* Convert 'referenceable_status' option from array to integer to match the
* change in the field settings form where the element has been changed from
* a checkboxes element (array) to a radios element (integer).
*
* Reference: @link http://drupal.org/node/416134 @endlink
*/
function userreference_update_6002() {
$ret = array();
$result = db_query("SELECT field_name, global_settings FROM {". content_field_tablename() ."} WHERE type = 'userreference'");
while ($userreference = db_fetch_object($result)) {
$global_settings = unserialize($userreference->global_settings);
$referenceable_status = array_filter($global_settings['referenceable_status']);
$global_settings['referenceable_status'] = (!empty($referenceable_status) ? 1 : '');
// We can't 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'", serialize($global_settings), $userreference->field_name);
$ret[] = array(
'success' => TRUE,
'query' => t("The 'referenceable_status' option for %field has been fixed.", array('%field' => $userreference->field_name)),
);
}
// Rebuild content caches only if necessary.
if (!empty($ret)) {
content_clear_type_cache();
}
return $ret;
}