Ejemplo n.º 1
0
function stats_check_uptodate($courseid = 0)
{
    global $CFG, $DB;
    if (empty($courseid)) {
        $courseid = SITEID;
    }
    $latestday = stats_get_start_from('daily');
    if (time() - 60 * 60 * 24 * 2 < $latestday) {
        // we're ok
        return NULL;
    }
    $a = new stdClass();
    $a->daysdone = $DB->get_field_sql("SELECT COUNT(DISTINCT(timeend)) FROM {stats_daily}");
    // how many days between the last day and now?
    $a->dayspending = ceil((stats_get_base_daily() - $latestday) / (60 * 60 * 24));
    if ($a->dayspending == 0 && $a->daysdone != 0) {
        return NULL;
        // we've only just started...
    }
    //return error as string
    return get_string('statscatchupmode', 'error', $a);
}
Ejemplo n.º 2
0
function stats_check_uptodate($courseid = 0)
{
    global $CFG;
    if (empty($courseid)) {
        $courseid = SITEID;
    }
    $latestday = stats_get_start_from('daily');
    if (time() - 60 * 60 * 24 * 2 < $latestday) {
        // we're ok
        return NULL;
    }
    $a = new object();
    $a->daysdone = get_field_sql("SELECT count(distinct(timeend)) from {$CFG->prefix}stats_daily");
    // how many days between the last day and now?
    $a->dayspending = ceil((stats_get_base_daily() - $latestday) / (60 * 60 * 24));
    if ($a->dayspending == 0 && $a->daysdone != 0) {
        return NULL;
        // we've only just started...
    }
    //return error as string
    return get_string('statscatchupmode', 'error', $a);
}
Ejemplo n.º 3
0
 /**
  * Test the function that gets the start date from the config.
  */
 public function test_statslib_get_start_from()
 {
     global $CFG, $DB;
     $dataset = $this->load_xml_data_file(__DIR__ . "/fixtures/statslib-test01.xml");
     $DB->delete_records('log');
     // Don't ask.  I don't think get_timezone_offset works correctly.
     $day = self::DAY - get_timezone_offset($CFG->timezone);
     $CFG->statsfirstrun = 'all';
     // Allow 1 second difference in case we cross a second boundary.
     // Note: within 3 days of a DST change - -3 days != 3 * 24 hours (it may be more or less).
     $this->assertLessThanOrEqual(1, stats_get_start_from('daily') - strtotime('-3 days', time()), 'All start time');
     $this->prepare_db($dataset[0], array('log'));
     $records = $DB->get_records('log');
     $this->assertEquals($day + 14410, stats_get_start_from('daily'), 'Log entry start');
     $CFG->statsfirstrun = 'none';
     $this->assertLessThanOrEqual(1, stats_get_start_from('daily') - strtotime('-3 days', time()), 'None start time');
     $CFG->statsfirstrun = 14515200;
     $this->assertLessThanOrEqual(1, stats_get_start_from('daily') - (time() - 14515200), 'Specified start time');
     $this->prepare_db($dataset[1], array('stats_daily'));
     $this->assertEquals($day + DAYSECS, stats_get_start_from('daily'), 'Daily stats start time');
     // New log stores.
     $this->preventResetByRollback();
     $this->assertFileExists("{$CFG->dirroot}/{$CFG->admin}/tool/log/store/standard/version.php");
     set_config('enabled_stores', 'logstore_standard', 'tool_log');
     set_config('buffersize', 0, 'logstore_standard');
     set_config('logguests', 1, 'logstore_standard');
     get_log_manager(true);
     $this->assertEquals(0, $DB->count_records('logstore_standard_log'));
     $DB->delete_records('stats_daily');
     $CFG->statsfirstrun = 'all';
     $firstoldtime = $DB->get_field_sql('SELECT MIN(time) FROM {log}');
     $this->assertEquals($firstoldtime, stats_get_start_from('daily'));
     \core_tests\event\create_executed::create(array('context' => context_system::instance()))->trigger();
     \core_tests\event\read_executed::create(array('context' => context_system::instance()))->trigger();
     \core_tests\event\update_executed::create(array('context' => context_system::instance()))->trigger();
     \core_tests\event\delete_executed::create(array('context' => context_system::instance()))->trigger();
     // Fake the origin of events.
     $DB->set_field('logstore_standard_log', 'origin', 'web', array());
     $logs = $DB->get_records('logstore_standard_log');
     $this->assertCount(4, $logs);
     $firstnew = reset($logs);
     $this->assertGreaterThan($firstoldtime, $firstnew->timecreated);
     $DB->set_field('logstore_standard_log', 'timecreated', 10, array('id' => $firstnew->id));
     $this->assertEquals(10, stats_get_start_from('daily'));
     $DB->set_field('logstore_standard_log', 'timecreated', $firstnew->timecreated, array('id' => $firstnew->id));
     $DB->delete_records('log');
     $this->assertEquals($firstnew->timecreated, stats_get_start_from('daily'));
     set_config('enabled_stores', '', 'tool_log');
     get_log_manager(true);
 }
Ejemplo n.º 4
0
    /**
     * Test the function that gets the start date from the config
     */
    public function test_statslib_get_start_from() {
        global $CFG, $DB;

        $dataset = $this->load_xml_data_file(__DIR__."/fixtures/statslib-test01.xml");
        $time = time();
        $DB->delete_records('log');

        // Don't ask.  I don't think get_timezone_offset works correctly.
        $day = self::DAY - get_timezone_offset($CFG->timezone);

        $CFG->statsfirstrun = 'all';
        // Allow 1 second difference in case we cross a second boundary.
        $this->assertLessThanOrEqual(1, stats_get_start_from('daily') - ($time - (3 * 24 * 3600)), 'All start time');

        $this->prepare_db($dataset[0], array('log'));
        $records = $DB->get_records('log');

        $this->assertEquals($day + 14410, stats_get_start_from('daily'), 'Log entry start');

        $CFG->statsfirstrun = 'none';
        $this->assertLessThanOrEqual(1, stats_get_start_from('daily') - ($time - (3 * 24 * 3600)), 'None start time');

        $CFG->statsfirstrun = 14515200;
        $this->assertLessThanOrEqual(1, stats_get_start_from('daily') - ($time - (14515200)), 'Specified start time');

        $this->prepare_db($dataset[1], array('stats_daily'));
        $this->assertEquals($day + (24 * 3600), stats_get_start_from('daily'), 'Daily stats start time');
    }