| 1 |
<?php |
<?php |
| 2 |
// $Id: db_maintenance.module,v 1.11.2.2.2.2 2008/10/01 05:14:01 jgraham Exp $ |
// $Id: db_maintenance.module,v 1.11.2.2.2.3 2008/10/01 05:43:02 jgraham Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* @file |
* @file |
| 70 |
|
|
| 71 |
/** |
/** |
| 72 |
* Callback page for manually optimizing tables. |
* Callback page for manually optimizing tables. |
|
* |
|
| 73 |
*/ |
*/ |
| 74 |
function db_maintenance_optimize_tables_page() { |
function db_maintenance_optimize_tables_page() { |
| 75 |
db_maintenance_optimize_tables(); |
db_maintenance_optimize_tables(); |
| 104 |
|
|
| 105 |
/** |
/** |
| 106 |
* Implementation of hook_cron(). |
* Implementation of hook_cron(). |
|
* |
|
| 107 |
*/ |
*/ |
| 108 |
function db_maintenance_cron() { |
function db_maintenance_cron() { |
| 109 |
$last_run = variable_get('db_maintenance_cron_last', 0); |
$last_run = variable_get('db_maintenance_cron_last', 0); |
| 117 |
if ($optimize_frequencty != -1 && $interval > $last_run) { |
if ($optimize_frequencty != -1 && $interval > $last_run) { |
| 118 |
db_maintenance_optimize_tables(); |
db_maintenance_optimize_tables(); |
| 119 |
} |
} |
| 120 |
|
|
| 121 |
$last_db_backup = variable_get('db_maintenance_last_db_backup', 0); |
$last_db_backup = variable_get('db_maintenance_last_db_backup', 0); |
| 122 |
$db_backup_freq = variable_get('db_maintenance_db_backup_frequency', -1); |
$db_backup_freq = variable_get('db_maintenance_db_backup_frequency', -1); |
| 123 |
$files_backup_freq = variable_get('db_maintenance_files_backup_frequency', -1); |
$files_backup_freq = variable_get('db_maintenance_files_backup_frequency', -1); |
| 124 |
$last_files_backup = variable_get('db_maintenance_last_files_backup', 0); |
$last_files_backup = variable_get('db_maintenance_last_files_backup', 0); |
| 125 |
|
|
| 126 |
if ($db_backup_freq != -1 && $last_db_backup <= $now - $db_backup_freq) { |
if ($db_backup_freq != -1 && $last_db_backup <= $now - $db_backup_freq) { |
| 127 |
$email['db_backup'] = db_maintenance_do_db_backup(); |
$email['db_backup'] = db_maintenance_do_db_backup(); |
| 128 |
variable_set('db_maintenance_last_db_backup', $now); |
variable_set('db_maintenance_last_db_backup', $now); |
| 129 |
} |
} |
| 130 |
|
|
| 131 |
if ($files_backup_freq != -1 && $last_files_backup <= $now - $files_backup_freq) { |
if ($files_backup_freq != -1 && $last_files_backup <= $now - $files_backup_freq) { |
| 132 |
$email['files_backup'] = db_maintanence_do_files_backup(); |
$email['files_backup'] = db_maintanence_do_files_backup(); |
| 133 |
variable_set('db_maintenance_last_files_backup', $now); |
variable_set('db_maintenance_last_files_backup', $now); |
| 134 |
} |
} |
| 135 |
|
|
| 136 |
db_maintenance_email($email); |
db_maintenance_email($email); |
| 137 |
|
|
| 138 |
} |
} |
| 139 |
|
|
| 140 |
/** |
/** |
| 141 |
* Perform the maintenance. |
* Perform the maintenance. |
|
* |
|
| 142 |
*/ |
*/ |
| 143 |
function db_maintenance_optimize_tables() { |
function db_maintenance_optimize_tables() { |
| 144 |
global $db_url; |
global $db_url; |
| 154 |
foreach ($databases as $db => $connection) { |
foreach ($databases as $db => $connection) { |
| 155 |
$config_tables = variable_get('db_maintenance_table_list_'. $db, NULL); |
$config_tables = variable_get('db_maintenance_table_list_'. $db, NULL); |
| 156 |
// Only proceed if tables are selected for this database. |
// Only proceed if tables are selected for this database. |
| 157 |
if (is_array($config_tables) && sizeof($config_tables) > 0) { |
if (is_array($config_tables) && count($config_tables) > 0) { |
| 158 |
$db_name = $db == 'default' ? 'Drupal' : $db; |
$db_name = $db == 'default' ? 'Drupal' : $db; |
| 159 |
while (list(, $table_name) = each($config_tables)) { |
while (list(, $table_name) = each($config_tables)) { |
| 160 |
// Set the database to query. |
// Set the database to query. |
| 163 |
if (_db_maintenance_determine_software() == 'mysql') { |
if (_db_maintenance_determine_software() == 'mysql') { |
| 164 |
$result = db_query('OPTIMIZE TABLE %s', $table_name); |
$result = db_query('OPTIMIZE TABLE %s', $table_name); |
| 165 |
$status = db_fetch_array($result); |
$status = db_fetch_array($result); |
| 166 |
while($status[] = db_fetch_array($result)) { |
while ($status[] = db_fetch_array($result)) { |
| 167 |
// get all of the rows |
// get all of the rows |
| 168 |
} |
} |
| 169 |
db_maintenance_check_status($status, 'OPTIMIZE'); |
db_maintenance_check_status($status, 'OPTIMIZE'); |
| 206 |
'#default_value' => variable_get('db_maintenance_log', 0), |
'#default_value' => variable_get('db_maintenance_log', 0), |
| 207 |
'#description' => t('If enabled, a watchdog entry will be made each time tables are optimized, containing information which tables were involved.') |
'#description' => t('If enabled, a watchdog entry will be made each time tables are optimized, containing information which tables were involved.') |
| 208 |
); |
); |
| 209 |
|
|
| 210 |
$form['db_maintenance_repair'] = array( |
$form['db_maintenance_repair'] = array( |
| 211 |
'#type' => 'checkbox', |
'#type' => 'checkbox', |
| 212 |
'#title' => 'Attempt REPAIR of table if OPTIMIZE is problematic', |
'#title' => 'Attempt REPAIR of table if OPTIMIZE is problematic', |
| 213 |
'#default_value' => variable_get('db_maintenance_repair', 0), |
'#default_value' => variable_get('db_maintenance_repair', 0), |
| 214 |
'#description' => t('If enabled and a table receives a non-okay status from the OPTIMIZE then a repair of that table will be attempted. In the case of REPAIR all resulting status are logged via watchdog.') |
'#description' => t('If enabled and a table receives a non-okay status from the OPTIMIZE then a repair of that table will be attempted. In the case of REPAIR all resulting status are logged via watchdog.') |
| 215 |
); |
); |
| 216 |
|
|
| 217 |
$frequency = array( |
$frequency = array( |
| 218 |
-1 => t('Never'), |
-1 => t('Never'), |
| 219 |
0 => t('Run during every cron'), |
0 => t('Run during every cron'), |
| 251 |
'#options' => $options, |
'#options' => $options, |
| 252 |
'#default_value' => variable_get('db_maintenance_table_list_'. $db, ''), |
'#default_value' => variable_get('db_maintenance_table_list_'. $db, ''), |
| 253 |
'#description' => t('Selected tables will be optimized during cron runs.'), |
'#description' => t('Selected tables will be optimized during cron runs.'), |
| 254 |
'#multiple' => true, |
'#multiple' => TRUE, |
| 255 |
'#attributes' => array('size' => count($options)), |
'#attributes' => array('size' => count($options)), |
| 256 |
); |
); |
| 257 |
} |
} |
| 258 |
|
|
| 259 |
$form['db_maintenance_db_backup_frequency'] = array( |
$form['db_maintenance_db_backup_frequency'] = array( |
| 260 |
'#type' => 'select', |
'#type' => 'select', |
| 261 |
'#title' => t('Database Backup frequency'), |
'#title' => t('Database Backup frequency'), |
| 263 |
'#options' => $frequency, |
'#options' => $frequency, |
| 264 |
'#default_value' => variable_get('db_maintenance_db_backup_frequency', -1), |
'#default_value' => variable_get('db_maintenance_db_backup_frequency', -1), |
| 265 |
); |
); |
| 266 |
|
|
| 267 |
$form['db_maintenance_files_backup_frequency'] = array( |
$form['db_maintenance_files_backup_frequency'] = array( |
| 268 |
'#type' => 'select', |
'#type' => 'select', |
| 269 |
'#title' => t('Files Backup frequency'), |
'#title' => t('Files Backup frequency'), |
| 271 |
'#options' => $frequency, |
'#options' => $frequency, |
| 272 |
'#default_value' => variable_get('db_maintenance_files_backup_frequency', -1), |
'#default_value' => variable_get('db_maintenance_files_backup_frequency', -1), |
| 273 |
); |
); |
| 274 |
|
|
| 275 |
$form['db_maintenance_backup_directory'] = array( |
$form['db_maintenance_backup_directory'] = array( |
| 276 |
'#type' => 'textfield', |
'#type' => 'textfield', |
| 277 |
'#title' => t('Backup directory'), |
'#title' => t('Backup directory'), |
| 278 |
'#description' => t('Directory to store backup files in'), |
'#description' => t('Directory to store backup files in'), |
| 279 |
'#default_value' => variable_get('db_maintenance_backup_directory', '/tmp'), |
'#default_value' => variable_get('db_maintenance_backup_directory', '/tmp'), |
| 280 |
); |
); |
| 281 |
|
|
| 282 |
$form['db_maintenance_path_to_tar'] = array( |
$form['db_maintenance_path_to_tar'] = array( |
| 283 |
'#type' => 'textfield', |
'#type' => 'textfield', |
| 284 |
'#title' => t('Path to tar'), |
'#title' => t('Path to tar'), |
| 285 |
'#default_value' => variable_get('db_maintenance_path_to_tar', '/bin/tar'), |
'#default_value' => variable_get('db_maintenance_path_to_tar', '/bin/tar'), |
| 286 |
); |
); |
| 287 |
|
|
| 288 |
$form['db_maintenance_path_to_mysqldump'] = array( |
$form['db_maintenance_path_to_mysqldump'] = array( |
| 289 |
'#type' => 'textfield', |
'#type' => 'textfield', |
| 290 |
'#title' => t('Path to mysqldump'), |
'#title' => t('Path to mysqldump'), |
| 291 |
'#default_value' => variable_get('db_maintenance_path_to_mysqldump', '/usr/bin/mysqldump'), |
'#default_value' => variable_get('db_maintenance_path_to_mysqldump', '/usr/bin/mysqldump'), |
| 292 |
); |
); |
| 293 |
|
|
| 294 |
$form['db_maintenance_email_notify'] = array( |
$form['db_maintenance_email_notify'] = array( |
| 295 |
'#type' => 'textfield', |
'#type' => 'textfield', |
| 296 |
'#title' => t('Email address to notify'), |
'#title' => t('Email address to notify'), |
| 306 |
// if -1 then we do not backup so the extra field validation should only happen when appropriate |
// if -1 then we do not backup so the extra field validation should only happen when appropriate |
| 307 |
$dbfreq = $form_state['values']['db_maintenance_db_backup_frequency']; |
$dbfreq = $form_state['values']['db_maintenance_db_backup_frequency']; |
| 308 |
$filesfreq = $form_state['values']['db_maintenance_files_backup_frequency']; |
$filesfreq = $form_state['values']['db_maintenance_files_backup_frequency']; |
| 309 |
|
|
| 310 |
// only validate backup directory if we need to |
// only validate backup directory if we need to |
| 311 |
if (($dbfreq != -1 || $filesfreq != -1)) { |
if (($dbfreq != -1 || $filesfreq != -1)) { |
| 312 |
if (!is_dir($form_state['values']['db_maintenance_backup_directory'])) { |
if (!is_dir($form_state['values']['db_maintenance_backup_directory'])) { |
| 321 |
if (!is_file($form_state['values']['db_maintenance_path_to_tar'])) { |
if (!is_file($form_state['values']['db_maintenance_path_to_tar'])) { |
| 322 |
form_set_error('db_maintenance_path_to_tar', t('Path to tar is incorrect.')); |
form_set_error('db_maintenance_path_to_tar', t('Path to tar is incorrect.')); |
| 323 |
} |
} |
| 324 |
elseif(!is_executable($form_state['values']['db_maintenance_path_to_tar'])) { |
elseif (!is_executable($form_state['values']['db_maintenance_path_to_tar'])) { |
| 325 |
form_set_error('db_maintenance_path_to_tar', t('tar is not executable.')); |
form_set_error('db_maintenance_path_to_tar', t('tar is not executable.')); |
| 326 |
} |
} |
| 327 |
} |
} |
| 328 |
|
|
| 329 |
if ($dbfreq != -1) { |
if ($dbfreq != -1) { |
| 330 |
if (!is_file($form_state['values']['db_maintenance_path_to_mysqldump'])) { |
if (!is_file($form_state['values']['db_maintenance_path_to_mysqldump'])) { |
| 331 |
form_set_error('db_maintenance_path_to_mysqldump', t('Path to mysqldump is incorrect.')); |
form_set_error('db_maintenance_path_to_mysqldump', t('Path to mysqldump is incorrect.')); |
| 332 |
} |
} |
| 333 |
elseif(!is_executable($form_state['values']['db_maintenance_path_to_mysqldump'])) { |
elseif (!is_executable($form_state['values']['db_maintenance_path_to_mysqldump'])) { |
| 334 |
form_set_error('db_maintenance_path_to_mysqldump', t('mysqldump is not executable.')); |
form_set_error('db_maintenance_path_to_mysqldump', t('mysqldump is not executable.')); |
| 335 |
} |
} |
| 336 |
} |
} |
| 339 |
$emails = explode(',', $form_state['values']['db_maintenance_email_notify']); |
$emails = explode(',', $form_state['values']['db_maintenance_email_notify']); |
| 340 |
if (!empty($emails)) { |
if (!empty($emails)) { |
| 341 |
$bad = array(); |
$bad = array(); |
| 342 |
foreach($emails as $email) { |
foreach ($emails as $email) { |
| 343 |
$email = trim($email); |
$email = trim($email); |
| 344 |
if (!valid_email_address($email)) { |
if (!valid_email_address($email)) { |
| 345 |
$bad[] = $email; |
$bad[] = $email; |
| 371 |
return $db_type; |
return $db_type; |
| 372 |
} |
} |
| 373 |
else { |
else { |
| 374 |
return false; |
return FALSE; |
| 375 |
} |
} |
| 376 |
} |
} |
| 377 |
|
|
| 378 |
function db_maintenance_check_status($status, $op) { |
function db_maintenance_check_status($status, $op) { |
| 379 |
// mysql return codes indicating okay/success all others assumed to be "bad" |
// mysql return codes indicating okay/success all others assumed to be "bad" |
| 380 |
$DB_MAINTENANCE_OKAY = array('Table is already up to date', 'OK'); |
$DB_MAINTENANCE_OKAY = array('Table is already up to date', 'OK'); |
| 381 |
foreach($status as $key => $return) { |
foreach ($status as $key => $return) { |
| 382 |
if (is_numeric($key) && !empty($return)) { |
if (is_numeric($key) && !empty($return)) { |
| 383 |
if (in_array($return['Msg_text'], $DB_MAINTENANCE_OKAY)) { |
if (in_array($return['Msg_text'], $DB_MAINTENANCE_OKAY)) { |
| 384 |
// everything okay only log if explicitly set or we did a repair |
// everything okay only log if explicitly set or we did a repair |
| 385 |
if(variable_get('db_maintenance_log', 0) || $op == 'REPAIR') { |
if (variable_get('db_maintenance_log', 0) || $op == 'REPAIR') { |
| 386 |
watchdog('db_maintenance', t('Success: !op table !table, type: !type, message: !message', array('!op' => $op, '!table' => $return['Table'], '!type' => $return['Msg_type'], '!message' => $return['Msg_text']))); |
watchdog('db_maintenance', 'Success: !op table !table, type: !type, message: !message', array('!op' => $op, '!table' => $return['Table'], '!type' => $return['Msg_type'], '!message' => $return['Msg_text'])); |
| 387 |
} |
} |
| 388 |
} |
} |
| 389 |
else { |
else { |
| 390 |
// problems encountered |
// problems encountered |
| 391 |
watchdog('db_maintenance', t('Failure: !op table !table type: !type, message: !message', array('!op' => $op, '!table' => $return['Table'], '!type' => $return['Msg_type'], '!message' => $return['Msg_text'])), WATCHDOG_ERROR); |
watchdog('db_maintenance', 'Failure: !op table !table type: !type, message: !message', array('!op' => $op, '!table' => $return['Table'], '!type' => $return['Msg_type'], '!message' => $return['Msg_text']), WATCHDOG_ERROR); |
| 392 |
|
|
| 393 |
// attempt repair if config is set and makes sense |
// attempt repair if config is set and makes sense |
| 394 |
if (variable_get('db_maintenance_repair', 0) && $op == 'OPTIMIZE' && !empty($return['Table'])) { |
if (variable_get('db_maintenance_repair', 0) && $op == 'OPTIMIZE' && !empty($return['Table'])) { |
| 395 |
$result = db_query('REPAIR TABLE %s', $return['Table']); |
$result = db_query('REPAIR TABLE %s', $return['Table']); |
| 396 |
$status = array(); |
$status = array(); |
| 397 |
while($status[] = db_fetch_array($result)) { |
while ($status[] = db_fetch_array($result)) { |
| 398 |
// get all of the rows |
// get all of the rows |
| 399 |
} |
} |
| 400 |
db_maintenance_check_status($status, 'REPAIR'); |
db_maintenance_check_status($status, 'REPAIR'); |
| 402 |
} |
} |
| 403 |
} |
} |
| 404 |
} |
} |
| 405 |
|
|
| 406 |
// check non-numeric entries (mysql has such a lovely return setup) |
// check non-numeric entries (mysql has such a lovely return setup) |
| 407 |
if (isset($status['Table']) && isset($status['Op']) && isset($status['Msg_type']) && isset($status['Msg_text'])) { |
if (isset($status['Table']) && isset($status['Op']) && isset($status['Msg_type']) && isset($status['Msg_text'])) { |
| 408 |
$new_status = array(); |
$new_status = array(); |
| 417 |
if (!empty($email) && !empty($email_list)) { |
if (!empty($email) && !empty($email_list)) { |
| 418 |
$message = array(); |
$message = array(); |
| 419 |
$backupdir = variable_get('db_maintenance_backup_directory', '/tmp'); |
$backupdir = variable_get('db_maintenance_backup_directory', '/tmp'); |
| 420 |
foreach($email as $task => $status) { |
foreach ($email as $task => $status) { |
| 421 |
switch($task) { |
switch ($task) { |
| 422 |
case 'db_backup': |
case 'db_backup': |
| 423 |
if (is_file($status)) { |
if (is_file($status)) { |
| 424 |
$message[] = t('Database backed up. mysqldump is available at \'@STATUS@\' when connected to \'@URL@\'', array('@STATUS@' => $status, '@URL' => $base_url)); |
$message[] = t('Database backed up. mysqldump is available at \'@STATUS@\' when connected to \'@URL@\'', array('@STATUS@' => $status, '@URL' => $base_url)); |
| 460 |
$dateformat = 'Ymd_H-i-s'; |
$dateformat = 'Ymd_H-i-s'; |
| 461 |
$dbname = db_maintenance_get_db_info('dbname'); |
$dbname = db_maintenance_get_db_info('dbname'); |
| 462 |
$now = time(); |
$now = time(); |
| 463 |
$date = date($dateformat, $now); |
$date = format_date($now, 'custom', $dateformat); |
| 464 |
$filename = $backupdir.'/'.$date.'_'.$dbname.'_db.sql'; |
$filename = $backupdir .'/'. $date .'_'. $dbname .'_db.sql'; |
| 465 |
$mysqloptions = db_maintenance_get_mysql_options(); |
$mysqloptions = db_maintenance_get_mysql_options(); |
| 466 |
|
|
| 467 |
$mysqldumpexec = $mysqldump.' '.$mysqloptions.' > '.$filename; |
$mysqldumpexec = $mysqldump .' '. $mysqloptions .' > '. $filename; |
| 468 |
if (is_dir($backupdir)) { |
if (is_dir($backupdir)) { |
| 469 |
exec($mysqldumpexec, $output, $return); |
exec($mysqldumpexec, $output, $return); |
| 470 |
//variable_set('db_maintenance_debug', variable_get('db_maintenance_debug', '') . 'MYSQLDUMP: '.$mysqldumpexec.' ('. var_export($return, TRUE) .') '. var_export($output, TRUE)."\n"); |
$output=implode('<br />', $output); |
| 471 |
|
// variable_set('db_maintenance_debug', variable_get('db_maintenance_debug', '') . 'MYSQLDUMP: '.$mysqldumpexec.' ('. var_export($return, TRUE) .') '. var_export($output, TRUE)."\n"); |
| 472 |
if (!$return && !is_file($filename)) { |
if (!$return && !is_file($filename)) { |
| 473 |
|
watchdog('db_maintenance', $output, NULL, WATCHDOG_ERROR); |
| 474 |
return FALSE; |
return FALSE; |
|
watchdog('db_maintenance', $output, WATCHDOG_ERROR); |
|
| 475 |
} |
} |
| 476 |
else { |
else { |
| 477 |
return $filename; |
return $filename; |
| 478 |
} |
} |
| 479 |
} |
} |
| 480 |
else { |
else { |
| 481 |
|
watchdog('db_maintenance', 'backup directory does not exist', array(), WATCHDOG_ERROR); |
| 482 |
return FALSE; |
return FALSE; |
|
watchdog('db_maintenance', t('backup directory does not exist'), WATCHDOG_ERROR); |
|
| 483 |
} |
} |
| 484 |
} |
} |
| 485 |
|
|
| 490 |
$dateformat = 'Ymd_H-i-s'; |
$dateformat = 'Ymd_H-i-s'; |
| 491 |
$dbname = db_maintenance_get_db_info('dbname'); |
$dbname = db_maintenance_get_db_info('dbname'); |
| 492 |
$now = time(); |
$now = time(); |
| 493 |
$date = date($dateformat, $now); |
$date = format_date($now, 'custom', $dateformat); |
| 494 |
if (is_file($tarpath) && is_dir($filespath) && is_dir($backupdir)) { |
if (is_file($tarpath) && is_dir($filespath) && is_dir($backupdir)) { |
| 495 |
$backupname = $date.'_'.$dbname.'_files.tar.gz'; |
$backupname = $date .'_'. $dbname .'_files.tar.gz'; |
| 496 |
$command = 'tar -cvzf '.$backupdir.'/'.$backupname.' '.$filespath; |
$command = "tar -cvzf $backupdir/$backupname --exclude=*". $dbname ."_files.tar.gz --exclude=*". $dbname ."_db.sql $filespath"; |
| 497 |
|
$output = array(); |
| 498 |
exec($command, $output, $return); |
exec($command, $output, $return); |
| 499 |
//variable_set('db_maintenance_debug', variable_get('db_maintenance_debug', '') . 'TAR: '.$command.' ('. var_export($return, TRUE) .') '. var_export($output, TRUE) ."\n"); |
$output = implode('<br />', $output); |
| 500 |
|
// variable_set('db_maintenance_debug', variable_get('db_maintenance_debug', '') . 'TAR: '.$command.' ('. var_export($return, TRUE) .') '. var_export($output, TRUE) ."\n"); |
| 501 |
if (!$return) { |
if (!$return) { |
| 502 |
|
watchdog('db_maintenance', $output, NULL, WATCHDOG_ERROR); |
| 503 |
return FALSE; |
return FALSE; |
|
watchdog('db_maintenance', $output, WATCHDOG_ERROR); |
|
| 504 |
} |
} |
| 505 |
else { |
else { |
| 506 |
if (!is_file($backupdir.'/'.$backupname)) { |
if (!is_file($backupdir .'/'. $backupname)) { |
| 507 |
|
watchdog('db_maintenance', 'failed to create files backup file: !output', array('!output' => $output), WATCHDOG_ERROR); |
| 508 |
return FALSE; |
return FALSE; |
|
watchdog('db_maintenance', t('failed to create files backup file').': '.$output, WATCHDOG_ERROR); |
|
| 509 |
} |
} |
| 510 |
return $backupdir.'/'.$backupname; |
return $backupdir .'/'. $backupname; |
| 511 |
} |
} |
| 512 |
} |
} |
| 513 |
else { |
else { |
| 514 |
watchdog('db_maintenance', t('Files dir not present, backup dir not present or path to tar incorrect'), WATCHDOG_ERROR); |
watchdog('db_maintenance', 'Files dir not present, backup dir not present or path to tar incorrect', array(), WATCHDOG_ERROR); |
| 515 |
return FALSE; |
return FALSE; |
| 516 |
} |
} |
| 517 |
} |
} |
| 519 |
function db_maintenance_get_db_info($param) { |
function db_maintenance_get_db_info($param) { |
| 520 |
global $db_url; |
global $db_url; |
| 521 |
$url = parse_url($db_url); |
$url = parse_url($db_url); |
| 522 |
|
|
| 523 |
switch(strtolower($param)) { |
switch (drupal_strtolower($param)) { |
| 524 |
case 'pass': |
case 'pass': |
| 525 |
case 'password': |
case 'password': |
| 526 |
if(isset($url['pass'])) { |
if (isset($url['pass'])) { |
| 527 |
$return = urldecode($url['pass']); |
return urldecode($url['pass']); |
| 528 |
} |
} |
| 529 |
else { |
else { |
| 530 |
$return = ''; |
return ''; |
| 531 |
} |
} |
|
break; |
|
| 532 |
case 'user': |
case 'user': |
| 533 |
case 'username': |
case 'username': |
| 534 |
$return = urldecode($url['user']); |
return urldecode($url['user']); |
|
break; |
|
| 535 |
case 'host': |
case 'host': |
| 536 |
case 'hostname': |
case 'hostname': |
| 537 |
$return = urldecode($url['host']); |
return urldecode($url['host']); |
|
break; |
|
| 538 |
case 'db': |
case 'db': |
| 539 |
case 'database': |
case 'database': |
| 540 |
case 'dbname': |
case 'dbname': |
| 541 |
case 'name': |
case 'name': |
| 542 |
$url['path'] = urldecode($url['path']); |
$url['path'] = urldecode($url['path']); |
| 543 |
$return = substr($url['path'], 1); |
return drupal_substr($url['path'], 1); |
|
break; |
|
| 544 |
case 'port': |
case 'port': |
| 545 |
if (isset($url['port'])) { |
if (isset($url['port'])) { |
| 546 |
$return = urldecode($url['port']); |
return urldecode($url['port']); |
| 547 |
} |
} |
| 548 |
else { |
else { |
| 549 |
$return = ''; |
return ''; |
| 550 |
} |
} |
|
break; |
|
| 551 |
default: |
default: |
| 552 |
$return = ''; |
return ''; |
|
break; |
|
| 553 |
} |
} |
|
return $return; |
|
| 554 |
} |
} |
| 555 |
|
|
| 556 |
function db_maintenance_get_mysql_options() { |
function db_maintenance_get_mysql_options() { |
| 561 |
$url['path'] = urldecode($url['path']); |
$url['path'] = urldecode($url['path']); |
| 562 |
$url['user'] = urldecode($url['user']); |
$url['user'] = urldecode($url['user']); |
| 563 |
|
|
| 564 |
if(isset($url['pass'])) { |
if (isset($url['pass'])) { |
| 565 |
$url['pass'] = urldecode($url['pass']); |
$url['pass'] = urldecode($url['pass']); |
| 566 |
} |
} |
| 567 |
else { |
else { |
| 569 |
} |
} |
| 570 |
|
|
| 571 |
if ($url['host']) { |
if ($url['host']) { |
| 572 |
$options[] = '--host='.$url['host']; |
$options[] = '--host='. $url['host']; |
| 573 |
} |
} |
| 574 |
if (!empty($url['port'])) { |
if (!empty($url['port'])) { |
| 575 |
$options[] = '--port='.$url['port']; |
$options[] = '--port='. $url['port']; |
| 576 |
} |
} |
| 577 |
if ($url['pass'] != '') { |
if ($url['pass'] != '') { |
| 578 |
$options[] = '--password='.$url['pass']; |
$options[] = '--password='. $url['pass']; |
| 579 |
} |
} |
| 580 |
if($url['user']) { |
if ($url['user']) { |
| 581 |
$options[] = '--user='.$url['user']; |
$options[] = '--user='. $url['user']; |
| 582 |
} |
} |
| 583 |
|
|
| 584 |
$return = implode(' ', $options); |
$return = implode(' ', $options); |
| 585 |
|
|
| 586 |
$return .= ' '.substr($url['path'], 1); // db name is 'path' with '/' pre-pended |
$return .= ' '. drupal_substr($url['path'], 1); // db name is 'path' with '/' pre-pended |
| 587 |
|
|
| 588 |
return $return; |
return $return; |
| 589 |
} |
} |
| 590 |
|
|