Commit c3c9f247 authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Modify feedback control upgrade:


Rename new columns to allowcomments, approvecomments for consistency with view & artefact tables
Add approvecomments column to view & artefact tables
Move all view_access_usr, view_access_group, view_access_token records into an expanded view_access table
Drop view_access_usr, view_access_group, view_access_token
Signed-off-by: default avatarRichard Mansfield <richardm@catalyst.net.nz>
parent ad58dc2d
......@@ -349,6 +349,7 @@
<FIELD NAME="author" TYPE="int" LENGTH="10" NOTNULL="false" />
<FIELD NAME="authorname" TYPE="text" NOTNULL="false" />
<FIELD NAME="allowcomments" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" />
<FIELD NAME="approvecomments" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" />
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id" />
......@@ -599,6 +600,7 @@
<FIELD NAME="type" TYPE="char" LENGTH="50" NOTNULL="true" />
<FIELD NAME="visits" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" />
<FIELD NAME="allowcomments" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="1" />
<FIELD NAME="approvecomments" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" />
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id" />
......@@ -666,59 +668,25 @@
<TABLE NAME="view_access">
<FIELDS>
<FIELD NAME="view" TYPE="int" LENGTH="10" NOTNULL="true" />
<FIELD NAME="accesstype" TYPE="char" LENGTH="16" NOTNULL="true" ENUM="true" ENUMVALUES="'public', 'loggedin', 'friends'" DEFAULT="public" />
<FIELD NAME="startdate" TYPE="datetime" NOTNULL="false" />
<FIELD NAME="stopdate" TYPE="datetime" NOTNULL="false" />
<FIELD NAME="allowfeedback" TYPE="int" LENGTH="10" NOTNULL="true" />
<FIELD NAME="approvefeedback" TYPE="int" LENGTH="10" NOTNULL="true" />
</FIELDS>
<KEYS>
<KEY NAME="viewfk" TYPE="foreign" FIELDS="view" REFTABLE="view" REFFIELDS="id" />
</KEYS>
</TABLE>
<TABLE NAME="view_access_group">
<FIELDS>
<FIELD NAME="view" TYPE="int" LENGTH="10" NOTNULL="true" />
<FIELD NAME="group" TYPE="int" LENGTH="10" NOTNULL="true" />
<FIELD NAME="accesstype" TYPE="char" LENGTH="16" NOTNULL="false" ENUM="true" ENUMVALUES="'public', 'loggedin', 'friends'" DEFAULT="public" />
<FIELD NAME="group" TYPE="int" LENGTH="10" NOTNULL="false" />
<FIELD NAME="role" TYPE="char" LENGTH="255" NOTNULL="false" />
<FIELD NAME="usr" TYPE="int" LENGTH="10" NOTNULL="false" />
<FIELD NAME="token" TYPE="char" LENGTH="100" NOTNULL="false" />
<FIELD NAME="visible" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="1" />
<FIELD NAME="startdate" TYPE="datetime" NOTNULL="false" />
<FIELD NAME="stopdate" TYPE="datetime" NOTNULL="false" />
<FIELD NAME="allowfeedback" TYPE="int" LENGTH="10" NOTNULL="true" />
<FIELD NAME="approvefeedback" TYPE="int" LENGTH="10" NOTNULL="true" />
<FIELD NAME="allowcomments" TYPE="int" LENGTH="1" NOTNULL="false" DEFAULT="0" />
<FIELD NAME="approvecomments" TYPE="int" LENGTH="1" NOTNULL="false" DEFAULT="1" />
</FIELDS>
<KEYS>
<KEY NAME="viewfk" TYPE="foreign" FIELDS="view" REFTABLE="view" REFFIELDS="id" />
<KEY NAME="groupfk" TYPE="foreign" FIELDS="group" REFTABLE="group" REFFIELDS="id" />
</KEYS>
</TABLE>
<TABLE NAME="view_access_usr">
<FIELDS>
<FIELD NAME="view" TYPE="int" LENGTH="10" NOTNULL="true" />
<FIELD NAME="usr" TYPE="int" LENGTH="10" NOTNULL="true" />
<FIELD NAME="startdate" TYPE="datetime" NOTNULL="false" />
<FIELD NAME="stopdate" TYPE="datetime" NOTNULL="false" />
<FIELD NAME="allowfeedback" TYPE="int" LENGTH="10" NOTNULL="true" />
<FIELD NAME="approvefeedback" TYPE="int" LENGTH="10" NOTNULL="true" />
</FIELDS>
<KEYS>
<KEY NAME="viewfk" TYPE="foreign" FIELDS="view" REFTABLE="view" REFFIELDS="id" />
<KEY NAME="usrfk" TYPE="foreign" FIELDS="usr" REFTABLE="usr" REFFIELDS="id" />
</KEYS>
</TABLE>
<TABLE NAME="view_access_token">
<FIELDS>
<FIELD NAME="view" TYPE="int" LENGTH="10" NOTNULL="true" />
<FIELD NAME="token" TYPE="char" LENGTH="100" NOTNULL="true" />
<FIELD NAME="startdate" TYPE="datetime" NOTNULL="false" />
<FIELD NAME="stopdate" TYPE="datetime" NOTNULL="false" />
<FIELD NAME="visible" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="1" />
<FIELD NAME="allowfeedback" TYPE="int" LENGTH="10" NOTNULL="true" />
<FIELD NAME="approvefeedback" TYPE="int" LENGTH="10" NOTNULL="true" />
</FIELDS>
<KEYS>
<KEY NAME="viewfk" TYPE="foreign" FIELDS="view" REFTABLE="view" REFFIELDS="id" />
<KEY NAME="primary" TYPE="primary" FIELDS="token" />
</KEYS>
<INDEXES>
<INDEX NAME="tokenuk" UNIQUE="true" FIELDS="token"/>
</INDEXES>
</TABLE>
<TABLE NAME="view_visit">
<FIELDS>
......
......@@ -1861,22 +1861,96 @@ function xmldb_core_upgrade($oldversion=0) {
}
if ($oldversion < 2010062502) {
//new feature feedback control on views
$field = new XMLDBField('allowfeedback');
$field->setAttributes(XMLDB_TYPE_INTEGER, '10');
$field2 = new XMLDBField('approvefeedback');
$field2->setAttributes(XMLDB_TYPE_INTEGER, '10');
$table = new XMLDBTable('view_access');
$field = new XMLDBField('allowcomments');
$field->setAttributes(XMLDB_TYPE_INTEGER, 1, null, XMLDB_NOTNULL, null, null, null, 0);
add_field($table, $field);
add_field($table, $field2);
$table = new XMLDBTable('view_access_group');
$field = new XMLDBField('approvecomments');
$field->setAttributes(XMLDB_TYPE_INTEGER, 1, null, XMLDB_NOTNULL, null, null, null, 1);
add_field($table, $field);
add_field($table, $field2);
$table = new XMLDBTable('view_access_usr');
// Add comment approval to view/artefact (default 0)
$field = new XMLDBField('approvecomments');
$field->setAttributes(XMLDB_TYPE_INTEGER, 1, null, XMLDB_NOTNULL, null, null, null, 0);
$table = new XMLDBTable('view');
add_field($table, $field);
add_field($table, $field2);
$table = new XMLDBTable('view_access_token');
$table = new XMLDBTable('artefact');
add_field($table, $field);
// view_access_(group|usr|token) tables are getting wide with duplicated columns,
// so just create all the necessary columns in view_access and move stuff there
$table = new XMLDBTable('view_access');
$field = new XMLDBField('accesstype');
$field->setAttributes(XMLDB_TYPE_CHAR, 16, null, null);
change_field_notnull($table, $field);
$field = new XMLDBField('group');
$field->setAttributes(XMLDB_TYPE_INTEGER, 10, null, null);
add_field($table, $field);
$field = new XMLDBField('role');
$field->setAttributes(XMLDB_TYPE_CHAR, 255, null, null);
add_field($table, $field);
$field = new XMLDBField('usr');
$field->setAttributes(XMLDB_TYPE_INTEGER, 10, null, null);
add_field($table, $field);
$field = new XMLDBField('token');
$field->setAttributes(XMLDB_TYPE_CHAR, 100, null, null);
add_field($table, $field);
add_field($table, $field2);
$field = new XMLDBField('visible');
$field->setAttributes(XMLDB_TYPE_INTEGER, 1, null, XMLDB_NOTNULL, null, null, null, 1);
add_field($table, $field);
// Copy data to view_access
execute_sql('
INSERT INTO {view_access} (view, accesstype, "group", role, startdate, stopdate)
SELECT view, NULL, "group", role, startdate, stopdate FROM {view_access_group}'
);
execute_sql('
INSERT INTO {view_access} (view, accesstype, usr, startdate, stopdate)
SELECT view, NULL, usr, startdate, stopdate FROM {view_access_usr}'
);
execute_sql('
INSERT INTO {view_access} (view, accesstype, token, visible, startdate, stopdate)
SELECT view, NULL, token, visible, startdate, stopdate FROM {view_access_token}'
);
// Add foreign keys
$key = new XMLDBKey('groupfk');
$key->setAttributes(XMLDB_KEY_FOREIGN, array('group'), 'group', array('id'));
add_key($table, $key);
$key = new XMLDBKey('usrfk');
$key->setAttributes(XMLDB_KEY_FOREIGN, array('usr'), 'usr', array('id'));
add_key($table, $key);
$index = new XMLDBIndex('tokenuk');
$index->setAttributes(XMLDB_INDEX_UNIQUE, array('token'));
add_index($table, $index);
// Exactly one of accesstype, group, usr, token must be not null
execute_sql('ALTER TABLE {view_access} ADD CHECK (
(accesstype IS NOT NULL AND "group" IS NULL AND usr IS NULL AND token IS NULL) OR
(accesstype IS NULL AND "group" IS NOT NULL AND usr IS NULL AND token IS NULL) OR
(accesstype IS NULL AND "group" IS NULL AND usr IS NOT NULL AND token IS NULL) OR
(accesstype IS NULL AND "group" IS NULL AND usr IS NULL AND token IS NOT NULL)
)');
// Drop old tables
$table = new XMLDBTable('view_access_group');
// drop_table($table);
$table = new XMLDBTable('view_access_usr');
// drop_table($table);
$table = new XMLDBTable('view_access_token');
// drop_table($table);
}
return $status;
......
......@@ -591,6 +591,12 @@ function core_postinst() {
(author IS NOT NULL AND authorname IS NULL ) OR
(author IS NULL AND authorname IS NOT NULL)
)');
execute_sql('ALTER TABLE {view_access} ADD CHECK (
(accesstype IS NOT NULL AND "group" IS NULL AND usr IS NULL AND token IS NULL) OR
(accesstype IS NULL AND "group" IS NOT NULL AND usr IS NULL AND token IS NULL) OR
(accesstype IS NULL AND "group" IS NULL AND usr IS NOT NULL AND token IS NULL) OR
(accesstype IS NULL AND "group" IS NULL AND usr IS NULL AND token IS NOT NULL)
)');
set_antispam_defaults();
set_remoteavatars_default();
......
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