325 lines
8.9 KiB
Plaintext
325 lines
8.9 KiB
Plaintext
<?php
|
|
|
|
/**
|
|
* @file
|
|
* Install, update and uninstall functions for the shortcut module.
|
|
*/
|
|
|
|
use Drupal\Core\Database\Database;
|
|
use Drupal\Core\Language\Language;
|
|
|
|
/**
|
|
* Implements hook_schema().
|
|
*/
|
|
function shortcut_schema() {
|
|
$schema['shortcut'] = array(
|
|
'description' => 'Stores shortcut items.',
|
|
'fields' => array(
|
|
'id' => array(
|
|
'type' => 'serial',
|
|
'not null' => TRUE,
|
|
'description' => 'Primary Key: Unique shortcut ID.',
|
|
),
|
|
'uuid' => array(
|
|
'type' => 'varchar',
|
|
'length' => 128,
|
|
'not null' => FALSE,
|
|
'description' => 'Unique Key: Universally unique identifier for this shortcut.',
|
|
),
|
|
'shortcut_set' => array(
|
|
'type' => 'varchar',
|
|
'length' => 32,
|
|
'not null' => TRUE,
|
|
'default' => '',
|
|
'description' => 'The bundle of the shortcut.',
|
|
),
|
|
'langcode' => array(
|
|
'type' => 'varchar',
|
|
'length' => 12,
|
|
'not null' => TRUE,
|
|
'default' => '',
|
|
'description' => 'The {language}.langcode of the original variant of this shortcut.',
|
|
),
|
|
'weight' => array(
|
|
'description' => 'Weight among shortcuts in the same shortcut set.',
|
|
'type' => 'int',
|
|
'not null' => TRUE,
|
|
'default' => 0,
|
|
),
|
|
'route_name' => array(
|
|
'description' => 'The machine name of a defined Symfony Route this menu item represents.',
|
|
'type' => 'varchar',
|
|
'length' => 255,
|
|
),
|
|
'route_parameters' => array(
|
|
'description' => 'Serialized array of route parameters of this shortcut.',
|
|
'type' => 'blob',
|
|
'size' => 'big',
|
|
'not null' => FALSE,
|
|
'serialize' => TRUE,
|
|
),
|
|
),
|
|
'primary key' => array('id'),
|
|
'unique keys' => array(
|
|
'uuid' => array('uuid'),
|
|
),
|
|
);
|
|
|
|
$schema['shortcut_field_data'] = array(
|
|
'description' => 'Stores shortcut properties.',
|
|
'fields' => array(
|
|
'id' => array(
|
|
'type' => 'int',
|
|
'unsigned' => TRUE,
|
|
'not null' => TRUE,
|
|
'description' => 'The {shortcut}.id of the shortcut.',
|
|
),
|
|
'langcode' => array(
|
|
'type' => 'varchar',
|
|
'length' => 12,
|
|
'not null' => TRUE,
|
|
'default' => '',
|
|
'description' => 'The {language}.langcode of this variant of this shortcut.',
|
|
),
|
|
'default_langcode' => array(
|
|
'type' => 'int',
|
|
'not null' => TRUE,
|
|
'default' => 1,
|
|
'description' => 'Boolean indicating whether the current variant is in the original entity language.',
|
|
),
|
|
'title' => array(
|
|
'type' => 'varchar',
|
|
'length' => 32,
|
|
'not null' => FALSE,
|
|
'description' => 'The title of the shortcut.',
|
|
),
|
|
),
|
|
'foreign keys' => array(
|
|
'shortcut' => array(
|
|
'table' => 'shortcut',
|
|
'columns' => array('id' => 'id'),
|
|
),
|
|
),
|
|
'primary key' => array('id', 'langcode'),
|
|
);
|
|
|
|
$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 shortcut sets into configuration.
|
|
*/
|
|
function shortcut_update_8000() {
|
|
$uuid = \Drupal::service('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();
|
|
}
|
|
\Drupal::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');
|
|
}
|
|
|
|
/**
|
|
* Create the database tables for the new 'shortcut' entity type.
|
|
*/
|
|
function shortcut_update_8002() {
|
|
$tables['shortcut'] = array(
|
|
'description' => 'Stores shortcut items.',
|
|
'fields' => array(
|
|
'id' => array(
|
|
'type' => 'serial',
|
|
'not null' => TRUE,
|
|
'description' => 'Primary Key: Unique shortcut ID.',
|
|
),
|
|
'uuid' => array(
|
|
'type' => 'varchar',
|
|
'length' => 128,
|
|
'not null' => FALSE,
|
|
'description' => 'Unique Key: Universally unique identifier for this shortcut.',
|
|
),
|
|
'shortcut_set' => array(
|
|
'type' => 'varchar',
|
|
'length' => 32,
|
|
'not null' => TRUE,
|
|
'default' => '',
|
|
'description' => 'The bundle of the shortcut.',
|
|
),
|
|
'langcode' => array(
|
|
'type' => 'varchar',
|
|
'length' => 12,
|
|
'not null' => TRUE,
|
|
'default' => '',
|
|
'description' => 'The {language}.langcode of the original variant of this shortcut.',
|
|
),
|
|
'weight' => array(
|
|
'description' => 'Weight among shortcuts in the same shortcut set.',
|
|
'type' => 'int',
|
|
'not null' => TRUE,
|
|
'default' => 0,
|
|
),
|
|
'route_name' => array(
|
|
'description' => 'The machine name of a defined Symfony Route this menu item represents.',
|
|
'type' => 'varchar',
|
|
'length' => 255,
|
|
),
|
|
'route_parameters' => array(
|
|
'description' => 'Serialized array of route parameters of this shortcut.',
|
|
'type' => 'blob',
|
|
'size' => 'big',
|
|
'not null' => FALSE,
|
|
'serialize' => TRUE,
|
|
),
|
|
),
|
|
'primary key' => array('id'),
|
|
'unique keys' => array(
|
|
'uuid' => array('uuid'),
|
|
),
|
|
);
|
|
|
|
$tables['shortcut_field_data'] = array(
|
|
'description' => 'Stores shortcut properties.',
|
|
'fields' => array(
|
|
'id' => array(
|
|
'type' => 'int',
|
|
'unsigned' => TRUE,
|
|
'not null' => TRUE,
|
|
'description' => 'The {shortcut}.id of the shortcut.',
|
|
),
|
|
'langcode' => array(
|
|
'type' => 'varchar',
|
|
'length' => 12,
|
|
'not null' => TRUE,
|
|
'default' => '',
|
|
'description' => 'The {language}.langcode of this variant of this shortcut.',
|
|
),
|
|
'default_langcode' => array(
|
|
'type' => 'int',
|
|
'not null' => TRUE,
|
|
'default' => 1,
|
|
'description' => 'Boolean indicating whether the current variant is in the original entity language.',
|
|
),
|
|
'title' => array(
|
|
'type' => 'varchar',
|
|
'length' => 32,
|
|
'not null' => FALSE,
|
|
'description' => 'The title of the shortcut.',
|
|
),
|
|
),
|
|
'foreign keys' => array(
|
|
'shortcut' => array(
|
|
'table' => 'shortcut',
|
|
'columns' => array('id' => 'id'),
|
|
),
|
|
),
|
|
'primary key' => array('id', 'langcode'),
|
|
);
|
|
|
|
$schema = Database::getConnection()->schema();
|
|
$schema->createTable('shortcut', $tables['shortcut']);
|
|
$schema->createTable('shortcut_field_data', $tables['shortcut_field_data']);
|
|
}
|
|
|
|
/**
|
|
* Migrate shortcuts into their own storage tables.
|
|
*/
|
|
function shortcut_update_8003() {
|
|
$shortcuts = db_select('menu_links', 'ml')
|
|
->fields('ml')
|
|
->condition('menu_name', 'shortcut-%', 'LIKE')
|
|
->execute()
|
|
->fetchAllAssoc('mlid');
|
|
|
|
foreach ($shortcuts as $shortcut) {
|
|
$record_id = db_insert('shortcut')
|
|
->fields(array(
|
|
'uuid' => $shortcut->uuid,
|
|
'shortcut_set' => substr($shortcut->menu_name, 9),
|
|
'langcode' => Language::LANGCODE_NOT_SPECIFIED,
|
|
'weight' => $shortcut->weight,
|
|
'route_name' => $shortcut->route_name,
|
|
'route_parameters' => $shortcut->route_parameters,
|
|
))
|
|
->execute();
|
|
db_insert('shortcut_field_data')
|
|
->fields(array(
|
|
'id' => $record_id,
|
|
'langcode' => Language::LANGCODE_NOT_SPECIFIED,
|
|
'default_langcode' => 1,
|
|
'title' => $shortcut->link_title,
|
|
))
|
|
->execute();
|
|
}
|
|
if (!empty($shortcuts)) {
|
|
db_delete('menu_links')
|
|
->condition('mlid', array_keys($shortcuts), 'IN')
|
|
->execute();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @} End of "addtogroup updates-7.x-to-8.x".
|
|
* The next series of updates should start at 9000.
|
|
*/
|