1 |
efrain |
1 |
<?php
|
|
|
2 |
// This file is part of Moodle - http://moodle.org/
|
|
|
3 |
//
|
|
|
4 |
// Moodle is free software: you can redistribute it and/or modify
|
|
|
5 |
// it under the terms of the GNU General Public License as published by
|
|
|
6 |
// the Free Software Foundation, either version 3 of the License, or
|
|
|
7 |
// (at your option) any later version.
|
|
|
8 |
//
|
|
|
9 |
// Moodle is distributed in the hope that it will be useful,
|
|
|
10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
12 |
// GNU General Public License for more details.
|
|
|
13 |
//
|
|
|
14 |
// You should have received a copy of the GNU General Public License
|
|
|
15 |
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
16 |
|
|
|
17 |
/**
|
|
|
18 |
* @package block
|
|
|
19 |
* @subpackage rate_course
|
|
|
20 |
* @copyright 2009 Jenny Gray
|
|
|
21 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
22 |
*
|
|
|
23 |
* Code was Rewritten for Moodle 2.X By Atar + Plus LTD for Comverse LTD.
|
|
|
24 |
* @copyright © 2011 Comverse LTD.
|
|
|
25 |
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
|
|
|
26 |
*/
|
|
|
27 |
|
|
|
28 |
function xmldb_block_rate_course_upgrade($oldversion=0) {
|
|
|
29 |
global $CFG, $THEME, $db, $DB;
|
|
|
30 |
$result = true;
|
|
|
31 |
if ($oldversion < 2009020307) {
|
|
|
32 |
$oldblock = $DB->get_record('block', array('name'=>'rate_unit'));
|
|
|
33 |
$newblock = $DB->get_record('block', array('name'=>'rate_course'));
|
|
|
34 |
|
|
|
35 |
if ($oldblock) {
|
|
|
36 |
// First migrate data from rate_unit.
|
|
|
37 |
$ratings = $DB->get_recordset('rate_unit');
|
|
|
38 |
if ($ratings) {
|
|
|
39 |
while (!$ratings->EOF) {
|
|
|
40 |
$newrow = new stdClass();
|
|
|
41 |
$newrow->course = $ratings->fields['course'];
|
|
|
42 |
$newrow->userid = $ratings->fields['userid'];
|
|
|
43 |
$newrow->rating = $ratings->fields['course'];
|
|
|
44 |
$DB->insert_record('block_rate_course', $newrow);
|
|
|
45 |
$ratings->MoveNext();
|
|
|
46 |
}
|
|
|
47 |
}
|
|
|
48 |
|
|
|
49 |
// Swap the block instances over.
|
|
|
50 |
$instances = $DB->get_records('block_instance',
|
|
|
51 |
array('blockid'=>$oldblock->id));
|
|
|
52 |
if (!empty($instances)) {
|
|
|
53 |
foreach ($instances as $instance) {
|
|
|
54 |
$instance->blockid = $newblock->id;
|
|
|
55 |
$DB->update_record('block_instance', $instance);
|
|
|
56 |
}
|
|
|
57 |
}
|
|
|
58 |
$instances = $DB->get_records('block_pinned',
|
|
|
59 |
array('blockid'=>$oldblock->id));
|
|
|
60 |
if (!empty($instances)) {
|
|
|
61 |
foreach ($instances as $instance) {
|
|
|
62 |
$instance->blockid = $newblock->id;
|
|
|
63 |
$DB->update_record('block_pinned', $instance);
|
|
|
64 |
}
|
|
|
65 |
}
|
|
|
66 |
|
|
|
67 |
// Delete the old block stuff.
|
|
|
68 |
$DB->delete_records('block', array('id'=>$oldblock->id));
|
|
|
69 |
$DB->drop_plugin_tables($oldblock->name,
|
|
|
70 |
"$CFG->dirroot/blocks/$oldblock->name/db/install.xml",
|
|
|
71 |
false); // Old obsoleted table names.
|
|
|
72 |
$DB->drop_plugin_tables('block_'.$oldblock->name, "$CFG->dirroot/blocks/$oldblock->name/db/install.xml", false);
|
|
|
73 |
capabilities_cleanup('block/'.$oldblock->name);
|
|
|
74 |
}
|
|
|
75 |
}
|
|
|
76 |
return $result;
|
|
|
77 |
}
|