当前位置: 首页>>代码示例>>PHP>>正文


PHP progress_bar类代码示例

本文整理汇总了PHP中progress_bar的典型用法代码示例。如果您正苦于以下问题:PHP progress_bar类的具体用法?PHP progress_bar怎么用?PHP progress_bar使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了progress_bar类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: xmldb_assignment_upgrade

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 < 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');
    }

    // Moodle v2.4.0 release upgrade line
    // Put any upgrade step following this


    // Moodle v2.5.0 release upgrade line.
    // Put any upgrade step following this.


    return true;
}
开发者ID:verbazend,项目名称:AWFA,代码行数:60,代码来源:upgrade.php

示例2: xmldb_qtype_ddmarker_install

/**
 * Installation code for the ddmarker question type. It converts all existing imagetarget questions to ddmarker
 */
function xmldb_qtype_ddmarker_install()
{
    global $DB, $OUTPUT;
    $from = 'FROM {question_categories} cat, {question} q';
    $where = ' WHERE q.qtype = \'imagetarget\' AND q.category =  cat.id ';
    $sql = 'SELECT q.*, cat.contextid ' . $from . $where . 'ORDER BY cat.id, q.name';
    $questions = $DB->get_records_sql($sql);
    if (!empty($questions)) {
        require_once dirname(__FILE__) . '/../lib.php';
        $dragssql = 'SELECT drag.* ' . $from . ', {qtype_ddmarker_drags} drag' . $where . ' AND drag.questionid = q.id';
        $drags = xmldb_qtype_ddmarker_index_array_of_records_by_key('questionid', $DB->get_records_sql($dragssql));
        $dropssql = 'SELECT drp.* ' . $from . ', {qtype_ddmarker_drops} drp' . $where . ' AND drp.questionid = q.id';
        $drops = xmldb_qtype_ddmarker_index_array_of_records_by_key('questionid', $DB->get_records_sql($dropssql));
        $answerssql = 'SELECT answer.* ' . $from . ', {question_answers} answer' . $where . ' AND answer.question = q.id';
        $answers = xmldb_qtype_ddmarker_index_array_of_records_by_key('question', $DB->get_records_sql($answerssql));
        $imgfiles = $DB->get_records_sql_menu('SELECT question, qimage FROM {question_imagetarget}');
        $progressbar = new progress_bar('qtype_ddmarker_convert_from_imagetarget');
        $progressbar->create();
        $done = 0;
        foreach ($questions as $question) {
            qtype_ddmarker_convert_image_target_question($question, $imgfiles[$question->id], $answers[$question->id]);
            $done++;
            $progressbar->update($done, count($questions), get_string('convertingimagetargetquestion', 'qtype_ddmarker', $question));
        }
        list($qsql, $qparams) = $DB->get_in_or_equal(array_keys($questions));
        $DB->delete_records_select('question_answers', 'question ' . $qsql, $qparams);
        $dbman = $DB->get_manager();
        $dbman->drop_table(new xmldb_table('question_imagetarget'));
    }
}
开发者ID:ndunand,项目名称:moodle-qtype_ddmarker,代码行数:33,代码来源:install.php

示例3: print_progress

    /**
     * Called before starting to upgrade all the attempts at a particular quiz.
     * @param int $done the number of quizzes processed so far.
     * @param int $outof the total number of quizzes to process.
     * @param int $quizid the id of the quiz that is about to be processed.
     */
    protected function print_progress($done, $outof, $quizid) {
        if (is_null($this->progressbar)) {
            $this->progressbar = new progress_bar('qe2upgrade');
            $this->progressbar->create();
        }

        gc_collect_cycles(); // This was really helpful in PHP 5.2. Perhaps remove.
        $a = new stdClass();
        $a->done = $done;
        $a->outof = $outof;
        $a->info = $quizid;
        $this->progressbar->update($done, $outof, get_string('upgradingquizattempts', 'quiz', $a));
    }
开发者ID:JP-Git,项目名称:moodle,代码行数:19,代码来源:upgradelib.php

示例4: xmldb_qtype_essay_upgrade

/**
 * Upgrade code for the essay question type.
 * @param int $oldversion the version we are upgrading from.
 */
function xmldb_qtype_essay_upgrade($oldversion)
{
    global $CFG, $DB;
    $dbman = $DB->get_manager();
    // Moodle v2.2.0 release upgrade line
    // Put any upgrade step following this
    if ($oldversion < 2011102701) {
        $sql = "\n                  FROM {question} q\n                  JOIN {question_answers} qa ON qa.question = q.id\n\n                 WHERE q.qtype = 'essay'\n                   AND " . $DB->sql_isnotempty('question_answers', 'feedback', false, true);
        // In Moodle <= 2.0 essay had both question.generalfeedback and question_answers.feedback.
        // This was silly, and in Moodel >= 2.1 only question.generalfeedback. To avoid
        // dataloss, we concatenate question_answers.feedback onto the end of question.generalfeedback.
        $count = $DB->count_records_sql("\n                SELECT COUNT(1) {$sql}");
        if ($count) {
            $progressbar = new progress_bar('essay23', 500, true);
            $done = 0;
            $toupdate = $DB->get_recordset_sql("\n                    SELECT q.id,\n                           q.generalfeedback,\n                           q.generalfeedbackformat,\n                           qa.feedback,\n                           qa.feedbackformat\n                    {$sql}");
            foreach ($toupdate as $data) {
                $progressbar->update($done, $count, "Updating essay feedback ({$done}/{$count}).");
                upgrade_set_timeout(60);
                if ($data->generalfeedbackformat == $data->feedbackformat) {
                    $DB->set_field('question', 'generalfeedback', $data->generalfeedback . $data->feedback, array('id' => $data->id));
                } else {
                    $newdata = new stdClass();
                    $newdata->id = $data->id;
                    $newdata->generalfeedback = qtype_essay_convert_to_html($data->generalfeedback, $data->generalfeedbackformat) . qtype_essay_convert_to_html($data->feedback, $data->feedbackformat);
                    $newdata->generalfeedbackformat = FORMAT_HTML;
                    $DB->update_record('question', $newdata);
                }
            }
            $progressbar->update($count, $count, "Updating essay feedback complete!");
            $toupdate->close();
        }
        // Essay savepoint reached.
        upgrade_plugin_savepoint(true, 2011102701, 'qtype', 'essay');
    }
    if ($oldversion < 2011102702) {
        // Then we delete the old question_answers rows for essay questions.
        $DB->delete_records_select('question_answers', "question IN (SELECT id FROM {question} WHERE qtype = 'essay')");
        // Essay savepoint reached.
        upgrade_plugin_savepoint(true, 2011102702, 'qtype', 'essay');
    }
    // Moodle v2.3.0 release upgrade line
    // Put any upgrade step following this
    // Moodle v2.4.0 release upgrade line
    // Put any upgrade step following this
    return true;
}
开发者ID:vinoth4891,项目名称:clinique,代码行数:51,代码来源:upgrade.php

示例5: diarize

 /**
  * Segmente le document numérique et stocke le résultat en base de données
  */
 public function diarize()
 {
     // On commence par supprimer
     $query = "delete from explnum_segments where explnum_segment_explnum_num = " . $this->explnum->explnum_id;
     mysql_query($query);
     $query = "delete from explnum_speakers where explnum_speaker_explnum_num = " . $this->explnum->explnum_id;
     mysql_query($query);
     // Gestion de la progress_bar
     $progress_bar = new progress_bar("upload to server");
     $progress_bar->set_percent(0);
     $this->speechFile = $this->diarization->sendFile($this->getFile());
     // 		$this->speechFile = $this->diarization->getFile(67);
     $status = $this->speechFile->getStatus();
     while ($status != "diarization_phase7") {
         if ($status == "uploaded") {
             $progress_bar->set_percent(round(1 / 8 * 100));
         } else {
             $nb = str_replace("diarization_phase", "", $status);
             $progress_bar->set_percent(round(($nb + 1) / 8 * 100));
         }
         $progress_bar->set_text($status);
         $status = $this->speechFile->getStatus();
         sleep(0.5);
     }
     sleep(10);
     $progress_bar->hide();
     $speakers = $this->speechFile->getSpeakers();
     $speakers_ids = array();
     // Tableau associant l'identifiant du speaker avec son identifiant dans la table
     foreach ($speakers as $speaker) {
         $query = "insert into explnum_speakers (explnum_speaker_explnum_num, explnum_speaker_speaker_num, explnum_speaker_gender) values (" . $this->explnum->explnum_id . ", '" . $speaker->getID() . "', '" . $speaker->getGender() . "')";
         mysql_query($query);
         $speakers_ids[$speaker->getID()] = mysql_insert_id();
     }
     $segments = $this->speechFile->getSegments();
     foreach ($segments as $segment) {
         $query = "insert into explnum_segments (explnum_segment_explnum_num, explnum_segment_speaker_num, explnum_segment_start, explnum_segment_duration, explnum_segment_end) values (" . $this->explnum->explnum_id . ", '" . $speakers_ids[$segment->getSpeaker()->getID()] . "', " . $segment->getStart() . ", " . $segment->getDuration() . ", " . $segment->getEnd() . ")";
         mysql_query($query);
     }
 }
开发者ID:bouchra012,项目名称:PMB,代码行数:43,代码来源:diarization_docnum.class.php

示例6: geogebra_migrate_files

/**
 * Migrate geogebra package to new area if found
 *
 * @return
 */
function geogebra_migrate_files()
{
    global $CFG, $DB;
    $fs = get_file_storage();
    $sqlfrom = "FROM {geogebra} j\n                JOIN {modules} m ON m.name = 'geogebra'\n                JOIN {course_modules} cm ON (cm.module = m.id AND cm.instance = j.id)";
    $count = $DB->count_records_sql("SELECT COUNT('x') {$sqlfrom}");
    $rs = $DB->get_recordset_sql("SELECT j.id, j.url, j.course, cm.id AS cmid {$sqlfrom} ORDER BY j.course, j.id");
    if ($rs->valid()) {
        $pbar = new progress_bar('migrategeogebrafiles', 500, true);
        $i = 0;
        foreach ($rs as $geogebra) {
            $i++;
            upgrade_set_timeout(180);
            // set up timeout, may also abort execution
            $pbar->update($i, $count, "Migrating geogebra files - {$i}/{$count}.");
            $context = context_module::instance($geogebra->cmid);
            $coursecontext = context_course::instance($geogebra->course);
            if (!geogebra_is_valid_external_url($geogebra->url)) {
                // first copy local files if found - do not delete in case they are shared ;-)
                $geogebrafile = clean_param($geogebra->url, PARAM_PATH);
                $pathnamehash = sha1("/{$coursecontext->id}/course/legacy/0/{$geogebrafile}");
                if ($file = $fs->get_file_by_hash($pathnamehash)) {
                    $file_record = array('contextid' => $context->id, 'component' => 'mod_geogebra', 'filearea' => 'content', 'itemid' => 0, 'filepath' => '/');
                    try {
                        $fs->create_file_from_storedfile($file_record, $file);
                    } catch (Exception $x) {
                        // ignore any errors, we can not do much anyway
                    }
                    $geogebra->url = $pathnamehash;
                } else {
                    $geogebra->url = '';
                }
                $DB->update_record('geogebra', $geogebra);
            }
        }
    }
    $rs->close();
}
开发者ID:ninelanterns,项目名称:moodle-mod_geogebra,代码行数:43,代码来源:upgradelib.php

示例7: upgrade_mysql_fix_lob_columns

/**
 * Migrate all text and binary columns to big size - mysql only.
 */
function upgrade_mysql_fix_lob_columns()
{
    // we are not using standard API for changes of column intentionally
    global $DB;
    if ($DB->get_dbfamily() !== 'mysql') {
        return;
    }
    $pbar = new progress_bar('mysqlconvertlobs', 500, true);
    $prefix = $DB->get_prefix();
    $tables = $DB->get_tables();
    asort($tables);
    $tablecount = count($tables);
    $i = 0;
    foreach ($tables as $table) {
        $i++;
        // set appropriate timeout - 1 minute per thousand of records should be enough, min 60 minutes just in case
        $count = $DB->count_records($table, array());
        $timeout = $count / 1000 * 60;
        $timeout = $timeout < 60 * 60 ? 60 * 60 : (int) $timeout;
        $sql = "SHOW COLUMNS FROM `{{$table}}`";
        $rs = $DB->get_recordset_sql($sql);
        foreach ($rs as $column) {
            upgrade_set_timeout($timeout);
            $column = (object) array_change_key_case((array) $column, CASE_LOWER);
            if ($column->type === 'tinytext' or $column->type === 'mediumtext' or $column->type === 'text') {
                $notnull = $column->null === 'NO' ? 'NOT NULL' : 'NULL';
                $default = (!is_null($column->default) and $column->default !== '') ? "DEFAULT '{$column->default}'" : '';
                // primary, unique and inc are not supported for texts
                $sql = "ALTER TABLE `{$prefix}{$table}` MODIFY COLUMN `{$column->field}` LONGTEXT {$notnull} {$default}";
                $DB->change_database_structure($sql);
            }
            if ($column->type === 'tinyblob' or $column->type === 'mediumblob' or $column->type === 'blob') {
                $notnull = $column->null === 'NO' ? 'NOT NULL' : 'NULL';
                $default = (!is_null($column->default) and $column->default !== '') ? "DEFAULT '{$column->default}'" : '';
                // primary, unique and inc are not supported for blobs
                $sql = "ALTER TABLE `{$prefix}{$table}` MODIFY COLUMN `{$column->field}` LONGBLOB {$notnull} {$default}";
                $DB->change_database_structure($sql);
            }
        }
        $rs->close();
        $pbar->update($i, $tablecount, "Converted LOB columns in MySQL database - {$i}/{$tablecount}.");
    }
}
开发者ID:nmicha,项目名称:moodle,代码行数:46,代码来源:upgradelib.php

示例8: xmldb_main_upgrade


//.........这里部分代码省略.........
            $key = new xmldb_key('pushid-platform', XMLDB_KEY_UNIQUE, array('pushid', 'platform'));
            $dbman->drop_key($table, $key);
        }
        upgrade_main_savepoint(true, 2014072400.01);
    }
    if ($oldversion < 2014080801.0) {
        // Define index behaviour (not unique) to be added to question_attempts.
        $table = new xmldb_table('question_attempts');
        $index = new xmldb_index('behaviour', XMLDB_INDEX_NOTUNIQUE, array('behaviour'));
        // Conditionally launch add index behaviour.
        if (!$dbman->index_exists($table, $index)) {
            $dbman->add_index($table, $index);
        }
        // Main savepoint reached.
        upgrade_main_savepoint(true, 2014080801.0);
    }
    if ($oldversion < 2014082900.01) {
        // Fixing possible wrong MIME type for 7-zip and Rar files.
        $filetypes = array('%.7z' => 'application/x-7z-compressed', '%.rar' => 'application/x-rar-compressed');
        upgrade_mimetypes($filetypes);
        upgrade_main_savepoint(true, 2014082900.01);
    }
    if ($oldversion < 2014082900.02) {
        // Replace groupmembersonly usage with new availability system.
        $transaction = $DB->start_delegated_transaction();
        if ($CFG->enablegroupmembersonly) {
            // If it isn't already enabled, we need to enable availability.
            if (!$CFG->enableavailability) {
                set_config('enableavailability', 1);
            }
            // Count all course-modules with groupmembersonly set (for progress
            // bar).
            $total = $DB->count_records('course_modules', array('groupmembersonly' => 1));
            $pbar = new progress_bar('upgradegroupmembersonly', 500, true);
            // Get all these course-modules, one at a time.
            $rs = $DB->get_recordset('course_modules', array('groupmembersonly' => 1), 'course, id');
            $i = 0;
            foreach ($rs as $cm) {
                // Calculate and set new availability value.
                $availability = upgrade_group_members_only($cm->groupingid, $cm->availability);
                $DB->set_field('course_modules', 'availability', $availability, array('id' => $cm->id));
                // Update progress.
                $i++;
                $pbar->update($i, $total, "Upgrading groupmembersonly settings - {$i}/{$total}.");
            }
            $rs->close();
        }
        // Define field groupmembersonly to be dropped from course_modules.
        $table = new xmldb_table('course_modules');
        $field = new xmldb_field('groupmembersonly');
        // Conditionally launch drop field groupmembersonly.
        if ($dbman->field_exists($table, $field)) {
            $dbman->drop_field($table, $field);
        }
        // Unset old config variable.
        unset_config('enablegroupmembersonly');
        $transaction->allow_commit();
        upgrade_main_savepoint(true, 2014082900.02);
    }
    if ($oldversion < 2014100100.0) {
        // Define table messageinbound_handlers to be created.
        $table = new xmldb_table('messageinbound_handlers');
        // Adding fields to table messageinbound_handlers.
        $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
        $table->add_field('component', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null);
        $table->add_field('classname', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
开发者ID:isuruAb,项目名称:moodle,代码行数:67,代码来源:upgrade.php

示例9: xmldb_data_upgrade

function xmldb_data_upgrade($oldversion) {
    global $CFG, $DB, $OUTPUT;

    $dbman = $DB->get_manager();

//===== 1.9.0 upgrade line ======//

    if ($oldversion < 2007101512) {
    /// Launch add field asearchtemplate again if does not exists yet - reported on several sites

        $table = new xmldb_table('data');
        $field = new xmldb_field('asearchtemplate', XMLDB_TYPE_TEXT, 'small', null, null, null, null, 'jstemplate');

        if (!$dbman->field_exists($table, $field)) {
            $dbman->add_field($table, $field);
        }
        upgrade_mod_savepoint(true, 2007101512, 'data');
    }

    if ($oldversion < 2007101513) {
        // Upgrade all the data->notification currently being
        // NULL to 0
        $sql = "UPDATE {data} SET notification=0 WHERE notification IS NULL";
        $DB->execute($sql);

        $table = new xmldb_table('data');
        $field = new xmldb_field('notification', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'editany');
        // First step, Set NOT NULL
        $dbman->change_field_notnull($table, $field);
        // Second step, Set default to 0
        $dbman->change_field_default($table, $field);
        upgrade_mod_savepoint(true, 2007101513, 'data');
    }

    if ($oldversion < 2008081400) {
        $pattern = '/\#\#delete\#\#(\s+)\#\#approve\#\#/';
        $replacement = '##delete##$1##approve##$1##export##';
        $rs = $DB->get_recordset('data');
        foreach ($rs as $data) {
            $data->listtemplate = preg_replace($pattern, $replacement, $data->listtemplate);
            $data->singletemplate = preg_replace($pattern, $replacement, $data->singletemplate);
            $DB->update_record('data', $data);
        }
        $rs->close();

        upgrade_mod_savepoint(true, 2008081400, 'data');
    }

    if ($oldversion < 2008091400) {

        /////////////////////////////////////
        /// new file storage upgrade code ///
        /////////////////////////////////////

        $fs = get_file_storage();

        $empty = $DB->sql_empty(); // silly oracle empty string handling workaround

        $sqlfrom = "FROM {data_content} c
                    JOIN {data_fields} f     ON f.id = c.fieldid
                    JOIN {data_records} r    ON r.id = c.recordid
                    JOIN {data} d            ON d.id = r.dataid
                    JOIN {modules} m         ON m.name = 'data'
                    JOIN {course_modules} cm ON (cm.module = m.id AND cm.instance = d.id)
                   WHERE ".$DB->sql_compare_text('c.content', 2)." <> '$empty' AND c.content IS NOT NULL
                         AND (f.type = 'file' OR f.type = 'picture')";

        $count = $DB->count_records_sql("SELECT COUNT('x') $sqlfrom");

        $rs = $DB->get_recordset_sql("SELECT c.id, f.type, r.dataid, c.recordid, f.id AS fieldid, r.userid, c.content, c.content1, d.course, r.userid, cm.id AS cmid $sqlfrom ORDER BY d.course, d.id");

        if ($rs->valid()) {
            $pbar = new progress_bar('migratedatafiles', 500, true);

            $i = 0;
            foreach ($rs as $content) {
                $i++;
                upgrade_set_timeout(60); // set up timeout, may also abort execution
                $pbar->update($i, $count, "Migrating data entries - $i/$count.");

                $filepath = "$CFG->dataroot/$content->course/$CFG->moddata/data/$content->dataid/$content->fieldid/$content->recordid/$content->content";
                $context = get_context_instance(CONTEXT_MODULE, $content->cmid);

                if (!file_exists($filepath)) {
                    continue;
                }

                $filearea = 'content';
                $oldfilename = $content->content;
                $filename    = clean_param($oldfilename, PARAM_FILE);
                if ($filename === '') {
                    continue;
                }
                if (!$fs->file_exists($context->id, 'mod_data', $filearea, $content->id, '/', $filename)) {
                    $file_record = array('contextid'=>$context->id, 'component'=>'mod_data', 'filearea'=>$filearea, 'itemid'=>$content->id, 'filepath'=>'/', 'filename'=>$filename, 'userid'=>$content->userid);
                    if ($fs->create_file_from_pathname($file_record, $filepath)) {
                        unlink($filepath);
                        if ($oldfilename !== $filename) {
                            // update filename if needed
                            $DB->set_field('data_content', 'content', $filename, array('id'=>$content->id));
//.........这里部分代码省略.........
开发者ID:rolandovanegas,项目名称:moodle,代码行数:101,代码来源:upgrade.php

示例10: upgrade_migrate_files_blog

/**
 * Moves all block attachments
 *
 * Unfortunately this function uses core file related functions - it might be necessary to tweak it if something changes there :-(
 */
function upgrade_migrate_files_blog()
{
    global $DB, $CFG;
    $fs = get_file_storage();
    $count = $DB->count_records_select('post', "module='blog' AND attachment IS NOT NULL AND attachment <> '1'");
    if ($rs = $DB->get_recordset_select('post', "module='blog' AND attachment IS NOT NULL AND attachment <> '1'")) {
        upgrade_set_timeout(60 * 20);
        // set up timeout, may also abort execution
        $pbar = new progress_bar('migrateblogfiles', 500, true);
        $i = 0;
        foreach ($rs as $entry) {
            $i++;
            $pathname = "{$CFG->dataroot}/blog/attachments/{$entry->id}/{$entry->attachment}";
            if (!file_exists($pathname)) {
                $entry->attachment = NULL;
                $DB->update_record('post', $entry);
                continue;
            }
            $filename = clean_param($entry->attachment, PARAM_FILE);
            if ($filename === '') {
                // weird file name, ignore it
                $entry->attachment = NULL;
                $DB->update_record('post', $entry);
                continue;
            }
            if (!is_readable($pathname)) {
                notify(" File not readable, skipping: " . $pathname);
                continue;
            }
            if (!$fs->file_exists(SYSCONTEXTID, 'blog', $entry->id, '/', $filename)) {
                $file_record = array('contextid' => SYSCONTEXTID, 'filearea' => 'blog', 'itemid' => $entry->id, 'filepath' => '/', 'filename' => $filename, 'timecreated' => filectime($pathname), 'timemodified' => filemtime($pathname), 'userid' => $entry->userid);
                $fs->create_file_from_pathname($file_record, $pathname);
            }
            @unlink($pathname);
            @rmdir("{$CFG->dataroot}/blog/attachments/{$entry->id}/");
            $entry->attachment = 1;
            // file name not needed there anymore
            $DB->update_record('post', $entry);
            $pbar->update($i, $count, "Migrated blog attachments - {$i}/{$count}.");
        }
        $rs->close();
    }
    @rmdir("{$CFG->dataroot}/blog/attachments/");
    @rmdir("{$CFG->dataroot}/blog/");
}
开发者ID:nicolasconnault,项目名称:moodle2.0,代码行数:50,代码来源:upgradelib.php

示例11: xmldb_main_upgrade


//.........这里部分代码省略.........
        upgrade_main_savepoint(true, 2012030100.01);
    }
    if ($oldversion < 2012030100.02) {
        // migrate all numbers to signed - it should be safe to interrupt this and continue later
        upgrade_mysql_fix_unsigned_columns();
        // Main savepoint reached
        upgrade_main_savepoint(true, 2012030100.02);
    }
    if ($oldversion < 2012030900.01) {
        // migrate all texts and binaries to big size - it should be safe to interrupt this and continue later
        upgrade_mysql_fix_lob_columns();
        // Main savepoint reached
        upgrade_main_savepoint(true, 2012030900.01);
    }
    if ($oldversion < 2012031500.01) {
        // Upgrade old course_allowed_modules data to be permission overrides.
        if ($CFG->restrictmodulesfor === 'all') {
            $courses = $DB->get_records_menu('course', array(), 'id', 'id, 1');
        } else {
            if ($CFG->restrictmodulesfor === 'requested') {
                $courses = $DB->get_records_menu('course', array('retrictmodules' => 1), 'id', 'id, 1');
            } else {
                $courses = array();
            }
        }
        if (!$dbman->table_exists('course_allowed_modules')) {
            // Upgrade must already have been run on this server. This might happen,
            // for example, during development of these changes.
            $courses = array();
        }
        $modidtoname = $DB->get_records_menu('modules', array(), 'id', 'id, name');
        $coursecount = count($courses);
        if ($coursecount) {
            $pbar = new progress_bar('allowedmods', 500, true);
            $transaction = $DB->start_delegated_transaction();
        }
        $i = 0;
        foreach ($courses as $courseid => $notused) {
            $i += 1;
            upgrade_set_timeout(60);
            // 1 minute per course should be fine.
            $allowedmoduleids = $DB->get_records_menu('course_allowed_modules', array('course' => $courseid), 'module', 'module, 1');
            if (empty($allowedmoduleids)) {
                // This seems to be the best match for backwards compatibility,
                // not necessarily with the old code in course_allowed_module function,
                // but with the code that used to be in the coures settings form.
                $allowedmoduleids = explode(',', $CFG->defaultallowedmodules);
                $allowedmoduleids = array_combine($allowedmoduleids, $allowedmoduleids);
            }
            $context = context_course::instance($courseid);
            list($roleids) = get_roles_with_cap_in_context($context, 'moodle/course:manageactivities');
            list($managerroleids) = get_roles_with_cap_in_context($context, 'moodle/site:config');
            foreach ($managerroleids as $roleid) {
                unset($roleids[$roleid]);
            }
            foreach ($modidtoname as $modid => $modname) {
                if (isset($allowedmoduleids[$modid])) {
                    // Module is allowed, no worries.
                    continue;
                }
                $capability = 'mod/' . $modname . ':addinstance';
                foreach ($roleids as $roleid) {
                    assign_capability($capability, CAP_PREVENT, $roleid, $context);
                }
            }
            $pbar->update($i, $coursecount, "Upgrading legacy course_allowed_modules data - {$i}/{$coursecount}.");
开发者ID:nigeli,项目名称:moodle,代码行数:67,代码来源:upgrade.php

示例12: xmldb_main_upgrade


//.........这里部分代码省略.........
    // The ability to backup user (private) files is out completely - MDL-29248
    if ($oldversion < 2012030100.01) {
        unset_config('backup_general_user_files', 'backup');
        unset_config('backup_general_user_files_locked', 'backup');
        unset_config('backup_auto_user_files', 'backup');
        upgrade_main_savepoint(true, 2012030100.01);
    }
    if ($oldversion < 2012030900.01) {
        // Migrate all numbers to signed & all texts and binaries to big size.
        // It should be safe to interrupt this and continue later.
        upgrade_mysql_fix_unsigned_and_lob_columns();
        // Main savepoint reached
        upgrade_main_savepoint(true, 2012030900.01);
    }
    if ($oldversion < 2012031500.01) {
        // Upgrade old course_allowed_modules data to be permission overrides.
        if ($CFG->restrictmodulesfor === 'all') {
            $courses = $DB->get_records_menu('course', array(), 'id', 'id, 1');
        } else {
            if ($CFG->restrictmodulesfor === 'requested') {
                $courses = $DB->get_records_menu('course', array('restrictmodules' => 1), 'id', 'id, 1');
            } else {
                $courses = array();
            }
        }
        if (!$dbman->table_exists('course_allowed_modules')) {
            // Upgrade must already have been run on this server. This might happen,
            // for example, during development of these changes.
            $courses = array();
        }
        $modidtoname = $DB->get_records_menu('modules', array(), 'id', 'id, name');
        $coursecount = count($courses);
        if ($coursecount) {
            $pbar = new progress_bar('allowedmods', 500, true);
            $transaction = $DB->start_delegated_transaction();
        }
        $i = 0;
        foreach ($courses as $courseid => $notused) {
            $i += 1;
            upgrade_set_timeout(60);
            // 1 minute per course should be fine.
            $allowedmoduleids = $DB->get_records_menu('course_allowed_modules', array('course' => $courseid), 'module', 'module, 1');
            if (empty($allowedmoduleids)) {
                // This seems to be the best match for backwards compatibility,
                // not necessarily with the old code in course_allowed_module function,
                // but with the code that used to be in the coures settings form.
                $allowedmoduleids = explode(',', $CFG->defaultallowedmodules);
                $allowedmoduleids = array_combine($allowedmoduleids, $allowedmoduleids);
            }
            $context = context_course::instance($courseid);
            list($roleids) = get_roles_with_cap_in_context($context, 'moodle/course:manageactivities');
            list($managerroleids) = get_roles_with_cap_in_context($context, 'moodle/site:config');
            foreach ($managerroleids as $roleid) {
                unset($roleids[$roleid]);
            }
            foreach ($modidtoname as $modid => $modname) {
                if (isset($allowedmoduleids[$modid])) {
                    // Module is allowed, no worries.
                    continue;
                }
                $capability = 'mod/' . $modname . ':addinstance';
                foreach ($roleids as $roleid) {
                    assign_capability($capability, CAP_PREVENT, $roleid, $context);
                }
            }
            $pbar->update($i, $coursecount, "Upgrading legacy course_allowed_modules data - {$i}/{$coursecount}.");
开发者ID:HuiChangZhai,项目名称:moodle,代码行数:67,代码来源:upgrade.php

示例13: xmldb_qtype_essay_upgrade

/**
 * Upgrade code for the essay question type.
 * @param int $oldversion the version we are upgrading from.
 */
function xmldb_qtype_essay_upgrade($oldversion) {
    global $CFG, $DB;

    $dbman = $DB->get_manager();

    // Moodle v2.2.0 release upgrade line
    // Put any upgrade step following this.

    if ($oldversion < 2011102701) {
        $sql = "
                  FROM {question} q
                  JOIN {question_answers} qa ON qa.question = q.id

                 WHERE q.qtype = 'essay'
                   AND " . $DB->sql_isnotempty('question_answers', 'feedback', false, true);
        // In Moodle <= 2.0 essay had both question.generalfeedback and question_answers.feedback
        // This was silly, and in Moodel >= 2.1 only question.generalfeedback. To avoid
        // dataloss, we concatenate question_answers.feedback onto the end of question.generalfeedback.
        $count = $DB->count_records_sql("
                SELECT COUNT(1) $sql");
        if ($count) {
            $progressbar = new progress_bar('essay23', 500, true);
            $done = 0;

            $toupdate = $DB->get_recordset_sql("
                    SELECT q.id,
                           q.generalfeedback,
                           q.generalfeedbackformat,
                           qa.feedback,
                           qa.feedbackformat
                    $sql");

            foreach ($toupdate as $data) {
                $progressbar->update($done, $count, "Updating essay feedback ($done/$count).");
                upgrade_set_timeout(60);
                if ($data->generalfeedbackformat == $data->feedbackformat) {
                    $DB->set_field('question', 'generalfeedback',
                            $data->generalfeedback . $data->feedback,
                            array('id' => $data->id));

                } else {
                    $newdata = new stdClass();
                    $newdata->id = $data->id;
                    $newdata->generalfeedback =
                            qtype_essay_convert_to_html($data->generalfeedback, $data->generalfeedbackformat) .
                            qtype_essay_convert_to_html($data->feedback,        $data->feedbackformat);
                    $newdata->generalfeedbackformat = FORMAT_HTML;
                    $DB->update_record('question', $newdata);
                }
            }

            $progressbar->update($count, $count, "Updating essay feedback complete!");
            $toupdate->close();
        }

        // Essay savepoint reached.
        upgrade_plugin_savepoint(true, 2011102701, 'qtype', 'essay');
    }

    if ($oldversion < 2011102702) {
        // Then we delete the old question_answers rows for essay questions.
        $DB->delete_records_select('question_answers',
                "question IN (SELECT id FROM {question} WHERE qtype = 'essay')");

        // Essay savepoint reached.
        upgrade_plugin_savepoint(true, 2011102702, 'qtype', 'essay');
    }

    // Moodle v2.3.0 release upgrade line
    // Put any upgrade step following this.

    // Moodle v2.4.0 release upgrade line
    // Put any upgrade step following this.

    if ($oldversion < 2013011800) {
        // Then we delete the old question_answers rows for essay questions.
        $DB->delete_records_select('qtype_essay_options', "NOT EXISTS (
                SELECT 1 FROM {question} WHERE qtype = 'essay' AND
                    {question}.id = {qtype_essay_options}.questionid)");

        // Essay savepoint reached.
        upgrade_plugin_savepoint(true, 2013011800, 'qtype', 'essay');
    }

    if ($oldversion < 2013021700) {
        // Create new fields responsetemplate and responsetemplateformat in qtyep_essay_options table.
        $table = new xmldb_table('qtype_essay_options');
        $field = new xmldb_field('responsetemplate', XMLDB_TYPE_TEXT, null, null,
                    null, null, null, 'graderinfoformat');
        if (!$dbman->field_exists($table, $field)) {
            $dbman->add_field($table, $field);
        }

        $field = new xmldb_field('responsetemplateformat', XMLDB_TYPE_INTEGER, '4',
                null, XMLDB_NOTNULL, null, '0', 'responsetemplate');
        if (!$dbman->field_exists($table, $field)) {
//.........这里部分代码省略.........
开发者ID:verbazend,项目名称:AWFA,代码行数:101,代码来源:upgrade.php

示例14: lesson_upgrade_grades

/**
 * Update all grades in gradebook.
 *
 * @global object
 */
function lesson_upgrade_grades()
{
    global $DB;
    $sql = "SELECT COUNT('x')\n              FROM {lesson} l, {course_modules} cm, {modules} m\n             WHERE m.name='lesson' AND m.id=cm.module AND cm.instance=l.id";
    $count = $DB->count_records_sql($sql);
    $sql = "SELECT l.*, cm.idnumber AS cmidnumber, l.course AS courseid\n              FROM {lesson} l, {course_modules} cm, {modules} m\n             WHERE m.name='lesson' AND m.id=cm.module AND cm.instance=l.id";
    $rs = $DB->get_recordset_sql($sql);
    if ($rs->valid()) {
        $pbar = new progress_bar('lessonupgradegrades', 500, true);
        $i = 0;
        foreach ($rs as $lesson) {
            $i++;
            upgrade_set_timeout(60 * 5);
            // set up timeout, may also abort execution
            lesson_update_grades($lesson, 0, false);
            $pbar->update($i, $count, "Updating Lesson grades ({$i}/{$count}).");
        }
    }
    $rs->close();
}
开发者ID:nmicha,项目名称:moodle,代码行数:25,代码来源:lib.php

示例15: regrade_all_needed

    function regrade_all_needed($quiz, $groupstudents) {
        global $DB, $OUTPUT;
        if (!has_capability('mod/quiz:regrade', $this->context)) {
            echo $OUTPUT->notification(get_string('regradenotallowed', 'quiz'));
            return;
        }
        // Fetch all attempts that need regrading
        if ($groupstudents) {
            list($usql, $params) = $DB->get_in_or_equal($groupstudents);
            $where = "qa.userid $usql AND ";
        } else {
            $where = '';
            $params = array();
        }
        $where .= "qa.quiz = ? AND qa.preview = 0 AND qa.uniqueid = qqr.attemptid AND qqr.regraded = 0";
        $params[] = $quiz->id;
        if (!$attempts = $DB->get_records_sql('SELECT qa.*, qqr.questionid FROM {quiz_attempts} qa, {quiz_question_regrade} qqr WHERE '. $where, $params)) {
            echo $OUTPUT->heading(get_string('noattemptstoregrade', 'quiz_overview'));
            return true;
        }
        $this->clear_regrade_table($quiz, $groupstudents);
        // Fetch all questions
        $questions = question_load_questions(explode(',',quiz_questions_in_quiz($quiz->questions)), 'qqi.grade AS maxgrade, qqi.id AS instance',
            '{quiz_question_instances} qqi ON qqi.quiz = ' . $quiz->id . ' AND q.id = qqi.question');

        // Print heading
        echo $OUTPUT->heading(get_string('regradingquiz', 'quiz', format_string($quiz->name)));

        $apb = new progress_bar('aregradingbar', 500, true);

        // Loop through all questions and all attempts and regrade while printing progress info
        $attemptstodo = count($attempts);
        $attemptsdone = 0;
        @flush();@ob_flush();
        $attemptschanged = array();
        foreach ($attempts as $attempt) {
            $question = $questions[$attempt->questionid];
            $changed = regrade_question_in_attempt($question, $attempt, $quiz, true);
            if ($changed) {
                $attemptschanged[] = $attempt->uniqueid;
                $usersschanged[] = $attempt->userid;
            }
            if (!empty($apb)) {
                $attemptsdone++;
                $a = new stdClass();
                $a->done = $attemptsdone;
                $a->todo = $attemptstodo;
                $apb->update($attemptsdone, $attemptstodo, get_string('attemptprogress', 'quiz_overview', $a));
            }
        }
        $this->check_overall_grades($quiz, array(), $attemptschanged);
    }
开发者ID:nuckey,项目名称:moodle,代码行数:52,代码来源:report.php


注:本文中的progress_bar类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。