upgrade.php 3.21 KB
Newer Older
Alastair Pharo's avatar
Alastair Pharo committed
1 2 3 4 5
<?php
/**
 *
 * @package    mahara
 * @subpackage artefact-internal
6
 * @author     Catalyst IT Ltd
7 8
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL version 3 or later
 * @copyright  For copyright information on Mahara, please see the README file distributed with this software.
Alastair Pharo's avatar
Alastair Pharo committed
9 10 11 12 13 14
 *
 */

defined('INTERNAL') || die();

function xmldb_artefact_blog_upgrade($oldversion=0) {
Aaron Wells's avatar
Aaron Wells committed
15

16
    if ($oldversion < 2008101602) {
17 18 19 20 21 22 23 24
        $table = new XMLDBTable('artefact_blog_blogpost_file_pending');
        $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, 10, XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
        $table->addFieldInfo('oldextension', XMLDB_TYPE_TEXT, null);
        $table->addFieldInfo('filetype', XMLDB_TYPE_TEXT, null);
        $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
        create_table($table);
    }

25 26
    if ($oldversion < 2009033100) {
        $bloguploadbase = get_config('dataroot') . 'artefact/blog/uploads/';
27 28 29 30 31 32
        if (is_dir($bloguploadbase)) {
            if ($basedir = opendir($bloguploadbase)) {
                while (false !== ($sessionupload = readdir($basedir))) {
                    if ($sessionupload != "." && $sessionupload != "..") {
                        $sessionupload = $bloguploadbase . $sessionupload;
                        $subdir = opendir($sessionupload);
33

34 35 36 37 38
                        while (false !== ($uploadfile = readdir($subdir))) {
                            if ($uploadfile != "." && $uploadfile != "..") {
                                $uploadfile = $sessionupload . '/' . $uploadfile;
                                unlink($uploadfile);
                            }
39
                        }
40 41
                        closedir($subdir);
                        rmdir($sessionupload);
42 43 44
                    }
                }
            }
45
            @rmdir($bloguploadbase);
46 47
        }
    }
48

49 50 51 52 53
    if ($oldversion < 2009081800) {
        $subscription = (object) array('plugin' => 'blog', 'event' => 'createuser', 'callfunction' => 'create_default_blog');
        ensure_record_exists('artefact_event_subscription', $subscription, $subscription);
    }

54 55 56 57
    if ($oldversion < 2011091400) {
        delete_records('artefact_cron', 'plugin', 'blog', 'callfunction', 'clean_post_files');
    }

58 59 60 61
    if ($oldversion < 2015011500) {
        delete_records('institution_config', 'field', 'progressbaritem_blog_blog');
    }

62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
    if ($oldversion < 2015011501) {
        $records = get_records_select_array('artefact', "artefacttype = ? AND description LIKE '%artefact/file/download.php%'", array('blogpost'), 'id', 'id, description, author');
        if ($records) {
            require_once('embeddedimage.php');
            foreach ($records as $rec) {
                set_field(
                        'artefact',
                        'description',
                        EmbeddedImage::prepare_embedded_images(
                                $rec->description,
                                'blogpost',
                                $rec->id,
                                null,
                                $rec->author
                        ),
                        'id',
                        $rec->id
                );
            }
        }
    }
Elliot Pahl's avatar
Elliot Pahl committed
83
    return true;
Alastair Pharo's avatar
Alastair Pharo committed
84
}