moodle/mod/assignment/db/upgrade.php
Rossiani Wijaya b8ba23ca23 MDL-31987 Assignment module: Assignment count submissions correctly.
For advanced upload assignment, store file count of each submission
into assignment_submissions.numfiles

When counting submissions, if the assignment is open and tracking
drafts, only submissions which has send for marking are counted.
Otherwise, submissions which has numfiles > 0 are counted.

Also change a hardcoded 'submitted' to ASSIGNMENT_STATUS_SUBMITTED.

This patch was originally written by: Sunner Sun <sunner@gmail.com>.

I made some modifation to fixed count_real_submissions() query (ref: MDL-32207) in /mod/assignment/type/upload/assignment.class.php file
2012-07-02 14:26:45 +08:00

76 lines
2.7 KiB
PHP

<?php
// This file keeps track of upgrades to
// the assignment module
//
// Sometimes, changes between versions involve
// alterations to database structures and other
// major things that may break installations.
//
// The upgrade function in this file will attempt
// to perform all the necessary actions to upgrade
// your older installation to the current version.
//
// If there's something it cannot do itself, it
// will tell you what you need to do.
//
// The commands in here will all be database-neutral,
// using the methods of database_manager class
//
// Please do not forget to use upgrade_set_timeout()
// before any action that may take longer time to finish.
function xmldb_assignment_upgrade($oldversion) {
global $CFG, $DB, $OUTPUT;
$dbman = $DB->get_manager();
// Moodle v2.2.0 release upgrade line
// Put any upgrade step following this
// Moodle v2.3.0 release upgrade line
// Put any upgrade step following this
if ($oldversion < 2012062800) {
// Fixed/updated numfiles field in assignment_submissions table to count the actual
// number of files has been uploaded.
upgrade_set_timeout(600); // increase excution time for in large sites
$fs = get_file_storage();
$selectcount = 'SELECT COUNT(s.id), cm.id AS cmid';
$select = 'SELECT s.id, cm.id AS cmid';
$query = " FROM {assignment_submissions} s
INNER JOIN {course_modules} cm
ON s.assignment = cm.instance
JOIN {assignment} a
ON a.id = s.assignment
WHERE a.assignmenttype in ('upload', 'uploadsingle') AND
cm.module = (SELECT id
FROM {modules}
WHERE name = 'assignment')";
$countsubmissions = $DB->count_records_sql($selectcount. $query);
$submissions = $DB->get_recordset_sql($select. $query);
$pbar = new progress_bar('assignmentupgradenumfiles', 500, true);
$i = 0;
foreach ($submissions as $sub) {
$i++;
if ($context = context_module::instance($sub->cmid)) {
$sub->numfiles = count($fs->get_area_files($context->id, 'mod_assignment', 'submission', $sub->id, 'sortorder', false));
$DB->update_record('assignment_submissions', $sub);
}
$pbar->update($i, $countsubmissions, "Counting files of submissions ($i/$countsubmissions)");
}
$submissions->close();
// assignment savepoint reached
upgrade_mod_savepoint(true, 2012062800, 'assignment');
}
return true;
}