Commit e5bdacad authored by Son Nguyen's avatar Son Nguyen
Browse files

Add 2 new fields: "group" and "institution" into the table "collection"



These field will be used to enable collections in group and institution.
See also Bug#886080

Change-Id: I208ee9ee518a9d28e72930cdb0cf1dc4647eaf2f
Signed-off-by: default avatarSon Nguyen <son.nguyen@catalyst.net.nz>
parent 1560013e
......@@ -918,7 +918,7 @@
<TABLE NAME="collection">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true" />
<FIELD NAME="owner" TYPE="int" LENGTH="10" NOTNULL="true" />
<FIELD NAME="owner" TYPE="int" LENGTH="10" NOTNULL="false" />
<FIELD NAME="ctime" TYPE="datetime" NOTNULL="true" />
<FIELD NAME="mtime" TYPE="datetime" NOTNULL="true" />
<FIELD NAME="name" TYPE="text" NOTNULL="true" />
......@@ -927,12 +927,16 @@
<FIELD NAME="submittedgroup" TYPE="int" LENGTH="10" NOTNULL="false" />
<FIELD NAME="submittedhost" TYPE="char" LENGTH="255" NOTNULL="false" />
<FIELD NAME="submittedtime" TYPE="datetime" NOTNULL="false" />
<FIELD NAME="group" TYPE="int" LENGTH="10" NOTNULL="false" />
<FIELD NAME="institution" TYPE="char" LENGTH="255" NOTNULL="false" />
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id" />
<KEY NAME="usrfk" TYPE="foreign" FIELDS="owner" REFTABLE="usr" REFFIELDS="id" />
<KEY NAME="submittedgroupfk" TYPE="foreign" FIELDS="submittedgroup" REFTABLE="group" REFFIELDS="id" />
<KEY NAME="submittedhostfk" TYPE="foreign" FIELDS="submittedhost" REFTABLE="host" REFFIELDS="wwwroot" />
<KEY NAME="groupfk" TYPE="foreign" FIELDS="group" REFTABLE="group" REFFIELDS="id" />
<KEY NAME="institutionfk" TYPE="foreign" FIELDS="institution" REFTABLE="institution" REFFIELDS="name" />
</KEYS>
</TABLE>
<TABLE NAME="collection_view">
......
......@@ -3025,5 +3025,39 @@ function xmldb_core_upgrade($oldversion=0) {
insert_record('cron', $cron);
}
if ($oldversion < 2012070200) {
$table = new XMLDBTable('collection');
$field = new XMLDBField('group');
$field->setAttributes(XMLDB_TYPE_INTEGER, 10, null, null, null, null, null, null);
add_field($table, $field);
$field = new XMLDBField('institution');
$field->setAttributes(XMLDB_TYPE_CHAR, 255, null, null, null, null, null, null);
add_field($table, $field);
$field = new XMLDBField('owner');
$field->setAttributes(XMLDB_TYPE_INTEGER, 10, null, null);
change_field_notnull($table, $field);
// For PostgresSQL, change_field_notnull of $field=owner with precision = 10 BIGINT(10)
// will add a temporary column, move data from owner column, remove the column 'owner'
// and then rename the temporary column to 'owner'. Therefore, all indexes and foreign keys
// related to column 'owner' will be removed
if (is_postgres()) {
$key = new XMLDBKey('owner');
$key->setAttributes(XMLDB_KEY_FOREIGN, array('owner'), 'usr', array('id'));
add_key($table, $key);
}
$key = new XMLDBKey('group');
$key->setAttributes(XMLDB_KEY_FOREIGN, array('group'), 'group', array('id'));
add_key($table, $key);
$key = new XMLDBKey('institution');
$key->setAttributes(XMLDB_KEY_FOREIGN, array('institution'), 'institution', array('name'));
add_key($table, $key);
// Add constraints
execute_sql('ALTER TABLE {collection} ADD CHECK (
(owner IS NOT NULL AND "group" IS NULL AND institution IS NULL) OR
(owner IS NULL AND "group" IS NOT NULL AND institution IS NULL) OR
(owner IS NULL AND "group" IS NULL AND institution IS NOT NULL)
)');
}
return $status;
}
......@@ -640,6 +640,11 @@ function core_postinst() {
(accesstype IS NULL AND "group" IS NULL AND usr IS NULL AND token IS NOT NULL AND institution IS NULL) OR
(accesstype IS NULL AND "group" IS NULL AND usr IS NULL AND token IS NULL AND institution IS NOT NULL)
)');
execute_sql('ALTER TABLE {collection} ADD CHECK (
(owner IS NOT NULL AND "group" IS NULL AND institution IS NULL) OR
(owner IS NULL AND "group" IS NOT NULL AND institution IS NULL) OR
(owner IS NULL AND "group" IS NULL AND institution IS NOT NULL)
)');
set_antispam_defaults();
reload_html_filters();
......
......@@ -30,7 +30,7 @@ defined('INTERNAL') || die();
$config = new StdClass;
// See https://wiki.mahara.org/index.php/Developer_Area/Version_Numbering_Policy
// For upgrades on stable branches, increment the version by one. On master, use the date.
$config->version = 2012062902;
$config->version = 2012070200;
$config->release = '1.6.0dev';
$config->minupgradefrom = 2008040200;
$config->minupgraderelease = '1.0.0 (release tag 1.0.0_RELEASE)';
......
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