Commit 2c916081 authored by Robert Lyon's avatar Robert Lyon Committed by Gerrit Code Review
Browse files

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

parents ae531c51 63256d28
...@@ -1002,6 +1002,7 @@ function institution_submit(Pieform $form, $values) { ...@@ -1002,6 +1002,7 @@ function institution_submit(Pieform $form, $values) {
$page->name = $name; $page->name = $name;
$page->ctime = $now; $page->ctime = $now;
$page->mtime = $now; $page->mtime = $now;
$page->mauthor = $USER->get('id');
$page->content = get_string($page->name . 'defaultcontent', 'install', get_string('staticpageconfiginstitution', 'install')); $page->content = get_string($page->name . 'defaultcontent', 'install', get_string('staticpageconfiginstitution', 'install'));
$page->institution = $newinstitution->name; $page->institution = $newinstitution->name;
insert_record('site_content', $page); insert_record('site_content', $page);
......
...@@ -1002,7 +1002,7 @@ ...@@ -1002,7 +1002,7 @@
<FIELD NAME="content" TYPE="text" NOTNULL="true" /> <FIELD NAME="content" TYPE="text" NOTNULL="true" />
<FIELD NAME="ctime" TYPE="datetime" NOTNULL="true" /> <FIELD NAME="ctime" TYPE="datetime" NOTNULL="true" />
<FIELD NAME="mtime" 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"/> <FIELD NAME="institution" TYPE="char" LENGTH="255" NOTNULL="true"/>
</FIELDS> </FIELDS>
<KEYS> <KEYS>
......
...@@ -5570,5 +5570,23 @@ function xmldb_core_upgrade($oldversion=0) { ...@@ -5570,5 +5570,23 @@ function xmldb_core_upgrade($oldversion=0) {
ensure_record_exists('event_type', $event, $event); 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; return $status;
} }
...@@ -721,18 +721,6 @@ function core_install_lastcoredata_defaults() { ...@@ -721,18 +721,6 @@ function core_install_lastcoredata_defaults() {
$institution->priority = 0; $institution->priority = 0;
insert_record('institution', $institution); 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 = new StdClass;
$auth_instance->instancename = 'Internal'; $auth_instance->instancename = 'Internal';
$auth_instance->priority='1'; $auth_instance->priority='1';
...@@ -742,8 +730,9 @@ function core_install_lastcoredata_defaults() { ...@@ -742,8 +730,9 @@ function core_install_lastcoredata_defaults() {
$auth_instance->id = insert_record('auth_instance', $auth_instance, 'id', true); $auth_instance->id = insert_record('auth_instance', $auth_instance, 'id', true);
// Insert the root user // Insert the root user
$userid = 0;
$user = new StdClass; $user = new StdClass;
$user->id = 0; $user->id = $userid;
$user->username = 'root'; $user->username = 'root';
$user->password = '*'; $user->password = '*';
$user->salt = '*'; $user->salt = '*';
...@@ -763,6 +752,19 @@ function core_install_lastcoredata_defaults() { ...@@ -763,6 +752,19 @@ function core_install_lastcoredata_defaults() {
insert_record('usr', $user); 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 the default layout options
install_view_layout_defaults(); install_view_layout_defaults();
......
...@@ -16,7 +16,7 @@ $config = new stdClass(); ...@@ -16,7 +16,7 @@ $config = new stdClass();
// See https://wiki.mahara.org/wiki/Developer_Area/Version_Numbering_Policy // 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. // 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->series = '18.04';
$config->release = '18.04dev'; $config->release = '18.04dev';
$config->minupgradefrom = 2015030409; $config->minupgradefrom = 2015030409;
......
...@@ -527,6 +527,7 @@ EOD; ...@@ -527,6 +527,7 @@ EOD;
$page->name = $name; $page->name = $name;
$page->ctime = $now; $page->ctime = $now;
$page->mtime = $now; $page->mtime = $now;
$page->mauthor = 0;
$page->content = get_string($page->name . 'defaultcontent', 'install', get_string('staticpageconfiginstitution', 'install')); $page->content = get_string($page->name . 'defaultcontent', 'install', get_string('staticpageconfiginstitution', 'install'));
$page->institution = $newinstitution->name; $page->institution = $newinstitution->name;
insert_record('site_content', $page); 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