3
* Mahara: Electronic portfolio, weblog, resume builder and social networking
4
* Copyright (C) 2006-2008 Catalyst IT Ltd (http://www.catalyst.net.nz)
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.
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.
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/>.
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
27
defined('INTERNAL') || die();
29
function xmldb_artefact_file_upgrade($oldversion=0) {
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);
40
// Put all folders into artefact_file_files
41
$folders = get_column_sql("
44
LEFT OUTER JOIN {artefact_file_files} f ON a.id = f.artefact
45
WHERE a.artefacttype = 'folder' AND f.artefact IS NULL");
47
foreach ($folders as $folderid) {
48
$data = (object) array('artefact' => $folderid, 'adminfiles' => 0);
49
insert_record('artefact_file_files', $data);
54
if ($oldversion < 2007011800) {
55
// Make sure the default quota is set
56
set_config_plugin('artefact', 'file', 'defaultquota', 10485760);
59
if ($oldversion < 2007011801) {
61
$table = new XMLDBTable('artefact_file_image');
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);
67
$table->addKeyInfo('artefactfk', XMLDB_KEY_FOREIGN, array('artefact'), 'artefact', array('id'));
69
$status = $status && create_table($table);
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);
79
$data->artefact = $imageid;
80
if (file_exists($path)) {
81
list($data->width, $data->height) = getimagesize($path);
84
if (empty($data->width) || empty($data->height)) {
88
insert_record('artefact_file_image', $data);
92
if ($oldversion < 2007013100) {
93
// Add new tables for file/mime types
94
$table = new XMLDBTable('artefact_file_file_types');
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);
99
$table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('description'));
101
create_table($table);
103
$table = new XMLDBTable('artefact_file_mime_types');
105
$table->addFieldInfo('mimetype', XMLDB_TYPE_TEXT, 128, null, XMLDB_NOTNULL);
106
$table->addFieldInfo('description', XMLDB_TYPE_TEXT, 128, null, XMLDB_NOTNULL);
108
$table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('mimetype'));
109
$table->addKeyInfo('descriptionfk', XMLDB_KEY_FOREIGN, array('description'), 'artefact_file_file_types', array('description'));
111
create_table($table);
113
safe_require('artefact', 'file');
114
PluginArtefactFile::resync_filetype_list();
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);
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)");
132
// everything up to here we pre mysql support.