View source
<?php
function entity_menu_links_install() {
$table = 'menu_links_revision';
$schema = drupal_get_schema($table);
db_create_table($table, $schema);
$schema = drupal_get_schema('menu_links');
$fields = $schema['fields'];
if (!db_field_exists('menu_links', 'vid')) {
db_add_field('menu_links', 'vid', $fields['vid']);
}
if (!db_field_exists('menu_links', 'uuid')) {
db_add_field('menu_links', 'uuid', $fields['uuid']);
}
entity_menu_links_install_revisions();
uuid_sync_all();
db_update('system')
->fields(array(
'weight' => 15,
))
->condition('name', 'entity_menu_links')
->execute();
}
function entity_menu_links_install_revisions() {
$links = drupal_get_schema('menu_links');
$revisions = drupal_get_schema('menu_links_revision');
$rev_fields = $revisions['fields'];
unset($rev_fields['vuuid'], $rev_fields['timestamp'], $rev_fields['vid']);
$links_fields = $links['fields'];
unset($links_fields['uuid'], $links_fields['vid']);
$menu_links_revision_fields = implode(',', array_keys($rev_fields)) . ', timestamp';
$menu_links_fields = implode(',', array_keys($links_fields)) . ', ' . time();
global $databases;
if (isset($databases['default']['default']['driver']) && $databases['default']['default']['driver'] == 'sqlsrv') {
$menu_links_revision_fields = str_replace('external', '[external]', $menu_links_revision_fields);
$menu_links_fields = str_replace('external', '[external]', $menu_links_fields);
}
$query = "INSERT INTO {menu_links_revision} ({$menu_links_revision_fields}) SELECT {$menu_links_fields} FROM {menu_links} WHERE module = :module";
db_query($query, array(
':module' => 'menu',
));
$query = 'UPDATE {menu_links} SET vid = (SELECT vid FROM {menu_links_revision} WHERE {menu_links}.mlid = mlid) WHERE module = :module';
db_query($query, array(
':module' => 'menu',
));
}
function entity_menu_links_uninstall() {
db_drop_table('menu_links_revision');
db_drop_index('menu_links', 'menu_links_revision');
db_drop_field('menu_links', 'vid');
db_drop_field('menu_links', 'uuid');
}
function entity_menu_links_module_implements_alter(&$implementations, $hook) {
if ($hook == 'schema_alter') {
unset($implementations['entity_menu_links']);
$implementations['entity_menu_links'] = '';
}
}
function entity_menu_links_schema_alter(&$schema = array()) {
$schema['menu_links']['fields']['vid'] = array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'description' => 'Revision id.',
);
$schema['menu_links']['fields']['uuid'] = array(
'type' => 'char',
'length' => 36,
'not null' => TRUE,
'default' => '',
'description' => 'The Universally Unique Identifier.',
);
$schema['menu_links_revision'] = $schema['menu_links'];
$schema['menu_links_revision']['module'] = 'entity_menu_links';
$schema['menu_links_revision']['name'] = 'menu_links_revision';
$schema['menu_links_revision']['fields']['mlid'] = array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
);
$schema['menu_links_revision']['fields']['vid'] = array(
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
);
$schema['menu_links_revision']['fields']['timestamp'] = array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
);
$schema['menu_links_revision']['fields']['vuuid'] = $schema['menu_links_revision']['fields']['uuid'];
unset($schema['menu_links_revision']['fields']['uuid']);
$schema['menu_links_revision']['primary key'] = array(
'vid',
);
$schema['menu_links_revision']['foreign keys'] = array(
'versioned_menu_link' => array(
'table' => 'menu_links',
'columns' => array(
'mlid' => 'mlid',
),
),
);
}
function entity_menu_links_update_7101() {
db_update('system')
->fields(array(
'weight' => 15,
))
->condition('name', 'entity_menu_links')
->execute();
}