-
Notifications
You must be signed in to change notification settings - Fork 0
/
shortcut.install
106 lines (97 loc) · 2.45 KB
/
shortcut.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
<?php
/**
* @file
* Install, update and uninstall functions for the shortcut module.
*/
use Drupal\Component\Uuid\Uuid;
/**
* Implements hook_uninstall().
*/
function shortcut_uninstall() {
// Delete the menu links associated with each shortcut set.
// @todo find a way to clean-up associated menu links.
/*foreach (entity_load_multiple('shortcut') as $shortcut_set) {
menu_delete_links('shortcut-' . $shortcut_set->id());
}*/
}
/**
* Implements hook_schema().
*/
function shortcut_schema() {
$schema['shortcut_set_users'] = array(
'description' => 'Maps users to shortcut sets.',
'fields' => array(
'uid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'description' => 'The {users}.uid for this set.',
),
'set_name' => array(
'type' => 'varchar',
'length' => 32,
'not null' => TRUE,
'default' => '',
'description' => "The {shortcut_set}.set_name that will be displayed for this user.",
),
),
'primary key' => array('uid'),
'indexes' => array(
'set_name' => array('set_name'),
),
'foreign keys' => array(
'set_user' => array(
'table' => 'users',
'columns' => array('uid' => 'uid'),
),
'set_name' => array(
'table' => 'shortcut_set',
'columns' => array('set_name' => 'set_name'),
),
),
);
return $schema;
}
/**
* @addtogroup updates-7.x-to-8.x
* @{
*/
/**
* Migrate shortcuts into configuration.
*/
function shortcut_update_8000() {
$uuid = new Uuid();
$result = db_query('SELECT * from {shortcut_set}');
$ids = array();
foreach ($result as $set) {
// Save a config object.
if ($set->set_name == 'shortcut-set-1') {
// Change default shortcut id.
$set->set_name = 'default';
// Update menu links.
db_update('menu_links')
->fields(array(
'menu_name' => 'shortcut-default'
))
->condition('menu_name', 'shortcut-set-1')
->execute();
}
config('shortcut.set.' . $set->set_name)
->set('id', $set->set_name)
->set('label', $set->title)
->set('uuid', $uuid->generate())
->save();
$ids[] = $set->set_name;
}
}
/**
* Drop the {shortcut_set} table.
*/
function shortcut_update_8001() {
db_drop_table('shortcut_set');
}
/**
* @} End of "addtogroup updates-7.x-to-8.x".
* The next series of updates should start at 9000.
*/