Commit 63256d28 authored by Robert Lyon's avatar Robert Lyon

Bug 1734182: site_content mauthor to be set to 'root' user on install

This way if we ever query / display who has edited the content we can
know user = 0 is the installed version.

behatnotneeded

Change-Id: I81973a315d7953f29249425ae52712ec2334634f
Signed-off-by: Robert Lyon's avatarRobert Lyon <robertl@catalyst.net.nz>
parent c270263c
......@@ -1002,6 +1002,7 @@ function institution_submit(Pieform $form, $values) {
$page->name = $name;
$page->ctime = $now;
$page->mtime = $now;
$page->mauthor = $USER->get('id');
$page->content = get_string($page->name . 'defaultcontent', 'install', get_string('staticpageconfiginstitution', 'install'));
$page->institution = $newinstitution->name;
insert_record('site_content', $page);
......
......@@ -1002,7 +1002,7 @@
<FIELD NAME="content" TYPE="text" NOTNULL="true" />
<FIELD NAME="ctime" TYPE="datetime" NOTNULL="true" />
<FIELD NAME="mtime" TYPE="datetime" NOTNULL="true" />
<FIELD NAME="mauthor" TYPE="int" LENGTH="10" NOTNULL="false" />
<FIELD NAME="mauthor" TYPE="int" LENGTH="10" NOTNULL="true" />
<FIELD NAME="institution" TYPE="char" LENGTH="255" NOTNULL="true"/>
</FIELDS>
<KEYS>
......
......@@ -5570,5 +5570,23 @@ function xmldb_core_upgrade($oldversion=0) {
ensure_record_exists('event_type', $event, $event);
}
if ($oldversion < 2018010500) {
log_debug('Make site_content mauthor field have a user id by defaut');
// Defaults to usr = 0 on install
execute_sql("UPDATE {site_content} SET mauthor = 0 WHERE mauthor IS NULL");
$table = new XMLDBTable('site_content');
$key = new XMLDBKEY('mauthorfk');
$key->setAttributes(XMLDB_KEY_FOREIGN, array('mauthor'), 'usr', array('id'));
drop_key($table, $key);
$field = new XMLDBField('mauthor');
$field->setAttributes(XMLDB_TYPE_INTEGER, 10, null, XMLDB_NOTNULL);
change_field_notnull($table, $field);
$key = new XMLDBKEY('mauthorfk');
$key->setAttributes(XMLDB_KEY_FOREIGN, array('mauthor'), 'usr', array('id'));
add_key($table, $key);
}
return $status;
}
......@@ -721,18 +721,6 @@ function core_install_lastcoredata_defaults() {
$institution->priority = 0;
insert_record('institution', $institution);
$pages = site_content_pages();
$now = db_format_timestamp(time());
foreach ($pages as $name) {
$page = new stdClass();
$page->name = $name;
$page->ctime = $now;
$page->mtime = $now;
$page->content = get_string($page->name . 'defaultcontent', 'install', get_string('staticpageconfigdefault', 'install'));
$page->institution = 'mahara';
insert_record('site_content', $page);
}
$auth_instance = new StdClass;
$auth_instance->instancename = 'Internal';
$auth_instance->priority='1';
......@@ -742,8 +730,9 @@ function core_install_lastcoredata_defaults() {
$auth_instance->id = insert_record('auth_instance', $auth_instance, 'id', true);
// Insert the root user
$userid = 0;
$user = new StdClass;
$user->id = 0;
$user->id = $userid;
$user->username = 'root';
$user->password = '*';
$user->salt = '*';
......@@ -763,6 +752,19 @@ function core_install_lastcoredata_defaults() {
insert_record('usr', $user);
}
$pages = site_content_pages();
$now = db_format_timestamp(time());
foreach ($pages as $name) {
$page = new stdClass();
$page->name = $name;
$page->ctime = $now;
$page->mtime = $now;
$page->mauthor = $userid;
$page->content = get_string($page->name . 'defaultcontent', 'install', get_string('staticpageconfigdefault', 'install'));
$page->institution = 'mahara';
insert_record('site_content', $page);
}
// install the default layout options
install_view_layout_defaults();
......
......@@ -16,7 +16,7 @@ $config = new stdClass();
// See https://wiki.mahara.org/wiki/Developer_Area/Version_Numbering_Policy
// For upgrades on stable branches, increment the version by one. On master, use the date.
$config->version = 2018010400;
$config->version = 2018010500;
$config->series = '18.04';
$config->release = '18.04dev';
$config->minupgradefrom = 2015030409;
......
......@@ -527,6 +527,7 @@ EOD;
$page->name = $name;
$page->ctime = $now;
$page->mtime = $now;
$page->mauthor = 0;
$page->content = get_string($page->name . 'defaultcontent', 'install', get_string('staticpageconfiginstitution', 'install'));
$page->institution = $newinstitution->name;
insert_record('site_content', $page);
......
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