Skip to content

Commit

Permalink
Don't use session object storage
Browse files Browse the repository at this point in the history
  • Loading branch information
slusarz committed Apr 14, 2014
1 parent fbae04d commit 961d8fc
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 38 deletions.
6 changes: 3 additions & 3 deletions imp/lib/Application.php
Expand Up @@ -162,11 +162,11 @@ protected function _init()
*/
public function logout()
{
global $injector, $session;
global $injector;

/* Clean up dangling IMP_Compose objects. */
foreach (array_keys($session->get('imp', 'compose_cache', Horde_Session::TYPE_ARRAY)) as $key) {
$injector->getInstance('IMP_Factory_Compose')->create($key)->destroy('cancel');
foreach ($injector->getInstance('IMP_Factory_Compose')->getAllObs() as $val) {
$val->destroy('cancel');
}

/* Destroy any IMP_Mailbox_List cached entries, since they will not
Expand Down
3 changes: 1 addition & 2 deletions imp/lib/Auth.php
Expand Up @@ -15,8 +15,7 @@
* This class provides authentication for IMP.
*
* The following is the list of IMP session variables:
* - compose_cache: (array) List of compose objects that have not yet been
* garbage collected.
* - compose_ob: (array) Active compose objects.
* - file_upload: (integer) If file uploads are allowed, the max size.
* - filteravail: (boolean) Can we apply filters manually?
* - imap_ob: (IMP_Imap) The IMAP client object.
Expand Down
7 changes: 1 addition & 6 deletions imp/lib/Basic/Pgp.php
Expand Up @@ -174,14 +174,9 @@ protected function _importKeyDialog($target)
*/
protected function _reloadWindow()
{
global $session;

$href = $session->retrieve($this->vars->reload);
$session->purge($this->vars->reload);

echo Horde::wrapInlineScript(array(
'opener.focus();'.
'opener.location.href="' . $href . '";',
'opener.location.href="' . base64_decode($this->vars->reload) . '";',
'window.close();'
));
exit;
Expand Down
7 changes: 1 addition & 6 deletions imp/lib/Basic/Smime.php
Expand Up @@ -154,14 +154,9 @@ protected function _importKeyDialog($target)
*/
protected function _reloadWindow()
{
global $session;

$href = $session->retrieve($this->vars->reload);
$session->purge($this->vars->reload);

echo Horde::wrapInlineScript(array(
'opener.focus();'.
'opener.location.href="' . $href . '";',
'opener.location.href="' . base64_decode($this->vars->reload) . '";',
'window.close();'
));
exit;
Expand Down
36 changes: 22 additions & 14 deletions imp/lib/Factory/Compose.php
Expand Up @@ -20,8 +20,13 @@
* @license http://www.horde.org/licenses/gpl GPL
* @package IMP
*/
class IMP_Factory_Compose extends Horde_Core_Factory_Base implements Horde_Shutdown_Task
class IMP_Factory_Compose
extends Horde_Core_Factory_Base
implements Horde_Shutdown_Task
{
/** Storage key for compose objects. */
const STORAGE_KEY = 'compose_ob/';

/**
* Instances.
*
Expand All @@ -48,10 +53,12 @@ public function __construct(Horde_Injector $injector)
*/
public function create($cacheid = null)
{
global $session;

if (empty($cacheid)) {
$cacheid = strval(new Horde_Support_Randomid());
} elseif (!isset($this->_instances[$cacheid])) {
$this->_instances[$cacheid] = $GLOBALS['session']->retrieve($cacheid);
$this->_instances[$cacheid] = $session->get('imp', self::STORAGE_KEY . $cacheid);
}

if (empty($this->_instances[$cacheid])) {
Expand All @@ -68,28 +75,29 @@ public function shutdown()
{
global $session;

$cache = $session->get('imp', 'compose_cache', Horde_Session::TYPE_ARRAY);
$changed = false;

foreach ($this->_instances as $key => $val) {
switch ($val->changed) {
case 'changed':
$session->store($val, false, $key);
$cache[$key] = 1;
$changed = true;
$session->set('imp', self::STORAGE_KEY . $key, $val);
break;

case 'deleted':
unset($cache[$key]);
$session->purge($key);
$changed = true;
$session->remove('imp', self::STORAGE_KEY . $key);
break;
}
}
}

if ($changed) {
$session->set('imp', 'compose_cache', $cache);
}
/**
* Return a list of all compose objects currently stored in the session.
*
* @return array List of IMP_Compose objects.
*/
public function getAllObs()
{
global $session;

return $session->get('imp', self::STORAGE_KEY, $session::TYPE_ARRAY);
}

}
6 changes: 3 additions & 3 deletions imp/lib/Factory/Ftree.php
Expand Up @@ -25,7 +25,7 @@ class IMP_Factory_Ftree
implements Horde_Shutdown_Task
{
/* Storage key in session. */
const STORAGE_KEY = 'imp_ftree';
const STORAGE_KEY = 'ftree';

/**
* @var IMP_Ftree
Expand All @@ -41,7 +41,7 @@ public function create(Horde_Injector $injector)
{
global $registry, $session;

$this->_instance = $session->retrieve(self::STORAGE_KEY);
$this->_instance = $session->get('imp', self::STORAGE_KEY);

if (!($this->_instance instanceof IMP_Ftree)) {
$this->_instance = new IMP_Ftree();
Expand All @@ -68,7 +68,7 @@ public function shutdown()

/* Only need to store the object if the tree has changed. */
if ($this->_instance->changed) {
$session->store($this->_instance, true, self::STORAGE_KEY);
$session->set('imp', self::STORAGE_KEY, $this->_instance);
}
}

Expand Down
2 changes: 1 addition & 1 deletion imp/lib/Prefs/Special/PgpPrivateKey.php
Expand Up @@ -95,7 +95,7 @@ public function display(Horde_Core_Prefs_Ui $ui)
if ($session->get('imp', 'file_upload')) {
$view->import_pgp_private = true;
$page_output->addInlineScript(array(
'$("import_pgp_personal").observe("click", function(e) { ' . Horde::popupJs($pgp_url, array('params' => array('actionID' => 'import_personal_key', 'reload' => $session->store($ui->selfUrl()->setRaw(true), false)), 'height' => 275, 'width' => 750, 'urlencode' => true)) . '; e.stop(); })'
'$("import_pgp_personal").observe("click", function(e) { ' . Horde::popupJs($pgp_url, array('params' => array('actionID' => 'import_personal_key', 'reload' => base64_encode($ui->selfUrl()->setRaw(true))), 'height' => 275, 'width' => 750, 'urlencode' => true)) . '; e.stop(); })'
), true);
}
}
Expand Down
2 changes: 1 addition & 1 deletion imp/lib/Prefs/Special/PgpPublicKey.php
Expand Up @@ -77,7 +77,7 @@ public function display(Horde_Core_Prefs_Ui $ui)
$view->no_source = !$prefs->getValue('add_source');
if (!$view->no_source) {
$page_output->addInlineScript(array(
'$("import_pgp_public").observe("click", function(e) { ' . Horde::popupJs($pgp_url, array('params' => array('actionID' => 'import_public_key', 'reload' => $session->store($ui->selfUrl()->setRaw(true), false)), 'height' => 275, 'width' => 750, 'urlencode' => true)) . '; e.stop(); })'
'$("import_pgp_public").observe("click", function(e) { ' . Horde::popupJs($pgp_url, array('params' => array('actionID' => 'import_public_key', 'reload' => base64_encode($ui->selfUrl()->setRaw(true))), 'height' => 275, 'width' => 750, 'urlencode' => true)) . '; e.stop(); })'
), true);
}
}
Expand Down
2 changes: 1 addition & 1 deletion imp/lib/Prefs/Special/SmimePrivateKey.php
Expand Up @@ -74,7 +74,7 @@ public function display(Horde_Core_Prefs_Ui $ui)
} elseif ($session->get('imp', 'file_upload')) {
$view->import = true;
$page_output->addInlineScript(array(
'$("import_smime_personal").observe("click", function(e) { ' . Horde::popupJs($smime_url, array('params' => array('actionID' => 'import_personal_certs', 'reload' => $session->store($ui->selfUrl()->setRaw(true), false)), 'height' => 275, 'width' => 750, 'urlencode' => true)) . '; e.stop(); })'
'$("import_smime_personal").observe("click", function(e) { ' . Horde::popupJs($smime_url, array('params' => array('actionID' => 'import_personal_certs', 'reload' => base64_encode($ui->selfUrl()->setRaw(true))), 'height' => 275, 'width' => 750, 'urlencode' => true)) . '; e.stop(); })'
), true);
}
}
Expand Down
2 changes: 1 addition & 1 deletion imp/lib/Prefs/Special/SmimePublicKey.php
Expand Up @@ -74,7 +74,7 @@ public function display(Horde_Core_Prefs_Ui $ui)
$view->no_source = !$prefs->getValue('add_source');
if (!$view->no_source) {
$page_output->addInlineScript(array(
'$("import_smime_public").observe("click", function(e) { ' . Horde::popupJs($smime_url, array('params' => array('actionID' => 'import_public_key', 'reload' => $session->store($ui->selfUrl()->setRaw(true), false)), 'height' => 275, 'width' => 750, 'urlencode' => true)) . '; e.stop(); })'
'$("import_smime_public").observe("click", function(e) { ' . Horde::popupJs($smime_url, array('params' => array('actionID' => 'import_public_key', 'reload' => base64_encode($ui->selfUrl()->setRaw(true))), 'height' => 275, 'width' => 750, 'urlencode' => true)) . '; e.stop(); })'
), true);
}
}
Expand Down

0 comments on commit 961d8fc

Please sign in to comment.