Skip to content
Snippets Groups Projects
Commit 1c5338ac authored by Jared Hancock's avatar Jared Hancock
Browse files

Add concept of initial data

We should move initial data out of the install SQL file, which will make way
for a few things:

  * Internationalization -- which breaks the migrater model currently.
        Moving the data outside the install script makes it translatable
        without changing the SQL hash
  * Review -- Migrations which add more data don't highlight new features
        that need review to the adminsitrator
parent 5cac196a
No related branches found
No related tags found
No related merge requests found
......@@ -86,3 +86,4 @@ osTicket is supported by several magical open source projects including:
* [PEAR/Net_Socket](http://pear.php.net/package/Net_Socket)
* [PEAR/Serivces_JSON](http://pear.php.net/package/Services_JSON)
* [phplint](http://antirez.com/page/phplint.html)
* [Spyc](http://github.com/mustangostang/spyc)
This diff is collapsed.
......@@ -48,4 +48,13 @@ class Error /* extends Exception */ {
}
}
class InitialDataError extends Error {
var $title = 'Problem with install initial data';
}
function raise_error($message, $class=false) {
if (!$class) $class = 'Error';
new $class($message);
}
?>
......@@ -13,6 +13,7 @@
vim: expandtab sw=4 ts=4 sts=4:
**********************************************************************/
require_once INCLUDE_DIR.'class.yaml.php';
class EmailTemplateGroup {
......@@ -58,7 +59,8 @@ class EmailTemplateGroup {
'desc'=>'Alert sent to staff on stale or overdue tickets.'),
'staff.pwreset' => array(
'name' => 'Staff Password Reset',
'desc' => 'Notice sent to staff with the password reset link.'),
'desc' => 'Notice sent to staff with the password reset link.',
'default' => 'templates/staff.pwreset.txt'),
);
function EmailTemplateGroup($id){
......@@ -111,6 +113,10 @@ class EmailTemplateGroup {
return $this->isEnabled();
}
function getLanguage() {
return 'en_US';
}
function isInUse(){
global $cfg;
......@@ -143,6 +149,9 @@ class EmailTemplateGroup {
if ($tpl=EmailTemplate::lookupByName($this->getId(), $name, $this))
return $tpl;
if ($tpl=EmailTemplate::fromInitialData($name, $this))
return $tpl;
$ost->logWarning('Template Fetch Error', "Unable to fetch '$name' template - id #".$this->getId());
return false;
}
......@@ -333,11 +342,12 @@ class EmailTemplateGroup {
class EmailTemplate {
var $id;
var $ht;
var $_group;
function EmailTemplate($id, $group=null){
$this->id=0;
$this->load($id);
if ($id) $this->load($id);
if ($group) $this->_group = $group;
}
......@@ -469,5 +479,24 @@ class EmailTemplate {
function lookup($id, $group=null) {
return ($id && is_numeric($id) && ($t= new EmailTemplate($id, $group)) && $t->getId()==$id)?$t:null;
}
/**
* Load the template from the initial_data directory. The format of the
* file should be free flow text. The first line is the subject and the
* rest of the file is the body.
*/
function fromInitialData($name, $group=null) {
$templ = new EmailTemplate(0, $group);
$lang = ($group) ? $group->getLanguage() : 'en_US';
$info = YamlDataParser::load(I18N_DIR . "$lang/templates/$name.yaml");
if (isset($info['subject']) && isset($info['body'])) {
$templ->ht = $info;
return $templ;
}
raise_error("$lang/templates/$name.yaml: "
. 'Email templates must define both "subject" and "body" parts of the template',
'InitialDataError');
return false;
}
}
?>
<?php
/*********************************************************************
class.yaml.php
Parses YAML data files into PHP associative arrays. Useful for initial
data shipped with osTicket.
Currently, this module uses the pure-php implementation Spyc, written by
- Chris Wanstrath
- Vlad Andersen
and released under an MIT license. The software is available at
https://github.com/mustangostang/spyc
Jared Hancock <jared@osticket.com>
Copyright (c) 2006-2013 osTicket
http://www.osticket.com
Released under the GNU General Public License WITHOUT ANY WARRANTY.
See LICENSE.TXT for details.
vim: expandtab sw=4 ts=4 sts=4:
$Id: $
**********************************************************************/
require_once "Spyc.php";
class YamlDataParser {
/* static */
function load($file) {
if (!file_exists($file)) {
raise_error("$file: File does not exist", 'YamlParserError');
return false;
}
return Spyc::YAMLLoad($file);
}
}
class YamlParserError extends Error {
var $title = 'Error parsing YAML document';
}
?>
#
# Email template: staff.pwreset
#
# Sent when a staff member requests a password reset via the <a>Forgot my
# password</a> link in the staff control login screen
#
---
subject: osTicket Staff Password Reset
body: |
You or perhaps somebody you know has submitted a password reset request on
your behalf for the helpdesk at %{url}.
If you feel that this has been done in error. Delete and disregard this
email. Your account is still secure and no one has been given access to it.
It is not locked and your password has not been reset. Someone could have
mistakenly entered your email address.
Follow the link below to login to the help desk and change your password.
%{reset_link}
......@@ -11,6 +11,12 @@ if (is_a($template, EmailTemplateGroup)) {
$action = 'implement';
$extras = array('code_name'=>$selected, 'tpl_id'=>$tpl_id);
$msgtemplates=$template->all_names;
// Attempt to lookup the default data if it is defined
$default = @$template->getMsgTemplate($selected);
if ($default) {
$info['subj'] = $default->getSubject();
$info['body'] = $default->getBody();
}
} else {
// Template edit
$id = $template->getId();
......
......@@ -70,6 +70,7 @@
define('SETUP_DIR',INCLUDE_DIR.'setup/');
define('UPGRADE_DIR', INCLUDE_DIR.'upgrader/');
define('I18N_DIR', INCLUDE_DIR.'i18n/');
/*############## Do NOT monkey with anything else beyond this point UNLESS you really know what you are doing ##############*/
......
......@@ -9,6 +9,7 @@ class Test {
'/include/htmLawed.php',
'/include/PasswordHash.php',
'/include/pear/',
'/include/Spyc.php',
);
function Test() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment