Permalink
Browse files

Merge branch 'MDL-31987_assignment_m23' of git://github.com/rwijaya/m…

…oodle into MOODLE_23_STABLE
  • Loading branch information...
2 parents 8633142 + 4b0e6f3 commit 3e839bd5139634925a6e3923f2ac48677272d68e @danpoltawski danpoltawski committed Jul 2, 2012
Showing with 49 additions and 6 deletions.
  1. +36 −0 mod/assignment/db/upgrade.php
  2. +12 −5 mod/assignment/type/upload/assignment.class.php
  3. +1 −1 mod/assignment/version.php
@@ -32,6 +32,42 @@ function xmldb_assignment_upgrade($oldversion) {
// Moodle v2.3.0 release upgrade line
// Put any upgrade step following this
+ if ($oldversion < 2012061701) {
+ // Fixed/updated numfiles field in assignment_submissions table to count the actual
+ // number of files has been uploaded when sendformarking is disabled
+ upgrade_set_timeout(600); // increase excution time for in large sites
+ $fs = get_file_storage();
+
+ // Fetch the moduleid for use in the course_modules table
+ $moduleid = $DB->get_field('modules', 'id', array('name' => 'assignment'), MUST_EXIST);
+
+ $selectcount = 'SELECT COUNT(s.id) ';
+ $select = 'SELECT s.id, cm.id AS cmid ';
+ $query = 'FROM {assignment_submissions} s
+ JOIN {assignment} a ON a.id = s.assignment
+ JOIN {course_modules} cm ON a.id = cm.instance AND cm.module = :moduleid
+ WHERE assignmenttype = :assignmenttype';
+
+ $params = array('moduleid' => $moduleid, 'assignmenttype' => 'upload');
+
+ $countsubmissions = $DB->count_records_sql($selectcount.$query, $params);
+ $submissions = $DB->get_recordset_sql($select.$query, $params);
+
+ $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, 2012061701, 'assignment');
+ }
return true;
}
@@ -395,8 +395,8 @@ function process_feedback($formdata=null) {
/**
* Counts all complete (real) assignment submissions by enrolled students. This overrides assignment_base::count_real_submissions().
- * This is necessary for advanced file uploads where we need to check that the data2 field is equal to "submitted" to determine
- * if a submission is complete.
+ * This is necessary for tracked advanced file uploads where we need to check that the data2 field is equal to ASSIGNMENT_STATUS_SUBMITTED
+ * to determine if a submission is complete.
*
* @param int $groupid (optional) If nonzero then count is restricted to this group
* @return int The number of submissions
@@ -411,13 +411,19 @@ function count_real_submissions($groupid=0) {
list($enroledsql, $params) = get_enrolled_sql($context, 'mod/assignment:view', $groupid);
$params['assignmentid'] = $this->cm->instance;
- // Get ids of users enrolled in the given course.
+ $query = '';
+ if ($this->drafts_tracked() and $this->isopen()) {
+ $query = ' AND ' . $DB->sql_compare_text('s.data2') . " = '" . ASSIGNMENT_STATUS_SUBMITTED . "'";
+ } else {
+ // Count on submissions with files actually uploaded
+ $query = " AND s.numfiles > 0";
+ }
return $DB->count_records_sql("SELECT COUNT('x')
FROM {assignment_submissions} s
LEFT JOIN {assignment} a ON a.id = s.assignment
INNER JOIN ($enroledsql) u ON u.id = s.userid
- WHERE s.assignment = :assignmentid AND
- s.data2 = 'submitted'", $params);
+ WHERE s.assignment = :assignmentid" .
+ $query, $params);
}
function print_responsefiles($userid, $return=false) {
@@ -581,6 +587,7 @@ function upload_file($mform, $options) {
$formdata = file_postupdate_standard_filemanager($formdata, 'files', $options, $this->context, 'mod_assignment', 'submission', $submission->id);
$updates = new stdClass();
$updates->id = $submission->id;
+ $updates->numfiles = count($fs->get_area_files($this->context->id, 'mod_assignment', 'submission', $submission->id, 'sortorder', false));
$updates->timemodified = time();
$DB->update_record('assignment_submissions', $updates);
add_to_log($this->course->id, 'assignment', 'upload',
@@ -25,7 +25,7 @@
defined('MOODLE_INTERNAL') || die();
-$module->version = 2012061700; // The current module version (Date: YYYYMMDDXX)
+$module->version = 2012061701; // The current module version (Date: YYYYMMDDXX)
$module->requires = 2012061700; // Requires this Moodle version
$module->component = 'mod_assignment'; // Full name of the plugin (used for diagnostics)
$module->cron = 60;

0 comments on commit 3e839bd

Please sign in to comment.