예제 #1
0
/**
 * this function schedules the user synchronisation updates
 *
 * Implementation specific : Generic
 */
function local_ent_installer_cron()
{
    global $CFG;
    if (!get_config('local_ent_installer', 'cron_enable')) {
        return;
    }
    $now = time();
    $needscron = false;
    $chour = 0 + get_config('local_ent_installer', 'cron_hour');
    $cmin = 0 + get_config('local_ent_installer', 'cron_min');
    $cfreq = get_config('local_ent_installer', 'cron_enable');
    $now = time();
    $nowdt = getdate($now);
    $expectedtime = get_config('local_ent_installer', 'last_sync_date') + $cfreq - HOURSEC;
    $crondebug = optional_param('crondebug', false, PARAM_BOOL);
    if ($now < $expectedtime && !$crondebug) {
        return;
    }
    if (!empty($CFG->ent_installer_running)) {
        return;
    }
    if ($nowdt['hours'] * 60 + $nowdt['minutes'] >= $chour * 60 + $cmin || $crondebug) {
        set_config('ent_installer_running', 1);
        set_config('last_sync_date', $now, 'local_ent_installer');
        // Get ldap params from real ldap plugin.
        $ldapauth = get_auth_plugin('ldap');
        $options = array('host' => $CFG->wwwroot);
        // Run the customised synchro.
        local_ent_installer_sync_users($ldapauth, $options);
        set_config('ent_installer_running', null);
    } else {
        mtrace('waiting for valid time ');
    }
}
예제 #2
0
require_capability('moodle/site:config', $systemcontext);
$syncstr = get_string('synchroniseusers', 'local_ent_installer');
$PAGE->set_context($systemcontext);
$PAGE->set_heading($syncstr);
$PAGE->set_pagelayout('admin');
$mform = new SyncUsersForm();
// Get ldap params from real ldap plugin.
$ldapauth = get_auth_plugin('ldap');
if ($mform->is_cancelled()) {
    redirect(new moodle_url('/admin/settings.php', array('section' => 'local_ent_installer')));
}
echo $OUTPUT->header();
echo $OUTPUT->heading($syncstr);
if ($data = $mform->get_data()) {
    // Get ldap params from real ldap plugin.
    $ldapauth = get_auth_plugin('ldap');
    // Run the customised synchro.
    $options['force'] = @$data->force;
    $options['verbose'] = true;
    echo '<div class="console">';
    echo '<pre>';
    local_ent_installer_sync_users($ldapauth, $options);
    echo '</pre>';
    echo '</div>';
} else {
    $mform->display();
}
echo '<p><center>';
echo $OUTPUT->single_button(new moodle_url('/admin/settings.php', array('section' => 'local_ent_installer')), get_string('backtosettings', 'local_ent_installer'));
echo '</center></p>';
echo $OUTPUT->footer();