2009-10-17 00:51:53 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* Install, update and uninstall functions for the shortcut module.
|
|
|
|
*/
|
|
|
|
|
2013-01-28 21:57:01 +00:00
|
|
|
use Drupal\Component\Uuid\Uuid;
|
|
|
|
|
2009-10-17 00:51:53 +00:00
|
|
|
/**
|
2009-12-04 16:49:48 +00:00
|
|
|
* Implements hook_uninstall().
|
2009-10-17 00:51:53 +00:00
|
|
|
*/
|
|
|
|
function shortcut_uninstall() {
|
|
|
|
// Delete the menu links associated with each shortcut set.
|
2013-01-19 05:26:12 +00:00
|
|
|
// @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());
|
|
|
|
}*/
|
2009-10-17 00:51:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-12-04 16:49:48 +00:00
|
|
|
* Implements hook_schema().
|
2009-10-17 00:51:53 +00:00
|
|
|
*/
|
|
|
|
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(
|
2010-08-22 13:55:53 +00:00
|
|
|
'set_user' => array(
|
|
|
|
'table' => 'users',
|
|
|
|
'columns' => array('uid' => 'uid'),
|
|
|
|
),
|
|
|
|
'set_name' => array(
|
|
|
|
'table' => 'shortcut_set',
|
|
|
|
'columns' => array('set_name' => 'set_name'),
|
|
|
|
),
|
2009-10-17 00:51:53 +00:00
|
|
|
),
|
|
|
|
);
|
|
|
|
|
|
|
|
return $schema;
|
|
|
|
}
|
2013-01-19 05:26:12 +00:00
|
|
|
|
|
|
|
/**
|
2013-02-01 03:27:16 +00:00
|
|
|
* @addtogroup updates-7.x-to-8.x
|
2013-01-19 05:26:12 +00:00
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Migrate shortcuts into configuration.
|
|
|
|
*/
|
|
|
|
function shortcut_update_8000() {
|
2013-01-28 21:57:01 +00:00
|
|
|
$uuid = new Uuid();
|
2013-01-19 05:26:12 +00:00
|
|
|
$result = db_query('SELECT * from {shortcut_set}');
|
2013-01-28 21:57:01 +00:00
|
|
|
$ids = array();
|
2013-01-19 05:26:12 +00:00
|
|
|
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.
|
2013-01-28 21:57:01 +00:00
|
|
|
db_update('menu_links')
|
|
|
|
->fields(array(
|
|
|
|
'menu_name' => 'shortcut-default'
|
|
|
|
))
|
|
|
|
->condition('menu_name', 'shortcut-set-1')
|
|
|
|
->execute();
|
2013-01-19 05:26:12 +00:00
|
|
|
}
|
|
|
|
config('shortcut.set.' . $set->set_name)
|
|
|
|
->set('id', $set->set_name)
|
|
|
|
->set('label', $set->title)
|
2013-01-28 21:57:01 +00:00
|
|
|
->set('uuid', $uuid->generate())
|
2013-01-19 05:26:12 +00:00
|
|
|
->save();
|
2013-01-28 21:57:01 +00:00
|
|
|
$ids[] = $set->set_name;
|
2013-01-19 05:26:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Drop the {shortcut_set} table.
|
|
|
|
*/
|
|
|
|
function shortcut_update_8001() {
|
|
|
|
db_drop_table('shortcut_set');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-02-01 03:27:16 +00:00
|
|
|
* @} End of "addtogroup updates-7.x-to-8.x".
|
2013-01-19 05:26:12 +00:00
|
|
|
* The next series of updates should start at 9000.
|
|
|
|
*/
|