Commit e73dce18 authored by Nigel McNie's avatar Nigel McNie Committed by Nigel McNie
Browse files
parents 7b8fa02f ae3d91c2
......@@ -25,28 +25,37 @@
*/
define('INTERNAL',1);
define('INSTALLER',1);
require(dirname(dirname(__FILE__)) . '/init.php');
$name = clean_requestdata('name',PARAM_ALPHAEXT,REQUEST_EITHER);
// todo upgrade stuff
sleep(1);
// key, success, newversion ,errormessage
$upgrade = check_upgrades($name);
$data = array(
'key' => $name,
'success' => true,
'newversion' => 0.1,
);
'key' => $name
);
if (!empty($upgrade)) {
$data['newversion'] = $upgrade->torelease . '( ' . $upgrade->to . ')' ;
if ($name == 'core') {
$funname = 'upgrade_core';
}
else {
$funname = 'upgrade_plugin';
}
try {
$funname($upgrade);
$data['success'] = 1;
}
catch (Exception $e) {
error_log(print_r($e,true));
$data['errormessage'] = $e->getMessage();
$data['success'] = 0;
}
}
else {
$data['success'] = 1;
$data['errormessage'] = get_string('nothingtoupgrade','admin');
}
echo json_encode($data);
?>
\ No newline at end of file
......@@ -24,7 +24,8 @@
*
*/
define('INTERNAL',1);
define('INTERNAL', 1);
define('INSTALLER', 1);
require(dirname(dirname(__FILE__)).'/init.php');
......
<?xml version="1.0" encoding="UTF-8" ?>
<XMLDB PATH="lib/db" VERSION="20060926" COMMENT="XMLDB file for core Mahara tables"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../lib/xmldb/xmldb.xsd"
>
<TABLES>
</TABLES>
</XMLDB>
\ No newline at end of file
<?php
/**
* This program is part of Mahara
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* @package mahara
* @subpackage core or plugintype/pluginname
* @author Your Name <you@example.org>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz
*
*/
defined('INTERNAL') || die();
function xmldb_artefact_internal_upgrade($oldversion=0) {
$status = true;
return $status;
}
?>
......@@ -69,6 +69,7 @@ if (!isset($CFG->wwwroot)) {
require('mahara.php');
ensure_sanity();
require('dml.php');
require('ddl.php');
require('constants.php');
require('web.php');
require('session.php');
......@@ -108,8 +109,14 @@ catch (Exception $e) {
// nice message should be displayed explaining the problem etc. etc.
throw new Exception($errormessage);
}
load_config();
try {
load_config();
}
catch (DatalibException $e) {
if (!defined('INSTALLER')) {
throw $e;
}
}
if (!get_config('theme')) {
// if it's not set, we're probably not installed,
......
......@@ -4,4 +4,5 @@ $string['component'] = 'Component or plugin';
$string['fromversion'] = 'From version';
$string['toversion'] = 'To version';
$string['notinstalled'] = 'Not installed';
$string['nothingtoupgrade'] = 'Nothing to upgrade';
?>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8" ?>
<XMLDB PATH="lib/db" VERSION="20060926" COMMENT="XMLDB file for core Mahara tables"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../lib/xmldb/xmldb.xsd"
>
<TABLES>
<TABLE NAME="installed_artefact" COMMENT="Information about each installed artefact plugin" NEXT="config">
<FIELDS>
<FIELD NAME="name" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" ENUM="false" NEXT="version" />
<FIELD NAME="version" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="false" SEQUENCE="false" ENUM="false" PREVIOUS="name" NEXT="active"/>
<FIELD NAME="active" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="1" SEQUENCE="false" ENUM="false" PREVIOUS="version"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="name" COMMENT="Primary key for installed artefact plugins" />
</KEYS>
</TABLE>
<TABLE NAME="config" COMMENT="Mahara configuration variables" NEXT="config_artefact" PREVIOUS="installed_artefact">
<FIELDS>
<FIELD NAME="field" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" ENUM="false" NEXT="value"/>
<FIELD NAME="value" TYPE="text" LENGTH="small" NOTNULL="true" SEQUENCE="false" ENUM="false" PREVIOUS="field"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="field" COMMENT="Primary key for config" />
</KEYS>
</TABLE>
<TABLE NAME="config_artefact" COMMENT="Mahara artefact plugins configuration variables" PREVIOUS="config">
<FIELDS>
<FIELD NAME="plugin" TYPE="char" LENGTH="100" NOTNULL="true" SEQUENCE="false" ENUM="false" NEXT="field"/>
<FIELD NAME="field" TYPE="char" LENGTH="100" NOTNULL="true" SEQUENCE="false" ENUM="false" PREVIOUS="plugin" NEXT="value"/>
<FIELD NAME="value" TYPE="text" LENGTH="small" NOTNULL="true" SEQUENCE="false" ENUM="false" PREVIOUS="field"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="plugin,field" COMMENT="Primary key for config_artefact" NEXT="pluginfk" />
<KEY NAME="pluginfk" TYPE="foreign" FIELDS="plugin" REFTABLE="installed_artefact" REFFIELDS="name" PREVIOUS="primary"/>
</KEYS>
</TABLE>
</TABLES>
</XMLDB>
\ No newline at end of file
<?php
/**
* This program is part of Mahara
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* @package mahara
* @subpackage core or plugintype/pluginname
* @author Your Name <you@example.org>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz
*
*/
defined('INTERNAL') || die();
function xmldb_core_upgrade($oldversion=0) {
$status = true;
return $status;
}
?>
This diff is collapsed.
......@@ -554,33 +554,9 @@ function get_field($table, $field, $field1, $value1, $field2=null, $value2=null,
$select = where_clause_prepared($field1, $field2, $field3);
$values = where_values_prepared($value1, $value2, $value3);
$rs = get_recordset_sql($sql, $values);
if ($rs->RecordCount() == 1) {
return reset($rs->fields);
} else {
throw new DatalibException('Got more than one row when getting a field value');
}
//return get_field_sql('SELECT ' . $field . ' FROM ' . get_config('dbprefix') . $table . ' ' . $select, $values);
return get_field_sql('SELECT ' . $field . ' FROM ' . get_config('dbprefix') . $table . ' ' . $select, $values);
}
/**
* Get a single value from a table row where a particular select clause is true.
*
* @param string $table the table to query.
* @param string $return the field to return the value of.
* @param string $select A fragment of SQL to be used in a where clause in the SQL call.
* @return mixed the specified value.
* @throws DatalibException
*/
// NOTE: Commented out until an overwhelming reason is found to uncomment them
/*
function get_field_select($table, $return, $select, $values=null) {
if ($select) {
$select = 'WHERE '. $select;
}
return get_field_sql('SELECT ' . $return . ' FROM ' . get_config('dbprefix') . $table . ' ' . $select, $values);
}
*/
/**
* Get a single value from a table.
*
......@@ -588,8 +564,6 @@ function get_field_select($table, $return, $select, $values=null) {
* @return mixed the specified value.
* @throws DatalibException
*/
// NOTE: Commented out until an overwhelming reason is found to uncomment them
/*
function get_field_sql($sql, $values=null) {
$rs = get_recordset_sql($sql, $values);
if ($rs && $rs->RecordCount() == 1) {
......@@ -598,7 +572,6 @@ function get_field_sql($sql, $values=null) {
return false;
}
}
*/
/**
* Set a single field in every table row where all the given fields match the given values.
......@@ -620,7 +593,7 @@ function set_field($table, $newfield, $newvalue, $field1, $value1, $field2=null,
global $db;
$select = where_clause_prepared($field1, $field2, $field3);
$values = where_values_prepared($newfield, $value1, $value2, $value3);
$values = where_values_prepared($newvalue, $value1, $value2, $value3);
try {
$stmt = $db->Prepare('UPDATE '. get_config('dbprefix') . $table .' SET '. $newfield .' = ? ' . $select);
......@@ -1021,16 +994,15 @@ function column_type($table, $column) {
* This function will execute an array of SQL commands, returning
* true/false if any error is found and stopping/continue as desired.
* It's widely used by all the ddllib.php functions
*
*
* @private
* @param array sqlarr array of sql statements to execute
* @param boolean continue to specify if must continue on error (true) or stop (false)
* @param boolean feedback to specify to show status info (true) or not (false)
* @param boolean true if everything was ok, false if some error was found
*/
// NOTE: if this is used by ddllib then it should be in there, NOT in here. If the first
// person who discovers this comment can verify that ddllib still needs it, then they
// can move it.
/*
// in dml not ddl because we want to keep ddl 'clean upstream' - p
function execute_sql_arr($sqlarr, $continue=true, $feedback=true) {
if (!is_array($sqlarr)) {
......@@ -1048,7 +1020,6 @@ function execute_sql_arr($sqlarr, $continue=true, $feedback=true) {
}
return $status;
}
*/
/**
* This function, called from setup.php includes all the configuration
......@@ -1063,8 +1034,8 @@ function configure_dbconnection() {
// more later..
}
function is_postgres() {
return (strpos(get_config('dbtype'), 'postgres' === 0));
function is_postgres() {
return (strpos(get_config('dbtype'), 'postgres') === 0);
}
?>
......@@ -32,53 +32,57 @@ defined('INTERNAL') || die();
* for which need to be upgraded/installed
* @returns array of objects
*/
function check_upgrades() {
function check_upgrades($name = null) {
$toupgrade = array();
$installing = false;
require('version.php');
// check core first...
if (!$coreversion = get_config('version')) {
$core = new StdClass;
$core->install = true;
$core->to = $config->version;
$core->torelease = $config->release;
$toupgrade['core'] = $core;
$installing = true;
if (empty($name) || $name == 'core') {
if (!$coreversion = get_config('version')) {
$core = new StdClass;
$core->install = true;
$core->to = $config->version;
$core->torelease = $config->release;
$toupgrade['core'] = $core;
$installing = true;
}
else if ($config->version > $coreversion) {
$core = new StdClass;
$core->upgrade = true;
$core->from = $coreversion;
$core->fromrelease = get_config('release');
$core->to = $config->version;
$core->torelease = $config->release;
$toupgrade['core'] = $core;
}
}
$plugins = array();
if (strpos($name,'artefact.') === 0) {
$plugins[] = substr($name,9);
}
else if ($config->version > $coreversion) {
$core = new StdClass;
$core->upgrade = true;
$core->from = $coreversion;
$core->fromrelease = get_config('release');
$core->to = $config->version;
$core->torelease = $config->release;
$toupgrade['core'] = $core;
}
// artefact plugins next..
// Note: on initial installation each plugin configuration
// version check will cause an exception, which is caught
// just fine although it does show in the logs (with the
// default logging configuration)
$dirhandle = opendir(get_config('docroot').'artefact/');
while (false !== ($dir = readdir($dirhandle))) {
if (!empty($installing) && $dir != 'internal') {
continue;
else if (empty($name)) {
// artefact plugins next..
$dirhandle = opendir(get_config('docroot').'artefact/');
while (false !== ($dir = readdir($dirhandle))) {
if (strpos($dir,'.') === 0) {
continue;
}
if (!empty($installing) && $dir != 'internal') {
continue;
}
$plugins[] = $dir;
}
require(get_config('docroot').'artefact/'.$dir.'/version.php');
}
foreach ($plugins as $dir) {
require(get_config('docroot') . 'artefact/' . $dir . '/version.php');
$pluginversion = 0;
try {
$pluginversion = get_config_plugin('arfetact',$dir,'version');
}
catch (DatalibException $e) {
if (empty($installing)) {
// it's ok to have an exception here
// the table won't exist...
throw $e;
}
$pluginversion = get_config_plugin('arfetact', $dir, 'version');
}
catch (Exception $e) { }
if (empty($pluginversion)) {
$plugin = new StdClass;
$plugin->install = true;
......@@ -90,16 +94,87 @@ function check_upgrades() {
$plugin = new StdClass;
$plugin->upgrade = true;
$plugin->from = $pluginversion;
$plugin->fromrelease = get_config_plugin('artefact',$dir,'release');
try {
$plugin->fromrelease = get_config_plugin('artefact',$dir,'release');
}
catch (Exception $e) { }
$plugin->to = $config->version;
$plugin->torelease = $config->release;
$toupgrade['artefact.' . $dir] = $plugin;
}
}
// if we've just asked for one, don't return an array...
if (!empty($name) && count($toupgrade) == 1) {
$upgrade = new StdClass;
$upgrade->name = $name;
foreach ((array)$toupgrade[$name] as $key => $value) {
$upgrade->{$key} = $value;
}
return $upgrade;
}
return $toupgrade;
}
function upgrade_core($upgrade) {
$location = get_config('libroot') . '/db/';
if (!empty($upgrade->install)) {
$status = install_from_xmldb_file($location . 'install.xml');
}
else {
require_once($location . 'upgrade.php');
$status = xmldb_core_upgrade($upgrade->from);
}
if (!$status) {
throw new DatalibException("Failed to upgrade core");
}
$status = set_config('version', $upgrade->to);
$status = $status && set_config('release', $upgrade->torelease);
return $status;
}
function upgrade_plugin($upgrade) {
$plugintype = '';
$pluginname = '';
if (strpos($upgrade->name,'artefact.') === 0) {
$pluginname = substr($upgrade->name,9);
$plugintype = 'artefact';
}
$location = get_config('dirroot') . $plugintype . '/' . $pluginname . '/db/';
if (!empty($upgrade->install)) {
// @todo check file exists first - reasonable for it not to have
// db tables at all. should still insert version number and cron etc
// @todo add to installed_artefacts
$status = install_from_xmldb_file($location . 'install.xml');
}
else {
require_once($location . 'upgrade.php');
// @todo check file exists first - reasonable for it not to have
// db tables at all. should still insert version number and cron etc
$function = 'xmldb_' . $plugintype . '_' . $pluginname . '_upgrade';
$status = $function($upgrade->from);
}
if (!$status) {
throw new DatalibException("Failed to upgrade $upgrade->name");
}
$status = set_config_plugin($plugintype,$pluginname,'version',$upgrade->to);
$status = $status && set_config_plugin($plugintype,$pluginname,'release',$upgrade->torelease);
// @todo here is where plugins register events and set their crons up
return $status;
}
/**
* work around silly php settings
* and broken setup stuff about the install
......@@ -335,13 +410,13 @@ function load_config() {
try {
$dbconfig = get_records('config');
}
catch (DatalibException $e) {
catch (ADODB_Exception $e) {
return false;
}
foreach ($dbconfig as $cfg) {
if (isset($CFG->{$cfg->field}) && $CFG->{$cfg->field} != $CFG->value) {
log_info('Overriding database configuration for ' . $cfg->field . ' with config file value ' . $cfg->field);
// @todo warn that we're overriding db config with $CFG
continue;
}
$CFG->{$cfg->field} = $cfg->value;
......@@ -374,10 +449,23 @@ function get_config($key) {
* @param string $value config value
*/
function set_config($key, $value) {
if (set_field('config',$key,$value,'field',$key)) {
if (get_record('config','field',$key)) {
if (set_field('config','value',$value,'field',$key)) {
$status = true;
}
}
else {
$config = new StdClass;
$config->field = $key;
$config->value = $value;
$status = insert_record('config',$config);
}
if (!empty($status)) {
$CFG->{$key} = $value;
return true;
}
return false;
}
......@@ -411,6 +499,28 @@ function get_config_plugin($plugintype, $pluginname, $key) {
return $value;
}
function set_config_plugin($plugintype, $pluginname, $key, $value) {
$tablename = 'config_' . $plugintype;
if (get_field($table,'value','plugin',$pluginname,'field',$key)) {
if (set_field($table,'value',$key,'plugin',$pluginname, 'field',$value)) {
$status = true;
}
}
else {
$pconfig = new StdClass;
$pconfig->plugin = $pluginname;
$pconfig->field = $key;
$pconfig->value = $value;
$status = insert_record($table,$pconfig);
}
if ($status) {
$CFG->plugin->{$plugintype}->{$pluginname}->{$key} = $value;
return true;
}
return false;
}
/**
* This function prints an array or object
* wrapped inside <pre></pre>
......
<?php // $Id: XMLDBTable.class.php,v 1.11 2006/09/28 17:25:00 stronk7 Exp $
<?php // $Id: XMLDBTable.class.php,v 1.16 2006/10/08 09:36:54 stronk7 Exp $
///////////////////////////////////////////////////////////////////////////
// //
......@@ -891,6 +891,24 @@ class XMLDBTable extends XMLDBObject {
return $results;
}
/**
* This function will return the SQL code needed to modify the enum of one field in the table for the specified DB and
* prefix. Just one simple wrapper over generators.
*/
function getModifyEnumSQL ($dbtype, $prefix, $xmldb_field, $statement_end=true) {
$results = array();
$classname = 'XMLDB' . $dbtype;
$generator = new $classname();
$generator->setPrefix($prefix);
$results = $generator->getModifyEnumSQL($this, $xmldb_field);
if ($statement_end) {
$results = $generator->getEndedStatements($results);
}
return $results;
}
/**
* This function will return the SQL code needed to modify the default of one field in the table for the specified DB and
* prefix. Just one simple wrapper over generators.
......@@ -945,6 +963,24 @@ class XMLDBTable extends XMLDBObject {
return $results;
}
/**
* This function will return the SQL code needed to rename one key from the table for the specified DB and
* prefix. Just one simple wrapper over generators.
*/
function getRenameKeySQL ($dbtype, $prefix, $xmldb_key, $newname, $statement_end=true) {
$results = array();