示例#1
0
 /**
  * Insert a checkbox for selecting the current row for batch operations
  *
  * @param stdClass $row
  * @return string
  */
 function col_select(stdClass $row)
 {
     global $CFG;
     $version = get_config('assignment_' . $row->type, 'version');
     require_once $CFG->dirroot . '/mod/assign/locallib.php';
     if (assign::can_upgrade_assignment($row->type, $version)) {
         $row->upgradable = true;
         return '<input type="checkbox" name="selectedassignment" value="' . $row->id . '"/>';
     }
     $row->upgradable = false;
     return '';
 }
 /**
  * This function will attempt to upgrade the newly restored assignment to an instance of mod_assign if
  * mod_assignment is currently disabled and mod_assign is enabled and mod_assign says it can upgrade this assignment.
  *
  * @return none
  */
 private function upgrade_mod_assign()
 {
     global $DB, $CFG;
     // The current module must exist.
     $pluginmanager = core_plugin_manager::instance();
     $plugininfo = $pluginmanager->get_plugin_info('mod_assign');
     // Check that the assignment module is installed.
     if ($plugininfo && $plugininfo->is_installed_and_upgraded()) {
         // Include the required mod assign upgrade code.
         require_once $CFG->dirroot . '/mod/assign/upgradelib.php';
         require_once $CFG->dirroot . '/mod/assign/locallib.php';
         // Get the id and type of this assignment.
         $newinstance = $this->task->get_activityid();
         $record = $DB->get_record('assignment', array('id' => $newinstance), 'assignmenttype', MUST_EXIST);
         $type = $record->assignmenttype;
         $subplugininfo = $pluginmanager->get_plugin_info('assignment_' . $type);
         // See if it is possible to upgrade.
         if (assign::can_upgrade_assignment($type, $subplugininfo->versiondb)) {
             $assignment_upgrader = new assign_upgrade_manager();
             $log = '';
             $success = $assignment_upgrader->upgrade_assignment($newinstance, $log);
             if (!$success) {
                 throw new restore_step_exception('mod_assign_upgrade_failed', $log);
             }
         }
     }
 }
示例#3
0
/**
 * Load a list of all the assignmentids that can be upgraded
 * @return array of assignment ids
 */
function tool_assignmentupgrade_load_all_upgradable_assignmentids()
{
    global $DB, $CFG;
    require_once $CFG->dirroot . '/mod/assign/locallib.php';
    // first find all the unique assignment types
    $types = $DB->get_records_sql('SELECT plugin AS assignmenttype, value AS version FROM {config_plugins} WHERE name = ? AND plugin LIKE ?', array('version', 'assignment_%'));
    $upgradabletypes = array();
    foreach ($types as $assignment) {
        $shorttype = substr($assignment->assignmenttype, strlen('assignment_'));
        if (assign::can_upgrade_assignment($shorttype, $assignment->version)) {
            $upgradabletypes[] = $shorttype;
        }
    }
    list($sql, $params) = $DB->get_in_or_equal($upgradabletypes);
    $records = $DB->get_records_sql('SELECT id from {assignment} where assignmenttype ' . $sql, $params);
    $ids = array();
    foreach ($records as $record) {
        $ids[] = $record->id;
    }
    return $ids;
}