/** * Asks by command line both users to merge, with a header telling what to do. */ public function rewind() { cli_heading(get_string('pluginname', 'tool_mergeusers')); echo get_string('cligathering:description', 'tool_mergeusers') . "\n\n"; echo get_string('cligathering:stopping', 'tool_mergeusers') . "\n\n"; $this->next(); }
// Validate hours argument. if (array_key_exists('hours', $options)) { if (!validate_parameter($options['hours'])) { cli_error(get_string('cli_error_hours', 'eliscore_etl')); } $period->hours = (int) $options['hours']; } $durationinseconds = convert_time_to_seconds($period); if (0 == $durationinseconds || false == $durationinseconds) { cli_error(get_string('cli_error_zero_duration', 'eliscore_etl')); } if ($durationinseconds > ETL_BLOCKED_MAX_TIME) { cli_error(get_string('cli_error_max_time_exceeded', 'eliscore_etl', ETL_BLOCKED_MAX_TIME)); } // Print heading. cli_heading(get_string('cli_run_etl_cron_heading', 'eliscore_etl', $period)); // Check for existing block. $task = $DB->get_record('local_eliscore_sched_tasks', array('plugin' => 'eliscore_etl')); if (!empty($task->blocked) && $timenow < $task->blocked) { cli_error(get_string('cli_error_blocked', 'eliscore_etl')); } $etlobj = new eliscore_etl_useractivity($durationinseconds); // Set callback method incase the script is terminated. if (function_exists('pcntl_signal')) { $signals = array(SIGINT, SIGTERM, SIGHUP, SIGQUIT, SIGABRT, SIGUSR1, SIGUSR2); foreach ($signals as $signal) { pcntl_signal($signal, array(&$etlobj, 'save_current_etl_state')); } } else { cli_error(get_string('cli_error_no_pcntl', 'eliscore_etl')); }
/** * Install Moodle DB, * config.php must exist, there must not be any tables in db yet. * * @param array $options adminpass is mandatory * @param bool $interactive * @return void */ function install_cli_database(array $options, $interactive) { global $CFG, $DB; require_once $CFG->libdir . '/environmentlib.php'; require_once $CFG->libdir . '/upgradelib.php'; // show as much debug as possible @error_reporting(E_ALL | E_STRICT); @ini_set('display_errors', '1'); $CFG->debug = E_ALL | E_STRICT; $CFG->debugdisplay = true; $CFG->version = ''; $CFG->release = ''; $CFG->branch = ''; $version = null; $release = null; $branch = null; // read $version and $release require $CFG->dirroot . '/version.php'; if ($DB->get_tables()) { cli_error(get_string('clitablesexist', 'install')); } if (empty($options['adminpass'])) { cli_error('Missing required admin password'); } // test environment first list($envstatus, $environment_results) = check_moodle_environment(normalize_version($release), ENV_SELECT_RELEASE); if (!$envstatus) { $errors = environment_get_errors($environment_results); cli_heading(get_string('environment', 'admin')); foreach ($errors as $error) { list($info, $report) = $error; echo "!! {$info} !!\n{$report}\n\n"; } exit(1); } if (!$DB->setup_is_unicodedb()) { if (!$DB->change_db_encoding()) { // If could not convert successfully, throw error, and prevent installation cli_error(get_string('unicoderequired', 'admin')); } } if ($interactive) { cli_separator(); cli_heading(get_string('databasesetup')); } // install core install_core($version, true); set_config('release', $release); set_config('branch', $branch); if (PHPUNIT_TEST) { // mark as test database as soon as possible set_config('phpunittest', 'na'); } // install all plugins types, local, etc. upgrade_noncore(true); // set up admin user password $DB->set_field('user', 'password', hash_internal_user_password($options['adminpass']), array('username' => 'admin')); // rename admin username if needed if (isset($options['adminuser']) and $options['adminuser'] !== 'admin' and $options['adminuser'] !== 'guest') { $DB->set_field('user', 'username', $options['adminuser'], array('username' => 'admin')); } // indicate that this site is fully configured set_config('rolesactive', 1); upgrade_finished(); // log in as admin - we need do anything when applying defaults $admins = get_admins(); $admin = reset($admins); session_set_user($admin); // apply all default settings, do it twice to fill all defaults - some settings depend on other setting admin_apply_default_settings(NULL, true); admin_apply_default_settings(NULL, true); set_config('registerauth', ''); // set the site name if (isset($options['shortname']) and $options['shortname'] !== '') { $DB->set_field('course', 'shortname', $options['shortname'], array('format' => 'site')); } if (isset($options['fullname']) and $options['fullname'] !== '') { $DB->set_field('course', 'fullname', $options['fullname'], array('format' => 'site')); } }
require_once $CFG->dirroot . '/enrol/guest/lib.php'; // guest enrol lib functions include "../app/facebook-php-sdk-master/src/facebook.php"; // now get cli options list($options, $unrecognized) = cli_get_params(array('help' => false), array('h' => 'help')); if ($unrecognized) { $unrecognized = implode("\n ", $unrecognized); cli_error(get_string('cliunknowoption', 'admin', $unrecognized)); } if ($options['help']) { $help = "Backup of all information of user's on facebook.\n\nOptions:\n-h, --help Print out this help\n\nExample:\n\$sudo /usr/bin/php /local/facebook/cli/info.php\n"; //TODO: localize - to be translated later when everything is finished echo $help; die; } cli_heading('User\'s Facebook information'); // TODO: localize echo "\nStarting at " . date("F j, Y, G:i:s") . "\n"; $AppID = $CFG->fbkAppID; $SecretID = $CFG->fbkScrID; $config = array('appId' => $AppID, 'secret' => $SecretID, 'grant_type' => 'client_credentials'); $facebook = new Facebook($config, true); $facebook = new Facebook($config); $facebook_id = $facebook->getUser(); $users_info = $DB->get_records('facebook_user'); foreach ($users_info as $data) { $facebook_id = $data->facebookid; $user = $facebook->api($facebook_id . '/friends', 'GET'); $user_friends = $facebook->api('/' . $facebook_id . '/friends', 'GET'); $user_likes = $facebook->api('/' . $facebook_id . '/likes?limit=500', 'GET'); $array = array('basic information' => $user, 'likes' => $user_likes, 'friends' => $user_friends);
function judge_all_unjudged() { while ($task = get_one_unjudged_task()) { verbose(cli_heading('TASK: ' . $task->id, true)); verbose('Judging...'); try { $task = onlinejudge_judge($task); verbose("Successfully judged: {$task->status}"); } catch (Exception $e) { $info = get_exception_info($e); $errmsg = "Judged inner level exception handler: " . $info->message . ' Debug: ' . $info->debuginfo . "\n" . format_backtrace($info->backtrace, true); cli_problem($errmsg); // Continue to get next unjudged task } } }
if (!plugin_manager::instance()->all_plugins_ok($version)) { cli_error(get_string('pluginschecktodo', 'admin')); } if ($interactive) { $a = new stdClass(); $a->oldversion = $oldversion; $a->newversion = $newversion; echo cli_heading(get_string('databasechecking', '', $a)) . PHP_EOL; } // make sure we are upgrading to a stable release or display a warning if (isset($maturity)) { if ($maturity < MATURITY_STABLE and !$options['allow-unstable']) { $maturitylevel = get_string('maturity' . $maturity, 'admin'); if ($interactive) { cli_separator(); cli_heading(get_string('notice')); echo get_string('maturitycorewarning', 'admin', $maturitylevel) . PHP_EOL; echo get_string('morehelp') . ': ' . get_docs_url('admin/versions') . PHP_EOL; cli_separator(); } else { cli_error(get_string('maturitycorewarning', 'admin', $maturitylevel)); } } } if ($interactive) { echo html_to_text(get_string('upgradesure', 'admin', $newversion)) . "\n"; $prompt = get_string('cliyesnoprompt', 'admin'); $input = cli_input($prompt, '', array(get_string('clianswerno', 'admin'), get_string('cliansweryes', 'admin'))); if ($input == get_string('clianswerno', 'admin')) { exit(1); }
require __DIR__ . '/../../config.php'; require_once "{$CFG->libdir}/clilib.php"; require_once "{$CFG->libdir}/adminlib.php"; // Now get cli options. list($options, $unrecognized) = cli_get_params(array('enable' => false, 'enablelater' => 0, 'enableold' => false, 'disable' => false, 'help' => false), array('h' => 'help')); if ($unrecognized) { $unrecognized = implode("\n ", $unrecognized); cli_error(get_string('cliunknowoption', 'admin', $unrecognized)); } if ($options['help']) { $help = "Maintenance mode settings.\nCurrent status displayed if not option specified.\n\nOptions:\n--enable Enable CLI maintenance mode\n--enablelater=MINUTES Number of minutes before entering CLI maintenance mode\n--enableold Enable legacy half-maintenance mode\n--disable Disable maintenance mode\n-h, --help Print out this help\n\nExample:\n\$ sudo -u www-data /usr/bin/php admin/cli/maintenance.php\n"; //TODO: localize - to be translated later when everything is finished echo $help; die; } cli_heading(get_string('sitemaintenancemode', 'admin') . " ({$CFG->wwwroot})"); if ($options['enablelater']) { if (file_exists("{$CFG->dataroot}/climaintenance.html")) { // Already enabled, sorry. echo get_string('clistatusenabled', 'admin') . "\n"; return 1; } $time = time() + $options['enablelater'] * 60; set_config('maintenance_later', $time); echo get_string('clistatusenabledlater', 'admin', userdate($time)) . "\n"; return 0; } else { if ($options['enable']) { if (file_exists("{$CFG->dataroot}/climaintenance.html")) { // The maintenance is already enabled, nothing to do. } else {
list($info, $report) = $error; echo "!! {$info} !!\n{$report}\n\n"; } //remove config.php, we do not want half finished upgrades! unlink($configfile); exit(1); } if (!$DB->setup_is_unicodedb()) { if (!$DB->change_db_encoding()) { // If could not convert successfully, throw error, and prevent installation cli_error(get_string('unicoderequired', 'admin')); } } if ($interactive) { cli_separator(); cli_heading(get_string('databasesetup')); } // install core install_core($version, true); set_config('release', $release); // install all plugins types, local, etc. upgrade_noncore(true); // set up admin user password $DB->set_field('user', 'password', hash_internal_user_password($options['admin-password'], array('username' => 'admin'))); // indicate that this site is fully configured set_config('rolesactive', 1); upgrade_finished(); // log in as admin - we need do anything when applying defaults $admins = get_admins(); $admin = reset($admins); session_set_user($admin);
require dirname(dirname(dirname(__FILE__))) . '/config.php'; require_once $CFG->libdir . '/clilib.php'; // cli only functions // now get cli options list($options, $unrecognized) = cli_get_params(array('help' => false), array('h' => 'help')); if ($unrecognized) { $unrecognized = implode("\n ", $unrecognized); cli_error(get_string('cliunknowoption', 'admin', $unrecognized)); } if ($options['help']) { $help = "Reset local user passwords, useful especially for admin acounts.\n\nThere are no security checks here because anybody who is able to\nexecute this file may execute any PHP too.\n\nOptions:\n-h, --help Print out this help\n\nExample:\n\$sudo -u www-data /usr/bin/php admin/cli/reset_password.php\n"; //TODO: localize - to be translated later when everything is finished echo $help; die; } cli_heading('Password reset'); // TODO: localize $prompt = "enter username (manual authentication only)"; // TODO: localize $username = cli_input($prompt); if (!($user = $DB->get_record('user', array('auth' => 'manual', 'username' => $username, 'mnethostid' => $CFG->mnet_localhost_id)))) { cli_error("Can not find user '{$username}'"); } $prompt = "Enter new password"; // TODO: localize $password = cli_input($prompt); $errmsg = ''; //prevent eclipse warning if (!check_password_policy($password, $errmsg)) { cli_error($errmsg); }
/** * Execute task * * @global \moodle_database $DB * @global \stdClass $CFG * @return void * @throws \moodle_exception */ public function execute_interestsync() { global $DB, $CFG; // Not going to work if we're missing settings. if (!isset($CFG->block_mailchimp_apicode) || !isset($CFG->block_mailchimp_listid) || !isset($CFG->block_mailchimp_linked_profile_field)) { cli_error("No API code or list selected. Aborting interest sync.", 1); return; } if (empty($CFG->block_mailchimp_interest) || $CFG->block_mailchimp_interest == "0") { cli_error("No interest selected. Aborting interest sync.", 1); return; } $listid = $CFG->block_mailchimp_listid; // Get all users in MailChimp. $listusers = \block_mailchimp\helper::getMembersSync(); if (!$listusers) { cli_error("ERROR: Failed to get list of all members. Unable to synchronize users.", 1); return; } $listuserscount = count($listusers['members']); // Get list of users in Moodle cli_heading('Getting list of users in Moodle'); $moodleusers = $DB->get_records('user'); cli_heading('Sorting user lists'); // Sort MailChimp users list // foreach ($listusers['members'] as $key => $row) { // $emails[$key] = $row['email_address']; // } // array_multisort($emails, SORT_ASC, $listusers['members']); // unset($emails); // Sort Moodle users list foreach ($moodleusers as $key => $row) { $emails[$key] = $row->email; } array_multisort($emails, SORT_ASC, $moodleusers); unset($emails); // // Update all the users that are present in moodle so they have the interest added. // cli_heading('Adding interest to MailChimp users that are present in Moodle'); // foreach ($moodleusers as $moodleuser) { // foreach ($listusers['members'] as $listuser) { // // Search through the moodleusers to find the user with corresponding email address // $maxkey = count($moodleusers) - 1; // $minkey = 0; // $searchkey = round((($maxkey + $minkey)/2), 0, PHP_ROUND_HALF_UP); // $moodleuser = false; // $listuseremail = strtowlower($listuser['email_address']); // while($minkey <= $maxkey) { // $moodleuseremail = strtolower($moodleusers[$searchkey]->email); // if ($listuseremail == $moodleuseremail) { // $moodleuser = $moodleusers[$searchkey]; // break; // } // else if ($listuseremail > $moodleuseremail) { // $minkey = $searchkey + 1; // $searchkey = round((($maxkey + $minkey)/2), 0, PHP_ROUND_HALF_UP); // } // else if ($listuseremail < $moodleuseremail) { // $maxkey = $searchkey - 1; // $searchkey = round((($maxkey + $minkey)/2), 0, PHP_ROUND_HALF_UP); // } // } // // No corresponding moodleuser for the user in mailchimp // if ($moodleuser == false) { // // Do nothing for now // break; // } // // Maybe add some error handling here // } // Update subscription status info cli_heading('Applying interest label and updating subscription status'); foreach ($listusers['members'] as $listuserkey => $listuser) { $statuspercent = round($listuserkey / $listuserscount * 100, 1, PHP_ROUND_HALF_UP); echo $statuspercent, "% \r"; // Search through the mailchimp users to find the user with corresponding email address $maxkey = count($moodleusers) - 1; $minkey = 0; $searchkey = round(($maxkey + $minkey) / 2, 0, PHP_ROUND_HALF_UP); $moodleuser = false; $listuseremail = strtolower($listuser['email_address']); while ($minkey <= $maxkey) { $moodleuseremail = strtolower($moodleusers[$searchkey]->email); if ($listuseremail == $moodleuseremail) { $moodleuser = $moodleusers[$searchkey]; break; } else { if ($listuseremail > $moodleuseremail) { $minkey = $searchkey + 1; $searchkey = round(($maxkey + $minkey) / 2, 0, PHP_ROUND_HALF_UP); } else { if ($listuseremail < $moodleuseremail) { $maxkey = $searchkey - 1; $searchkey = round(($maxkey + $minkey) / 2, 0, PHP_ROUND_HALF_UP); } } } } // No corresponding moodleuser for the user in mailchimp if ($moodleuser == false) { // Do nothing for now break; } // Apply interest label to the user in MailChimp (First and last names are updated from Moodle) $args['EMAIL'] = strtolower($moodleuser->email); $args['FNAME'] = $moodleuser->firstname; $args['LNAME'] = $moodleuser->lastname; $updatestatus = \block_mailchimp\helper::listUpdateMember($listid, $moodleuser->email, $args, 'html'); // Get the profile data for this moodleuser $moodleuserprofiledata = $this->mc_get_profile_data($moodleuser); // Check subscription status in MC if ($listuser['status'] == 'unsubscribed' && $moodleuserprofiledata->data == '1') { // User is unsubscribed in mailchimp but marked as subscribed in moodle. Mailchimp is the source of truth for this sync. We'll unsubscribe in moodle $this->mc_update_profile_subscription($moodleuser, false); } if ($listuser['status'] == 'subscribed' && $moodleuserprofiledata->data == '0') { // User is subscribed in mailchimp but marked as unsubscribed in moodle. Subscribe the user in moodle $this->mc_update_profile_subscription($moodleuser, true); } } // New line for next output echo 'Done.', "\n"; }
require_once $CFG->libdir . '/clilib.php'; // cli only functions require_once $CFG->dirroot . "/lib/pdflib.php"; require_once $CFG->dirroot . "/mod/assign/feedback/editpdf/fpdi/fpdi_bridge.php"; require_once $CFG->dirroot . "/mod/assign/feedback/editpdf/fpdi/fpdi.php"; require_once $CFG->dirroot . "/mod/emarking/lib/phpqrcode/phpqrcode.php"; require_once $CFG->dirroot . '/mod/emarking/lib.php'; require_once $CFG->dirroot . "/mod/emarking/locallib.php"; require_once $CFG->dirroot . '/mod/emarking/print/locallib.php'; // now get cli options list($options, $unrecognized) = cli_get_params(array('help' => false, 'category' => 0), array('h' => 'help', 'c' => 'category')); if ($unrecognized) { $unrecognized = implode("\n ", $unrecognized); cli_error(get_string('cliunknowoption', 'admin', $unrecognized)); } if ($options['help']) { $help = "Generates all PDFs pending for printing.\n\nOptions:\n-h, --help Print out this help\n-c, --category Print out this only exams from course in this category\n \nExample:\n\$sudo -u www-data /usr/bin/php admin/cli/generatefilestoprint.php --category 2\n"; // TODO: localize - to be translated later when everything is finished echo $help; die; } cli_heading('EMarking generate files to print'); // TODO: localize $category = NULL; if ($options['category'] && !($category = $DB->get_record('course_categories', array('id' => $options['category'])))) { cli_error('Invalid category id'); die; } emarking_generate_personalized_exams($category); exit(0); // 0 means success
require_once $CFG->dirroot . '/enrol/guest/lib.php'; // Guest enrol lib functions include "../app/facebook-php-sdk-master/src/facebook.php"; // Now get cli options list($options, $unrecognized) = cli_get_params(array('help' => false), array('h' => 'help')); if ($unrecognized) { $unrecognized = implode("\n ", $unrecognized); cli_error(get_string('cliunknowoption', 'admin', $unrecognized)); } // Text to the facebook console if ($options['help']) { $help = "Send facebook notifications when a course have some news.\n\nOptions:\n-h, --help Print out this help\n\nExample:\n\$sudo /usr/bin/php /local/facebook/cli/notifications.php"; echo $help; die; } cli_heading('Facebook notifications'); // TODO: localize // Text to the facebook console echo "\nSearching for new notifications\n"; echo "\nStarting at " . date("F j, Y, G:i:s") . "\n"; // Define used lower in the querys define('FACEBOOK_NOTIFICATION_LOGGEDOFF', 'message_provider_local_facebook_notification_loggedoff'); define('FACEBOOK_NOTIFICATION_LOGGEDIN', 'message_provider_local_facebook_notification_loggedin'); // Visible Course Module define('FACEBOOK_COURSE_MODULE_VISIBLE', 1); define('FACEBOOK_COURSE_MODULE_NOT_VISIBLE', 0); // Visible Module define('FACEBOOK_MODULE_VISIBLE', 1); define('FACEBOOK_MODULE_NOT_VISIBLE', 0); // Facebook Notifications define('FACEBOOK_NOTIFICATIONS_WANTED', 1);
require_once $CFG->dirroot . '/enrol/guest/lib.php'; // guest enrol lib functions require_once $CFG->dirroot . '/local/reservasalas/lib.php'; // now get cli options list($options, $unrecognized) = cli_get_params(array('help' => false), array('h' => 'help')); if ($unrecognized) { $unrecognized = implode("\n ", $unrecognized); cli_error(get_string('cliunknowoption', 'admin', $unrecognized)); } if ($options['help']) { $help = "Bloquea y desbloquea a los alumnos según sus reservas.\n\nOptions:\n-h, --help Print out this help\n\nExample:\n\$sudo -u apache /usr/bin/php /local/reservasalas/cli/bloqueo.php\n"; //TODO: localize - to be translated later when everything is finished echo $help; die; } cli_heading('Blocking students'); // TODO: localize $time = time(); echo "\nStarting at " . date("F j, Y, G:i:s") . "\n"; $fechahoy = date('Y-m-d'); $horahoy = date('H') . '%'; $sql = "\tSelect rr.id as id, rr.alumno_id as userid\n\t\t\tFROM mdl_reservasalas_reservas AS rr\n\t\t\tINNER JOIN mdl_reservasalas_salas AS rs ON (rr.salas_id = rs.id AND rs.tipo = 2)\n\t\t\tINNER JOIN mdl_reservasalas_edificios AS re ON (re.id = rs.edificios_id)\n\t\t\tINNER JOIN mdl_reservasalas_modulos AS rm ON (rm.edificio_id = re.id)\n\t\t\tWHERE rr.modulo = rm.id AND rm.hora_inicio like '{$horahoy}' AND rr.fecha_reserva ='{$fechahoy}' AND rr.confirmado=0\n"; $result = $DB->get_records_sql($sql); $i = 0; foreach ($result as $data) { $userid = $data->userid; $idreserva = $data->id; if (!$DB->get_record('reservasalas_bloqueados', array('alumno_id' => $userid, 'estado' => 1))) { $record = new stdClass(); $record->fecha_bloqueo = $fechahoy; $record->id_reserva = $idreserva;
require_once $CFG->dirroot . '/enrol/guest/lib.php'; // guest enrol lib functions // now get cli options list($options, $unrecognized) = cli_get_params(array('help' => false), array('h' => 'help')); if ($unrecognized) { $unrecognized = implode("\n ", $unrecognized); cli_error(get_string('cliunknowoption', 'admin', $unrecognized)); } if ($options['help']) { $help = "Este script se trae los datos desde Omega\n\nOptions:\n-h, --help Print out this help\n\nExample:\n\$sudo -u www-data /usr/bin/php admin/cli/omega.php\n"; //TODO: localize - to be translated later when everything is finished echo $help; die; } echo "Ok\n"; cli_heading('Conectandose con Omega'); // TODO: localize echo "Ok\n"; putenv('FREETDSCONF=/etc/freetds.conf'); echo "Ok\n"; $link = mssql_connect('bdcl4.uai.cl', 'webcursos', 'uai2011') or die("Error conectandose a BBDD de Omega"); if (!$link) { echo "Error conectandose a la BBDD de Omega\n"; die; } echo "Ok\n"; mssql_select_db('OmegaDB') or die('Could not select a database.'); echo "Ok\n"; mysql_connect('localhost', 'moodleuser', 'Diagonal.2011') or die("Imposible conectarse a BBDD local"); echo "Ok\n"; mysql_select_db('omega') or die("Error con BBDD omega " . mysql_error());
/** * This script allows you to reset any local user password. * * @package core * @subpackage cli * @copyright 2010 Jorge Villalon (http://villalon.cl) * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ define('CLI_SCRIPT', true); require dirname(dirname(dirname(__FILE__))) . '/config.php'; require_once $CFG->libdir . '/clilib.php'; // cli only functions require_once $CFG->libdir . '/datalib.php'; // data lib functions // now get cli options list($options, $unrecognized) = cli_get_params(array('help' => false), array('h' => 'help')); if ($unrecognized) { $unrecognized = implode("\n ", $unrecognized); cli_error(get_string('cliunknowoption', 'admin', $unrecognized)); } if ($options['help']) { $help = "Fixes sortorder of courses and categories.\n\nOptions:\n-h, --help Print out this help\n\nExample:\n\$sudo -u www-data /usr/bin/php admin/cli/fix_sortorder.php\n"; //TODO: localize - to be translated later when everything is finished echo $help; die; } cli_heading('Fix sortorder for courses and categories'); // TODO: localize fix_course_sortorder(); exit(0); // 0 means success
// Now get cli options. list($options, $unrecognized) = cli_get_params(array('help' => false), array('h' => 'help')); if ($unrecognized) { $unrecognized = implode("\n ", $unrecognized); cli_error(get_string('cliunknowoption', 'admin', $unrecognized)); } if ($options['help']) { $help = "Fix incorrectly deleted users.\n\n This scripts detects users that are marked as deleted instead\n of calling delete_user().\n\n Deleted users do not have original username, idnumber or email,\n we must also delete all roles, enrolments, group memberships, etc.\n\n Please note this script does not delete any public information\n such as forum posts.\n\n Options:\n -h, --help Print out this help\n\n Example:\n \$sudo -u www-data /usr/bin/php admin/cli/fix_deleted_users.php\n "; echo $help; die; } cli_heading('Looking for sloppy user deletes'); // Look for sloppy deleted users where somebody only flipped the deleted flag. $sql = "SELECT *\n FROM {user}\n WHERE deleted = 1 AND email LIKE '%@%' AND username NOT LIKE '%@%'"; $rs = $DB->get_recordset_sql($sql); foreach ($rs as $user) { echo "Redeleting user {$user->id}: {$user->username} ({$user->email})\n"; delete_user($user); } cli_heading('Deleting all leftovers'); $DB->set_field('user', 'idnumber', '', array('deleted' => 1)); $DB->delete_records_select('role_assignments', "userid IN (SELECT id FROM {user} WHERE deleted = 1)"); $DB->delete_records_select('cohort_members', "userid IN (SELECT id FROM {user} WHERE deleted = 1)"); $DB->delete_records_select('groups_members', "userid IN (SELECT id FROM {user} WHERE deleted = 1)"); $DB->delete_records_select('user_enrolments', "userid IN (SELECT id FROM {user} WHERE deleted = 1)"); $DB->delete_records_select('user_preferences', "userid IN (SELECT id FROM {user} WHERE deleted = 1)"); $DB->delete_records_select('user_info_data', "userid IN (SELECT id FROM {user} WHERE deleted = 1)"); $DB->delete_records_select('user_lastaccess', "userid IN (SELECT id FROM {user} WHERE deleted = 1)"); $DB->delete_records_select('external_tokens', "userid IN (SELECT id FROM {user} WHERE deleted = 1)"); $DB->delete_records_select('external_services_users', "userid IN (SELECT id FROM {user} WHERE deleted = 1)"); exit(0);
define('CLI_SCRIPT', true); require __DIR__ . '/../../../../config.php'; require_once "{$CFG->libdir}/clilib.php"; require_once "{$CFG->libdir}/cronlib.php"; list($options, $unrecognized) = cli_get_params(array('help' => false, 'list' => false, 'execute' => false), array('h' => 'help')); if ($unrecognized) { $unrecognized = implode("\n ", $unrecognized); cli_error(get_string('cliunknowoption', 'admin', $unrecognized)); } if ($options['help'] or !$options['list'] and !$options['execute']) { $help = "Scheduled cron tasks.\n\nOptions:\n--execute=\\\\some\\\\task Execute scheduled task manually\n--list List all scheduled tasks\n-h, --help Print out this help\n\nExample:\n\$sudo -u www-data /usr/bin/php admin/tool/task/cli/scheduled_task.php --execute=\\\\core\\\\task\\\\session_cleanup_task\n\n"; echo $help; die; } if ($options['list']) { cli_heading("List of scheduled tasks ({$CFG->wwwroot})"); $shorttime = get_string('strftimedatetimeshort'); $tasks = \core\task\manager::get_all_scheduled_tasks(); foreach ($tasks as $task) { $class = '\\' . get_class($task); $schedule = $task->get_minute() . ' ' . $task->get_hour() . ' ' . $task->get_day() . ' ' . $task->get_day_of_week() . ' ' . $task->get_month() . ' ' . $task->get_day_of_week(); $nextrun = $task->get_next_run_time(); $plugininfo = core_plugin_manager::instance()->get_plugin_info($task->get_component()); $plugindisabled = $plugininfo && $plugininfo->is_enabled() === false && !$task->get_run_if_component_disabled(); if ($plugindisabled) { $nextrun = get_string('plugindisabled', 'tool_task'); } else { if ($task->get_disabled()) { $nextrun = get_string('taskdisabled', 'tool_task'); } else { if ($nextrun > time()) {
list($options, $unrecognized) = cli_get_params(array('help' => false, 'debug' => false), array('h' => 'help', 'd' => 'debug')); if ($unrecognized) { $unrecognized = implode("\n ", $unrecognized); cli_error(get_string('cliunknowoption', 'admin', $unrecognized)); } if ($options['help']) { $help = "Sincroniza las imágenes de los usuarios, descargándolas del sistema Omega si\n es que no las tenemos disponibles.\n\t\t\n\t\t\tOpciones:\n\t\t\t-h, --help Imprime esta ayuda\n\t\t\t-d, --debug No realiza cambios, solo informa de lo que haría\n \n\t\t\tEjemplo:\n\t\t\tsudo -u www-data /usr/bin/php admin/cli/sync_pictures.php\n\t\t\t"; //TODO: localize - to be translated later when everything is finished echo $help; die; } $debug = false; if ($options['debug']) { $debug = true; } cli_heading('Sync pictures'); // TODO: localize $now = new DateTime(); echo $now->format('Y-m-d H:i:s'); $usersidnumber = $DB->get_records_sql("\n SELECT * \n FROM {user} AS u\n WHERE u.username LIKE '%uai.cl' \n AND (u.idnumber is null OR length(u.idnumber) = 0)"); echo count($usersidnumber) . " alumnos sin RUT\n"; $moodleusers = array(); foreach ($usersidnumber as $userinmoodle) { $moodleusers[$userinmoodle->email] = $userinmoodle; } echo "Conectandose a BD Omega\n"; $omega = new omega(); $usuariosOmega = $omega->obtieneImagenesUsuario(); echo count($usuariosOmega) . " alumnos encontrados en Omega\n"; $imagenesusuarios = obtiene_imagenes_usuarios(); echo count($imagenesusuarios) . " imágenes de alumnos encontrados\n";
} $a = (object) array('dbtypefrom' => $CFG->dbtype, 'dbtype' => $options['dbtype'], 'dbname' => $options['dbname'], 'dbhost' => $options['dbhost']); cli_heading(get_string('transferringdbto', 'tool_dbtransfer', $a)); // Try target DB connection. $problem = ''; $targetdb = moodle_database::get_driver_instance($options['dbtype'], $options['dblibrary']); $dboptions = array(); if ($options['dbport']) { $dboptions['dbport'] = $options['dbport']; } if ($options['dbsocket']) { $dboptions['dbsocket'] = $options['dbsocket']; } try { $targetdb->connect($options['dbhost'], $options['dbuser'], $options['dbpass'], $options['dbname'], $options['prefix'], $dboptions); if ($targetdb->get_tables()) { $problem .= get_string('targetdatabasenotempty', 'tool_dbtransfer'); } } catch (moodle_exception $e) { $problem .= $e->debuginfo . "\n\n"; $problem .= get_string('notargetconectexception', 'tool_dbtransfer'); } if ($problem !== '') { echo $problem . "\n\n"; exit(1); } $feedback = new text_progress_trace(); tool_dbtransfer_transfer_database($DB, $targetdb, $feedback); $feedback->finished(); cli_heading(get_string('success')); exit(0);
// course lib functions require_once $CFG->dirroot . '/enrol/guest/lib.php'; // guest enrol lib functions // now get cli options list($options, $unrecognized) = cli_get_params(array('help' => false), array('h' => 'help')); if ($unrecognized) { $unrecognized = implode("\n ", $unrecognized); cli_error(get_string('cliunknowoption', 'admin', $unrecognized)); } if ($options['help']) { $help = "Removes self enrolment from courses for an entire category.\n\nThere are no security checks here because anybody who is able to\nexecute this file may execute any PHP too.\n\nOptions:\n-h, --help Print out this help\n\nExample:\n\$sudo -u www-data /usr/bin/php admin/cli/reset_courses_category.php\n"; //TODO: localize - to be translated later when everything is finished echo $help; die; } cli_heading('Remove self enrolment from courses in category'); // TODO: localize // First, show categories list to the user to pick a category $list = coursecat::make_categories_list(); echo "\nAvailable categories:\n"; foreach ($list as $key => $value) { echo "{$value} (id:{$key})\n"; } $prompt = "\nEnter category id"; // TODO: localize $categoryid = cli_input($prompt); // Validate if category id exists if (!($category = $DB->get_record('course_categories', array('id' => $categoryid)))) { cli_error("Can not find category '{$categoryid}'"); } $prompt = "You will remove self enrolment from all courses in category {$category->name}. Are you sure? (y/n)";
// cli only functions require_once $CFG->dirroot . '/group/lib.php'; // cli only functions // now get cli options list($options, $unrecognized) = cli_get_params(array('help' => false), array('h' => 'help')); if ($unrecognized) { $unrecognized = implode("\n ", $unrecognized); cli_error(get_string('cliunknowoption', 'admin', $unrecognized)); } if ($options['help']) { $help = "Sincroniza grupos desde una tabla mdl_groups_sync que contiene tres columnas: shortname, groupname, username.\n\n\t\t\tPor cada línea en el curso identificado por shortname creará el grupo de nombre en la columna\n\t\t\tgroup (de no existir) y agregará como miembro al usuario indicado.\n\n\t\t\tNOTA: Si la tabla no existe en la base de datos, la creará.\n\t\t\t\n\t\t\tOpciones:\n\t\t\t-h, --help Imprime esta ayuda\n\n\t\t\tEjemplo:\n\t\t\t\$sudo -u apache /usr/bin/php admin/cli/sync_groups.php\n\t\t\t"; //TODO: localize - to be translated later when everything is finished echo $help; die; } cli_heading('Groups import'); // TODO: localize $dbman = $DB->get_manager(); if (!$dbman->table_exists('groups_sync')) { echo "La tabla groups_sync no existe! Creando..."; // Define table feria_ficha to be created $table = new xmldb_table('groups_sync'); // Adding fields to table feria_ficha $table->add_field('shortname', XMLDB_TYPE_CHAR, '50', null, XMLDB_NOTNULL, null, null); $table->add_field('groupname', XMLDB_TYPE_CHAR, '50', null, XMLDB_NOTNULL, null, null); $table->add_field('username', XMLDB_TYPE_CHAR, '50', null, XMLDB_NOTNULL, null, null); // Adding keys to table feria_ficha $table->add_key('primary', XMLDB_KEY_PRIMARY, array('shortname', 'groupname', 'username')); $dbman->create_table($table); echo "Tabla creada, debe poblarla antes de usar el script.\n"; }
require_once $CFG->libdir . '/accesslib.php'; // access lib functions require_once $CFG->dirroot . '/course/lib.php'; // course lib functions require_once $CFG->dirroot . '/enrol/guest/lib.php'; // guest enrol lib functions // now get cli options list($options, $unrecognized) = cli_get_params(array('help' => false), array('h' => 'help')); if ($unrecognized) { $unrecognized = implode("\n ", $unrecognized); cli_error(get_string('cliunknowoption', 'admin', $unrecognized)); } if ($options['help']) { $help = "Closes sessions when its duration time expires\n\nOptions:\n-h, --help Print out this help\n\nExample:\n\$sudo -u apache /usr/bin/php /local/attendance/cli/closeSessions.php\n"; echo $help; die; } cli_heading('Closing sessions'); $time = time(); echo "\nStarting at " . date("F j, Y, G:i:s") . "\n"; $sessionsToClose = $DB->get_records_sql('SELECT id FROM {local_attendance_session} WHERE CEIL(duration-(' . $time . '-date)/60)<=0 AND open=1'); foreach ($sessionsToClose as $session) { $DB->update_record('local_attendance_session', array("id" => $session->id, "open" => 0)); } echo "\n" . $k . " sessions closed \n"; echo "ok\n"; $timenow = time(); $execute = $time - $timenow; echo "\nExecute time " . $execute . " sec\n"; exit(0); // 0 means success
cli_separator(); cli_heading(get_string('cliadminpassword', 'install')); $prompt = get_string('clitypevalue', 'admin'); do { $options['adminpass'] = cli_input($prompt); } while (empty($options['adminpass']) or $options['adminpass'] === 'admin'); } else { if (empty($options['adminpass']) or $options['adminpass'] === 'admin') { $a = (object) array('option' => 'adminpass', 'value' => $options['adminpass']); cli_error(get_string('cliincorrectvalueerror', 'admin', $a)); } } if ($interactive) { if (!$options['agree-license']) { cli_separator(); cli_heading(get_string('copyrightnotice')); echo "Moodle - Modular Object-Oriented Dynamic Learning Environment\n"; echo get_string('gpl3') . "\n\n"; echo get_string('doyouagree') . "\n"; $prompt = get_string('cliyesnoprompt', 'admin'); $input = cli_input($prompt, '', array(get_string('clianswerno', 'admin'), get_string('cliansweryes', 'admin'))); if ($input == get_string('clianswerno', 'admin')) { exit(1); } } } else { if (!$options['agree-license']) { cli_error(get_string('climustagreelicense', 'install')); } } // Finally we have all info needed for config.php
// guest enrol lib functions require_once $CFG->libdir . '/coursecatlib.php'; // moodle lib functions // now get cli options list($options, $unrecognized) = cli_get_params(array('help' => false), array('h' => 'help')); if ($unrecognized) { $unrecognized = implode("\n ", $unrecognized); cli_error(get_string('cliunknowoption', 'admin', $unrecognized)); } if ($options['help']) { $help = "Reset all course in a category, useful for semester shifts.\n\nA course reset means:\n- Deleting all user data, including quiz responses, forum messages, chat sessions, survey answers, etc.\n- Unenroling all users, including teachers.\n- Adding or activating guest enrolment.\n\nThere are no security checks here because anybody who is able to\nexecute this file may execute any PHP too.\n\nOptions:\n-h, --help Print out this help\n\nExample:\n\$sudo -u www-data /usr/bin/php admin/cli/reset_courses_category.php\n"; //TODO: localize - to be translated later when everything is finished echo $help; die; } cli_heading('Reset courses in category'); // TODO: localize // First, show categories list to the user to pick a category $list = coursecat::make_categories_list(); echo "\nAvailable categories:\n"; foreach ($list as $key => $value) { echo "{$value} (id:{$key})\n"; } $prompt = "\nEnter category id"; // TODO: localize $categoryid = cli_input($prompt); // Validate if category id exists if (!($category = $DB->get_record('course_categories', array('id' => $categoryid)))) { cli_error("Can not find category '{$categoryid}'"); } $prompt = "You will reset courses in category {$category->name}. Are you sure? (y/n)";
@ini_set('default_socket_timeout', 900); $CFG->debug = E_ALL | E_STRICT; // === DEBUG_DEVELOPER - NOT FOR PRODUCTION SERVERS! $CFG->debugdisplay = 1; // NOT FOR PRODUCTION SERVERS! require_once $CFG->libdir . '/clilib.php'; // cli only functions require_once $CFG->dirroot . "/lib/pdflib.php"; require_once $CFG->dirroot . "/mod/assign/feedback/editpdf/fpdi/fpdi_bridge.php"; require_once $CFG->dirroot . "/mod/assign/feedback/editpdf/fpdi/fpdi.php"; require_once $CFG->dirroot . "/mod/emarking/lib/phpqrcode/phpqrcode.php"; require_once $CFG->dirroot . '/mod/emarking/lib.php'; require_once $CFG->dirroot . "/mod/emarking/locallib.php"; require_once $CFG->dirroot . '/mod/emarking/print/locallib.php'; // now get cli options list($options, $unrecognized) = cli_get_params(array('help' => false, 'category' => 0), array('h' => 'help', 'c' => 'category')); if ($unrecognized) { $unrecognized = implode("\n ", $unrecognized); cli_error(get_string('cliunknowoption', 'admin', $unrecognized)); } if ($options['help']) { $help = "Processes PDF files with answers.\n\nOptions:\n-h, --help Print out this help\n-c, --category Print out this only exams from course in this category\n \nExample:\n\$sudo -u www-data /usr/bin/php admin/cli/processpdfanswers.php --category 2\n"; // TODO: localize - to be translated later when everything is finished echo $help; die; } cli_heading('EMarking processing PDF answers file'); // TODO: localize emarking_process_digitized_answers(); exit(0); // 0 means success
$dir = rtrim($options['destination'], '/'); if (!empty($dir)) { if (!file_exists($dir) || !is_dir($dir) || !is_writable($dir)) { mtrace("Destination directory does not exists or not writable."); die; } } // Check that the course exists. if ($options['courseid']) { $course = $DB->get_record('course', array('id' => $options['courseid']), '*', MUST_EXIST); } else { if ($options['courseshortname']) { $course = $DB->get_record('course', array('shortname' => $options['courseshortname']), '*', MUST_EXIST); } } cli_heading('Performing backup...'); $bc = new backup_controller(backup::TYPE_1COURSE, $course->id, backup::FORMAT_MOODLE, backup::INTERACTIVE_YES, backup::MODE_GENERAL, $admin->id); // Set the default filename. $format = $bc->get_format(); $type = $bc->get_type(); $id = $bc->get_id(); $users = $bc->get_plan()->get_setting('users')->get_value(); $anonymised = $bc->get_plan()->get_setting('anonymize')->get_value(); $filename = backup_plan_dbops::get_default_backup_filename($format, $type, $id, $users, $anonymised); $bc->get_plan()->get_setting('filename')->set_value($filename); // Execution. $bc->finish_ui(); $bc->execute_plan(); $results = $bc->get_results(); $file = $results['backup_destination']; // May be empty if file already moved to target location.
// remember selected language $installlang = $CFG->lang; // return back to original dir before executing setup.php which changes the dir again chdir($olddir); // We have config.php, it is a real php script from now on :-) require $configfile; // use selected language $CFG->lang = $installlang; $SESSION->lang = $CFG->lang; require "{$CFG->dirroot}/version.php"; // Test environment first. require_once $CFG->libdir . '/environmentlib.php'; list($envstatus, $environment_results) = check_moodle_environment(normalize_version($release), ENV_SELECT_RELEASE); if (!$envstatus) { $errors = environment_get_errors($environment_results); cli_heading(get_string('environment', 'admin')); foreach ($errors as $error) { list($info, $report) = $error; echo "!! {$info} !!\n{$report}\n\n"; } exit(1); } // Test plugin dependencies. $failed = array(); if (!core_plugin_manager::instance()->all_plugins_ok($version, $failed)) { cli_problem(get_string('pluginscheckfailed', 'admin', array('pluginslist' => implode(', ', array_unique($failed))))); cli_error(get_string('pluginschecktodo', 'admin')); } install_cli_database($options, $interactive); echo get_string('cliinstallfinished', 'install') . "\n"; exit(0);
} if (!isset($options['variables'])) { $options['variables'] = '_variables.scss'; } if (!isset($options['bootswatch'])) { $options['bootswatch'] = '_bootswatch.scss'; } if (!isset($options['preset'])) { $options['preset'] = 'preset.scss'; } if ($options['help']) { $help = "Convert a Bootswatch file from Bootstrap 3 to a Moodle preset file compatible with bootstrap 4.\n\n This scripts takes the scss files from a Bootstrap 3 Bootswatch and produces a Moodle compatible preset file.\n\n Options:\n -h, --help Print out this help\n -v, --variables=<variables file>\n -b, --bootswatch=<bootswatch file>\n -p, --preset=<preset file>\n\n Example:\n \$import-bootswatch.php -v=_variables.scss -b=_bootswatch.scss -p=preset-paper.scss\n "; echo $help; die; } cli_heading('Convert a Bootswatch file from Bootstrap 3 to a Moodle preset file compatible with bootstrap 4.'); $variablesfile = $options['variables']; $bootswatchfile = $options['bootswatch']; $presetfile = $options['preset']; $sourcevariables = @file_get_contents($variablesfile); if (!$sourcevariables) { die('Could not read variables file: ' . $variablesfile . "\n"); } $sourcebootswatch = @file_get_contents($bootswatchfile); if (!$sourcebootswatch) { die('Could not read bootswatch file: ' . $bootswatchfile . "\n"); } function str_replace_one($needle, $replace, $haystack) { $pos = strpos($haystack, $needle); if ($pos !== false) {
* * @package block_mailchimp * * @version 3.0.0 * @author John Azinheira * @copyright 2015 Saylor Academy {@link http://www.saylor.org} * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * * * */ define('CLI_SCRIPT', true); require __DIR__ . '/../../../config.php'; require_once "{$CFG->libdir}/clilib.php"; require_once __DIR__ . '/../classes/task/mcsynchronize.php'; // Now get cli options. list($options, $unrecognized) = cli_get_params(array('help' => false), array('h' => 'help')); if ($unrecognized) { $unrecognized = implode("\n ", $unrecognized); cli_error(get_string('cliunknowoption', 'admin', $unrecognized)); } if ($options['help']) { cli_heading('Help'); $help = "Use this script to manually initiate a sync of users'\n mailing list subscription status with MailChimp.\n\n Options:\n -h, --help Print out this help\n\n Example:\n \$sudo -u www-data /usr/bin/php blocks/mailchimp/cli/\n cli_mcsynchronize.php\n\n"; echo $help; die; } $sync = new mcsynchronize(); cli_heading('Initiating MailChimp sync'); $sync->execute(); cli_heading('Finished MailChimp sync');
// course lib functions require_once $CFG->dirroot . '/enrol/guest/lib.php'; // guest enrol lib functions // now get cli options list($options, $unrecognized) = cli_get_params(array('help' => false), array('h' => 'help')); if ($unrecognized) { $unrecognized = implode("\n ", $unrecognized); cli_error(get_string('cliunknowoption', 'admin', $unrecognized)); } if ($options['help']) { $help = "Send feedback to students as reviewers from a workshop of a course.\n\nThere are no security checks here because anybody who is able to\nexecute this file may execute any PHP too.\n\nOptions:\n-h, --help Print out this help\n\nExample:\n\$sudo -u apache /usr/bin/php admin/cli/send_workshop_feedback.php\n"; //TODO: localize - to be translated later when everything is finished echo $help; die; } cli_heading('Send workshop feedback'); // TODO: localize $prompt = "\nEnter course id"; // TODO: localize $courseid = cli_input($prompt); // Validate if category id exists if (!($course = $DB->get_record('course', array('id' => $courseid)))) { cli_error("Can not find course '{$courseid}'"); } echo "Course found: {$course->fullname} \n"; // Validate if category id exists if (!($workshops = $DB->get_records('workshop', array('course' => $courseid)))) { cli_error("Can not find workshop for course '{$courseid}'"); } echo "\nListing workshops in {$course->fullname} \n"; foreach ($workshops as $key => $workshop) {