forked from wellebee/viewfield
-
Notifications
You must be signed in to change notification settings - Fork 0
/
viewfield.install
80 lines (76 loc) · 2.69 KB
/
viewfield.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
78
79
80
<?php
/**
* @file
* Installation functions for Viewfield module.
*/
/**
* Implements hook_field_schema().
*/
function viewfield_field_schema($field) {
return array(
'columns' => array(
'vname' => array(
'type' => 'varchar',
'not null' => FALSE,
// Views requires at least 96 chars for the view name and display, plus
// we need 1 for our delimiter. Round up to a common value of 128.
'length' => 128,
),
'vargs' => array(
'type' => 'varchar',
'not null' => FALSE,
'length' => 255,
),
),
);
}
/**
* Migrate force_default value from widget to instance settings.
*/
function viewfield_update_7200() {
$result = db_query("SELECT fci.id, fci.data FROM {field_config} fc INNER JOIN {field_config_instance} fci ON fc.id = fci.field_id WHERE fc.type = 'viewfield'");
foreach ($result as $record) {
$data = unserialize($record->data);
if (isset($data['widget']['settings']['force_default'])) {
// Protect against the case where a user has upgraded viewfield, produced
// a new instance-level force_default, and only later runs update.php.
if (!isset($data['settings']['force_default'])) {
$data['settings']['force_default'] = $data['widget']['settings']['force_default'];
}
unset($data['widget']['settings']['force_default']);
db_update('field_config_instance')
->fields(array('data' => serialize($data)))
->condition('id', $record->id)
->execute();
}
}
}
/**
* Migrate allowed_views value from field to instance settings.
*/
function viewfield_update_7201() {
$fields = db_query("SELECT id, data FROM {field_config} WHERE type = 'viewfield'");
foreach ($fields as $field) {
$fc_data = unserialize($field->data);
if (isset($fc_data['settings']['allowed_views'])) {
$instances = db_query("SELECT id, data FROM {field_config_instance} WHERE field_id = :field_id", array(':field_id' => $field->id));
foreach ($instances as $instance) {
$fci_data = unserialize($instance->data);
// Write new setting only if a new one hasn't been created before
// running this update.
if (!isset($fci_data['settings']['allowed_views'])) {
$fci_data['settings']['allowed_views'] = $fc_data['settings']['allowed_views'];
db_update('field_config_instance')
->fields(array('data' => serialize($fci_data)))
->condition('id', $instance->id)
->execute();
}
}
unset($fc_data['settings']['allowed_views']);
db_update('field_config')
->fields(array('data' => serialize($fc_data)))
->condition('id', $field->id)
->execute();
}
}
}