Commit 73538818 authored by Penny Leach's avatar Penny Leach Committed by Nigel McNie
Browse files

moved all the STATEMENTs out of install.xml into postinst, split postinst into...

moved all the STATEMENTs out of install.xml into postinst, split postinst into two - right after core data & right at the end
parent 3b0c2456
...@@ -32,9 +32,9 @@ define('JSON', 1); ...@@ -32,9 +32,9 @@ define('JSON', 1);
require(dirname(dirname(__FILE__)) . '/init.php'); require(dirname(dirname(__FILE__)) . '/init.php');
require(get_config('libroot') . 'upgrade.php'); require(get_config('libroot') . 'upgrade.php');
$install = param_boolean('install'); $name = param_variable('name');
$install = ($name == 'firstcoredata' || $name == 'lastcoredata');
if (!$install) { if (!$install) {
$name = param_variable('name');
$upgrade = check_upgrades($name); $upgrade = check_upgrades($name);
if (empty($upgrade->disablelogin)) { if (empty($upgrade->disablelogin)) {
...@@ -42,23 +42,23 @@ if (!$install) { ...@@ -42,23 +42,23 @@ if (!$install) {
} }
} }
$data = array(
'key' => $name
);
if ($install) { if ($install) {
$message = '';
if (!get_config('installed')) { if (!get_config('installed')) {
try { try {
core_install_defaults(); $fun = 'core_install_' . $name . '_defaults';
$fun();
} }
catch (SQLException $e) { catch (SQLException $e) {
json_reply('local', $e->getMessage()); json_reply('local', array('key' => $name, 'errormessage' => $e->getMessage()));
} }
} }
json_reply(false, $message); $data['coredata'] = true;
json_reply(false, $data);
} }
$data = array(
'key' => $name
);
if (!empty($upgrade)) { if (!empty($upgrade)) {
$data['newversion'] = $upgrade->torelease . ' (' . $upgrade->to . ')' ; $data['newversion'] = $upgrade->torelease . ' (' . $upgrade->to . ')' ;
if ($name == 'core') { if ($name == 'core') {
......
...@@ -43,7 +43,6 @@ if (!$upgrades) { ...@@ -43,7 +43,6 @@ if (!$upgrades) {
die_info(get_string('noupgrades', 'admin')); die_info(get_string('noupgrades', 'admin'));
} }
$js = 'var todo = ' . json_encode(array_keys($upgrades)) . ";\n";
$loadingicon = theme_get_url('images/loading.gif'); $loadingicon = theme_get_url('images/loading.gif');
$successicon = theme_get_url('images/success.gif'); $successicon = theme_get_url('images/success.gif');
$failureicon = theme_get_url('images/failure.gif'); $failureicon = theme_get_url('images/failure.gif');
...@@ -57,53 +56,18 @@ $coresuccess = json_encode(get_string('coredatasuccess', 'admin')); ...@@ -57,53 +56,18 @@ $coresuccess = json_encode(get_string('coredatasuccess', 'admin'));
// Check if Mahara is being installed. An extra hook is required to insert core // Check if Mahara is being installed. An extra hook is required to insert core
// data if so. // data if so.
if (!empty($upgrades['core']->install)) { if (!empty($upgrades['core']->install)) {
$upgrades['firstcoredata'] = true;
$upgrades['lastcoredata'] = true;
$smarty->assign('install', true); $smarty->assign('install', true);
$installjs =<<< EOJS }
$('coredata').innerHTML = '<img src="{$loadingicon}" alt="' + {$loadingstring} + '" />';
sendjsonrequest(
'upgrade.json.php',
{ 'install' : 1 },
'GET',
function (data) {
if ( !data.error ) {
var message = {$coresuccess};
if (data.message) {
message += ' (' + data.message + ')';
}
$('coredata').innerHTML = '<img src="{$successicon}" alt=":)" /> ' + message;
$('finished').style.visibility = 'visible';
}
else {
var message = '';
if (data.message) {
message = data.message;
}
else {
message = {$failurestring};
}
$('coredata').innerHTML = '<img src="{$failureicon}" alt=":(" /> ' + message;
}
},
function () {
$('coredata').innerHTML = '<img src="{$failureicon}" alt=":(" /> ' + {$failurestring};
},
true); // quiet.
EOJS; $js = <<< EOJS
}
else {
$installjs = '';
}
$js .= <<< EOJS
function processNext() { function processNext() {
var element = todo.shift(); var element = todo.shift();
if ( ! element ) { if (!element) {
// we're done $('finished').style.visibility = 'visible';
$installjs return; // done
return;
} }
$(element).innerHTML = '<img src="{$loadingicon}" alt="' + {$loadingstring} + '" />'; $(element).innerHTML = '<img src="{$loadingicon}" alt="' + {$loadingstring} + '" />';
...@@ -111,13 +75,18 @@ $js .= <<< EOJS ...@@ -111,13 +75,18 @@ $js .= <<< EOJS
sendjsonrequest('upgrade.json.php', { 'name': element }, 'GET', function (data) { sendjsonrequest('upgrade.json.php', { 'name': element }, 'GET', function (data) {
if ( !data.error ) { if ( !data.error ) {
var message; var message;
if (data.install) { if (data.coredata) {
message = {$installsuccessstring}; message = {$coresuccess};
} }
else { else {
message = {$successstring}; if (data.install) {
message = {$installsuccessstring};
}
else {
message = {$successstring};
}
message += data.newversion;
} }
message += data.newversion;
$(data.key).innerHTML = '<img src="{$successicon}" alt=":)" /> ' + message; $(data.key).innerHTML = '<img src="{$successicon}" alt=":)" /> ' + message;
} }
else { else {
...@@ -141,6 +110,8 @@ $js .= <<< EOJS ...@@ -141,6 +110,8 @@ $js .= <<< EOJS
addLoadEvent( processNext ); addLoadEvent( processNext );
EOJS; EOJS;
uksort($upgrades, 'sort_upgrades');
$js .= "\n" . 'var todo = ' . json_encode(array_keys($upgrades)) . ";\n";
$smarty->assign('INLINEJAVASCRIPT', $js); $smarty->assign('INLINEJAVASCRIPT', $js);
$smarty->assign_by_ref('upgrades', $upgrades); $smarty->assign_by_ref('upgrades', $upgrades);
...@@ -149,4 +120,6 @@ if (isset($upgrades['core'])) { ...@@ -149,4 +120,6 @@ if (isset($upgrades['core'])) {
} }
$smarty->display('admin/upgrade.tpl'); $smarty->display('admin/upgrade.tpl');
?> ?>
<TABLE NAME="blocktype_category">
<FIELDS>
<FIELD NAME="name" TYPE="char" LENGTH="50" NOTNULL="true" />
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="name" />
</KEYS>
</TABLE>
<TABLE NAME="blocktype_installed_category">
<FIELDS>
<FIELD NAME="blocktype" TYPE="char" LENGTH="50" NOTNULL="true" />
<FIELD NAME="category" TYPE="char" LENGTH="50" NOTNULL="true" />
</FIELDS>
<KEYS>
<KEY NAME="blocktypefk" TYPE="foreign" FIELDS="blocktype" REFTABLE="blocktype_installed" REFFIELDS="name" />
<KEY NAME="categoryfk" TYPE="foreign" FIELDS="category" REFTABLE="blocktype_category" REFFIELDS="name" />
</KEYS>
</TABLE>
...@@ -411,7 +411,7 @@ ...@@ -411,7 +411,7 @@
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true" /> <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true" />
<FIELD NAME="view" TYPE="int" LENGTH="10" NOTNULL="true" /> <FIELD NAME="view" TYPE="int" LENGTH="10" NOTNULL="true" />
<FIELD NAME="artefact" TYPE="int" LENGTH="10" NOTNULL="true" /> <FIELD NAME="artefact" TYPE="int" LENGTH="10" NOTNULL="true" />
<FIELD NAME="block" TYPE="text" NOTNULL="true" /> <FIELD NAME="block" TYPE="int" LENGTH="10" NOTNULL="true" />
<FIELD NAME="ctime" TYPE="datetime" NOTNULL="true" /> <FIELD NAME="ctime" TYPE="datetime" NOTNULL="true" />
<FIELD NAME="format" TYPE="text" NOTNULL="true" /> <FIELD NAME="format" TYPE="text" NOTNULL="true" />
</FIELDS> </FIELDS>
...@@ -554,65 +554,4 @@ ...@@ -554,65 +554,4 @@
</KEYS> </KEYS>
</TABLE> </TABLE>
</TABLES> </TABLES>
<STATEMENTS>
<STATEMENT NAME="insert config" TYPE="insert" TABLE="config">
<SENTENCES>
<SENTENCE TEXT="(field, value) VALUES ('session_timeout', 1800)" />
<SENTENCE TEXT="(field, value) VALUES ('sitename', 'Mahara')" />
<SENTENCE TEXT="(field, value) VALUES ('pathtofile', '/usr/bin/file')" />
</SENTENCES>
</STATEMENT>
<STATEMENT NAME="insert application" TYPE="insert" TABLE="application">
<SENTENCES>
<SENTENCE TEXT="(name, displayname, xmlrpcserverurl, ssolandurl) VALUES ('moodle', 'Moodle','/mnet/xmlrpc/server.php','/auth/mnet/land.php')" />
<SENTENCE TEXT="(name, displayname, xmlrpcserverurl, ssolandurl) VALUES ('mahara', 'Mahara','/api/xmlrpc/server.php','/auth/xmlrpc/land.php')" />
</SENTENCES>
</STATEMENT>
<STATEMENT NAME="insert event types" TYPE="insert" TABLE="event_type">
<SENTENCES>
<SENTENCE TEXT="(name) VALUES ('createuser')" />
<SENTENCE TEXT="(name) VALUES ('updateuser')" />
<SENTENCE TEXT="(name) VALUES ('suspenduser')" />
<SENTENCE TEXT="(name) VALUES ('unsuspenduser')" />
<SENTENCE TEXT="(name) VALUES ('deleteuser')" />
<SENTENCE TEXT="(name) VALUES ('undeleteuser')" />
<SENTENCE TEXT="(name) VALUES ('expireuser')" />
<SENTENCE TEXT="(name) VALUES ('unexpireuser')" />
<SENTENCE TEXT="(name) VALUES ('deactivateuser')" />
<SENTENCE TEXT="(name) VALUES ('activateuser')" />
<SENTENCE TEXT="(name) VALUES ('saveartefact')" />
<SENTENCE TEXT="(name) VALUES ('deleteartefact')" />
<SENTENCE TEXT="(name) VALUES ('saveview')" />
<SENTENCE TEXT="(name) VALUES ('deleteview')" />
</SENTENCES>
</STATEMENT>
<STATEMENT NAME="insert activity types" TYPE="insert" TABLE="activity_type">
<SENTENCES>
<SENTENCE TEXT="(name, admin, delay) VALUES ('maharamessage', 0, 0)" />
<SENTENCE TEXT="(name, admin, delay) VALUES ('usermessage', 0, 0)" />
<SENTENCE TEXT="(name, admin, delay) VALUES ('feedback', 0, 0)" />
<SENTENCE TEXT="(name, admin, delay) VALUES ('watchlist', 0, 1)" />
<SENTENCE TEXT="(name, admin, delay) VALUES ('newview', 0, 1)" />
<SENTENCE TEXT="(name, admin, delay) VALUES ('viewaccess', 0, 1)" />
<SENTENCE TEXT="(name, admin, delay) VALUES ('contactus', 1, 1)" />
<SENTENCE TEXT="(name, admin, delay) VALUES ('objectionable', 1, 1)" />
<SENTENCE TEXT="(name, admin, delay) VALUES ('virusrepeat', 1, 1)" />
<SENTENCE TEXT="(name, admin, delay) VALUES ('virusrelease', 1, 1)" />
</SENTENCES>
</STATEMENT>
<STATEMENT NAME="insert core cron jobs" TYPE="insert" TABLE="cron">
<SENTENCES>
<SENTENCE TEXT="(callfunction, minute, hour, day, month, dayofweek)
VALUES ('rebuild_artefact_parent_cache_dirty', '*', '*', '*', '*', '*')" />
<SENTENCE TEXT="(callfunction, minute, hour, day, month, dayofweek)
VALUES ('rebuild_artefact_parent_cache_complete', '0', '4', '*', '*', '*')" />
<SENTENCE TEXT="(callfunction, minute, hour, day, month, dayofweek)
VALUES ('auth_clean_partial_registrations', '5', '0', '*', '*', '*')"/>
<SENTENCE TEXT="(callfunction, minute, hour, day, month, dayofweek)
VALUES ('auth_handle_account_expiries', '5', '10', '*', '*', '*')"/>
<SENTENCE TEXT="(callfunction, minute, hour, day, month, dayofweek)
VALUES ('activity_process_queue', '*/5', '*', '*', '*', '*')"/>
</SENTENCES>
</STATEMENT>
</STATEMENTS>
</XMLDB> </XMLDB>
...@@ -809,7 +809,7 @@ function safe_require($plugintype, $pluginname, $filename='lib.php', $function=' ...@@ -809,7 +809,7 @@ function safe_require($plugintype, $pluginname, $filename='lib.php', $function='
function plugin_types() { function plugin_types() {
static $pluginstocheck; static $pluginstocheck;
if (empty($pluginstocheck)) { if (empty($pluginstocheck)) {
$pluginstocheck = array('blocktype', 'artefact', 'auth', 'notification', 'search'); $pluginstocheck = array('artefact', 'auth', 'notification', 'search', 'blocktype');
} }
return $pluginstocheck; return $pluginstocheck;
} }
......
...@@ -228,6 +228,7 @@ function check_upgrades($name=null) { ...@@ -228,6 +228,7 @@ function check_upgrades($name=null) {
if (count($toupgrade) == 1) { if (count($toupgrade) == 1) {
$toupgrade = array(); $toupgrade = array();
} }
uksort($toupgrade, 'sort_upgrades');
return $toupgrade; return $toupgrade;
} }
...@@ -490,26 +491,23 @@ function core_postinst() { ...@@ -490,26 +491,23 @@ function core_postinst() {
set_config('searchplugin', 'internal'); set_config('searchplugin', 'internal');
set_config('lang', 'en.utf8'); set_config('lang', 'en.utf8');
return $status; return $status;
} }
function core_install_lastcoredata_defaults() {
function core_install_defaults() {
// Install the default institution
db_begin(); db_begin();
$institution = new StdClass; $auth_instance = new StdClass;
$institution->name = 'mahara'; $institution->name = 'mahara';
$institution->displayname = 'No Institution'; $institution->displayname = 'No Institution';
$institution->authplugin = 'internal'; $institution->authplugin = 'internal';
insert_record('institution', $institution); insert_record('institution', $institution);
$auth_instance = new StdClass;
$auth_instance->instancename = 'internal'; $auth_instance->instancename = 'internal';
$auth_instance->priority='1'; $auth_instance->priority='1';
$auth_instance->institution = 'mahara'; $auth_instance->institution = 'mahara';
$auth_instance->authname = 'internal'; $auth_instance->authname = 'internal';
$auth_instance->id = insert_record('auth_instance', $auth_instance, 'id', true); $auth_instance->id = insert_record('auth_instance', $auth_instance, 'id', true);
$institution = new StdClass;
// Insert the root user // Insert the root user
$user = new StdClass; $user = new StdClass;
...@@ -528,7 +526,6 @@ function core_install_defaults() { ...@@ -528,7 +526,6 @@ function core_install_defaults() {
set_field('usr', 'id', 0, 'id', $newid); set_field('usr', 'id', 0, 'id', $newid);
} }
// Insert the admin user
$user = new StdClass; $user = new StdClass;
$user->username = 'admin'; $user->username = 'admin';
$user->password = 'mahara'; $user->password = 'mahara';
...@@ -544,12 +541,108 @@ function core_install_defaults() { ...@@ -544,12 +541,108 @@ function core_install_defaults() {
set_profile_field($user->id, 'email', $user->email); set_profile_field($user->id, 'email', $user->email);
set_profile_field($user->id, 'firstname', $user->firstname); set_profile_field($user->id, 'firstname', $user->firstname);
set_profile_field($user->id, 'lastname', $user->lastname); set_profile_field($user->id, 'lastname', $user->lastname);
set_config('installed', true); set_config('installed', true);
db_commit(); db_commit();
} }
function core_install_firstcoredata_defaults() {
// Install the default institution
db_begin();
set_config('session_timeout', 1800);
set_config('sitename', 'Mahara');
set_config('pathtofile', '/usr/bin/file');
// install the applications
$app = new StdClass;
$app->name = 'mahara';
$app->displayname = 'Mahara';
$app->xmlrpcserverurl = '/api/xmlrpc/server.php';
$app->ssolandurl = '/auth/xmlrpc/land.php';
insert_record('application', $app);
$app->name = 'moodle';
$app->displayname = 'Moodle';
$app->xmlrpcserverurl = '/mnet/xmlrpc/server.php';
$app->ssolandurl = '/auth/mnet/land.php';
insert_record('application', $app);
// insert the event types
$eventtypes = array(
'createuser',
'updateuser',
'suspenduser',
'unsuspenduser',
'deleteuser',
'undeleteuser',
'expireuser',
'unexpireuser',
'deactivateuser',
'activateuser',
'saveartefact',
'deleteartefact',
'saveview',
'deleteview',
);
foreach ($eventtypes as $et) {
$e = new StdClass;
$e->name = $et;
insert_record('event_type', $e);
}
// install the activity types
$activitytypes = array(
array('maharamessage', 0, 0),
array('usermessage', 0, 0),
array('feedback', 0, 0),
array('watchlist', 0, 1),
array('newview', 0, 1),
array('viewaccess', 0, 1),
array('contactus', 1, 1),
array('objectionable', 1, 1),
array('virusrepeat', 1, 1),
array('virusrelease', 1, 1),
);
foreach ($activitytypes as $at) {
$a = new StdClass;
$a->name = $at[0];
$a->admin = $at[1];
$a->delay = $at[2];
insert_record('activity_type', $a);
}
// install the cronjobs...
$cronjobs = array(
'rebuild_artefact_parent_cache_dirty' => array('*', '*', '*', '*', '*'),
'rebuild_artefact_parent_cache_complete' => array('0', '4', '*', '*', '*'),
'auth_clean_partial_registrations' => array('5', '0', '*', '*', '*'),
'auth_handle_account_expiries' => array('5', '10', '*', '*', '*'),
'activity_process_queue' => array('*/5', '*', '*', '*', '*'),
);
foreach ($cronjobs as $callfunction => $times) {
$cron = new StdClass;
$cron->callfunction = $callfunction;
$cron->minute = $times[0];
$cron->hour = $times[1];
$cron->day = $times[2];
$cron->month = $times[3];
$cron->dayofweek = $times[4];
insert_record('cron', $cron);
}
// install the blocktype categories
db_commit();
}
/**
* xmldb will pass us the xml file and we can perform any substitution as necessary
*/
function local_xmldb_contents_sub(&$contents) { function local_xmldb_contents_sub(&$contents) {
// the main install.xml file needs to sub in plugintype tables.
$searchstring = '<!-- PLUGIN_TYPE_SUBSTITUTION -->'; $searchstring = '<!-- PLUGIN_TYPE_SUBSTITUTION -->';
if (strstr($contents, $searchstring) === 0) { if (strstr($contents, $searchstring) === 0) {
return; return;
...@@ -559,20 +652,30 @@ function local_xmldb_contents_sub(&$contents) { ...@@ -559,20 +652,30 @@ function local_xmldb_contents_sub(&$contents) {
$plugintables = file_get_contents(get_config('docroot') . 'lib/db/plugintables.xml'); $plugintables = file_get_contents(get_config('docroot') . 'lib/db/plugintables.xml');
$tosub = ''; $tosub = '';
foreach (plugin_types() as $plugin) { foreach (plugin_types() as $plugin) {
// any that want their own stuff can put it in docroot/plugintype/lib/db/plugintables.xml - like auth is a bit special // any that want their own stuff can put it in docroot/plugintype/lib/db/plugintables.xml
//- like auth is a bit special
$specialcase = get_config('docroot') . $plugin . '/plugintables.xml'; $specialcase = get_config('docroot') . $plugin . '/plugintables.xml';
if (is_readable($specialcase)) { if (is_readable($specialcase)) {
$tosub .= file_get_contents($specialcase) . "\n"; $tosub .= file_get_contents($specialcase) . "\n";
} }
else { else {
$replaced = '';
// look for tables to put at the start...
$pretables = get_config('docroot') . $plugin . '/beforetables.xml';
if (is_readable($pretables)) {
$replaced = file_get_contents($pretables) . "\n";
}
// perform any additional once off substitutions
require_once(get_config('docroot') . $plugin . '/lib.php'); require_once(get_config('docroot') . $plugin . '/lib.php');
if (method_exists(generate_class_name($plugin), 'extra_xmldb_substitution')) { if (method_exists(generate_class_name($plugin), 'extra_xmldb_substitution')) {
$replaced = call_static_method(generate_class_name($plugin), 'extra_xmldb_substitution', $plugintables); $replaced .= call_static_method(generate_class_name($plugin), 'extra_xmldb_substitution', $plugintables);
} }
else { else {
$replaced = $plugintables; $replaced .= $plugintables;
} }
$tosub .= str_replace('__PLUGINTYPE__', $plugin, $replaced) . "\n"; $tosub .= str_replace('__PLUGINTYPE__', $plugin, $replaced) . "\n";
// look for any tables to put at the end..
$extratables = get_config('docroot') . $plugin . '/extratables.xml'; $extratables = get_config('docroot') . $plugin . '/extratables.xml';
if (is_readable($extratables)) { if (is_readable($extratables)) {
$tosub .= file_get_contents($extratables) . "\n"; $tosub .= file_get_contents($extratables) . "\n";
...@@ -592,7 +695,6 @@ function validate_plugin($plugintype, $pluginname, $pluginpath='') { ...@@ -592,7 +695,6 @@ function validate_plugin($plugintype, $pluginname, $pluginpath='') {
if (empty($pluginpath)) { if (empty($pluginpath)) {
$pluginpath = get_config('docroot') . $plugintype . '/' . $pluginname; $pluginpath = get_config('docroot') . $plugintype . '/' . $pluginname;
} }
error_log("looking for $pluginpath/version.php");
if (!file_exists($pluginpath . '/version.php')) { if (!file_exists($pluginpath . '/version.php')) {
throw new InstallationException(get_string('versionphpmissing', 'error', $plugintype, $pluginname)); throw new InstallationException(get_string('versionphpmissing', 'error', $plugintype, $pluginname));
} }
...@@ -604,4 +706,30 @@ function validate_plugin($plugintype, $pluginname, $pluginpath='') { ...@@ -604,4 +706,30 @@ function validate_plugin($plugintype, $pluginname, $pluginpath='') {
// @TODO more? // @TODO more?
// validate the plugin class // validate the plugin class
} }
/*
* the order things are installed/upgraded in matters
*/
function sort_upgrades($k1, $k2) {
if ($k1 == 'core') {
return -1;
}
else if ($k2 == 'core') {
return 1;
}
else if ($k1 == 'firstcoredata') {
return -1;
}
else if ($k2 == 'firstcoredata') {
return 1;
}
else if ($k1 == 'lastcoredata') {
return 1;
}
else if ($k2 == 'lastcoredata') {
return -1;
}
return 0;
}
?> ?>
...@@ -16,19 +16,16 @@ ...@@ -16,19 +16,16 @@
{foreach from=$upgrades key=name item=upgrade} {foreach from=$upgrades key=name item=upgrade}
<tr class="{cycle name=rows values=r1,r0}"> <tr class="{cycle name=rows values=r1,r0}">
<td>{$name}</td> <td>{$name}</td>
{if $name == 'firstcoredata' || $name == 'lastcoredata'}
<td></td>
<td></td>
{else}
<td>{if $upgrade->install} {str section='admin' tag='notinstalled'} {else} {$upgrade->fromrelease} {/if} </td> <td>{if $upgrade->install} {str section='admin' tag='notinstalled'} {else} {$upgrade->fromrelease} {/if} </td>
<td>{$upgrade->torelease}</td> <td>{$upgrade->torelease}</td>
{/if}
<td id="{$name}" class="msgscol">&nbsp;</td> <