Commit fd16e977 authored by vadim's avatar vadim
Browse files

#1087212 by dealancer: changed way of performing update

parent 6a2fd673
......@@ -52,25 +52,47 @@ function menu_token_uninstall() {
* Implementation of hook_update_N().
*/
function menu_token_update_6000() {
$ret = drupal_install_schema('menu_token');
drupal_get_schema(NULL, TRUE);
return $ret;
}
/**
* Implementation of hook_update_N().
*/
function menu_token_update_6001() {
$ret = array();
$schema['menu_token'] = array(
'description' => t('Menu token properties'),
'fields' => array (
'mlid' => array (
'description' => t('The menu link {menu_links}.mlid'),
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
),
'link_path' => array (
'description' => t('The actual path with tokens'),
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
),
'primary key' => array('mlid'),
'indexes' => array(
'mlid' => array('mlid'),
),
);
// create schema
db_create_table($ret, 'menu_token', $schema['menu_token']);
// ibsert records
foreach (variable_get('menu_token_enabled', array()) as $mlid => $link_path) {
$item = (object)array('mlid' => $mlid, 'link_path' => $link_path);
$status = drupal_write_record('menu_token', $item);
if (!$status) {
$ret['#abort'] = array('success' => FALSE, 'query' => 'Could not add records to databse');
return $ret;
}
unset($item);
$link_path = db_escape_string($link_path);
$ret[] = update_sql("INSERT INTO {menu_token} (mlid, link_path) VALUES ($mlid, '$link_path')");
}
variable_del('menu_token_enabled');
// delete variable in case of all queries were successful
$success = true;
foreach ($ret as $r) {
$success = $success && $r['success'];
}
if ($success) {
variable_del('menu_token_enabled');
}
return $ret;
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment