-
Notifications
You must be signed in to change notification settings - Fork 3
/
stanford_subsites.install
executable file
·126 lines (111 loc) · 2.88 KB
/
stanford_subsites.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
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
116
117
118
119
120
121
122
123
124
125
126
<?php
/**
* Implements hook_install().
*/
function stanford_subsites_install() {
// Because it is bundled in the feature we have to enable it.
variable_set('stanford_subsite_content_types', array('page'));
}
/**
* Implements hook_schema().
*/
function stanford_subsites_schema() {
$schema['subsite_index'] = array(
'description' => 'Keeps track of subsite related things',
'fields' => array(
'nid' => array(
'description' => 'Subsite nid',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
),
'tid' => array(
'description' => 'Subsite term id',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
),
'menu' => array(
'description' => 'Subsite menu name',
'type' => 'varchar',
'length' => 255,
'default' => '',
),
'context' => array(
'description' => 'context machine name',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'machine_name' => array(
'description' => 'subsite machine name',
'type' => 'varchar',
'length' => 64,
'not null' => TRUE,
'default' => '',
),
),
'indexes' => array(
'ntm' => array('nid', "tid", "menu"),
'nt' => array('nid', "tid"),
'nm' => array('nid', "menu"),
'tm' => array("tid", "menu"),
),
'unique keys' => array(
'tid' => array('tid'),
'machine_name' => array('machine_name'),
),
'primary key' => array('nid'),
);
return $schema;
}
/**
* Adds machine_name field to subsite_index field.
*/
function stanford_subsites_update_7200(&$sandbox) {
$field = array(
'description' => 'subsite machine name',
'type' => 'varchar',
'length' => 64,
'not null' => TRUE,
'default' => '',
);
$keys = array(
'unique_keys' => array(
'machine_name' => array('machine_name'),
)
);
db_add_field('subsite_index', 'machine_name', $field, $keys);
}
/**
* Generate machine_names for those that don't already have one.
*/
function stanford_subsites_update_7201(&$sandbox) {
drupal_flush_all_caches();
while ($result = stanford_subsite_index_get('machine_name', '')) {
$name = str_replace("--", "_", $result->menu);
$name = str_replace("-", "_", $name);
stanford_subsite_index_update($result->nid, NULL, NULL, NULL, $name);
}
}
/**
* Updates database schema
*/
function stanford_subsites_update_7300(&$sandbox) {
// Allow menu to be null.
$table = "subsite_index";
$field = "menu";
$field_new = "menu";
$spec = array(
'description' => 'Subsite menu name',
'type' => 'varchar',
'length' => 255,
'default' => '',
);
$keys_new = array();
// Do eet!
db_change_field($table, $field, $field_new, $spec, $keys_new);
// Keys.
db_drop_unique_key("subsite_index", "menu");
}