]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-19754 MDL-8776 MDL-19678 MDL-20314 Converting old post table to blog_entries...
authornicolasconnault <nicolasconnault>
Fri, 18 Sep 2009 06:57:52 +0000 (06:57 +0000)
committernicolasconnault <nicolasconnault>
Fri, 18 Sep 2009 06:57:52 +0000 (06:57 +0000)
blog/edit.php
blog/edit_form.php
blog/index.php
blog/lib.php
blog/locallib.php
blog/rsslib.php
lib/db/install.xml
lib/db/upgrade.php
version.php

index d519c72c645bc8c6d28e8218d216572471fcc39c..e7ecd285f71b5074fa6643ccea69a0e592ac6e1a 100755 (executable)
@@ -204,7 +204,7 @@ switch ($action) {
         $entry->fakesummary  = $existing->summary;
         $entry->publishstate = $existing->publishstate;
         $entry->format       = $existing->format;
-        $entry->tags         = tag_get_tags_array('post', $entry->id);
+        $entry->tags         = tag_get_tags_array('blog_entries', $entry->id);
         $entry->action       = $action;
 
         if (!empty($existing->courseassoc)) {
index e0c80d61e0bbca60dbaf2ce4a3630ac84f2a62b8..df0d801edc5192dad0556d1f050905cfd7ee9bdf 100644 (file)
@@ -43,7 +43,7 @@ class blog_edit_form extends moodleform {
 
         $mform->addElement('format', 'summaryformat', get_string('format'));
 
-        $mform->addElement('filemanager', 'attachment', get_string('attachment', 'forum'));
+        $mform->addElement('filemanager', 'attachments', get_string('attachment', 'forum'));
 
         //disable publishstate options that are not allowed
         $publishstates = array();
index 1f5365b478d06c8a7b29110cb9690d8f072234d1..e27296c18c33176526b5219b64680b74be98bd1d 100755 (executable)
@@ -61,7 +61,7 @@ $tabsfile = null;
 
 if (!$userid && has_capability('moodle/blog:view', $sitecontext) && $CFG->bloglevel > BLOG_USER_LEVEL) {
     if ($entryid) {
-        if (!$entryobject = $DB->get_record('post', array('module'=>'blog', 'id'=>$entryid))) {
+        if (!$entryobject = $DB->get_record('blog_entries', array('id'=>$entryid))) {
             print_error('nosuchentry', 'blog');
         }
         $userid = $entryobject->userid;
index 302fcbf1ad807332520871b1228c28a07cb4a843..1d9be1962ec0ddca4fefbe22f583239990938bb3 100755 (executable)
@@ -36,7 +36,9 @@ require_once($CFG->dirroot.'/tag/lib.php');
  */
 //not used at the moment, and may not need to be
 define('PAGE_BLOG_COURSE_VIEW', 'blog_course-view');
-
+define('BLOG_PUBLISHSTATE_DRAFT', 0);
+define('BLOG_PUBLISHSTATE_SITE', 1);
+define('BLOG_PUBLISHSTATE_PUBLIC', 2);
 
 /**
  * Checks to see if user has visited blogpages before, if not, install 2
@@ -293,17 +295,17 @@ function blog_fetch_external_entries($external_blog) {
                         'publishstate' => 'site',
                         'format' => FORMAT_HTML);
 
-        if (!$DB->record_exists('post', $params)) {
+        if (!$DB->record_exists('blog_entries', $params)) {
             $params['subject']      = $entry->get_title();
             $params['summary']      = $entry->get_description();
             $params['created']      = $entry->get_date('U');
             $params['lastmodified'] = $entry->get_date('U');
 
-            $id = $DB->insert_record('post', $params);
+            $id = $DB->insert_record('blog_entries', $params);
 
             // Set tags
             if ($tags = tag_get_tags_array('blog_external', $external_blog->id)) {
-                tag_set('post', $id, $tags);
+                tag_set('blog_entries', $id, $tags);
             }
         }
     }
@@ -435,9 +437,9 @@ function blog_get_headers() {
     // Case 1: only entryid is requested, ignore all other filters. courseid is used to give more contextual information
     // TODO Blog entries link has entryid instead of userid
     if (!empty($entryid)) {
-        $sql = 'SELECT u.* FROM {user} u, {post} p WHERE p.id = ? AND p.userid = u.id';
+        $sql = 'SELECT u.* FROM {user} u, {blog_entries} p WHERE p.id = ? AND p.userid = u.id';
         $user = $DB->get_record_sql($sql, array($entryid));
-        $entry = $DB->get_record('post', array('id' => $entryid));
+        $entry = $DB->get_record('blog_entries', array('id' => $entryid));
 
         $blog_url->param('userid', $user->id);
 
index 19cc15471df5f6ef71a2549a6fc6aa68c1abfee5..f6eef0523dbc281581d99a5188657140ccb92da8 100644 (file)
@@ -30,7 +30,7 @@
  * Blog_entry class. Represents an entry in a user's blog. Contains all methods for managing this entry.
  * This class does not contain any HTML-generating code. See blog_listing sub-classes for such code.
  * This class follows the Object Relational Mapping technique, its member variables being mapped to
- * the fields of the posts table.
+ * the fields of the blog_entries table.
  *
  * @package    moodlecore
  * @subpackage blog
@@ -43,19 +43,13 @@ class blog_entry {
     public $userid;
     public $subject;
     public $summary;
-    public $rating = 0;
-    public $attachment;
     public $publishstate;
 
     // Locked Database fields (Don't touch these)
-    public $courseid = 0;
-    public $groupid = 0;
-    public $module = 'blog';
-    public $moduleid = 0;
-    public $coursemoduleid = 0;
     public $content;
     public $format = 1;
-    public $uniquehash = '';
+    public $summaryformat = 1;
+    public $permalink = '';
     public $lastmodified;
     public $created;
     public $usermodified;
@@ -74,7 +68,7 @@ class blog_entry {
         global $DB, $PAGE;
 
         if (!empty($idorparams) && !is_array($idorparams) && !is_object($idorparams)) {
-            $object = $DB->get_record('post', array('id' => $idorparams));
+            $object = $DB->get_record('blog_entries', array('id' => $idorparams));
             foreach ($object as $var => $val) {
                 $this->$var = $val;
             }
@@ -178,13 +172,13 @@ class blog_entry {
         $blogassociations = $DB->get_records('blog_association', array('blogid' => $this->id));
         //determine text for publish state
         switch ($template['publishstate']) {
-            case 'draft':
+            case BLOG_PUBLISHSTATE_DRAFT:
                 $blogtype = get_string('publishtonoone', 'blog');
             break;
-            case 'site':
+            case BLOG_PUBLISHSTATE_SITE:
                 $blogtype = get_string('publishtosite', 'blog');
             break;
-            case 'public':
+            case BLOG_PUBLISHSTATE_PUBLIC:
                 $blogtype = get_string('publishtoworld', 'blog');
             break;
             default:
@@ -198,16 +192,16 @@ class blog_entry {
         $contentcell->text .= $template['body'];
         $contentcell->text .= $attachedimages;
 
-        // Uniquehash is used as a link to an external blog
-        if (!empty($this->uniquehash) && blog_is_valid_url($this->uniquehash)) {
+        // permalink is used as a link to an external blog
+        if (!empty($this->permalink) && blog_is_valid_url($this->permalink)) {
             $contentcell->text .= $OUTPUT->container_start('externalblog');
-            $contentcell->text .= $OUTPUT->link(html_link::make($this->uniquehash, get_string('linktooriginalentry', 'blog')));
+            $contentcell->text .= $OUTPUT->link(html_link::make($this->permalink, get_string('linktooriginalentry', 'blog')));
             $contentcell->text .= $OUTPUT->container_end();
         }
 
         // Links to tags
 
-        if (!empty($CFG->usetags) && ($blogtags = tag_get_tags_csv('post', $this->id)) ) {
+        if (!empty($CFG->usetags) && ($blogtags = tag_get_tags_csv('blog_entries', $this->id)) ) {
             $contentcell->text .= $OUTPUT->container_start('tags');
 
             if ($blogtags) {
@@ -320,14 +314,9 @@ class blog_entry {
         $this->created      = time();
 
         // Insert the new blog entry.
-        $this->id = $DB->insert_record('post', $this);
+        $this->id = $DB->insert_record('blog_entries', $this);
 
-        // Add blog attachment
-        if (!empty($this->form) && $this->form->get_new_filename('attachment')) {
-            if ($this->form->save_stored_file('attachment', SYSCONTEXTID, 'blog', $this->id, '/', $this->form->get_new_filename('attachment'), $USER->id)) {
-                $DB->set_field("post", "attachment", 1, array("id"=>$this->id));
-            }
-        }
+        // TODO File handling
 
         // Update tags.
         $this->add_tags_info();
@@ -338,7 +327,7 @@ class blog_entry {
 
         }
 
-        tag_set('post', $this->id, $this->tags);
+        tag_set('blog_entries', $this->id, $this->tags);
     }
 
     /**
@@ -362,19 +351,11 @@ class blog_entry {
         }
 
         $this->lastmodified = time();
-
-        if (!empty($this->form) && $this->form->get_new_filename('attachment')) {
-            $this->delete_attachments();
-            if ($this->form->save_stored_file('attachment', SYSCONTEXTID, 'blog', $this->id, '/', false, $USER->id)) {
-                $this->attachment = 1;
-            } else {
-                $this->attachment = 1;
-            }
-        }
-
+        
+        // TODO Handle attachments
         // Update record
-        $DB->update_record('post', $this);
-        tag_set('post', $this->id, $this->tags);
+        $DB->update_record('blog_entries', $this);
+        tag_set('blog_entries', $this->id, $this->tags);
 
         add_to_log(SITEID, 'blog', 'update', 'index.php?userid='.$USER->id.'&entryid='.$this->id, $this->subject);
     }
@@ -391,8 +372,8 @@ class blog_entry {
 
         $this->delete_attachments();
 
-        $DB->delete_records('post', array('id' => $this->id));
-        tag_set('post', $this->id, array());
+        $DB->delete_records('blog_entries', array('id' => $this->id));
+        tag_set('blog_entries', $this->id, array());
 
         add_to_log(SITEID, 'blog', 'delete', 'index.php?userid='. $this->userid, 'deleted blog entry with entry id# '. $this->id);
     }
@@ -457,6 +438,7 @@ class blog_entry {
      * if return=html, then return a html string.
      * if return=text, then return a text-only string.
      * otherwise, print HTML for non-images, and return image HTML
+     * TODO Fix this so that it displays attachments correctly
      *
      * @param bool $return Whether to return or print the generated code
      * @return void
@@ -531,7 +513,7 @@ class blog_entry {
             }
         }
 
-        tag_set('post', $this->id, $tags);
+        tag_set('blog_entries', $this->id, $tags);
     }
 
     /**
@@ -589,12 +571,12 @@ class blog_entry {
         }
 
         // coming for 1 entry, make sure it's not a draft
-        if ($this->publishstate == 'draft') {
+        if ($this->publishstate == BLOG_PUBLISHSTATE_DRAFT) {
             return false;  // can not view draft of others
         }
 
         // coming for 1 entry, make sure user is logged in, if not a public blog
-        if ($this->publishstate != 'public' && !isloggedin()) {
+        if ($this->publishstate != BLOG_PUBLISHSTATE_PUBLIC && !isloggedin()) {
             return false;
         }
 
@@ -632,15 +614,15 @@ class blog_entry {
 
         // everyone gets draft access
         if ($CFG->bloglevel >= BLOG_USER_LEVEL) {
-            $options['draft'] = get_string('publishtonoone', 'blog');
+            $options[BLOG_PUBLISHSTATE_DRAFT] = get_string('publishtonoone', 'blog');
         }
 
         if ($CFG->bloglevel > BLOG_USER_LEVEL) {
-            $options['site'] = get_string('publishtosite', 'blog');
+            $options[BLOG_PUBLISHSTATE_SITE] = get_string('publishtosite', 'blog');
         }
 
         if ($CFG->bloglevel >= BLOG_GLOBAL_LEVEL) {
-            $options['public'] = get_string('publishtoworld', 'blog');
+            $options[BLOG_PUBLISHSTATE_PUBLIC] = get_string('publishtoworld', 'blog');
         }
 
         return $options;
@@ -717,9 +699,9 @@ class blog_listing {
         }
 
         // The query used to locate blog entries is complicated.  It will be built from the following components:
-        $requiredfields = "p.*, u.firstname, u.lastname, u.email";  // the SELECT clause
-        $tables = array('p' => 'post', 'u' => 'user');   // components of the FROM clause (table_id => table_name)
-        $conditions = array('u.deleted = 0', 'p.userid = u.id', 'p.module = \'blog\'');  // components of the WHERE clause (conjunction)
+        $requiredfields = "b.*, u.firstname, u.lastname, u.email";  // the SELECT clause
+        $tables = array('b' => 'blog_entries', 'u' => 'user');   // components of the FROM clause (table_id => table_name)
+        $conditions = array('u.deleted = 0', 'b.userid = u.id');  // components of the WHERE clause (conjunction)
 
         // build up a clause for permission constraints
 
@@ -739,20 +721,20 @@ class blog_listing {
                 $assocexists = $DB->record_exists('blog_association', array());  //dont check association records if there aren't any
 
                 //begin permission sql clause
-                $permissionsql =  '(p.userid = ? ';
+                $permissionsql =  '(b.userid = ? ';
                 $params[] = $userid;
 
                 if ($CFG->bloglevel >= BLOG_SITE_LEVEL) { // add permission to view site-level entries
-                    $permissionsql .= " OR p.publishstate = 'site' ";
+                    $permissionsql .= " OR b.publishstate = " . BLOG_PUBLISHSTATE_SITE;
                 }
 
                 if ($CFG->bloglevel >= BLOG_GLOBAL_LEVEL) { // add permission to view global entries
-                    $permissionsql .= " OR p.publishstate = 'public' ";
+                    $permissionsql .= " OR b.publishstate = " . BLOG_PUBLISHSTATE_DRAFT;
                 }
 
                 $permissionsql .= ') ';   //close permissions sql clause
             } else {  // default is access to public entries
-                $permissionsql = "p.publishstate = 'public'";
+                $permissionsql = "b.publishstate = " . BLOG_PUBLISHSTATE_PUBLIC;
             }
             $conditions[] = $permissionsql;  //add permission constraints
         }
@@ -1001,7 +983,7 @@ class blog_filter_context extends blog_filter {
                     $this->overrides = array('site');
                     $context = get_context_instance(CONTEXT_COURSE, $this->id);
                     $this->tables['ba'] = 'blog_association';
-                    $this->conditions[] = 'p.id = ba.blogid';
+                    $this->conditions[] = 'b.id = ba.blogid';
                     $this->conditions[] = 'ba.contextid = '.$context->id;
                     break;
                 } else {
@@ -1017,8 +999,8 @@ class blog_filter_context extends blog_filter {
 
                     $context = get_context_instance(CONTEXT_MODULE, $this->id);
                     $this->tables['ba'] = 'blog_association';
-                    $this->tables['p']  = 'post';
-                    $this->conditions = array('p.id = ba.blogid', 'ba.contextid = ?');
+                    $this->tables['b']  = 'blog_entries';
+                    $this->conditions = array('b.id = ba.blogid', 'ba.contextid = ?');
                     $this->params = array($context->id);
                 }
                 break;
@@ -1060,7 +1042,7 @@ class blog_filter_user extends blog_filter {
             $this->overrides = array('course', 'site');
 
             $this->tables['gm'] = 'groups_members';
-            $this->conditions[] = 'p.userid = gm.userid';
+            $this->conditions[] = 'b.userid = gm.userid';
             $this->conditions[] = 'gm.groupid = ?';
             $this->params[]     = $this->id;
 
@@ -1069,7 +1051,7 @@ class blog_filter_user extends blog_filter {
                 $this->tables['ba'] = 'blog_association';
                 $this->conditions[] = 'gm.groupid = ?';
                 $this->conditions[] = 'ba.contextid = ?';
-                $this->conditions[] = 'ba.blogid = p.id';
+                $this->conditions[] = 'ba.blogid = b.id';
                 $this->params[]     = $this->id;
                 $this->params[]     = $course_context->id;
             }
@@ -1082,7 +1064,7 @@ class blog_filter_user extends blog_filter {
  * This filter defines a tag by which blog entries should be searched.
  */
 class blog_filter_tag extends blog_filter {
-    public $tables = array('t' => 'tag', 'ti' => 'tag_instance', 'p' => 'post');
+    public $tables = array('t' => 'tag', 'ti' => 'tag_instance', 'b' => 'blog_entries');
 
     /**
      * Constructor
@@ -1094,8 +1076,8 @@ class blog_filter_tag extends blog_filter {
         $this->id = $id;
 
         $this->conditions = array('ti.tagid = t.id',
-                                  "ti.itemtype = 'post'",
-                                  'ti.itemid = p.id',
+                                  "ti.itemtype = 'blog_entries'",
+                                  'ti.itemid = b.id',
                                   't.id = ?');
         $this->params = array($this->id);
     }
@@ -1122,8 +1104,8 @@ class blog_filter_search extends blog_filter {
     public function __construct($search_term) {
         global $DB;
         $ilike = $DB->sql_ilike();
-        $this->conditions = array("(p.summary $ilike '%$search_term%' OR
-                                    p.content $ilike '%$search_term%' OR
-                                    p.subject $ilike '%$search_term%')");
+        $this->conditions = array("(b.summary $ilike '%$search_term%' OR
+                                    b.content $ilike '%$search_term%' OR
+                                    b.subject $ilike '%$search_term%')");
     }
 }
index b59250adb24f486d2454ae4fce872d99952bc202..a31aa7dabf48b40f8e990d6f14210c62f8b6ae8b 100755 (executable)
@@ -76,7 +76,7 @@
                 $item->pubdate = $blog_entry->lastmodified;
                 $item->link = $CFG->wwwroot.'/blog/index.php?entryid='.$blog_entry->id;
                 $item->description = format_text($blog_entry->summary, $blog_entry->format);
-                if ( !empty($CFG->usetags) && ($blogtags = tag_get_tags_array('post', $blog_entry->id)) ) {
+                if ( !empty($CFG->usetags) && ($blogtags = tag_get_tags_array('blog_entries', $blog_entry->id)) ) {
                     if ($blogtags) {
                         $item->tags = $blogtags;
                     }
index 6b3300977768a031796a074320cb16a438314bd4..52e0908742bcc1c5339919b04cfd0d4fddcac932 100644 (file)
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8" ?>
-<XMLDB PATH="lib/db" VERSION="20090913" COMMENT="XMLDB file for core Moodle tables"
+<XMLDB PATH="lib/db" VERSION="20090917" COMMENT="XMLDB file for core Moodle tables"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:noNamespaceSchemaLocation="../../lib/xmldb/xmldb.xsd"
 >
         <INDEX NAME="blockinstanceid-contextid-pagetype-subpage" UNIQUE="true" FIELDS="blockinstanceid, contextid, pagetype, subpage"/>
       </INDEXES>
     </TABLE>
-    <TABLE NAME="blog_association" COMMENT="Associations of blog entries with courses and module instances." PREVIOUS="block_positions" NEXT="blog_external">
+    <TABLE NAME="blog_association" COMMENT="Associations of blog entries with courses and module instances." PREVIOUS="block_positions" NEXT="blog_entries">
       <FIELDS>
         <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" NEXT="contextid"/>
         <FIELD NAME="contextid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" PREVIOUS="id" NEXT="blogid"/>
         <INDEX NAME="blogid" UNIQUE="false" FIELDS="blogid" PREVIOUS="contextid"/>
       </INDEXES>
     </TABLE>
-    <TABLE NAME="blog_external" COMMENT="External blog links used for RSS copying of blog entries to Moodle." PREVIOUS="blog_association" NEXT="comments">
+    <TABLE NAME="blog_entries" COMMENT="Blog entries" PREVIOUS="blog_association">
       <FIELDS>
         <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" NEXT="userid"/>
-        <FIELD NAME="userid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" PREVIOUS="id" NEXT="name"/>
-        <FIELD NAME="name" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" PREVIOUS="userid" NEXT="description"/>
-        <FIELD NAME="description" TYPE="text" LENGTH="small" NOTNULL="false" SEQUENCE="false" PREVIOUS="name" NEXT="url"/>
-        <FIELD NAME="url" TYPE="text" LENGTH="small" NOTNULL="true" SEQUENCE="false" PREVIOUS="description" NEXT="timemodified"/>
-        <FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" PREVIOUS="url" NEXT="timefetched"/>
-        <FIELD NAME="timefetched" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="timemodified"/>
-      </FIELDS>
-      <KEYS>
-        <KEY NAME="id_key" TYPE="primary" FIELDS="id"/>
-      </KEYS>
-      <INDEXES>
-        <INDEX NAME="mdl1_blogexte_use_ix" UNIQUE="false" FIELDS="userid"/>
-      </INDEXES>
-    </TABLE>
-    <TABLE NAME="comments" COMMENT="moodle comments module" PREVIOUS="blog_external" NEXT="external_functions">
-      <FIELDS>
-        <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" NEXT="contextid"/>
-        <FIELD NAME="contextid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" PREVIOUS="id" NEXT="commentarea"/>
-        <FIELD NAME="commentarea" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" PREVIOUS="contextid" NEXT="itemid"/>
-        <FIELD NAME="itemid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" PREVIOUS="commentarea" NEXT="content"/>
-        <FIELD NAME="content" TYPE="text" LENGTH="small" NOTNULL="true" SEQUENCE="false" PREVIOUS="itemid" NEXT="format"/>
-        <FIELD NAME="format" TYPE="int" LENGTH="2" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="content" NEXT="userid"/>
-        <FIELD NAME="userid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" PREVIOUS="format" NEXT="timecreated"/>
-        <FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" PREVIOUS="userid"/>
-      </FIELDS>
-      <KEYS>
-        <KEY NAME="primary" TYPE="primary" FIELDS="id"/>
-      </KEYS>
-    </TABLE>
-    <TABLE NAME="external_functions" COMMENT="list of all external functions" PREVIOUS="comments" NEXT="external_services">
-      <FIELDS>
-        <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" NEXT="name"/>
-        <FIELD NAME="name" TYPE="char" LENGTH="200" NOTNULL="true" SEQUENCE="false" PREVIOUS="id" NEXT="classname"/>
-        <FIELD NAME="classname" TYPE="char" LENGTH="100" NOTNULL="true" SEQUENCE="false" PREVIOUS="name" NEXT="methodname"/>
-        <FIELD NAME="methodname" TYPE="char" LENGTH="100" NOTNULL="true" SEQUENCE="false" PREVIOUS="classname" NEXT="classpath"/>
-        <FIELD NAME="classpath" TYPE="char" LENGTH="255" NOTNULL="false" SEQUENCE="false" PREVIOUS="methodname" NEXT="component"/>
-        <FIELD NAME="component" TYPE="char" LENGTH="100" NOTNULL="true" SEQUENCE="false" PREVIOUS="classpath"/>
-      </FIELDS>
-      <KEYS>
-        <KEY NAME="primary" TYPE="primary" FIELDS="id"/>
-      </KEYS>
-      <INDEXES>
-        <INDEX NAME="name" UNIQUE="true" FIELDS="name" COMMENT="the external function names must be globally unique"/>
-      </INDEXES>
-    </TABLE>
-    <TABLE NAME="external_services" COMMENT="built in and custom external services" PREVIOUS="external_functions" NEXT="external_services_functions">
-      <FIELDS>
-        <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" NEXT="name"/>
-        <FIELD NAME="name" TYPE="char" LENGTH="200" NOTNULL="true" SEQUENCE="false" PREVIOUS="id" NEXT="enabled"/>
-        <FIELD NAME="enabled" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" PREVIOUS="name" NEXT="requiredcapability"/>
-        <FIELD NAME="requiredcapability" TYPE="char" LENGTH="150" NOTNULL="false" SEQUENCE="false" PREVIOUS="enabled" NEXT="restrictedusers"/>
-        <FIELD NAME="restrictedusers" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" PREVIOUS="requiredcapability" NEXT="component"/>
-        <FIELD NAME="component" TYPE="char" LENGTH="100" NOTNULL="false" SEQUENCE="false" PREVIOUS="restrictedusers"/>
+        <FIELD NAME="userid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" COMMENT="The author of the entry" PREVIOUS="id" NEXT="subject"/>
+        <FIELD NAME="subject" TYPE="char" LENGTH="255" NOTNULL="true" DEFAULT="blog entry" SEQUENCE="false" COMMENT="A short description for the entry" PREVIOUS="userid" NEXT="summary"/>
+        <FIELD NAME="summary" TYPE="text" LENGTH="big" NOTNULL="false" SEQUENCE="false" COMMENT="If the content field is used, this will be used as the teaser. Otherwise it is the full text of the blog entry" PREVIOUS="subject" NEXT="content"/>
+        <FIELD NAME="content" TYPE="text" LENGTH="big" NOTNULL="false" SEQUENCE="false" COMMENT="The full text of the blog entry" PREVIOUS="summary" NEXT="permalink"/>
+        <FIELD NAME="permalink" TYPE="char" LENGTH="255" NOTNULL="false" SEQUENCE="false" COMMENT="A permanent URL to the blog entry" PREVIOUS="content" NEXT="format"/>
+        <FIELD NAME="format" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" COMMENT="The format of the content field" PREVIOUS="permalink" NEXT="summaryformat"/>
+        <FIELD NAME="summaryformat" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" COMMENT="The format of the summary field" PREVIOUS="format" NEXT="attachment"/>
+        <FIELD NAME="attachment" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" COMMENT="Whether or not this blog entry has attachments" PREVIOUS="summaryformat" NEXT="publishstate"/>
+        <FIELD NAME="publishstate" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" COMMENT="Whether this is published as a draft or to everyone" PREVIOUS="attachment" NEXT="lastmodified"/>
+        <FIELD NAME="lastmodified" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" COMMENT="The timestamp of the last time this blog entry was modified" PREVIOUS="publishstate" NEXT="created"/>
+        <FIELD NAME="created" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" COMMENT="The timestamp at which this blog entry was created" PREVIOUS="lastmodified" NEXT="usermodified"/>
+        <FIELD NAME="usermodified" TYPE="int" LENGTH="10" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" COMMENT="The id of the user who last modified this blog entry" PREVIOUS="created"/>
       </FIELDS>
       <KEYS>
         <KEY NAME="primary" TYPE="primary" FIELDS="id"/>
       </KEYS>
       <INDEXES>
-        <INDEX NAME="name" UNIQUE="true" FIELDS="name"/>
+        <INDEX NAME="userid" UNIQUE="false" FIELDS="userid" NEXT="usermodified"/>
+        <INDEX NAME="usermodified" UNIQUE="false" FIELDS="usermodified" PREVIOUS="userid"/>
       </INDEXES>
     </TABLE>
-    <TABLE NAME="external_services_functions" COMMENT="lists functions available in each service group" PREVIOUS="external_services" NEXT="external_services_users">
-      <FIELDS>
-        <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" NEXT="externalserviceid"/>
-        <FIELD NAME="externalserviceid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" PREVIOUS="id" NEXT="functionname"/>
-        <FIELD NAME="functionname" TYPE="char" LENGTH="200" NOTNULL="true" SEQUENCE="false" PREVIOUS="externalserviceid"/>
-      </FIELDS>
-      <KEYS>
-        <KEY NAME="primary" TYPE="primary" FIELDS="id" NEXT="externalserviceid"/>
-        <KEY NAME="externalserviceid" TYPE="foreign" FIELDS="externalserviceid" REFTABLE="external_services" REFFIELDS="id" PREVIOUS="primary"/>
-      </KEYS>
-    </TABLE>
-    <TABLE NAME="external_services_users" COMMENT="users allowed to use services with restrictedusers flag" PREVIOUS="external_services_functions">
-      <FIELDS>
-        <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" NEXT="externalserviceid"/>
-        <FIELD NAME="externalserviceid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" PREVIOUS="id" NEXT="userid"/>
-        <FIELD NAME="userid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" PREVIOUS="externalserviceid"/>
-      </FIELDS>
-      <KEYS>
-        <KEY NAME="primary" TYPE="primary" FIELDS="id" NEXT="externalserviceid"/>
-        <KEY NAME="externalserviceid" TYPE="foreign" FIELDS="externalserviceid" REFTABLE="external_services" REFFIELDS="id" PREVIOUS="primary" NEXT="userid"/>
-        <KEY NAME="userid" TYPE="foreign" FIELDS="userid" REFTABLE="user" REFFIELDS="id" PREVIOUS="externalserviceid"/>
-      </KEYS>
-    </TABLE>
   </TABLES>
-</XMLDB>
\ No newline at end of file
+</XMLDB>
index 77a57aca3ffa693cc61a65a49df072b223403e72..b7c989a8fc7ca1c73e6397b5dca98da9604eabab 100644 (file)
@@ -2658,6 +2658,68 @@ WHERE gradeitemid IS NOT NULL AND grademax IS NOT NULL");
         upgrade_main_savepoint($result, 2009091310);
     }
 
+    if ($result && $oldversion < 2009091700) {
+
+    /// Define table blog_entries to be created
+        $table = new xmldb_table('blog_entries');
+
+    /// Adding fields to table blog_entries
+        $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
+        $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
+        $table->add_field('subject', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, 'blog entry');
+        $table->add_field('summary', XMLDB_TYPE_TEXT, 'big', null, null, null, null);
+        $table->add_field('content', XMLDB_TYPE_TEXT, 'big', null, null, null, null);
+        $table->add_field('permalink', XMLDB_TYPE_CHAR, '255', null, null, null, null);
+        $table->add_field('format', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
+        $table->add_field('summaryformat', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
+        $table->add_field('attachment', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
+        $table->add_field('publishstate', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
+        $table->add_field('lastmodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
+        $table->add_field('created', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
+        $table->add_field('usermodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null);
+
+    /// Adding keys to table blog_entries
+        $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
+        $table->add_key('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id'));
+        $table->add_key('usermodified', XMLDB_KEY_FOREIGN, array('usermodified'), 'user', array('id'));
+
+    /// Conditionally launch create table for blog_entries
+        if (!$dbman->table_exists($table)) {
+            $dbman->create_table($table);
+        }
+
+        // Now convert all entries in post table
+        if ($blogentries = $DB->get_records('post')) {
+            foreach ($blogentries as $blogentry) {
+                $newentry = new stdClass();
+                $newentry->userid = $blogentry->userid;
+                $newentry->subject = $blogentry->subject;
+                $newentry->summary = $blogentry->summary;
+                $newentry->summaryformat = $blogentry->summaryformat;
+                $newentry->content = $blogentry->content;
+                $newentry->format = $blogentry->format;
+                $newentry->permalink = $blogentry->uniquehash;
+                $newentry->lastmodified = $blogentry->lastmodified;
+                $newentry->created = $blogentry->created;
+                $newentry->usermodified = $blogentry->usermodified;
+
+                if ($blogentry->publishstate == 'draft') {
+                    $newentry->publishstate = 0;
+                } else {
+                    $newentry->publishstate = 1;
+                }
+                $newentry->id = $DB->insert_record('blog_entries', $newentry);
+
+                // Convert records in the tag_instance table to the new ids
+                $DB->set_field('tag_instance', 'itemid', $newentry->id, array('itemtype' => 'post', 'itemid' => $blogentry->id));
+            }
+            // Convert records in the tag_instance table to the new table name
+            $DB->set_field('tag_instance', 'itemtype', 'blog_entries', array('itemtype' => 'post'));
+        }
+    /// Main savepoint reached
+        upgrade_main_savepoint($result, 2009091700);
+    }
+
     return $result;
 }
 
index 19f8c61cd43d488fe44b08c3d33ed4aa1240ff89..e307ceb8e731fb321126f5d311270120258cf27f 100644 (file)
@@ -6,7 +6,7 @@
 // This is compared against the values stored in the database to determine
 // whether upgrades should be performed (see lib/db/*.php)
 
-    $version = 2009091310;  // YYYYMMDD   = date of the last version bump
+    $version = 2009091700;  // YYYYMMDD   = date of the last version bump
                             //         XX = daily increments
 
     $release = '2.0 dev (Build: 20090918)';  // Human-friendly version name