This repository has been archived by the owner on Jun 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfarm_livestock.install
77 lines (61 loc) · 2.71 KB
/
farm_livestock.install
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
/**
* @file
* Farm livestock install file.
*/
/**
* Implements hook_update_dependencies().
*/
function farm_livestock_update_dependencies() {
// Ensure that farm_update_7019 runs before farm_livestock_update_7001, so
// that the new Parents field is available.
$dependencies['farm_livestock'][7001] = array('farm' => 7019);
// Update 7003 (add movement field to medical logs) depends on
// farm_log_movement_update_7000().
$dependencies['farm_livestock'][7003] = array('farm_log_movement' => 7000);
return $dependencies;
}
/**
* Migrate Animal Description field to plain Description field (from farm_fields).
*/
function farm_livestock_update_7000(&$sandbox) {
// Revert this module's field_instance Features component.
features_revert(array('farm_livestock' => array('field_instance')));
// If the new description field database tables exist...
if (db_table_exists('field_data_field_farm_description') && db_table_exists('field_revision_field_farm_description')) {
// Copy all descriptions from the old database tables to the new ones.
db_query('INSERT INTO {field_data_field_farm_description} SELECT * FROM {field_data_field_farm_animal_description}');
db_query('INSERT INTO {field_revision_field_farm_description} SELECT * FROM {field_revision_field_farm_animal_description}');
// Delete the old field.
$field = field_info_instance('farm_asset', 'field_farm_animal_description', 'animal');
field_delete_instance($field);
}
}
/**
* Migrate Animal Parents field to plain Parents field (from farm_asset_children).
*/
function farm_livestock_update_7001(&$sandbox) {
// Revert this module's field_instance Features component.
features_revert(array('farm_livestock' => array('field_instance')));
// If the new description field database tables exist...
if (db_table_exists('field_data_field_farm_parent') && db_table_exists('field_revision_field_farm_parent')) {
// Copy all references from the old database tables to the new ones.
db_query('INSERT INTO {field_data_field_farm_parent} SELECT * FROM {field_data_field_farm_animal_parents}');
db_query('INSERT INTO {field_revision_field_farm_parent} SELECT * FROM {field_revision_field_farm_animal_parents}');
// Delete the old field.
$field = field_info_instance('farm_asset', 'field_farm_animal_parents', 'animal');
field_delete_instance($field);
}
}
/**
* Add new animal ID tag types: Chip, Other.
*/
function farm_livestock_update_7002(&$sandbox) {
features_revert(array('farm_livestock' => array('field_base', 'field_instance')));
}
/**
* Add new movement field to medical logs.
*/
function farm_livestock_update_7003(&$sandbox) {
features_revert(array('farm_livestock' => array('field_instance')));
}