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

oops: Fix several small, general issues

  * Fix translation of pages
  * Localize client thank-you page on new ticket
  * Fix adding new category
  * Fix crash on staff login when upgrading from < 1.9
  * Don't show self locks on ticket queue pages
parent 505257a9
Branches
Tags
No related merge requests found
......@@ -174,7 +174,7 @@ class ContentAjaxAPI extends AjaxController {
$vars = array_merge($content->getHashtable(), $_POST);
$errors = array();
if (!$content->save($id, $vars, $errors)) {
if (!$content->update($vars, $errors)) {
if ($errors['err'])
Http::response(422, $errors['err']);
else
......
......@@ -224,12 +224,11 @@ class Category extends VerySimpleModel {
/* ------------------> Static methods <--------------------- */
static function findIdByName($name) {
$object = self::objects()->filter(array(
$row = self::objects()->filter(array(
'name'=>$name
))->values_flat('category_id')->one();
))->values_flat('category_id')->first();
if ($object)
return $object[0];
return ($row) ? $row[0] : null;
}
static function findByName($name) {
......
......@@ -18,6 +18,8 @@
class OrmException extends Exception {}
class OrmConfigurationException extends Exception {}
// Database fields/tables do not match codebase
class InconsistentModelException extends OrmException {}
/**
* Meta information about a model including edges (relationships), table
......@@ -86,7 +88,8 @@ class ModelMeta implements ArrayAccess {
if (!isset($j['list']))
$j['list'] = true;
if (!isset($j['null']))
$j['null'] = $info['null'] ?: false;
// By default, reverse releationships can be empty lists
$j['null'] = true;
}
// XXX: Make this better (ie. composite keys)
$keys = array_keys($j['constraint']);
......@@ -2076,8 +2079,8 @@ class MysqlExecutor {
function execute() {
if (!($this->stmt = db_prepare($this->sql)))
throw new OrmException('Unable to prepare query: '.db_error()
.' '.$this->sql);
throw new InconsistentModelException(
'Unable to prepare query: '.db_error().' '.$this->sql);
if (count($this->params))
$this->_bind($this->params);
if (!$this->stmt->execute() || ! $this->stmt->store_result()) {
......
......@@ -220,6 +220,11 @@ class Page extends VerySimpleModel {
catch (DoesNotExist $ex) {
return null;
}
catch (InconsistentModelException $ex) {
// This largely happens on upgrades, and may specifically cause
// the staff login box to crash
return null;
}
}
static function lookupByType($type, $lang=false) {
......
......@@ -26,10 +26,9 @@ $total=$categories->count();
$page=($_GET['p'] && is_numeric($_GET['p']))?$_GET['p']:1;
$pageNav=new Pagenate($total, $page, PAGE_LIMIT);
$pageNav->setURL('categories.php',$qstr.'&sort='.urlencode($_REQUEST['sort']).'&order='.urlencode($_REQUEST['order']));
$pageNav->paginate($categories);
$qstr.='&order='.($order=='DESC'?'ASC':'DESC');
$categories = $categories->offset($pageNav->getStart())
->limit($pageNav->getLimit());
if ($total)
$showing=$pageNav->showing().' '.__('categories');
else
......
......@@ -19,11 +19,12 @@ if($page && $_REQUEST['a']!='add'){
$slug = Format::slugify($info['name']);
$qstr.='&id='.$page->getId();
$translations = CustomDataTranslation::allTranslations(
$page->getTranslateTag('body'), 'article');
$page->getTranslateTag('name:body'), 'article');
foreach ($cfg->getSecondaryLanguages() as $tag) {
foreach ($translations as $t) {
if (strcasecmp($t->lang, $tag) === 0) {
$info['trans'][$tag] = Format::viewableImages($t->text);
$C = $t->getComplex();
$info['trans'][$tag] = Format::viewableImages($C['body']);
break;
}
}
......
......@@ -110,7 +110,7 @@ $tickets->annotate(array(
// Select pertinent columns
// ------------------------------------------------------------
$tickets->values('lock__lock_id', 'staff_id', 'isoverdue', 'team_id', 'ticket_id', 'number', 'cdata__subject', 'user__default_email__address', 'source', 'cdata__:priority__priority_color', 'cdata__:priority__priority_desc', 'status_id', 'status__name', 'status__state', 'dept_id', 'dept__name', 'user__name', 'lastupdate');
$tickets->values('lock__staff_id', 'staff_id', 'isoverdue', 'team_id', 'ticket_id', 'number', 'cdata__subject', 'user__default_email__address', 'source', 'cdata__:priority__priority_color', 'cdata__:priority__priority_desc', 'status_id', 'status__name', 'status__state', 'dept_id', 'dept__name', 'user__name', 'lastupdate');
// Apply requested quick filter
......@@ -268,7 +268,7 @@ $_SESSION[':Q:tickets'] = $tickets;
$total += 1;
$tag=$T['staff_id']?'assigned':'openticket';
$flag=null;
if($T['lock__lock_id'])
if($T['lock__staff_id'] && $T['lock__staff_id'] != $thisstaff->getId())
$flag='locked';
elseif($T['isoverdue'])
$flag='overdue';
......@@ -289,7 +289,7 @@ $_SESSION[':Q:tickets'] = $tickets;
$tid=$T['number'];
$subject = Format::truncate($subject_field->display($subject_field->to_php($T['cdata__subject'])),40);
$threadcount=$T['thread_count'];
if(!strcasecmp($T['status__state'],'open') && !$T['isanswered'] && !$T['lock__lock_id']) {
if(!strcasecmp($T['status__state'],'open') && !$T['isanswered'] && !$T['lock__staff_id']) {
$tid=sprintf('<b>%s</b>',$tid);
}
?>
......
......@@ -67,13 +67,18 @@ if ($cfg->isClientLoginRequired()) {
}
require(CLIENTINC_DIR.'header.inc.php');
if($ticket
&& (
(($topic = $ticket->getTopic()) && ($page = $topic->getPage()))
|| ($page = $cfg->getThankYouPage())
)) {
if ($ticket
&& (
(($topic = $ticket->getTopic()) && ($page = $topic->getPage()))
|| ($page = $cfg->getThankYouPage())
)
) {
// Thank the user and promise speedy resolution!
echo Format::viewableImages($ticket->replaceVars($page->getBody()));
echo Format::viewableImages(
$ticket->replaceVars(
$page->getLocalBody()
)
);
}
else {
require(CLIENTINC_DIR.'open.inc.php');
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment