mirror of
https://github.com/Combodo/iTop.git
synced 2026-02-12 23:14:18 +01:00
Archives: refactoring of the API to enable/disable the archive mode
SVN:trunk[4696]
This commit is contained in:
@@ -54,12 +54,7 @@ class ajax_page extends WebPage implements iTabbedPage
|
||||
$this->sContentDisposition = 'inline';
|
||||
$this->m_sMenu = "";
|
||||
|
||||
if (class_exists('DBSearch')) // This class does not exist in the contect of the setup page
|
||||
{
|
||||
$bArchiveMode = utils::IsArchiveMode();
|
||||
DBSearch::SetArchiveModeDefault($bArchiveMode);
|
||||
if ($bArchiveMode) MetaModel::DBSetReadOnly();
|
||||
}
|
||||
utils::InitArchiveMode();
|
||||
}
|
||||
|
||||
public function AddTabContainer($sTabContainer, $sPrefix = '')
|
||||
|
||||
@@ -63,9 +63,7 @@ class iTopWebPage extends NiceWebPage implements iTabbedPage
|
||||
$this->bBreadCrumbEnabled = false;
|
||||
}
|
||||
|
||||
$bArchiveMode = utils::IsArchiveMode();
|
||||
DBSearch::SetArchiveModeDefault($bArchiveMode);
|
||||
if ($bArchiveMode) MetaModel::DBSetReadOnly();
|
||||
utils::InitArchiveMode();
|
||||
|
||||
$this->m_sMenu = "";
|
||||
$this->m_aMessages = array();
|
||||
|
||||
@@ -140,7 +140,10 @@ class utils
|
||||
}
|
||||
}
|
||||
|
||||
public static function IsArchiveMode()
|
||||
protected static $bPageMode = null;
|
||||
protected static $aModes = array();
|
||||
|
||||
public static function InitArchiveMode()
|
||||
{
|
||||
if (isset($_SESSION['archive_mode']))
|
||||
{
|
||||
@@ -152,7 +155,34 @@ class utils
|
||||
}
|
||||
$iCurrent = self::ReadParam('with-archive', $iDefault, true);
|
||||
$_SESSION['archive_mode'] = $iCurrent;
|
||||
return ($iCurrent == 1);
|
||||
self::$bPageMode = ($iCurrent == 1);
|
||||
}
|
||||
|
||||
public static function PushArchiveMode($bMode)
|
||||
{
|
||||
array_push(self::$aModes, $bMode);
|
||||
}
|
||||
|
||||
public static function PopArchiveMode()
|
||||
{
|
||||
array_pop(self::$aModes);
|
||||
}
|
||||
|
||||
public static function IsArchiveMode()
|
||||
{
|
||||
if (count(self::$aModes) > 0)
|
||||
{
|
||||
$bRet = end(self::$aModes);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (self::$bPageMode === null)
|
||||
{
|
||||
self::InitArchiveMode();
|
||||
}
|
||||
$bRet = self::$bPageMode;
|
||||
}
|
||||
return $bRet;
|
||||
}
|
||||
|
||||
public static function ReadParam($sName, $defaultValue = "", $bAllowCLI = false, $sSanitizationFilter = 'parameter')
|
||||
|
||||
@@ -48,7 +48,7 @@ abstract class DBSearch
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->m_bArchiveMode = self::GetArchiveModeDefault();
|
||||
$this->m_bArchiveMode = utils::IsArchiveMode();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -62,16 +62,6 @@ abstract class DBSearch
|
||||
abstract public function AllowAllData();
|
||||
abstract public function IsAllDataAllowed();
|
||||
|
||||
static $bArchiveModeDefault = false;
|
||||
static public function SetArchiveModeDefault($bEnable)
|
||||
{
|
||||
self::$bArchiveModeDefault = $bEnable;
|
||||
}
|
||||
static public function GetArchiveModeDefault()
|
||||
{
|
||||
return self::$bArchiveModeDefault;
|
||||
}
|
||||
|
||||
public function SetArchiveMode($bEnable)
|
||||
{
|
||||
$this->m_bArchiveMode = $bEnable;
|
||||
|
||||
@@ -3450,12 +3450,6 @@ abstract class MetaModel
|
||||
return $aDataDump;
|
||||
}
|
||||
|
||||
protected static $m_bReadOnlyMode = false;
|
||||
public static function DBSetReadOnly()
|
||||
{
|
||||
self::$m_bReadOnlyMode = true;
|
||||
}
|
||||
|
||||
/*
|
||||
* Determines wether the target DB is frozen or not
|
||||
*/
|
||||
@@ -3463,7 +3457,7 @@ abstract class MetaModel
|
||||
{
|
||||
// Improvement: check the mySQL variable -> Read-only
|
||||
|
||||
if (self::$m_bReadOnlyMode)
|
||||
if (utils::IsArchiveMode())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@@ -4600,7 +4594,7 @@ abstract class MetaModel
|
||||
$sModifierProperties = json_encode($aModifierProperties);
|
||||
$sQuerySign .= '_all_'.md5($sModifierProperties);
|
||||
}
|
||||
$sQuerySign .= DBSearch::GetArchiveModeDefault() ? '_arch_' : '';
|
||||
$sQuerySign .= utils::IsArchiveMode() ? '_arch_' : '';
|
||||
|
||||
if (!array_key_exists($sQuerySign, self::$aQueryCacheGetObject))
|
||||
{
|
||||
@@ -4693,10 +4687,9 @@ abstract class MetaModel
|
||||
|
||||
public static function GetObjectWithArchive($sClass, $iKey, $bMustBeFound = true, $bAllowAllData = false, $aModifierProperties = null)
|
||||
{
|
||||
$bPreviousMode = DBSearch::GetArchiveModeDefault();
|
||||
DBSearch::SetArchiveModeDefault(true);
|
||||
utils::PushArchiveMode(true);
|
||||
$oObject = static::GetObject($sClass, $iKey, $bMustBeFound, $bAllowAllData, $aModifierProperties);
|
||||
DBSearch::SetArchiveModeDefault($bPreviousMode);
|
||||
utils::PopArchiveMode();
|
||||
return $oObject;
|
||||
}
|
||||
|
||||
|
||||
@@ -87,9 +87,7 @@ $oApp->before(function(Symfony\Component\HttpFoundation\Request $oRequest, Silex
|
||||
}
|
||||
|
||||
// Enable archived data
|
||||
$bArchiveMode = utils::IsArchiveMode();
|
||||
DBSearch::SetArchiveModeDefault($bArchiveMode);
|
||||
if ($bArchiveMode) MetaModel::DBSetReadOnly();
|
||||
utils::InitArchiveMode();
|
||||
|
||||
// Enabling datalocalizer if needed
|
||||
if (!defined('DISABLE_DATA_LOCALIZER_PORTAL'))
|
||||
|
||||
@@ -379,7 +379,7 @@ try
|
||||
$oP->set_title(Dict::S('UI:ErrorPageTitle'));
|
||||
|
||||
// Attempt to load the object in archive mode
|
||||
DBSearch::SetArchiveModeDefault(true);
|
||||
utils::PushArchiveMode(true);
|
||||
if (is_numeric($id))
|
||||
{
|
||||
$oObj = MetaModel::GetObject($sClass, $id, false /* MustBeFound */);
|
||||
@@ -388,6 +388,7 @@ try
|
||||
{
|
||||
$oObj = MetaModel::GetObjectByName($sClass, $id, false /* MustBeFound */);
|
||||
}
|
||||
utils::PopArchiveMode();
|
||||
if (is_null($oObj))
|
||||
{
|
||||
$oP->P(Dict::S('UI:ObjectDoesNotExist'));
|
||||
|
||||
@@ -1312,9 +1312,7 @@ try
|
||||
|
||||
ApplicationContext::SetUrlMakerClass('MyPortalURLMaker');
|
||||
|
||||
$bArchiveMode = utils::IsArchiveMode();
|
||||
DBSearch::SetArchiveModeDefault($bArchiveMode);
|
||||
if ($bArchiveMode) MetaModel::DBSetReadOnly();
|
||||
utils::InitArchiveMode();
|
||||
|
||||
$aClasses = explode(',', MetaModel::GetConfig()->Get('portal_tickets'));
|
||||
$sMainClass = trim(reset($aClasses));
|
||||
|
||||
Reference in New Issue
Block a user