Skip to content

Commit

Permalink
MDL-14679 upgrade $DB conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
skodak committed May 31, 2008
1 parent ab122f4 commit 219f652
Show file tree
Hide file tree
Showing 45 changed files with 94 additions and 476 deletions.
2 changes: 1 addition & 1 deletion backup/db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

function xmldb_backup_upgrade($oldversion=0) {

global $CFG, $THEME, $db;
global $CFG, $THEME, $DB;

$result = true;

Expand Down
4 changes: 2 additions & 2 deletions blocks/activity_modules/block_activity_modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ function init() {
}

function get_content() {
global $CFG, $COURSE;
global $CFG, $COURSE, $DB;

if($this->content !== NULL) {
return $this->content;
Expand All @@ -21,7 +21,7 @@ function get_content() {
if ($COURSE->id == $this->instance->pageid) {
$course = $COURSE;
} else {
$course = get_record('course', 'id', $this->instance->pageid);
$course = get_record('course', array('id'=>$this->instance->pageid));
}

require_once($CFG->dirroot.'/course/lib.php');
Expand Down
2 changes: 1 addition & 1 deletion blocks/activity_modules/db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

function xmldb_block_activity_modules_upgrade($oldversion=0) {

global $CFG, $THEME, $db;
global $CFG, $THEME, $DB;

$result = true;

Expand Down
2 changes: 1 addition & 1 deletion blocks/admin/db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

function xmldb_block_admin_upgrade($oldversion=0) {

global $CFG, $THEME, $db;
global $CFG, $THEME, $DB;

$result = true;

Expand Down
23 changes: 11 additions & 12 deletions blocks/blog_tags/block_blog_tags.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ function specialization() {
}

function get_content() {

global $CFG, $SITE, $COURSE, $USER;
global $CFG, $SITE, $COURSE, $USER, $DB;

if (empty($CFG->usetags) || empty($CFG->bloglevel)) {
$this->content->text = '';
Expand Down Expand Up @@ -74,20 +73,20 @@ function get_content() {

$timewithin = time() - $this->config->timewithin * 24 * 60 * 60; /// convert to seconds

$sql = 'SELECT t.id, t.tagtype, t.rawname, t.name, COUNT(DISTINCT ti.id) AS ct ';
$sql .= "FROM {$CFG->prefix}tag t, {$CFG->prefix}tag_instance ti, {$CFG->prefix}post p ";
$sql .= 'WHERE t.id = ti.tagid ';
$sql .= 'AND p.id = ti.itemid ';

// admins should be able to read all tags
if (!has_capability('moodle/user:readuserblogs', get_context_instance(CONTEXT_SYSTEM))) {
$sql .= 'AND (p.publishstate = \'site\' or p.publishstate=\'public\') ';
$type .= " AND (p.publishstate = 'site' or p.publishstate='public')";
}
$sql .= "AND ti.timemodified > {$timewithin} ";
$sql .= 'GROUP BY t.id, t.tagtype, t.name, t.rawname ';
$sql .= 'ORDER BY ct DESC, t.name ASC';

if ($tags = get_records_sql($sql, 0, $this->config->numberoftags)) {
$sql = "SELECT t.id, t.tagtype, t.rawname, t.name, COUNT(DISTINCT ti.id) AS ct
FROM {tag} t, {tag_instance} ti, {post} p
WHERE t.id = ti.tagid AND p.id = ti.itemid
$type
AND ti.timemodified > $timewithin
GROUP BY t.id, t.tagtype, t.name, t.rawname
ORDER BY ct DESC, t.name ASC";

if ($tags = get_records_sql($sql, null, 0, $this->config->numberoftags)) {

/// There are 2 things to do:
/// 1. tags with the same count should have the same size class
Expand Down
2 changes: 1 addition & 1 deletion blocks/calendar_month/db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

function xmldb_block_calendar_month_upgrade($oldversion=0) {

global $CFG, $THEME, $db;
global $CFG, $THEME, $DB;

$result = true;

Expand Down
2 changes: 1 addition & 1 deletion blocks/calendar_upcoming/db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

function xmldb_block_calendar_upcoming_upgrade($oldversion=0) {

global $CFG, $THEME, $db;
global $CFG, $THEME, $DB;

$result = true;

Expand Down
2 changes: 1 addition & 1 deletion blocks/course_list/db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

function xmldb_block_course_list_upgrade($oldversion=0) {

global $CFG, $THEME, $db;
global $CFG, $THEME, $DB;

$result = true;

Expand Down
2 changes: 1 addition & 1 deletion blocks/course_summary/db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

function xmldb_block_course_summary_upgrade($oldversion=0) {

global $CFG, $THEME, $db;
global $CFG, $THEME, $DB;

$result = true;

Expand Down
6 changes: 4 additions & 2 deletions blocks/db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@

function xmldb_blocks_upgrade($oldversion=0) {

global $CFG, $THEME, $db;
global $CFG, $THEME, $DB;

$dbman = $DB->get_manager();

$result = true;

Expand All @@ -40,7 +42,7 @@ function xmldb_blocks_upgrade($oldversion=0) {
$field->set_attributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, null, null, 'visible');

/// Launch change of nullability for field configdata
$result = $result && change_field_notnull($table, $field);
$result = $result && $dbman->change_field_notnull($table, $field);
}


Expand Down
2 changes: 1 addition & 1 deletion blocks/news_items/db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

function xmldb_block_news_items_upgrade($oldversion=0) {

global $CFG, $THEME, $db;
global $CFG, $THEME, $DB;

$result = true;

Expand Down
2 changes: 1 addition & 1 deletion blocks/online_users/db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

function xmldb_block_online_users_upgrade($oldversion=0) {

global $CFG, $THEME, $db;
global $CFG, $THEME, $DB;

$result = true;

Expand Down
2 changes: 1 addition & 1 deletion blocks/participants/db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

function xmldb_block_participants_upgrade($oldversion=0) {

global $CFG, $THEME, $db;
global $CFG, $THEME, $DB;

$result = true;

Expand Down
2 changes: 1 addition & 1 deletion blocks/recent_activity/db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

function xmldb_block_recent_activity_upgrade($oldversion=0) {

global $CFG, $THEME, $db;
global $CFG, $THEME, $DB;

$result = true;

Expand Down
4 changes: 2 additions & 2 deletions blocks/rss_client/db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

function xmldb_block_rss_client_upgrade($oldversion=0) {

global $CFG, $THEME, $db;
global $CFG, $THEME, $DB;

$result = true;

Expand All @@ -30,7 +30,7 @@ function xmldb_block_rss_client_upgrade($oldversion=0) {

if ($result && $oldversion < 2007080100) { //New version in version.php
/// block_rss_timeout config setting must be block_rss_client_timeout
set_field('config', 'name', 'block_rss_client_timeout', 'name', 'block_rss_timeout');
$DB->set_field('config', 'name', 'block_rss_client_timeout', array('name'=>'block_rss_timeout'));
}

return $result;
Expand Down
2 changes: 1 addition & 1 deletion blocks/search/db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

function xmldb_block_search_upgrade($oldversion=0) {

global $CFG, $THEME, $db;
global $CFG, $THEME, $DB;

$result = true;

Expand Down
2 changes: 1 addition & 1 deletion blocks/search_forums/db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

function xmldb_block_search_forums_upgrade($oldversion=0) {

global $CFG, $THEME, $db;
global $CFG, $THEME, $DB;

$result = true;

Expand Down
8 changes: 5 additions & 3 deletions blocks/section_links/block_section_links.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ function init() {
}

function instance_config($instance) {
global $DB;

parent::instance_config($instance);
$course = get_record('course', 'id', $this->instance->pageid);
$course = get_record('course', array('id'=>$this->instance->pageid));
if (isset($course->format)) {
if ($course->format == 'topics') {
$this->title = get_string('topics', 'block_section_links');
Expand All @@ -26,7 +28,7 @@ function applicable_formats() {
}

function get_content() {
global $CFG, $USER, $COURSE;
global $CFG, $USER, $COURSE, $DB;

$highlight = 0;

Expand All @@ -45,7 +47,7 @@ function get_content() {
if ($this->instance->pageid == $COURSE->id) {
$course = $COURSE;
} else {
$course = get_record('course', 'id', $this->instance->pageid);
$course = get_record('course', array('id'=>$this->instance->pageid));
}
$context = get_context_instance(CONTEXT_COURSE, $course->id);

Expand Down
2 changes: 1 addition & 1 deletion blocks/section_links/db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

function xmldb_block_section_links_upgrade($oldversion=0) {

global $CFG, $THEME, $db;
global $CFG, $THEME, $DB;

$result = true;

Expand Down
4 changes: 2 additions & 2 deletions blocks/site_main_menu/block_site_main_menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function applicable_formats() {
}

function get_content() {
global $USER, $CFG, $COURSE;
global $USER, $CFG, $COURSE, $DB;

if ($this->content !== NULL) {
return $this->content;
Expand All @@ -29,7 +29,7 @@ function get_content() {
if ($COURSE->id == $this->instance->pageid) {
$course = $COURSE;
} else {
$course = get_record('course', 'id', $this->instance->pageid);
$course = get_record('course', array('id'=>$this->instance->pageid));
}

require_once($CFG->dirroot.'/course/lib.php');
Expand Down
4 changes: 2 additions & 2 deletions blocks/social_activities/block_social_activities.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function applicable_formats() {
}

function get_content() {
global $USER, $CFG, $COURSE;
global $USER, $CFG, $COURSE, $DB;

if ($this->content !== NULL) {
return $this->content;
Expand All @@ -29,7 +29,7 @@ function get_content() {
if ($COURSE->id == $this->instance->pageid) {
$course = $COURSE;
} else {
$course = get_record('course', 'id', $this->instance->pageid);
$course = get_record('course', array('id'=>$this->instance->pageid));
}

require_once($CFG->dirroot.'/course/lib.php');
Expand Down
2 changes: 1 addition & 1 deletion blocks/social_activities/db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

function xmldb_block_social_activities_upgrade($oldversion=0) {

global $CFG, $THEME, $db;
global $CFG, $THEME, $DB;

$result = true;

Expand Down
2 changes: 1 addition & 1 deletion enrol/paypal/db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

function xmldb_enrol_paypal_upgrade($oldversion=0) {

global $CFG, $THEME, $db;
global $CFG, $THEME, $DB;

$result = true;

Expand Down
2 changes: 1 addition & 1 deletion files/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
}


if (! $course = get_record("course", "id", $id) ) {
if (! $course = $DB->get_record("course", array("id"=>$id))) {
print_error('invalidcourseid');
}

Expand Down
5 changes: 2 additions & 3 deletions filter/activitynames/filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
//Modifications by stronk7.

function activitynames_filter($courseid, $text) {

global $CFG, $COURSE;
global $CFG, $COURSE, $DB;

// Trivial-cache - keyed on $cachedcourseid
static $activitylist = null;
Expand All @@ -30,7 +29,7 @@ function activitynames_filter($courseid, $text) {
if ($COURSE->id == $courseid) {
$course = $COURSE;
} else {
$course = get_record("course", "id", $courseid);
$course = $DB->get_record("course", array("id"=>$courseid));
}

if (!isset($course->modinfo)) {
Expand Down
2 changes: 1 addition & 1 deletion filter/algebra/algebradebug.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
$algebra = substr($query,8,$splitpos);
$md5 = md5($algebra);
if (strpos($query,'ShowDB') || strpos($query,'DeleteDB')) {
$texcache = get_record("cache_filters","filter","algebra", "md5key", $md5);
$texcache = $DB->get_record("cache_filters", array("filter"=>"algebra", "md5key"=>$md5));
}
if (strpos($query,'ShowDB')) {
if ($texcache) {
Expand Down
13 changes: 6 additions & 7 deletions filter/algebra/filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ function string_file_picture_algebra($imagefile, $tex= "", $height="", $width=""


function algebra_filter ($courseid, $text) {

global $CFG;
global $CFG, $DB;

/// Do a quick check using stripos to avoid unnecessary wor
if (!preg_match('/<algebra/i',$text) && !strstr($text,'@@')) {
Expand All @@ -101,9 +100,9 @@ function algebra_filter ($courseid, $text) {
# }
# if (strstr($scriptname,'post.php')) {
# $parent = forum_get_post_full($_GET['reply']);
# $discussion = get_record("forum_discussions","id",$parent->discussion);
# $discussion = $DB->get_record("forum_discussions",array("id"=>$parent->discussion));
# } else if (strstr($scriptname,'discuss.php')) {
# $discussion = get_record("forum_discussions","id",$_GET['d'] );
# $discussion = $DB->get_record("forum_discussions", array("id"=>$_GET['d']));
# } else {
# return $text;
# }
Expand Down Expand Up @@ -140,7 +139,7 @@ function algebra_filter ($courseid, $text) {
}
$md5 = md5($algebra);
$filename = $md5 . ".gif";
if (! $texcache = get_record("cache_filters","filter","algebra", "md5key", $md5)) {
if (! $texcache = $DB->get_record("cache_filters", array("filter"=>"algebra", "md5key"=>$md5))) {
$algebra = str_replace('&lt;','<',$algebra);
$algebra = str_replace('&gt;','>',$algebra);
$algebra = str_replace('<>','#',$algebra);
Expand Down Expand Up @@ -219,9 +218,9 @@ function algebra_filter ($courseid, $text) {
$texcache->filter = 'algebra';
$texcache->version = 1;
$texcache->md5key = $md5;
$texcache->rawtext = addslashes($texexp);
$texcache->rawtext = $texexp;
$texcache->timemodified = time();
insert_record("cache_filters",$texcache, false);
$DB->insert_record("cache_filters",$texcache, false);
$text = str_replace( $matches[0][$i], string_file_picture_algebra($filename, $texexp, '', '', $align), $text);
} else {
$text = str_replace( $matches[0][$i],"<b>Undetermined error:</b> ",$text);
Expand Down
2 changes: 1 addition & 1 deletion filter/algebra/pix.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

if (!file_exists($pathname)) {
$md5 = str_replace('.gif','',$image);
if ($texcache = get_record('cache_filters', 'filter', 'algebra', 'md5key', $md5)) {
if ($texcache = $DB->get_record('cache_filters', array('filter'=>'algebra', 'md5key'=>$md5))) {
if (!file_exists($CFG->dataroot.'/filter/algebra')) {
make_upload_directory('filter/algebra');
}
Expand Down
Loading

0 comments on commit 219f652

Please sign in to comment.