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

Merge branch 'develop' into develop-next

Conflicts:
	include/class.cron.php
parents 0298b949 31bb4ac0
Branches
Tags
No related merge requests found
...@@ -211,11 +211,11 @@ class TicketsAjaxAPI extends AjaxController { ...@@ -211,11 +211,11 @@ class TicketsAjaxAPI extends AjaxController {
foreach (TicketForm::getInstance()->getFields() as $f) { foreach (TicketForm::getInstance()->getFields() as $f) {
if (isset($req[$f->getFormName()]) if (isset($req[$f->getFormName()])
&& ($val = $req[$f->getFormName()])) { && ($val = $req[$f->getFormName()])) {
$name = $f->get('name') ? db_real_escape($f->get('name')) $name = $f->get('name') ? $f->get('name')
: 'field_'.$f->get('id'); : 'field_'.$f->get('id');
$cwhere = "cdata.\"$name\" LIKE '%".db_real_escape($val)."%'"; $cwhere = "cdata.`$name` LIKE '%".db_real_escape($val)."%'";
if ($f->getImpl()->hasIdValue() && is_numeric($val)) if ($f->getImpl()->hasIdValue() && is_numeric($val))
$cwhere .= " OR cdata.\"{$name}_id\" = ".db_input($val); $cwhere .= " OR cdata.`{$name}_id` = ".db_input($val);
$where .= ' AND ('.$cwhere.')'; $where .= ' AND ('.$cwhere.')';
$cdata_search = true; $cdata_search = true;
} }
......
...@@ -34,7 +34,9 @@ class Cron { ...@@ -34,7 +34,9 @@ class Cron {
function PurgeLogs() { function PurgeLogs() {
global $ost; global $ost;
if($ost) $ost->purgeLogs(); // Once a day on a 5-minute cron
if (rand(1,300) == 42)
if($ost) $ost->purgeLogs();
} }
function PurgeDrafts() { function PurgeDrafts() {
...@@ -47,6 +49,47 @@ class Cron { ...@@ -47,6 +49,47 @@ class Cron {
AttachmentFile::deleteOrphans(); AttachmentFile::deleteOrphans();
} }
function MaybeOptimizeTables() {
// Once a week on a 5-minute cron
$chance = rand(1,2000);
switch ($chance) {
case 42:
@db_query('OPTIMIZE TABLE '.TICKET_LOCK_TABLE);
break;
case 242:
@db_query('OPTIMIZE TABLE '.SYSLOG_TABLE);
break;
case 442:
@db_query('OPTIMIZE TABLE '.DRAFT_TABLE);
break;
// Start optimizing core ticket tables when we have an archiving
// system available
case 142:
#@db_query('OPTIMIZE TABLE '.TICKET_TABLE);
break;
case 542:
#@db_query('OPTIMIZE TABLE '.FORM_ENTRY_TABLE);
break;
case 642:
#@db_query('OPTIMIZE TABLE '.FORM_ANSWER_TABLE);
break;
case 342:
#@db_query('OPTIMIZE TABLE '.FILE_TABLE);
# XXX: Please do not add an OPTIMIZE for the file_chunk table!
break;
// Start optimizing user tables when we have a user directory
// sporting deletes
case 742:
#@db_query('OPTIMIZE TABLE '.USER_TABLE);
break;
case 842:
#@db_query('OPTIMIZE TABLE '.USER_EMAIL_TABLE);
break;
}
}
function run(){ //called by outside cron NOT autocron function run(){ //called by outside cron NOT autocron
global $ost; global $ost;
if (!$ost || $ost->isUpgradePending()) if (!$ost || $ost->isUpgradePending())
...@@ -57,6 +100,7 @@ class Cron { ...@@ -57,6 +100,7 @@ class Cron {
self::PurgeLogs(); self::PurgeLogs();
self::CleanOrphanedFiles(); self::CleanOrphanedFiles();
self::PurgeDrafts(); self::PurgeDrafts();
self::MaybeOptimizeTables();
Signal::send('cron'); Signal::send('cron');
} }
......
...@@ -245,7 +245,7 @@ class TicketForm extends DynamicForm { ...@@ -245,7 +245,7 @@ class TicketForm extends DynamicForm {
static function updateDynamicDataView($answer, $data) { static function updateDynamicDataView($answer, $data) {
// TODO: Detect $data['dirty'] for value and value_id // TODO: Detect $data['dirty'] for value and value_id
// We're chiefly concerned with Ticket form answers // We're chiefly concerned with Ticket form answers
if (!($e = $answer->getEntry()) || $e->get('object_type') != 'T') if (!($e = $answer->getEntry()) || $e->getForm()->get('type') != 'T')
return; return;
// $record = array(); // $record = array();
...@@ -303,7 +303,8 @@ Signal::connect('model.updated', ...@@ -303,7 +303,8 @@ Signal::connect('model.updated',
array('TicketForm', 'dropDynamicDataView'), array('TicketForm', 'dropDynamicDataView'),
'DynamicFormField', 'DynamicFormField',
// TODO: Lookup the dynamic form to verify {type == 'T'} // TODO: Lookup the dynamic form to verify {type == 'T'}
function($o, $d) { return isset($d['dirty']) && isset($d['dirty']['name']); }); function($o, $d) { return isset($d['dirty'])
&& (isset($d['dirty']['name']) || isset($d['dirty']['type'])); });
require_once(INCLUDE_DIR . "class.json.php"); require_once(INCLUDE_DIR . "class.json.php");
......
...@@ -147,11 +147,10 @@ class TicketLock { ...@@ -147,11 +147,10 @@ class TicketLock {
return db_query($sql); return db_query($sql);
} }
//Called via cron //Called via cron
function cleanup() { function cleanup() {
//Cleanup any expired locks. //Cleanup any expired locks.
db_query('DELETE FROM '.TICKET_LOCK_TABLE.' WHERE expire<NOW()'); db_query('DELETE FROM '.TICKET_LOCK_TABLE.' WHERE expire<NOW()');
@db_query('OPTIMIZE TABLE '.TICKET_LOCK_TABLE);
} }
} }
?> ?>
...@@ -228,12 +228,11 @@ class osTicket { ...@@ -228,12 +228,11 @@ class osTicket {
function alertAdmin($subject, $message, $log=false) { function alertAdmin($subject, $message, $log=false) {
//Set admin's email address //Set admin's email address
if(!($to=$this->getConfig()->getAdminEmail())) if (!($to = $this->getConfig()->getAdminEmail()))
$to=ADMIN_EMAIL; $to = ADMIN_EMAIL;
//append URL to the message //append URL to the message
$message.="\n\n".THISPAGE; $message.="\n\n".$this->getConfig()->getBaseUrl();
//Try getting the alert email. //Try getting the alert email.
$email=null; $email=null;
......
...@@ -18,6 +18,7 @@ class osTicketSession { ...@@ -18,6 +18,7 @@ class osTicketSession {
var $ttl = SESSION_TTL; var $ttl = SESSION_TTL;
var $data = ''; var $data = '';
var $data_hash = '';
var $id = ''; var $id = '';
function osTicketSession($ttl=0){ function osTicketSession($ttl=0){
...@@ -87,12 +88,16 @@ class osTicketSession { ...@@ -87,12 +88,16 @@ class osTicketSession {
list($this->data)=db_fetch_row($res); list($this->data)=db_fetch_row($res);
$this->id = $id; $this->id = $id;
} }
$this->data_hash = md5($this->data);
return $this->data; return $this->data;
} }
function write($id, $data){ function write($id, $data){
global $thisstaff; global $thisstaff;
if (md5($data) == $this->data_hash)
return;
$ttl = ($this && get_class($this) == 'osTicketSession') $ttl = ($this && get_class($this) == 'osTicketSession')
? $this->getTTL() : SESSION_TTL; ? $this->getTTL() : SESSION_TTL;
......
...@@ -102,9 +102,6 @@ class Ticket { ...@@ -102,9 +102,6 @@ class Ticket {
$this->thread = null; $this->thread = null;
$this->collaborators = null; $this->collaborators = null;
//REQUIRED: Preload thread obj - checked on lookup!
$this->getThread();
return true; return true;
} }
...@@ -1897,8 +1894,7 @@ class Ticket { ...@@ -1897,8 +1894,7 @@ class Ticket {
return ($id return ($id
&& is_numeric($id) && is_numeric($id)
&& ($ticket= new Ticket($id)) && ($ticket= new Ticket($id))
&& $ticket->getId()==$id && $ticket->getId()==$id)
&& $ticket->getThread())
?$ticket:null; ?$ticket:null;
} }
......
...@@ -66,6 +66,14 @@ class UserSession { ...@@ -66,6 +66,14 @@ class UserSession {
return($token); return($token);
} }
function getLastUpdate($htoken) {
if (!$htoken)
return 0;
@list($hash,$expire,$ip)=explode(":",$htoken);
return $expire;
}
function isvalidSession($htoken,$maxidletime=0,$checkip=false){ function isvalidSession($htoken,$maxidletime=0,$checkip=false){
global $cfg; global $cfg;
...@@ -122,7 +130,10 @@ class ClientSession extends Client { ...@@ -122,7 +130,10 @@ class ClientSession extends Client {
} }
function refreshSession(){ function refreshSession(){
global $_SESSION; $time = $this->session->getLastUpdate($_SESSION['_client']['token']);
// Deadband session token updates to once / 30-seconds
if (time() - $time < 30)
return;
$_SESSION['_client']['token']=$this->getSessionToken(); $_SESSION['_client']['token']=$this->getSessionToken();
//TODO: separate expire time from hash?? //TODO: separate expire time from hash??
} }
...@@ -160,7 +171,11 @@ class StaffSession extends Staff { ...@@ -160,7 +171,11 @@ class StaffSession extends Staff {
} }
function refreshSession(){ function refreshSession(){
global $_SESSION; $time = $this->session->getLastUpdate($_SESSION['_staff']['token']);
// Deadband session token updates to once / 30-seconds
if (time() - $time < 30)
return;
$_SESSION['_staff']['token']=$this->getSessionToken(); $_SESSION['_staff']['token']=$this->getSessionToken();
} }
......
...@@ -21,6 +21,7 @@ function staffLoginPage($msg='Unauthorized') { ...@@ -21,6 +21,7 @@ function staffLoginPage($msg='Unauthorized') {
exit; exit;
} }
define('AJAX_REQUEST', 1);
require('staff.inc.php'); require('staff.inc.php');
//Clean house...don't let the world see your crap. //Clean house...don't let the world see your crap.
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
vim: expandtab sw=4 ts=4 sts=4: vim: expandtab sw=4 ts=4 sts=4:
**********************************************************************/ **********************************************************************/
define('AJAX_REQUEST', 1);
require('staff.inc.php'); require('staff.inc.php');
ignore_user_abort(1);//Leave me a lone bro! ignore_user_abort(1);//Leave me a lone bro!
@set_time_limit(0); //useless when safe_mode is on @set_time_limit(0); //useless when safe_mode is on
......
...@@ -123,7 +123,9 @@ if($ost->isUpgradePending() && !$exempt) { ...@@ -123,7 +123,9 @@ if($ost->isUpgradePending() && !$exempt) {
$sysnotice.=' <a href="settings.php">Enable</a>.'; $sysnotice.=' <a href="settings.php">Enable</a>.';
} }
$nav = new StaffNav($thisstaff); if (!defined('AJAX_REQUEST'))
$nav = new StaffNav($thisstaff);
//Check for forced password change. //Check for forced password change.
if($thisstaff->forcePasswdChange() && !$exempt) { if($thisstaff->forcePasswdChange() && !$exempt) {
# XXX: Call staffLoginPage() for AJAX and API requests _not_ to honor # XXX: Call staffLoginPage() for AJAX and API requests _not_ to honor
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment