Commit 1f4036ca authored by Nigel McNie's avatar Nigel McNie Committed by Nigel McNie
Browse files

Changed the table names for filetype stuff to prefix

artefact_file_. Included the upgrade also.
parent 78f5c311
......@@ -24,5 +24,23 @@
<KEY NAME="artefactfk" TYPE="foreign" FIELDS="artefact" REFTABLE="artefact" REFFIELDS="id" />
</KEYS>
</TABLE>
<TABLE NAME="artefact_file_file_types">
<FIELDS>
<FIELD NAME="description" TYPE="text" LENGTH="128" NOTNULL="true"/>
<FIELD NAME="enabled" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="1"/>
</FIELD>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="description"/>
</TABLE>
<TABLE NAME="artefact_file_mime_types">
<FIELDS>
<FIELD NAME="mimetype" TYPE="text" LENGTH="128" NOTNULL="true"/>
<FIELD NAME="description" TYPE="text" LENGTH="128" NOTNULL="true"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="mimetype"/>
<KEY NAME="descriptionfk" TYPE="foreign" FIELDS="description" REFTABLE="artefact_file_file_types" REFFIELDS="description"/>
</KEY>
</TABLE>
</TABLES>
</XMLDB>
......@@ -90,6 +90,31 @@ function xmldb_artefact_file_upgrade($oldversion=0) {
}
}
if ($oldversion < 2007013100) {
// Add new tables for file/mime types
$table = new XMLDBTable('artefact_file_file_types');
$table->addFieldInfo('description', XMLDB_TYPE_TEXT, 128, null, XMLDB_NOTNULL);
$table->addFieldInfo('enabled', XMLDB_TYPE_INTEGER, 1, null, XMLDB_NOTNULL, null, null, null, 1);
$table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('description'));
create_table($table);
$table = new XMLDBTable('artefact_file_mime_types');
$table->addFieldInfo('mimetype', XMLDB_TYPE_TEXT, 128, null, XMLDB_NOTNULL);
$table->addFieldInfo('description', XMLDB_TYPE_TEXT, 128, null, XMLDB_NOTNULL);
$table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('mimetype'));
$table->addKeyInfo('descriptionfk', XMLDB_KEY_FOREIGN, array('description'), 'artefact_file_file_types', array('description'));
create_table($table);
safe_require('artefact', 'file');
PluginArtefactFile::resync_filetype_list();
}
return $status;
}
......
......@@ -149,7 +149,7 @@ class PluginArtefactFile extends PluginArtefact {
db_begin();
log_info('Beginning resync of filetype list');
$currentlist = get_column('file_types', 'description');
$currentlist = get_column('artefact_file_file_types', 'description');
$newlist = xmlize(file_get_contents(get_config('docroot') . 'artefact/file/filetypes.xml'));
$filetypes = $newlist['filetypes']['#']['filetype'];
$newfiletypes = array();
......@@ -164,7 +164,7 @@ class PluginArtefactFile extends PluginArtefact {
$record = new StdClass;
$record->description = $type;
$record->enabled = $filetype['#']['enabled'][0]['#'];
insert_record('file_types', $record);
insert_record('artefact_file_file_types', $record);
}
$newfiletypes[] = $type;
}
......@@ -175,15 +175,15 @@ class PluginArtefactFile extends PluginArtefact {
if (!in_array($type, $newfiletypes)) {
log_debug('Removing filetype: ' . $type);
unset($currentlist[$key]);
delete_records('mime_types', 'description', $type);
delete_records('file_types', 'description', $type);
delete_records('artefact_file_mime_types', 'description', $type);
delete_records('artefact_file_file_types', 'description', $type);
}
}
// Get a list of all current mimetypes for each file type
$currentmimetypes = array();
$dbmimetypes = get_records_array('mime_types');
$dbmimetypes = get_records_array('artefact_file_mime_types');
if ($dbmimetypes) {
foreach ($dbmimetypes as $mimetype) {
$currentmimetypes[$mimetype->description][] = $mimetype->mimetype;
......@@ -215,12 +215,12 @@ class PluginArtefactFile extends PluginArtefact {
if ((!isset($currentmimetypes[$description]) && $newmimetypes)
|| ((join('', $currentmimetypes[$description]) != join('', $newmimetypes)))) {
log_debug('Need to update mime types for ' . $description);
delete_records('mime_types', 'description', $description);
delete_records('artefact_file_mime_types', 'description', $description);
foreach ($newmimetypes as $newmimetype) {
$record = new StdClass;
$record->mimetype = $newmimetype;
$record->description = $description;
insert_record('mime_types', $record);
insert_record('artefact_file_mime_types', $record);
}
}
}
......@@ -582,7 +582,7 @@ class ArtefactTypeFile extends ArtefactTypeFileBase {
// Allowed file types
$filetypes = array();
foreach (get_records_array('file_types', null, null, 'description') as $filetype) {
foreach (get_records_array('artefact_file_file_types', null, null, 'description') as $filetype) {
$filetype->description = preg_replace('/[^a-zA-Z0-9_]/', '_', $filetype->description);
$filetypes[$filetype->description] = array(
'type' => 'checkbox',
......@@ -612,10 +612,10 @@ class ArtefactTypeFile extends ArtefactTypeFileBase {
public static function save_config_options($values) {
set_config_plugin('artefact', 'file', 'defaultquota', $values['defaultquota']);
foreach (get_records_array('file_types') as $filetype) {
foreach (get_records_array('artefact_file_file_types') as $filetype) {
$key = preg_replace('/[^a-zA-Z0-9_]/', '_', $filetype->description);
$filetype->enabled = intval($values[$key]);
update_record('file_types', $filetype, 'description');
update_record('artefact_file_file_types', $filetype, 'description');
}
}
......
......@@ -27,7 +27,7 @@
defined('INTERNAL') || die();
$config = new StdClass;
$config->version = 2007011801;
$config->release = '0.2';
$config->version = 2007013100;
$config->release = '0.3';
?>
......@@ -143,7 +143,7 @@ function xmldb_core_upgrade($oldversion=0) {
$table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
$table->addKeyInfo('usrfk', XMLDB_KEY_FOREIGN, array('usr'), 'usr', array('id'));
$status = $status && create_table($table);
create_table($table);
}
if ($oldversion < 2007011200) {
......@@ -191,7 +191,7 @@ function xmldb_core_upgrade($oldversion=0) {
if ($oldversion < 2007012500) {
$table = new XMLDBTable('usr_watchlist_artefact');
$field = new XMLDBFIELD('deleted');
$field = new XMLDBField('deleted');
$field->setAttributes(XMLDB_TYPE_INTEGER, 1, false, true, false, false, false, 0);
add_field($table, $field);
}
......
......@@ -88,9 +88,10 @@ class upload_manager {
return get_string('fileunknowntype');
}
$prefix = get_config('dbprefix');
$validtypes = get_column_sql('SELECT mimetype
FROM mime_types m
LEFT JOIN file_types f ON (m.description = f.description)
FROM ' . $prefix . 'artefact_file_mime_types m
LEFT JOIN ' . $prefix . 'artefact_file_file_types f ON (m.description = f.description)
WHERE f.enabled = 1');
if (!in_array($type, $validtypes)) {
return get_string('filetypenotallowed');
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment