/** * Checks whether the current database supports transactions. * If settings of this plugin are set up to allow only transactions, * this method aborts the execution. Otherwise, this method will return * true or false whether the current database supports transactions or not, * respectively. * @return bool true if database transactions are supported. false otherwise. */ public function checkTransactionSupport() { global $CFG; $transactionsSupported = tool_mergeusers_transactionssupported(); $forceOnlyTransactions = get_config('tool_mergeusers', 'transactions_only'); if (!$transactionsSupported && $forceOnlyTransactions) { if (CLI_SCRIPT) { cli_error('Error: ' . __METHOD__ . ':: ' . get_string('errortransactionsonly', 'tool_mergeusers', $CFG->dbtype)); } else { print_error('errortransactionsonly', 'tool_mergeusers', new moodle_url('/admin/tool/mergeusers/index.php'), $CFG->dbtype); } } return $transactionsSupported; }
*/ defined('MOODLE_INTERNAL') || die; if (has_capability('tool/mergeusers:mergeusers', context_system::instance())) { require_once $CFG->dirroot . '/' . $CFG->admin . '/tool/mergeusers/lib/autoload.php'; require_once $CFG->dirroot . '/' . $CFG->admin . '/tool/mergeusers/lib.php'; $ADMIN->add('accounts', new admin_category('tool_mergeusers', get_string('pluginname', 'tool_mergeusers'))); $ADMIN->add('tool_mergeusers', new admin_externalpage('tool_mergeusers_merge', get_string('pluginname', 'tool_mergeusers'), $CFG->wwwroot . '/' . $CFG->admin . '/tool/mergeusers/index.php', 'tool/mergeusers:mergeusers')); $ADMIN->add('tool_mergeusers', new admin_externalpage('tool_mergeusers_viewlog', get_string('viewlog', 'tool_mergeusers'), $CFG->wwwroot . '/' . $CFG->admin . '/tool/mergeusers/view.php', 'tool/mergeusers:mergeusers')); } if ($hassiteconfig) { require_once $CFG->dirroot . '/' . $CFG->admin . '/tool/mergeusers/lib/autoload.php'; require_once $CFG->dirroot . '/' . $CFG->admin . '/tool/mergeusers/lib.php'; // Add configuration for making user suspension optional $settings = new admin_settingpage('mergeusers_settings', get_string('pluginname', 'tool_mergeusers')); $settings->add(new admin_setting_configcheckbox('tool_mergeusers/suspenduser', get_string('suspenduser_setting', 'tool_mergeusers'), get_string('suspenduser_setting_desc', 'tool_mergeusers'), 1)); $supporting_lang = tool_mergeusers_transactionssupported() ? 'transactions_supported' : 'transactions_not_supported'; $settings->add(new admin_setting_configcheckbox('tool_mergeusers/transactions_only', get_string('transactions_setting', 'tool_mergeusers'), get_string('transactions_setting_desc', 'tool_mergeusers') . '<br /><br />' . get_string($supporting_lang, 'tool_mergeusers'), 1)); $config = tool_mergeusers_config::instance(); $none = get_string('none'); $options = array('none' => $none); foreach ($config->exceptions as $exception) { $options[$exception] = $exception; } unset($options['my_pages']); //duplicated records make MyMoodle does not work. $settings->add(new admin_setting_configmultiselect('tool_mergeusers/excluded_exceptions', get_string('excluded_exceptions', 'tool_mergeusers'), get_string('excluded_exceptions_desc', 'tool_mergeusers', $none), array('none'), $options)); // quiz attempts $quizStrings = new stdClass(); $quizStrings->{QuizAttemptsMerger::ACTION_RENUMBER} = get_string('qa_action_' . QuizAttemptsMerger::ACTION_RENUMBER, 'tool_mergeusers'); $quizStrings->{QuizAttemptsMerger::ACTION_DELETE_FROM_SOURCE} = get_string('qa_action_' . QuizAttemptsMerger::ACTION_DELETE_FROM_SOURCE, 'tool_mergeusers'); $quizStrings->{QuizAttemptsMerger::ACTION_DELETE_FROM_TARGET} = get_string('qa_action_' . QuizAttemptsMerger::ACTION_DELETE_FROM_TARGET, 'tool_mergeusers');
/** * Shows the result of a merging action. * @param object $to stdClass with at least id and username fields. * @param object $from stdClass with at least id and username fields. * @param bool $success true if merging was ok; false otherwise. * @param array $data logs of actions done if success, or list of errors on failure. * @param id $logid id of the record with the whole detail of this merging action. * @return string html with the results. */ public function results_page($to, $from, $success, array $data, $logid) { if ($success) { $resulttype = 'ok'; $dbmessage = 'dbok'; $notifytype = 'notifysuccess'; } else { $transactions = tool_mergeusers_transactionssupported() ? '_transactions' : '_no_transactions'; $resulttype = 'ko'; $dbmessage = 'dbko' . $transactions; $notifytype = 'notifyproblem'; } $output = $this->header(); $output .= $this->heading(get_string('mergeusers', 'tool_mergeusers')); $output .= $this->build_progress_bar(self::INDEX_PAGE_RESULTS_STEP); $output .= html_writer::empty_tag('br'); $output .= html_writer::start_tag('div', array('class' => 'result')); $output .= html_writer::start_tag('div', array('class' => 'title')); $output .= get_string('merging', 'tool_mergeusers'); if (!is_null($to) && !is_null($from)) { $output .= ' ' . get_string('usermergingheader', 'tool_mergeusers', $from) . ' ' . get_string('into', 'tool_mergeusers') . ' ' . get_string('usermergingheader', 'tool_mergeusers', $to); } $output .= html_writer::empty_tag('br') . html_writer::empty_tag('br'); $output .= get_string('logid', 'tool_mergeusers', $logid); $output .= html_writer::empty_tag('br'); $output .= get_string('log' . $resulttype, 'tool_mergeusers'); $output .= html_writer::end_tag('div'); $output .= html_writer::empty_tag('br'); $output .= html_writer::start_tag('div', array('class' => 'resultset' . $resulttype)); foreach ($data as $item) { $output .= $item . html_writer::empty_tag('br'); } $output .= html_writer::end_tag('div'); $output .= html_writer::end_tag('div'); $output .= html_writer::tag('div', html_writer::empty_tag('br')); $output .= $this->notification(html_writer::tag('center', get_string($dbmessage, 'tool_mergeusers')), $notifytype); $output .= html_writer::tag('center', $this->single_button(new moodle_url('/admin/tool/mergeusers/index.php'), get_string('continue'), 'get')); $output .= $this->footer(); return $output; }