adding some strings
[moodle-linuxchix.git] / mod / forum / db / postgres7.php
blob98c07ee11a2ae1eed4ba699d375db71fec59b479
1 <?php // $Id$
3 // THIS FILE IS DEPRECATED! PLEASE DO NOT MAKE CHANGES TO IT!
4 //
5 // IT IS USED ONLY FOR UPGRADES FROM BEFORE MOODLE 1.7, ALL
6 // LATER CHANGES SHOULD USE upgrade.php IN THIS DIRECTORY.
8 function forum_upgrade($oldversion) {
9 // This function does anything necessary to upgrade
10 // older versions to match current functionality
12 global $CFG;
14 if ($oldversion < 2003042402) {
15 execute_sql("INSERT INTO {$CFG->prefix}log_display (module, action, mtable, field) VALUES ('forum', 'move discussion', 'forum_discussions', 'name')");
18 if ($oldversion < 2003082500) {
19 table_column("forum", "", "assesstimestart", "integer", "10", "unsigned", "0", "", "assessed");
20 table_column("forum", "", "assesstimefinish", "integer", "10", "unsigned", "0", "", "assesstimestart");
23 if ($oldversion < 2003082502) {
24 execute_sql("UPDATE {$CFG->prefix}forum SET scale = (- scale)");
27 if ($oldversion < 2003100600) {
28 table_column("forum", "", "maxbytes", "integer", "10", "unsigned", "0", "", "scale");
31 if ($oldversion < 2004010100) {
32 table_column("forum", "", "assesspublic", "integer", "4", "unsigned", "0", "", "assessed");
35 if ($oldversion < 2004011404) {
36 table_column("forum_discussions", "", "userid", "integer", "10", "unsigned", "0", "", "firstpost");
38 if ($discussions = get_records_sql("SELECT d.id, p.userid
39 FROM {$CFG->prefix}forum_discussions as d,
40 {$CFG->prefix}forum_posts as p
41 WHERE d.firstpost = p.id")) {
42 foreach ($discussions as $discussion) {
43 update_record("forum_discussions", $discussion);
47 if ($oldversion < 2004012200) {
48 table_column("forum_discussions", "", "groupid", "integer", "10", "unsigned", "0", "", "userid");
51 if ($oldversion < 2004020600) {
52 table_column("forum_discussions", "", "usermodified", "integer", "10", "unsigned", "0", "", "timemodified");
55 if ($oldversion < 2004050300) {
56 table_column("forum","","rsstype","integer","2", "unsigned", "0", "", "forcesubscribe");
57 table_column("forum","","rssarticles","integer","2", "unsigned", "0", "", "rsstype");
58 set_config("forum_enablerssfeeds",0);
61 if ($oldversion < 2004060100) {
62 modify_database('', "CREATE TABLE prefix_forum_queue (
63 id SERIAL PRIMARY KEY,
64 userid integer default 0 NOT NULL,
65 discussionid integer default 0 NOT NULL,
66 postid integer default 0 NOT NULL
67 );");
70 if ($oldversion < 2004070700) { // This may be redoing it from STABLE but that's OK
71 table_column("forum_discussions", "groupid", "groupid", "integer", "10", "", "0", "");
75 if ($oldversion < 2004111700) {
76 execute_sql(" DROP INDEX {$CFG->prefix}forum_posts_parent_idx;",false);
77 execute_sql(" DROP INDEX {$CFG->prefix}forum_posts_discussion_idx;",false);
78 execute_sql(" DROP INDEX {$CFG->prefix}forum_posts_userid_idx;",false);
79 execute_sql(" DROP INDEX {$CFG->prefix}forum_discussions_forum_idx;",false);
80 execute_sql(" DROP INDEX {$CFG->prefix}forum_discussions_userid_idx;",false);
82 execute_sql(" CREATE INDEX {$CFG->prefix}forum_posts_parent_idx ON {$CFG->prefix}forum_posts (parent) ");
83 execute_sql(" CREATE INDEX {$CFG->prefix}forum_posts_discussion_idx ON {$CFG->prefix}forum_posts (discussion) ");
84 execute_sql(" CREATE INDEX {$CFG->prefix}forum_posts_userid_idx ON {$CFG->prefix}forum_posts (userid) ");
85 execute_sql(" CREATE INDEX {$CFG->prefix}forum_discussions_forum_idx ON {$CFG->prefix}forum_discussions (forum) ");
86 execute_sql(" CREATE INDEX {$CFG->prefix}forum_discussions_userid_idx ON {$CFG->prefix}forum_discussions (userid) ");
89 if ($oldversion < 2004111200) {
90 execute_sql("DROP INDEX {$CFG->prefix}forum_course_idx;",false);
91 execute_sql("DROP INDEX {$CFG->prefix}forum_queue_userid_idx;",false);
92 execute_sql("DROP INDEX {$CFG->prefix}forum_queue_discussion_idx;",false);
93 execute_sql("DROP INDEX {$CFG->prefix}forum_queue_postid_idx;",false);
94 execute_sql("DROP INDEX {$CFG->prefix}forum_ratings_userid_idx;",false);
95 execute_sql("DROP INDEX {$CFG->prefix}forum_ratings_post_idx;",false);
96 execute_sql("DROP INDEX {$CFG->prefix}forum_subscriptions_userid_idx;",false);
97 execute_sql("DROP INDEX {$CFG->prefix}forum_subscriptions_forum_idx;",false);
99 modify_database('','CREATE INDEX prefix_forum_course_idx ON prefix_forum (course);');
100 modify_database('','CREATE INDEX prefix_forum_queue_userid_idx ON prefix_forum_queue (userid);');
101 modify_database('','CREATE INDEX prefix_forum_queue_discussion_idx ON prefix_forum_queue (discussionid);');
102 modify_database('','CREATE INDEX prefix_forum_queue_postid_idx ON prefix_forum_queue (postid);');
103 modify_database('','CREATE INDEX prefix_forum_ratings_userid_idx ON prefix_forum_ratings (userid);');
104 modify_database('','CREATE INDEX prefix_forum_ratings_post_idx ON prefix_forum_ratings (post);');
105 modify_database('','CREATE INDEX prefix_forum_subscriptions_userid_idx ON prefix_forum_subscriptions (userid);');
106 modify_database('','CREATE INDEX prefix_forum_subscriptions_forum_idx ON prefix_forum_subscriptions (forum);');
109 if ($oldversion < 2005011500) {
110 modify_database('','CREATE TABLE prefix_forum_read (
111 id SERIAL PRIMARY KEY,
112 userid integer default 0 NOT NULL,
113 forumid integer default 0 NOT NULL,
114 discussionid integer default 0 NOT NULL,
115 postid integer default 0 NOT NULL,
116 firstread integer default 0 NOT NULL,
117 lastread integer default 0 NOT NULL
118 );');
120 modify_database('','CREATE INDEX prefix_forum_user_forum_idx ON prefix_forum_read (userid, forumid);');
121 modify_database('','CREATE INDEX prefix_forum_user_discussion_idx ON prefix_forum_read (userid, discussionid);');
122 modify_database('','CREATE INDEX prefix_forum_user_post_idx ON prefix_forum_read (userid, postid);');
124 set_config('upgrade', 'forumread'); // The upgrade of this table will be done later by admin/upgradeforumread.php
127 if ($oldversion < 2005032900) {
128 modify_database('','CREATE INDEX prefix_forum_posts_created_idx ON prefix_forum_posts (created);');
129 modify_database('','CREATE INDEX prefix_forum_posts_mailed_idx ON prefix_forum_posts (mailed);');
132 if ($oldversion < 2005041100) { // replace wiki-like with markdown
133 include_once( "$CFG->dirroot/lib/wiki_to_markdown.php" );
134 $wtm = new WikiToMarkdown();
135 $sql = "select course from {$CFG->prefix}forum_discussions, {$CFG->prefix}forum_posts ";
136 $sql .= "where {$CFG->prefix}forum_posts.discussion = {$CFG->prefix}forum_discussions.id ";
137 $sql .= "and {$CFG->prefix}forum_posts.id = ";
138 $wtm->update( 'forum_posts','message','format',$sql );
141 if ($oldversion < 2005042300) { // Add tracking prefs table
142 modify_database('','CREATE TABLE prefix_forum_track_prefs (
143 id SERIAL PRIMARY KEY,
144 userid integer default 0 NOT NULL,
145 forumid integer default 0 NOT NULL
146 );');
149 if ($oldversion < 2005042600) {
150 table_column('forum','','trackingtype','integer','2', 'unsigned', '1', '', 'forcesubscribe');
151 modify_database('','CREATE INDEX prefix_forum_track_user_forum_idx ON prefix_forum_track_prefs (userid, forumid);');
154 if ($oldversion < 2005042601) { // Mass cleanup of bad postgres upgrade scripts
155 modify_database('','ALTER TABLE prefix_forum ALTER trackingtype SET NOT NULL');
158 if ($oldversion < 2005111100) {
159 table_column('forum_discussions','','timestart','integer');
160 table_column('forum_discussions','','timeend','integer');
163 if ($oldversion < 2006011600) {
164 notify('forum_type does not exists, you can ignore and this will properly removed');
165 execute_sql("ALTER TABLE {$CFG->prefix}forum DROP CONSTRAINT {$CFG->prefix}forum_type");
166 execute_sql("ALTER TABLE {$CFG->prefix}forum ADD CONSTRAINT {$CFG->prefix}forum_type CHECK (type IN ('single','news','general','social','eachuser','teacher','qanda')) ");
169 if ($oldversion < 2006011601) {
170 table_column('forum','','warnafter');
171 table_column('forum','','blockafter');
172 table_column('forum','','blockperiod');
175 if ($oldversion < 2006011700) {
176 table_column('forum_posts','','mailnow','integer');
179 if ($oldversion < 2006011701) {
180 execute_sql("ALTER TABLE {$CFG->prefix}forum DROP CONSTRAINT {$CFG->prefix}forum_type_check");
183 if ($oldversion < 2006011702) {
184 execute_sql("INSERT INTO {$CFG->prefix}log_display (module, action, mtable, field) VALUES ('forum', 'user report', 'user', 'firstname||\' \'||lastname')");
187 if ($oldversion < 2006081800) {
188 // Upgrades for new roles and capabilities support.
189 require_once($CFG->dirroot.'/mod/forum/lib.php');
191 $forummod = get_record('modules', 'name', 'forum');
193 if ($forums = get_records('forum')) {
195 if (!$teacherroles = get_roles_with_capability('moodle/legacy:teacher', CAP_ALLOW)) {
196 notify('Default teacher role was not found. Roles and permissions '.
197 'for all your forums will have to be manually set after '.
198 'this upgrade.');
200 if (!$studentroles = get_roles_with_capability('moodle/legacy:student', CAP_ALLOW)) {
201 notify('Default student role was not found. Roles and permissions '.
202 'for all your forums will have to be manually set after '.
203 'this upgrade.');
205 if (!$guestroles = get_roles_with_capability('moodle/legacy:guest', CAP_ALLOW)) {
206 notify('Default guest role was not found. Roles and permissions '.
207 'for teacher forums will have to be manually set after '.
208 'this upgrade.');
210 foreach ($forums as $forum) {
211 if (!forum_convert_to_roles($forum, $forummod->id, $teacherroles,
212 $studentroles, $guestroles)) {
213 notify('Forum with id '.$forum->id.' was not upgraded');
216 // We need to rebuild all the course caches to refresh the state of
217 // the forum modules.
218 rebuild_course_cache();
220 } // End if.
222 // Drop column forum.open.
223 modify_database('', 'ALTER TABLE prefix_forum DROP COLUMN open;');
225 // Drop column forum.assesspublic.
226 modify_database('', 'ALTER TABLE prefix_forum DROP COLUMN assesspublic;');
229 if ($oldversion < 2006082700) {
230 $sql = "UPDATE {$CFG->prefix}forum_posts SET message = REPLACE(message, '".TRUSTTEXT."', '');";
231 $likecond = sql_ilike()." '%".TRUSTTEXT."%'";
232 while (true) {
233 if (!count_records_select('forum_posts', "message $likecond")) {
234 break;
236 execute_sql($sql);
240 ////// DO NOT ADD NEW THINGS HERE!! USE upgrade.php and the lib/ddllib.php functions.
242 return true;