Esempio n. 1
0
/**
 * Removes orphaned PHP report schedule records (i.e. PHP report schedule records
 * that have no associated ELIS scheduled task)
 *
 * @uses  $DB;
 */
function php_report_schedule_delete_unmatching_records() {
    global $DB;

    //need this concatenation to connect ELIS and PHP scheduling info
    $concat = local_elisreports_get_taskname_from_column('php_sched.id');

    //query to find the appropriate PHP report task ids
    $sql = "SELECT php_sched.id as id
            FROM {local_elisreports_schedule} php_sched
            LEFT JOIN {local_eliscore_sched_tasks} elis_sched
                   ON (elis_sched.taskname = {$concat})
                WHERE elis_sched.taskname IS NULL";

    //iterate and delete
    $rs = $DB->get_recordset_sql($sql);
    foreach ($rs as $res) {
        $DB->delete_records('local_elisreports_schedule', array('id' => $res->id));
    }
}
Esempio n. 2
0
/**
 * Obtains a recordset containing information about all scheduled PHP
 * report jobs for a particular report (to be used only from the scheduling UI since
 * this depends on the current user)
 *
 * @param   string     $report_shortname  Shortname of the report whose jobs we are looking up
 * @param   string     $fields            String containing the comma-separated list of fiedls
 *                                        to select, or NULL to use the default fields
 *
 * @return  recordset                     A recordset referring to the related records
 *
 * @uses    $CFG
 * @uses    $USER
 * @uses    $DB
 */
function local_elisreports_get_report_jobs_recordset($report_shortname, $fields = NULL) {
    global $CFG, $USER, $DB;

    //query parameters
    $params = array('shortname' => $report_shortname);

    //need this concatenation to connect ELIS and PHP scheduling info
    $concat = local_elisreports_get_taskname_from_column('schedule.id');

    if ($fields === NULL) {
        //default set of database fields to select
        $fields = "user.firstname,
                   user.lastname,
                   task.lastruntime,
                   task.nextruntime,
                   schedule.config,
                   schedule.id AS scheduleid";
    }

    //main query, involving ELIS and PHP schedling info
    $sql = "SELECT {$fields}
            FROM {local_eliscore_sched_tasks} task
            JOIN {local_elisreports_schedule} schedule
              ON task.taskname = {$concat}
            JOIN {$CFG->prefix}user user
              ON schedule.userid = user.id
            WHERE schedule.report = :shortname";

    if (!has_capability('local/elisreports:manageschedules', context_system::instance())) {
        //user does not have the necessary capability for viewing all scheduled instances,
        //so limit to their own
        $sql .= ' AND user.id = :userid';
        $params['userid'] = $USER->id;
    }

    return $DB->get_recordset_sql($sql, $params);
}