} if (empty($automation)) { echo $OUTPUT->header(); echo $OUTPUT->box(get_string('vmoodlesnapshot1', 'local_vmoodle')); echo $OUTPUT->continue_button(new moodle_url('/local/vmoodle/view.php', array('view' => 'management', 'what' => 'snapshot', 'step' => 1, 'wwwroot' => $wwwroot))); echo $OUTPUT->footer(); die; } else { // Chain following steps $vmoodlestep++; } } if ($vmoodlestep > 0) { if ($wwwroot == $CFG->wwwroot) { // Make fake Vmoodle record. $vmoodle = vmoodle_make_this(); $vdatabase = ''; $vdatapath = $CFG->dataroot; } else { // Get Vmoodle known record. $vmoodle = $DB->get_record('local_vmoodle', array('vhostname' => $wwwroot)); $vdatabase = ''; $vdatapath = $vmoodle->vdatapath; } if ($vmoodlestep == 1) { echo $OUTPUT->header(); // Auto dump the database in a master template_folder. if (!vmoodle_dump_database($vmoodle, $absolute_sqldir . $separator . 'vmoodle_master.sql')) { print_error('baddumpcommandpath', 'local_vmoodle'); if ($automation) { return -1;
/** * get a proper SQLdump command * @param object $vmoodledata the complete new host information * @return string the shell command */ function vmoodle_get_database_dump_cmd($vmoodledata) { global $CFG; // Checks if paths commands have been properly defined in 'vconfig.php'. if ($vmoodledata->vdbtype == 'mysql') { $pgm = !empty($CFG->local_vmoodle_cmd_mysql) ? stripslashes($CFG->local_vmoodle_cmd_mysql) : false; } elseif ($vmoodledata->vdbtype == 'mysqli') { $pgm = !empty($CFG->local_vmoodle_cmd_mysql) ? stripslashes($CFG->local_vmoodle_cmd_mysql) : false; } elseif ($vmoodledata->vdbtype == 'postgres') { // Needs to point the pg_restore command. $pgm = !empty($CFG->local_vmoodle_cmd_pgsql) ? stripslashes($CFG->local_vmoodle_cmd_pgsql) : false; } // Checks the needed program. // debug_trace("load_database_from_dump : checking database command"); if (!$pgm) { print_error('dbcommandnotconfigured', 'local_vmoodle'); return false; } $phppgm = str_replace("\\", '/', $pgm); $phppgm = str_replace("\"", '', $phppgm); $pgm = str_replace("/", DIRECTORY_SEPARATOR, $pgm); // debug_trace('load_database_from_dump : checking command is available'); if (!is_executable($phppgm)) { print_error('dbcommanddoesnotmatchanexecutablefile', 'local_vmoodle', $phppgm); return false; } // Retrieves the host configuration (more secure). $thisvmoodle = vmoodle_make_this(); if (strstr($thisvmoodle->vdbhost, ':') !== false) { list($thisvmoodle->vdbhost, $thisvmoodle->vdbport) = split(':', $thisvmoodle->vdbhost); } // Password. if (!empty($thisvmoodle->vdbpass)) { $thisvmoodle->vdbpass = '******' . escapeshellarg($thisvmoodle->vdbpass) . ' '; } // Making the command line (see 'vconfig.php' file for defining the right paths). if ($vmoodledata->vdbtype == 'mysql') { $sqlcmd = $pgm . ' -h' . $thisvmoodle->vdbhost . (isset($thisvmoodle->vdbport) ? ' -P' . $thisvmoodle->vdbport . ' ' : ' '); $sqlcmd .= '-u' . $thisvmoodle->vdblogin . ' ' . $thisvmoodle->vdbpass; $sqlcmd .= $vmoodledata->vdbname . ' < '; } elseif ($vmoodledata->vdbtype == 'mysqli') { $sqlcmd = $pgm . ' -h' . $thisvmoodle->vdbhost . (isset($thisvmoodle->vdbport) ? ' -P' . $thisvmoodle->vdbport . ' ' : ' '); $sqlcmd .= '-u' . $thisvmoodle->vdblogin . ' ' . $thisvmoodle->vdbpass; $sqlcmd .= $vmoodledata->vdbname . ' < '; } elseif ($vmoodledata->vdbtype == 'postgres') { $sqlcmd = $pgm . ' -Fc -h ' . $thisvmoodle->vdbhost . (isset($thisvmoodle->vdbport) ? ' -p ' . $thisvmoodle->vdbport . ' ' : ' '); $sqlcmd .= '-U ' . $thisvmoodle->vdblogin . ' '; $sqlcmd .= '-d ' . $vmoodledata->vdbname . ' -f '; } return $sqlcmd; }