~ubuntu-branches/ubuntu/maverick/mahara/maverick-updates

« back to all changes in this revision

Viewing changes to htdocs/artefact/file/db/upgrade.php

  • Committer: Bazaar Package Importer
  • Author(s): Nigel McNie
  • Date: 2008-04-29 11:15:39 UTC
  • Revision ID: james.westby@ubuntu.com-20080429111539-b28eqkagavaub2zr
Tags: upstream-1.0.2
ImportĀ upstreamĀ versionĀ 1.0.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/**
 
3
 * Mahara: Electronic portfolio, weblog, resume builder and social networking
 
4
 * Copyright (C) 2006-2008 Catalyst IT Ltd (http://www.catalyst.net.nz)
 
5
 *
 
6
 * This program is free software: you can redistribute it and/or modify
 
7
 * it under the terms of the GNU General Public License as published by
 
8
 * the Free Software Foundation, either version 3 of the License, or
 
9
 * (at your option) any later version.
 
10
 *
 
11
 * This program is distributed in the hope that it will be useful,
 
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 * GNU General Public License for more details.
 
15
 *
 
16
 * You should have received a copy of the GNU General Public License
 
17
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
18
 *
 
19
 * @package    mahara
 
20
 * @subpackage artefact-file
 
21
 * @author     Catalyst IT Ltd
 
22
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL
 
23
 * @copyright  (C) 2006-2008 Catalyst IT Ltd http://catalyst.net.nz
 
24
 *
 
25
 */
 
26
 
 
27
defined('INTERNAL') || die();
 
28
 
 
29
function xmldb_artefact_file_upgrade($oldversion=0) {
 
30
    
 
31
    $status = true;
 
32
 
 
33
    if ($oldversion < 2007010900) {
 
34
        $table = new XMLDBTable('artefact_file_files');
 
35
        $field = new XMLDBField('adminfiles');
 
36
        $field->setAttributes(XMLDB_TYPE_INTEGER, 1, false, true, false, null, null, 0);
 
37
        add_field($table, $field);
 
38
        set_field('artefact_file_files', 'adminfiles', 0);
 
39
 
 
40
        // Put all folders into artefact_file_files
 
41
        $folders = get_column_sql("
 
42
            SELECT a.id
 
43
            FROM {artefact} a
 
44
            LEFT OUTER JOIN {artefact_file_files} f ON a.id = f.artefact
 
45
            WHERE a.artefacttype = 'folder' AND f.artefact IS NULL");
 
46
        if ($folders) {
 
47
            foreach ($folders as $folderid) {
 
48
                $data = (object) array('artefact' => $folderid, 'adminfiles' => 0);
 
49
                insert_record('artefact_file_files', $data);
 
50
            }
 
51
        }
 
52
    }
 
53
 
 
54
    if ($oldversion < 2007011800) {
 
55
        // Make sure the default quota is set
 
56
        set_config_plugin('artefact', 'file', 'defaultquota', 10485760);
 
57
    }
 
58
 
 
59
    if ($oldversion < 2007011801) {
 
60
        // Create image table
 
61
        $table = new XMLDBTable('artefact_file_image');
 
62
 
 
63
        $table->addFieldInfo('artefact', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL);
 
64
        $table->addFieldInfo('width', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL);
 
65
        $table->addFieldInfo('height', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null);
 
66
 
 
67
        $table->addKeyInfo('artefactfk', XMLDB_KEY_FOREIGN, array('artefact'), 'artefact', array('id'));
 
68
 
 
69
        $status = $status && create_table($table);
 
70
 
 
71
        $images = get_column('artefact', 'id', 'artefacttype', 'image');
 
72
        log_debug(count($images));
 
73
        require_once(get_config('docroot') . 'artefact/lib.php');
 
74
        foreach ($images as $imageid) {
 
75
            $image = artefact_instance_from_id($imageid);
 
76
            $path = $image->get_path();
 
77
            $image->set('dirty', false);
 
78
            $data = new StdClass;
 
79
            $data->artefact = $imageid;
 
80
            if (file_exists($path)) {
 
81
                list($data->width, $data->height) = getimagesize($path);
 
82
            }
 
83
 
 
84
            if (empty($data->width) || empty($data->height)) {
 
85
                $data->width = 0;
 
86
                $data->height = 0;
 
87
            }
 
88
            insert_record('artefact_file_image', $data);
 
89
        }
 
90
    }
 
91
 
 
92
    if ($oldversion < 2007013100) {
 
93
        // Add new tables for file/mime types
 
94
        $table = new XMLDBTable('artefact_file_file_types');
 
95
 
 
96
        $table->addFieldInfo('description', XMLDB_TYPE_TEXT, 128, null, XMLDB_NOTNULL);
 
97
        $table->addFieldInfo('enabled', XMLDB_TYPE_INTEGER, 1, null, XMLDB_NOTNULL, null, null, null, 1);
 
98
 
 
99
        $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('description'));
 
100
 
 
101
        create_table($table);
 
102
 
 
103
        $table = new XMLDBTable('artefact_file_mime_types');
 
104
 
 
105
        $table->addFieldInfo('mimetype', XMLDB_TYPE_TEXT, 128, null, XMLDB_NOTNULL);
 
106
        $table->addFieldInfo('description', XMLDB_TYPE_TEXT, 128, null, XMLDB_NOTNULL);
 
107
 
 
108
        $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('mimetype'));
 
109
        $table->addKeyInfo('descriptionfk', XMLDB_KEY_FOREIGN, array('description'), 'artefact_file_file_types', array('description'));
 
110
 
 
111
        create_table($table);
 
112
 
 
113
        safe_require('artefact', 'file');
 
114
        PluginArtefactFile::resync_filetype_list();
 
115
    }
 
116
 
 
117
    if ($oldversion < 2007021400) {
 
118
        $table = new XMLDBTable('artefact_file_files');
 
119
        $field = new XMLDBField('oldextension');
 
120
        $field->setAttributes(XMLDB_TYPE_TEXT);
 
121
        add_field($table, $field);
 
122
    }
 
123
 
 
124
    if ($oldversion < 2007042500) {
 
125
        // migrate everything we had to change to  make mysql happy
 
126
        execute_sql("ALTER TABLE {artefact_file_file_types} ALTER COLUMN description TYPE varchar(32)");
 
127
        execute_sql("ALTER TABLE {artefact_file_mime_types} ALTER COLUMN mimetype TYPE varchar(128)");
 
128
        execute_sql("ALTER TABLE {artefact_file_mime_types} ALTER COLUMN description TYPE varchar(32)");
 
129
 
 
130
    }
 
131
 
 
132
    // everything up to here we pre mysql support.
 
133
    return $status;
 
134
}
 
135
 
 
136
?>