Ignore:
Timestamp:
May 2, 2016, 12:09:23 PM (3 years ago)
Author:
jrpelegrina
Message:

Updated to moodle 3.0.3

Location:
moodle/trunk/fuentes/lib/classes/task
Files:
2 added
1 deleted
6 edited

Legend:

Unmodified
Added
Removed
  • moodle/trunk/fuentes/lib/classes/task/delete_incomplete_users_task.php

    r136 r1331  
    6060                    continue;
    6161                }
     62                if ($user->lastname !== '' and $user->firstname !== '' and $user->email !== '') {
     63                    // This can happen on MySQL - see MDL-52831.
     64                    continue;
     65                }
    6266                delete_user($user);
    6367                mtrace(" Deleted not fully setup user $user->username ($user->id)");
  • moodle/trunk/fuentes/lib/classes/task/file_temp_cleanup_task.php

    r136 r1331  
    4747        $tmpdir = $CFG->tempdir;
    4848        // Default to last weeks time.
    49         $time = strtotime('-1 week');
     49        $time = time() - ($CFG->tempdatafoldercleanup * 3600);
    5050
    5151        $dir = new \RecursiveDirectoryIterator($tmpdir);
     
    8989                }
    9090            } else {
    91                 // Return the time modified to the original date.
    92                 touch($node, $modifieddateobject[$node]);
     91                // Return the time modified to the original date only for real files.
     92                if ($iter->isDir() && !$iter->isDot()) {
     93                    touch($node, $modifieddateobject[$node]);
     94                }
    9395            }
    9496        }
  • moodle/trunk/fuentes/lib/classes/task/legacy_plugin_cron_task.php

    r136 r1331  
    8080        // Run all cron jobs for each module.
    8181        mtrace("Starting activity modules");
    82         get_mailer('buffer');
    8382        if ($mods = $DB->get_records_select("modules", "cron > 0 AND ((? - lastcron) > cron) AND visible = 1", array($timenow))) {
    8483            foreach ($mods as $mod) {
     
    106105            }
    107106        }
    108         get_mailer('close');
    109107        mtrace("Finished activity modules");
    110108
  • moodle/trunk/fuentes/lib/classes/task/manager.php

    r136 r1331  
    5656
    5757        $tasks = null;
    58         require_once($file);
     58        include($file);
    5959
    6060        if (!isset($tasks)) {
     
    8686    public static function reset_scheduled_tasks_for_component($componentname) {
    8787        global $DB;
    88         $cronlockfactory = \core\lock\lock_config::get_lock_factory('cron');
    89 
    90         if (!$cronlock = $cronlockfactory->get_lock('core_cron', 10, 60)) {
    91             throw new \moodle_exception('locktimeout');
    92         }
    9388        $tasks = self::load_default_scheduled_tasks_for_component($componentname);
    94 
    95         $tasklocks = array();
     89        $validtasks = array();
     90
    9691        foreach ($tasks as $taskid => $task) {
    9792            $classname = get_class($task);
     
    10095            }
    10196
    102             // If there is an existing task with a custom schedule, do not override it.
    103             $currenttask = self::get_scheduled_task($classname);
    104             if ($currenttask && $currenttask->is_customised()) {
    105                 $tasks[$taskid] = $currenttask;
    106             }
    107 
    108             if (!$lock = $cronlockfactory->get_lock($classname, 10, 60)) {
    109                 // Could not get all the locks required - release all locks and fail.
    110                 foreach ($tasklocks as $tasklock) {
    111                     $tasklock->release();
     97            $validtasks[] = $classname;
     98
     99            if ($currenttask = self::get_scheduled_task($classname)) {
     100                if ($currenttask->is_customised()) {
     101                    // If there is an existing task with a custom schedule, do not override it.
     102                    continue;
    112103                }
    113                 $cronlock->release();
    114                 throw new \moodle_exception('locktimeout');
    115             }
    116             $tasklocks[] = $lock;
    117         }
    118 
    119         // Got a lock on cron and all the tasks for this component, time to reset the config.
    120         $DB->delete_records('task_scheduled', array('component' => $componentname));
    121         foreach ($tasks as $task) {
    122             $record = self::record_from_scheduled_task($task);
    123             $DB->insert_record('task_scheduled', $record);
    124         }
    125 
    126         // Release the locks.
    127         foreach ($tasklocks as $tasklock) {
    128             $tasklock->release();
    129         }
    130 
    131         $cronlock->release();
     104
     105                // Update the record from the default task data.
     106                self::configure_scheduled_task($task);
     107            } else {
     108                // Ensure that the first run follows the schedule.
     109                $task->set_next_run_time($task->get_next_scheduled_time());
     110
     111                // Insert the new task in the database.
     112                $record = self::record_from_scheduled_task($task);
     113                $DB->insert_record('task_scheduled', $record);
     114            }
     115        }
     116
     117        // Delete any task that is not defined in the component any more.
     118        $sql = "component = :component";
     119        $params = array('component' => $componentname);
     120        if (!empty($validtasks)) {
     121            list($insql, $inparams) = $DB->get_in_or_equal($validtasks, SQL_PARAMS_NAMED, 'param', false);
     122            $sql .= ' AND classname ' . $insql;
     123            $params = array_merge($params, $inparams);
     124        }
     125        $DB->delete_records_select('task_scheduled', $sql, $params);
    132126    }
    133127
     
    158152    public static function configure_scheduled_task(scheduled_task $task) {
    159153        global $DB;
    160         $cronlockfactory = \core\lock\lock_config::get_lock_factory('cron');
    161 
    162         if (!$cronlock = $cronlockfactory->get_lock('core_cron', 10, 60)) {
    163             throw new \moodle_exception('locktimeout');
    164         }
    165154
    166155        $classname = get_class($task);
    167156        if (strpos($classname, '\\') !== 0) {
    168157            $classname = '\\' . $classname;
    169         }
    170         if (!$lock = $cronlockfactory->get_lock($classname, 10, 60)) {
    171             $cronlock->release();
    172             throw new \moodle_exception('locktimeout');
    173158        }
    174159
     
    180165        $result = $DB->update_record('task_scheduled', $record);
    181166
    182         $lock->release();
    183         $cronlock->release();
    184167        return $result;
    185168    }
     
    479462        $where = "(lastruntime IS NULL OR lastruntime < :timestart1)
    480463                  AND (nextruntime IS NULL OR nextruntime < :timestart2)
    481                   AND disabled = 0";
     464                  AND disabled = 0
     465                  ORDER BY lastruntime, id ASC";
    482466        $params = array('timestart1' => $timestart, 'timestart2' => $timestart);
    483467        $records = $DB->get_records_select('task_scheduled', $where, $params);
     
    503487                if ($plugininfo) {
    504488                    if (($plugininfo->is_enabled() === false) && !$task->get_run_if_component_disabled()) {
    505                         mtrace($task->get_name().' skipped - the component '.$task->get_component().' is disabled');
    506489                        $lock->release();
    507490                        continue;
    508491                    }
     492                }
     493
     494                // Make sure the task data is unchanged.
     495                if (!$DB->record_exists('task_scheduled', (array) $record)) {
     496                    $lock->release();
     497                    continue;
    509498                }
    510499
  • moodle/trunk/fuentes/lib/classes/task/scheduled_task.php

    r136 r1331  
    3636    /** Maximum minute value. */
    3737    const MINUTEMAX = 59;
     38
    3839    /** Minimum hour value. */
    3940    const HOURMIN = 0;
     
    4142    const HOURMAX = 23;
    4243
     44    /** Minimum dayofweek value. */
     45    const DAYOFWEEKMIN = 0;
     46    /** Maximum dayofweek value. */
     47    const DAYOFWEEKMAX = 6;
     48
    4349    /** @var string $hour - Pattern to work out the valid hours */
    4450    private $hour = '*';
     
    174180     */
    175181    public function set_day_of_week($dayofweek) {
     182        if ($dayofweek === 'R') {
     183            $dayofweek = mt_rand(self::DAYOFWEEKMIN, self::DAYOFWEEKMAX);
     184        }
    176185        $this->dayofweek = $dayofweek;
    177186    }
     
    324333
    325334        // We need to change to the server timezone before using php date() functions.
    326         $origtz = date_default_timezone_get();
    327         if (!empty($CFG->timezone) && $CFG->timezone != 99) {
    328             date_default_timezone_set($CFG->timezone);
    329         }
     335        \core_date::set_default_server_timezone();
    330336
    331337        $daysinmonth = date("t");
     
    396402                           $nextvalidyear);
    397403
    398         // We need to change the timezone back so other date functions in moodle do not get confused.
    399         if (!empty($CFG->timezone) && $CFG->timezone != 99) {
    400             date_default_timezone_set($origtz);
    401         }
    402 
    403404        return $nexttime;
    404405    }
  • moodle/trunk/fuentes/lib/classes/task/send_failed_login_notifications_task.php

    r136 r1331  
    2929class send_failed_login_notifications_task extends scheduled_task {
    3030
     31    /** The maximum time period to look back (30 days = 30 * 24 * 3600) */
     32    const NOTIFY_MAXIMUM_TIME = 2592000;
     33
    3134    /**
    3235     * Get a descriptive name for this task (shown to admins).
     
    5154        $recip = get_users_from_config($CFG->notifyloginfailures, 'moodle/site:config');
    5255
    53         if (empty($CFG->lastnotifyfailure)) {
    54             $CFG->lastnotifyfailure = 0;
     56        // Do not look back more than 1 month to avoid crashes due to huge number of records.
     57        $maximumlastnotifytime = time() - self::NOTIFY_MAXIMUM_TIME;
     58        if (empty($CFG->lastnotifyfailure) || ($CFG->lastnotifyfailure < $maximumlastnotifytime)) {
     59            $CFG->lastnotifyfailure = $maximumlastnotifytime;
    5560        }
    5661
     
    6873        // and insert them into the cache_flags temp table.
    6974        $logmang = get_log_manager();
    70         $readers = $logmang->get_readers('\core\log\sql_internal_reader');
     75        $readers = $logmang->get_readers('\core\log\sql_internal_table_reader');
    7176        $reader = reset($readers);
    7277        $readername = key($readers);
     
    111116        // Now, select all the login error logged records belonging to the ips and infos
    112117        // since lastnotifyfailure, that we have stored in the cache_flags table.
     118        $namefields = get_all_user_name_fields(true, 'u');
    113119        $sql = "SELECT * FROM (
    114                         SELECT l.*, u.username
     120                        SELECT l.*, u.username, $namefields
    115121                          FROM {" . $logtable . "} l
    116122                          JOIN {cache_flags} cf ON l.ip = cf.name
     
    120126                               AND cf.flagtype = 'login_failure_by_ip'
    121127                    UNION ALL
    122                         SELECT l.*, u.username
     128                        SELECT l.*, u.username, $namefields
    123129                          FROM {" . $logtable . "} l
    124130                          JOIN {cache_flags} cf ON l.userid = " . $DB->sql_cast_char2int('cf.name') . "
     
    142148                $other = unserialize($log->other);
    143149                $a->info = empty($other['username']) ? '' : $other['username'];
     150                $a->name = get_string('unknownuser');
    144151            } else {
    145152                $a->info = $log->username;
     153                $a->name = fullname($log);
    146154            }
    147155            $a->ip = $log->ip;
Note: See TracChangeset for help on using the changeset viewer.