5 * Install, update, and uninstall functions for the message module.
9 * Implements hook_install().
11 function message_install() {
12 // Create the field holding the message text.
14 'field_name' => MESSAGE_FIELD_MESSAGE_TEXT
,
15 'type' => 'text_long',
16 'entity_types' => array('message_type'),
17 'cardinality' => FIELD_CARDINALITY_UNLIMITED
,
18 'translatable' => TRUE
,
21 $field = field_create_field($field);
23 'field_name' => MESSAGE_FIELD_MESSAGE_TEXT
,
24 'bundle' => 'message_type',
25 'entity_type' => 'message_type',
26 'label' => t('Message text'),
27 'description' => t('This is the text of all messages of this type.'),
30 'text_processing' => 1,
33 field_create_instance($instance);
35 variable_del('message_entity_delete_cleanup');
39 * Implements hook_uninstall().
41 function message_uninstall() {
42 $instance = field_info_instance('message_type', 'message_text', 'message_type');
43 field_delete_instance($instance);
44 field_delete_field('message_text');
46 variable_del('message_delete_cron_limit');
47 variable_del('message_purge_enable');
48 variable_del('message_purge_quota');
49 variable_del('message_purge_days');
53 * Implements hook_schema()
55 function message_schema() {
56 $schema['message_type_category'] = array(
57 'description' => 'Storage for user-defined message category.',
59 // Although the "category" should be enough as the primary key, the
60 // numeric ID is required for the internal use of entity API.
64 'description' => 'Primary Key: Numeric message type category ID.',
67 'description' => 'The unified identifier for a message type category.',
73 'description' => array(
74 'description' => 'Description for this message type category.',
81 'description' => 'The {languages}.language of this message type category.',
90 // Set the default to ENTITY_CUSTOM without using the constant as it is
91 // not safe to use it at this point.
94 'description' => 'The exportable status of the entity.',
97 'description' => 'The name of the providing module if the entity has been defined in code.',
103 'primary key' => array('id'),
104 'unique keys' => array(
105 'category' => array('category'),
109 $schema['message_type'] = array(
110 'description' => 'Storage for user-defined message templates.',
112 // Although the "name" should be enough as the primary key, the numeric ID
113 // is required for the internal use of entity API.
117 'description' => 'Primary Key: Numeric message type ID.',
120 'description' => 'The unified identifier for a message type.',
127 'description' => 'Reference to a message type category.',
131 'default' => 'message_type',
133 'description' => array(
134 'description' => 'Description for this message type.',
140 'argument_keys' => array(
141 'description' => 'Serialized array with the argument keys',
146 'description' => 'The {languages}.language of this message type.',
155 // Set the default to ENTITY_CUSTOM without using the constant as it is
156 // not safe to use it at this point.
159 'description' => 'The exportable status of the entity.',
162 'description' => 'The name of the providing module if the entity has been defined in code.',
167 'arguments' => array(
168 'description' => 'Serialized array with the arguments.',
173 'description' => 'Serialized array with general data.',
179 'primary key' => array('id'),
180 'unique keys' => array(
181 'name' => array('name'),
185 $schema['message'] = array(
186 'description' => 'An instance of a message type (e.g. like a node is an instance of a node type).',
191 'description' => 'The Unique ID of the message.',
194 'description' => 'Reference to a message a type.',
200 'arguments' => array(
201 'description' => 'Serialized array with the arguments',
206 'description' => 'The user ID of the acting user.',
208 'default value' => NULL
,
211 'timestamp' => array(
212 'description' => 'When the message instance was recorded.',
218 'description' => 'The {languages}.language of this message.',
225 'foreign keys' => array(
226 'message_type' => array(
227 'table' => 'message_type',
228 'columns' => array('type' => 'name'),
232 'columns' => array('uid' => 'uid'),
235 'primary key' => array('mid'),
242 * Add in the exportable entity db columns as required by the entity API.
244 function message_update_7000() {
245 db_add_field('message_type', 'status', array(
248 // Set the default to ENTITY_CUSTOM without using the constant as it is
249 // not safe to use it at this point.
252 'description' => 'The exportable status of the entity.',
254 db_add_field('message_type', 'module', array(
255 'description' => 'The name of the providing module if the entity has been defined in code.',
263 * Add the argument keys column of a message type.
265 function message_update_7001() {
266 db_add_field('message_type', 'argument_keys', array(
267 'description' => 'Serialized array with the argument keys',
274 * Update the message type text field to have text processing.
276 function message_update_7002() {
278 'field_name' => MESSAGE_FIELD_MESSAGE_TEXT
,
279 'bundle' => 'message_type',
280 'entity_type' => 'message_type',
281 'label' => t('Message text'),
282 'description' => t('This is the text of all messages of this type.'),
285 'text_processing' => 1,
288 field_update_instance($instance);
292 * Add message type category.
294 function message_update_7003() {
295 $schema['message_type_category'] = array(
296 'description' => 'Storage for user-defined message category.',
298 // Although the "category" should be enough as the primary key, the
299 // numeric ID is required for the internal use of entity API.
303 'description' => 'Primary Key: Numeric message type category ID.',
306 'description' => 'The unified identifier for a message type category.',
312 'description' => array(
313 'description' => 'Description for this message type category.',
322 // Set the default to ENTITY_CUSTOM without using the constant as it is
323 // not safe to use it at this point.
326 'description' => 'The exportable status of the entity.',
329 'description' => 'The name of the providing module if the entity has been defined in code.',
335 'primary key' => array('id'),
336 'unique keys' => array(
337 'category' => array('category'),
340 db_create_table('message_type_category', $schema['message_type_category']);
342 db_add_field('message_type', 'category', array(
343 'description' => 'Reference to a message type category.',
347 'default' => 'message_type',
352 * Rename the 'name' column to 'type' in {Message}.
354 function message_update_7004() {
356 'description' => 'Reference to a message a type.',
362 db_change_field('message', 'name', 'type', $column);
367 * Add "arguments" column to message-type.
369 function message_update_7005() {
371 'description' => 'Serialized array with the arguments',
375 db_add_field('message_type', 'arguments', $column);
379 * Add "data" column to message-type.
381 function message_update_7006() {
383 'description' => 'Serialized array with general data.',
388 db_add_field('message_type', 'data', $column);
392 * Add "language" column to all Message's related entities.
394 function message_update_7007(&$sandbox) {
395 // Update the existing entities, with the default language.
396 $langcode = language_default()->language
;
399 'message_type_category',
404 if (!isset($sandbox['total'])) {
405 foreach ($tables as
$key => $table) {
406 $name = str_replace('_', ' ', $table);
408 'description' => "The {languages}.language of this $name.",
414 db_add_field($table, 'language', $column);
416 if ($table == 'message') {
417 // We don't want to time out when updating messages, so we will
418 // process it using batches.
419 $query = db_select($table);
420 $sandbox['last'] = 0;
421 $sandbox['total'] = $query->countQuery()->execute()->fetchField();
422 $sandbox['#finished'] = 0;
427 'language' => $langcode,
433 elseif ($sandbox['total'] && $sandbox['last'] <= $sandbox['total']) {
438 'language' => $langcode,
440 ->condition('mid', $sandbox['last'], '>')
443 $sandbox['last'] += $batch_size;
444 $sandbox['#finished'] = min(0.99, $sandbox['last'] / $sandbox['total']);
447 // Finished processing.
448 $sandbox['#finished'] = 1;
453 * Make message-text field cardinality unlimited.
455 function message_update_7008() {
456 $field = field_info_field(MESSAGE_FIELD_MESSAGE_TEXT
);
457 $field['cardinality'] = FIELD_CARDINALITY_UNLIMITED
;
458 field_update_field($field);