[ Index ]

PHP Cross Reference of moodle-2.8

title

Body

[close]

/mod/assignment/db/ -> upgrade.php (source)

   1  <?php
   2  
   3  // This file keeps track of upgrades to
   4  // the assignment module
   5  //
   6  // Sometimes, changes between versions involve
   7  // alterations to database structures and other
   8  // major things that may break installations.
   9  //
  10  // The upgrade function in this file will attempt
  11  // to perform all the necessary actions to upgrade
  12  // your older installation to the current version.
  13  //
  14  // If there's something it cannot do itself, it
  15  // will tell you what you need to do.
  16  //
  17  // The commands in here will all be database-neutral,
  18  // using the methods of database_manager class
  19  //
  20  // Please do not forget to use upgrade_set_timeout()
  21  // before any action that may take longer time to finish.
  22  
  23  function xmldb_assignment_upgrade($oldversion) {
  24      global $CFG, $DB, $OUTPUT;
  25  
  26      require_once (__DIR__.'/upgradelib.php');
  27  
  28      $dbman = $DB->get_manager();
  29  
  30      // Moodle v2.2.0 release upgrade line
  31      // Put any upgrade step following this
  32  
  33      // Moodle v2.3.0 release upgrade line
  34      // Put any upgrade step following this
  35  
  36  
  37      if ($oldversion < 2012061701) {
  38          // Fixed/updated numfiles field in assignment_submissions table to count the actual
  39          // number of files has been uploaded when sendformarking is disabled
  40          upgrade_set_timeout(600);  // increase excution time for in large sites
  41          $fs = get_file_storage();
  42  
  43          // Fetch the moduleid for use in the course_modules table
  44          $moduleid = $DB->get_field('modules', 'id', array('name' => 'assignment'), MUST_EXIST);
  45  
  46          $selectcount = 'SELECT COUNT(s.id) ';
  47          $select      = 'SELECT s.id, cm.id AS cmid ';
  48          $query       = 'FROM {assignment_submissions} s
  49                          JOIN {assignment} a ON a.id = s.assignment
  50                          JOIN {course_modules} cm ON a.id = cm.instance AND cm.module = :moduleid
  51                          WHERE assignmenttype = :assignmenttype';
  52  
  53          $params = array('moduleid' => $moduleid, 'assignmenttype' => 'upload');
  54  
  55          $countsubmissions = $DB->count_records_sql($selectcount.$query, $params);
  56          $submissions = $DB->get_recordset_sql($select.$query, $params);
  57  
  58          $pbar = new progress_bar('assignmentupgradenumfiles', 500, true);
  59          $i = 0;
  60          foreach ($submissions as $sub) {
  61              $i++;
  62              if ($context = context_module::instance($sub->cmid)) {
  63                  $sub->numfiles = count($fs->get_area_files($context->id, 'mod_assignment', 'submission', $sub->id, 'sortorder', false));
  64                  $DB->update_record('assignment_submissions', $sub);
  65              }
  66              $pbar->update($i, $countsubmissions, "Counting files of submissions ($i/$countsubmissions)");
  67          }
  68          $submissions->close();
  69  
  70          // assignment savepoint reached
  71          upgrade_mod_savepoint(true, 2012061701, 'assignment');
  72      }
  73  
  74      // Moodle v2.4.0 release upgrade line
  75      // Put any upgrade step following this
  76  
  77  
  78      // Moodle v2.5.0 release upgrade line.
  79      // Put any upgrade step following this.
  80  
  81  
  82      // Moodle v2.6.0 release upgrade line.
  83      // Put any upgrade step following this.
  84  
  85      if ($oldversion < 2013121900) {
  86          // Define table assignment_upgrade to be created.
  87          $table = new xmldb_table('assignment_upgrade');
  88  
  89          // Adding fields to table assignment_upgrade.
  90          $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
  91          $table->add_field('oldcmid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0');
  92          $table->add_field('oldinstance', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0');
  93          $table->add_field('newcmid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0');
  94          $table->add_field('newinstance', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0');
  95          $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0');
  96  
  97          // Adding keys to table assignment_upgrade.
  98          $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
  99  
 100          // Adding indexes to table assignment_upgrade.
 101          $table->add_index('oldcmid', XMLDB_INDEX_NOTUNIQUE, array('oldcmid'));
 102          $table->add_index('oldinstance', XMLDB_INDEX_NOTUNIQUE, array('oldinstance'));
 103  
 104          // Conditionally launch create table for assignment_upgrade.
 105          if (!$dbman->table_exists($table)) {
 106              $dbman->create_table($table);
 107          }
 108  
 109          if ($module = $DB->get_record("modules", array("name" => "assignment"))) {
 110              $DB->set_field("modules", "visible", "0", array("id" => $module->id)); // Hide module.
 111          }
 112  
 113          $count = $DB->count_records('assignment');
 114          if ($count) {
 115              mod_assignment_pending_upgrades_notification($count);
 116          }
 117  
 118          // Assignment savepoint reached.
 119          upgrade_mod_savepoint(true, 2013121900, 'assignment');
 120      }
 121  
 122      // Moodle v2.7.0 release upgrade line.
 123      // Put any upgrade step following this.
 124  
 125      // Moodle v2.8.0 release upgrade line.
 126      // Put any upgrade step following this.
 127  
 128      return true;
 129  }
 130  
 131  


Generated: Fri Nov 28 20:29:05 2014 Cross-referenced by PHPXref 0.7.1