Commit 9c82fbb8 authored by Penny Leach's avatar Penny Leach
Browse files

more work on template installing and upgrading and stuff

parent 05e8977e
<?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
* @author Penny Leach <penny@catalyst.net.nz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz
*
*/
define('INTERNAL', 1);
define('ADMIN', 1);
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
require_once(get_config('libroot') . 'template.php');
$name = param_alpha('name');
try {
$template = template_parse($name);
upgrade_template($name, $template);
json_reply(false);
}
catch (TemplateParserException $e) {
json_reply(true, $e->getMessage());
}
?>
\ 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
* @author Penny Leach <penny@catalyst.net.nz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz
*
*/
define('INTERNAL', 1);
define('ADMIN', 1);
define('MENUITEM', 'confixextensions');
define('SUBMENUITEM', 'templateadmin');
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
require_once(get_config('libroot') . 'template.php');
$installedtemplates = get_column('template', 'name');
$alltemplates = array();
$templates = get_dir_contents(get_config('dataroot') . 'templates/');
foreach ($templates as $dir) {
$alltemplates[$dir] = array();
}
$templates = get_dir_contents(get_config('libroot') . 'templates/');
foreach ($templates as $dir) {
if (!array_key_exists($dir,$templates)) {
$alltemplates[$dir] = array();
}
}
foreach (array_keys($alltemplates) as $t) {
try {
$alltemplates[$t]['template'] = template_parse($t);
}
catch (TemplateParserException $e) {
$alltemplates[$t]['error'] = $e->getMessage();
}
if (in_array($t, $installedtemplates)) {
$alltemplates[$t]['installed'] = true;
}
}
$loadingicon = theme_get_image_path('loading.gif');
$successicon = theme_get_image_path('success.gif');
$failureicon = theme_get_image_path('failure.gif');
$loadingstring = get_string('upgradeloading', 'admin');
$successstring = get_string('upgradesuccess', 'admin');
$failurestring = get_string('upgradefailure', 'admin');
$javascript = <<<JAVASCRIPT
function installtemplate(name) {
var d = loadJSONDoc('../templateinstall.json.php', { 'name': name });
$(name + '.message').innerHTML = '<img src="{$loadingicon}" alt="{$loadingstring}" />';
d.addCallbacks(function (data) {
if (!data.error) {
var message = '{$successstring}' + data.newversion;
$(name + '.message').innerHTML = '<img src="{$successicon}" alt=":)" /> ' + message;
// move the whole thing into the list of installed plugins
// new parent node
$(name + '.status').src = '$successicon';
}
else {
var message = '';
if (data.message) {
message = data.message;
}
else {
message = '{$failurestring}';
}
$(name).innerHTML = '<img src="{$failureicon}" alt=":(" /> ' + message;
}
},
function () {
message = '{$failurestring}';
$(name).innerHTML = message;
});
}
JAVASCRIPT;
$smarty = smarty();
$smarty->assign('INLINEJAVASCRIPT', $javascript);
$smarty->assign('templates', $alltemplates);
$smarty->assign('installlink', 'installtemplate');
$smarty->display('admin/extensions/templates.tpl');
?>
......@@ -192,5 +192,5 @@ $string['notificationssaved'] = 'Notification settings saved';
$string['installed'] = 'Installed';
$string['errors'] = 'Errors';
$string['install'] = 'Install';
?>
......@@ -446,42 +446,20 @@ function upgrade_templates($continue=false) {
}
}
foreach ($dbtemplates as $name => $guff) {
if (!is_readable($guff['location'] . 'config.php')) {
$e = new TemplateParserException("missing config.php for template $name");
foreach ($dbtemplates as $name => $data) {
try {
$ids = upgrade_template($name, $data);
}
catch (TemplateParserException $e) {
if (empty($continue)) {
throw $e;
}
$exceptions[] = $e;
unset($dbtemplates[$name]);
continue;
}
require_once($guff['location'] . 'config.php');
$fordb = new StdClass;
$fordb->name = $name;
$fordb->mtime = db_format_timestamp(time());
$fordb->title = $template->title;
$fordb->description = $template->description;
$fordb->category = $template->category;
$fordb->mtime = db_format_timestamp(time());
$fordb->cacheddata = serialize($guff['parseddata']);
if (isset($guff['thumbnail'])) {
$fordb->thumbnail = 1;
}
if (isset($template->owner)) {
$fordb->owner = $template->owner;
}
else {
$fordb->owner = 0; // root user
}
if (record_exists('template', 'name', $name)) {
update_record('template', $fordb, 'name');
}
else {
$fordb->ctime = $fordb->mtime;
insert_record('template', $fordb);
}
}
if (count($dbtemplates) > 0) {
set_field_select('template', 'deleted', 1,
'name NOT IN (' . implode(',', db_array_to_ph(array_keys($dbtemplates))). ')',
......@@ -490,8 +468,52 @@ function upgrade_templates($continue=false) {
else {
set_field('template', 'deleted', 1);
}
return $exceptions;
}
/**
* This function upgrades or installs an individual template.
*
* @param $name the template name
* @param $data what you would get from template_parse
*/
function upgrade_template($name, $data) {
if (!is_readable($data['location'] . 'config.php')) {
$e = new TemplateParserException("missing config.php for template $name");
if (empty($continue)) {
throw $e;
}
$exceptions[] = $e;
continue;
}
require_once($data['location'] . 'config.php');
$fordb = new StdClass;
$fordb->name = $name;
$fordb->mtime = db_format_timestamp(time());
$fordb->title = $template->title;
$fordb->description = $template->description;
$fordb->category = $template->category;
$fordb->mtime = db_format_timestamp(time());
$fordb->cacheddata = serialize($data['parseddata']);
if (isset($data['thumbnail'])) {
$fordb->thumbnail = 1;
}
if (isset($template->owner)) {
$fordb->owner = $template->owner;
}
else {
$fordb->owner = 0; // root user
}
if (record_exists('template', 'name', $name)) {
update_record('template', $fordb, 'name');
}
else {
$fordb->ctime = $fordb->mtime;
insert_record('template', $fordb);
}
}
?>
......@@ -33,7 +33,7 @@
<ul id="{$plugintype}.notinstalled">
{foreach from=$notinstalled key='plugin' item='data'}
<li id="{$plugintype}.{$plugin}">{$plugin} {if $data.notinstallable} {str tag='notinstallable'} {$data.notinstallable}
{else} (<a href="" onClick="{$installlink}('{$plugintype}.{$plugin}'); return false;">install</a>)
{else} (<a href="" onClick="{$installlink}('{$plugintype}.{$plugin}'); return false;">{str tag='install' section='admin'}</a>)
{/if}
<div id="{$plugintype}.{$plugin}.message"></div>
</li>
......
{include file='header.tpl'}
<div id="column-left-full">
<div class="content">
<div class="box-cnrs"><span class="cnr-tl"><span class="cnr-tr"><span class="cnr-bl"><span class="cnr-br">
<div class="maincontent">
<h2>{str tag='templatesadmin' section='admin'}</h2>
<table id="admintemplates">
<tr>
<th>{str tag='name'}</th>
<th>{str tag='installed' section='admin'}</th>
<th>{str tag='errors' section='admin'}</th>
</tr>
{foreach from=$templates item='template' key='name'}
<tr>
<td>{$name}</td>
<td>{if $template.installed}
<img id="{$name}.status" alt="{str tag='yes'}" src="{image_path imagelocation='success.gif}" />
{else}
<img id="{$name}.status" alt="{str tag='yes'}" src="{image_path imagelocation='failure.gif}" />
{if !$template.installed}
<a href="" onClick="{$installlink}('{$name}'); return false;">{str tag='install' section='admin'}</a>
<span id="{$name}.message"></span>
{/if}
{/if}
</td>
<td>{if $template.error} {$template.error} {/if}</td>
</tr>
{/foreach}
</table>
</div>
</div>
{include file='footer.tpl'}
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