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

Log changes to group files

parent 4b11122d
......@@ -962,6 +962,10 @@ class ArtefactTypeFile extends ArtefactTypeFileBase {
return;
}
// Only changes to group files get put in the artefact_log table
public function can_be_logged() {
return (bool) $this->get('group');
}
}
class ArtefactTypeFolder extends ArtefactTypeFileBase {
......
......@@ -340,11 +340,17 @@ abstract class ArtefactType {
}
if (empty($this->id)) {
$this->id = insert_record('artefact', $fordb, 'id', true);
if ($this->can_be_logged()) {
$this->log('created');
}
if (!empty($this->parent)) {
$this->parentdirty = true;
}
}
else {
if ($this->can_be_logged()) {
$this->log('edited');
}
update_record('artefact', $fordb, 'id');
}
......@@ -430,6 +436,10 @@ abstract class ArtefactType {
delete_records('artefact_tag', 'artefact', $this->id);
delete_records('artefact_access_role', 'artefact', $this->id);
delete_records('artefact_access_usr', 'artefact', $this->id);
if ($this->can_be_logged()) {
$this->log('deleted');
}
// Delete the record itself.
delete_records('artefact', 'id', $this->id);
......@@ -692,6 +702,43 @@ abstract class ArtefactType {
$this->copy_extra($copy);
return $copy->get('id');
}
public function can_be_logged() {
return false;
}
public function log($action) {
global $USER;
$entry = (object) array(
'artefact' => $this->id,
'usr' => $USER->get('id'),
'time' => db_format_timestamp($this->mtime),
$action => 1,
);
if ($action == 'deleted') {
insert_record('artefact_log', $entry);
return;
}
$loggedfields = array('title', 'description', 'parent');
if ($action == 'edited') {
$old = get_record('artefact', 'id', $this->id);
foreach ($loggedfields as $key) {
if ($this->$key != $old->$key) {
$entry->$key = $this->$key;
$changed = true;
}
}
if (isset($changed)) {
insert_record('artefact_log', $entry);
}
}
if ($action == 'created') {
foreach ($loggedfields as $key) {
$entry->$key = $this->$key;
}
insert_record('artefact_log', $entry);
}
}
}
/**
......
......@@ -372,6 +372,25 @@
<KEY NAME="artefactfk" TYPE="foreign" FIELDS="artefact" REFTABLE="artefact" REFFIELDS="id" />
</KEYS>
</TABLE>
<TABLE NAME="artefact_log">
<FIELDS>
<FIELD NAME="artefact" TYPE="int" LENGTH="10" NOTNULL="true" />
<FIELD NAME="usr" TYPE="int" LENGTH="10" NOTNULL="false" />
<FIELD NAME="time" TYPE="datetime" NOTNULL="true" />
<FIELD NAME="title" TYPE="text" NOTNULL="false" />
<FIELD NAME="description" TYPE="text" NOTNULL="false" />
<FIELD NAME="parent" TYPE="int" LENGTH="10" NOTNULL="false" />
<FIELD NAME="created" TYPE="int" LENGTH="1" DEFAULT="0" NOTNULL="false" />
<FIELD NAME="deleted" TYPE="int" LENGTH="1" DEFAULT="0" NOTNULL="false" />
<FIELD NAME="edited" TYPE="int" LENGTH="1" DEFAULT="0" NOTNULL="false" />
</FIELDS>
<KEYS>
<KEY NAME="usrfk" TYPE="foreign" FIELDS="usr" REFTABLE="usr" REFFIELDS="id" />
</KEYS>
<INDEXES>
<INDEX NAME="artefactix" UNIQUE="false" FIELDS="artefact"/>
</INDEXES>
</TABLE>
<TABLE NAME="interaction_instance">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true" />
......
......@@ -1264,6 +1264,22 @@ function xmldb_core_upgrade($oldversion=0) {
insert_record('cron', $cron);
}
if ($oldversion < 2008090800) {
$table = new XMLDBTable('artefact_log');
$table->addFieldInfo('artefact', XMLDB_TYPE_INTEGER, 10, null, XMLDB_NOTNULL);
$table->addFieldInfo('usr', XMLDB_TYPE_INTEGER, 10, null, null);
$table->addFieldInfo('time', XMLDB_TYPE_DATETIME, null, null, XMLDB_NOTNULL);
$table->addFieldInfo('title', XMLDB_TYPE_TEXT, null);
$table->addFieldInfo('description', XMLDB_TYPE_TEXT, null);
$table->addFieldInfo('parent', XMLDB_TYPE_INTEGER, 10, null, null);
$table->addFieldInfo('created', XMLDB_TYPE_INTEGER, 1, null, null);
$table->addFieldInfo('deleted', XMLDB_TYPE_INTEGER, 1, null, null);
$table->addFieldInfo('edited', XMLDB_TYPE_INTEGER, 1, null, null);
$table->addIndexInfo('artefactix', XMLDB_INDEX_NOTUNIQUE, array('artefact'));
$table->addKeyInfo('usrfk', XMLDB_KEY_FOREIGN, array('usr'), 'usr', array('id'));
create_table($table);
}
return $status;
}
......
......@@ -27,7 +27,7 @@
defined('INTERNAL') || die();
$config = new StdClass;
$config->version = 2008090500;
$config->version = 2008090800;
$config->release = '1.1.0alpha2dev';
$config->minupgradefrom = 2007080700;
$config->minupgraderelease = '0.8.0 (release tag 0.8.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