From 0caf04d50301d0325ab8ba784852d2fa604cb69d Mon Sep 17 00:00:00 2001 From: Jared Hancock <jared@osticket.com> Date: Thu, 28 May 2015 09:51:42 -0500 Subject: [PATCH] orm: Clear model inspect cache on upgrade The ORM will cache the structure of the underlying tables (fields and such) in APC, and will needs to ensure such data is purged when the table structures change. --- include/class.orm.php | 16 +++++++++++----- include/class.upgrader.php | 4 +++- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/include/class.orm.php b/include/class.orm.php index 326736f81..43df8e29f 100644 --- a/include/class.orm.php +++ b/include/class.orm.php @@ -37,6 +37,8 @@ class ModelMeta implements ArrayAccess { 'select_related' => array(), 'view' => false, ); + static $model_cache; + var $model; function __construct($model) { @@ -147,21 +149,25 @@ class ModelMeta implements ArrayAccess { } function inspectFields() { - static $cache; - if (!isset($cache)) - $cache = function_exists('apc_fetch'); - if ($cache) { + if (!isset(self::$model_cache)) + self::$model_cache = function_exists('apc_fetch'); + if (self::$model_cache) { $key = md5(SECRET_SALT . GIT_VERSION . $this['table']); if ($fields = apc_fetch($key)) { return $fields; } } $fields = DbEngine::getCompiler()->inspectTable($this['table']); - if ($cache) { + if (self::$model_cache) { apc_store($key, $fields); } return $fields; } + + static function flushModelCache() { + if (self::$model_cache) + @apc_clear_cache('user'); + } } class VerySimpleModel { diff --git a/include/class.upgrader.php b/include/class.upgrader.php index 63fba34d8..aa45d831d 100644 --- a/include/class.upgrader.php +++ b/include/class.upgrader.php @@ -72,8 +72,10 @@ class Upgrader { function setState($state) { $this->state = $state; - if ($state == 'done') + if ($state == 'done') { $this->createUpgradedTicket(); + ModelMeta::flushModelCache(); + } } function createUpgradedTicket() { -- GitLab