Commit 855c40d3 authored by Richard Mansfield's avatar Richard Mansfield
Browse files

My Plans db changes:


- Rename artefact_task table for consistency with plugintype_pluginname scheme
- Rename task column to artefact for consistency with other artefact plugin tables
- Remove plugin upgrade and ensure both artefact and blocktype get installed by core upgrade
Signed-off-by: default avatarRichard Mansfield <richardm@catalyst.net.nz>
parent c8fac8be
......@@ -6,17 +6,17 @@
<TABLES>
<!-- This table is supposed to have a 1-1 relation with every row in the
artefact table with artefacttype = 'plan'. It contains additional data
artefact table with artefacttype = 'task'. It contains additional data
that isn't in the artefact table. -->
<TABLE NAME="artefact_task">
<TABLE NAME="artefact_plans_task">
<FIELDS>
<FIELD NAME="task" TYPE="int" LENGTH="10" SEQUENCE="true" NOTNULL="true" />
<FIELD NAME="artefact" TYPE="int" LENGTH="10" SEQUENCE="true" NOTNULL="true" />
<FIELD NAME="completiondate" TYPE="datetime" NOTNULL="false" />
<FIELD NAME="completed" TYPE="int" LENGTH="2" NOTNULL="true" DEFAULT="0" />
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="task" />
<KEY NAME="artefactfk" TYPE="foreign" FIELDS="task" REFTABLE="artefact" REFFIELDS="id" />
<KEY NAME="primary" TYPE="primary" FIELDS="artefact" />
<KEY NAME="artefactfk" TYPE="foreign" FIELDS="artefact" REFTABLE="artefact" REFFIELDS="id" />
</KEYS>
</TABLE>
</TABLES>
......
......@@ -29,33 +29,6 @@ defined('INTERNAL') || die();
function xmldb_artefact_plans_upgrade($oldversion=0) {
if ($oldversion < 2010072300) {
if (field_exists(new XMLDBTable('artefact_plan'), new XMLDBField('plan'))) {
execute_sql("ALTER TABLE {artefact_plan} RENAME TO {artefact_task}");
if (is_postgres()) {
execute_sql('
ALTER TABLE {artefact_task} RENAME COLUMN plan TO task;
ALTER TABLE {artefact_task} DROP CONSTRAINT {arteplan_pla_fk};
ALTER TABLE {artefact_task} ADD CONSTRAINT {artetask_tas_fk} FOREIGN KEY (task) REFERENCES {artefact}(id);
ALTER INDEX {arteplan_pla_pk} RENAME TO {artetask_tas_pk};
ALTER INDEX {arteplan_pla_ix} RENAME TO {artetask_tas_ix};
');
}
else if (is_mysql()) {
execute_sql('ALTER TABLE {artefact_task} CHANGE plan task TEXT');
execute_sql("ALTER TABLE {artefact_task} DROP FOREIGN KEY {arteplan_pla_fk}");
execute_sql("ALTER TABLE {artefact_task} DROP INDEX {arteplan_pla_ix}");
execute_sql("ALTER TABLE {artefact_task} CHANGE plan task BIGINT(10) DEFAULT NULL");
execute_sql("ALTER TABLE {artefact_task} ADD CONSTRAINT {artetask_tas_fk} FOREIGN KEY {artetask_tas_ix} (task) REFERENCES {artefact}(id)");
}
}
}
if ($oldversion < 2010072301) {
execute_sql("INSERT INTO {artefact_installed_type} (name,plugin) VALUES ('task','plans')");
execute_sql("UPDATE {artefact} SET artefacttype = 'task' WHERE artefacttype = 'plan'");
}
return true;
}
......
......@@ -247,7 +247,7 @@ class ArtefactTypeTask extends ArtefactType {
parent::__construct($id, $data);
if ($this->id) {
if ($pdata = get_record('artefact_task', 'task', $this->id, null, null, null, null, '*, ' . db_format_tsfield('completiondate'))) {
if ($pdata = get_record('artefact_plans_task', 'artefact', $this->id, null, null, null, null, '*, ' . db_format_tsfield('completiondate'))) {
foreach($pdata as $name => $value) {
if (property_exists($this, $name)) {
$this->$name = $value;
......@@ -274,7 +274,7 @@ class ArtefactTypeTask extends ArtefactType {
/**
* This method extends ArtefactType::commit() by adding additional data
* into the artefact_task table.
* into the artefact_plans_task table.
*
*/
public function commit() {
......@@ -297,16 +297,16 @@ class ArtefactTypeTask extends ArtefactType {
$date = db_format_timestamp($completiondate);
}
$data = (object)array(
'task' => $this->get('id'),
'artefact' => $this->get('id'),
'completed' => $this->get('completed'),
'completiondate' => $date,
);
if ($new) {
$success = insert_record('artefact_task', $data);
$success = insert_record('artefact_plans_task', $data);
}
else {
$success = update_record('artefact_task', $data, 'task');
$success = update_record('artefact_plans_task', $data, 'artefact');
}
db_commit();
......@@ -326,7 +326,7 @@ class ArtefactTypeTask extends ArtefactType {
}
db_begin();
delete_records('artefact_task', 'task', $this->id);
delete_records('artefact_plans_task', 'artefact', $this->id);
parent::delete();
db_commit();
......@@ -454,9 +454,10 @@ class ArtefactTypeTask extends ArtefactType {
$datenow = time(); // time now to use for formatting tasks by completion
($results = get_records_sql_array("
SELECT a.id, at.task, at.completed, ".db_format_tsfield('completiondate').", a.title, a.description, a.parent
SELECT a.id, at.artefact AS task, at.completed, ".db_format_tsfield('completiondate').",
a.title, a.description, a.parent
FROM {artefact} a
JOIN {artefact_task} at ON at.task = a.id
JOIN {artefact_plans_task} at ON at.artefact = a.id
WHERE a.owner = ? AND a.artefacttype = 'task'
AND a.parent = ?
ORDER BY at.completiondate DESC
......
......@@ -2128,5 +2128,14 @@ function xmldb_core_upgrade($oldversion=0) {
}
if ($oldversion < 2010081001) {
if ($data = check_upgrades('artefact.plans')) {
upgrade_plugin($data);
}
if ($data = check_upgrades('blocktype.plans/plans')) {
upgrade_plugin($data);
}
}
return $status;
}
......@@ -28,7 +28,7 @@
defined('INTERNAL') || die();
$config = new StdClass;
$config->version = 2010081000;
$config->version = 2010081001;
$config->release = '1.3.0beta4dev';
$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