mirror of
https://github.com/Combodo/iTop.git
synced 2026-02-13 07:24:13 +01:00
Obsolescence: background task setting (or resetting) the obsolescence date for obsolete data. The periodicity can be tuned by the mean of obsolescence.date_update_interval, defaulting to 10 minutes. Also renamed show_obsolete_data into obsolescence.show_obsolete_data for consistency.
SVN:trunk[4745]
This commit is contained in:
@@ -194,7 +194,7 @@ class utils
|
||||
*/
|
||||
public static function ShowObsoleteData()
|
||||
{
|
||||
$bDefault = MetaModel::GetConfig()->Get('show_obsolete_data'); // default is false
|
||||
$bDefault = MetaModel::GetConfig()->Get('obsolescence.show_obsolete_data'); // default is false
|
||||
$bShow = appUserPreferences::GetPref('show_obsolete_data', $bDefault);
|
||||
if (static::IsArchiveMode())
|
||||
{
|
||||
|
||||
55
core/background.inc.php
Normal file
55
core/background.inc.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
// Copyright (C) 2017 Combodo SARL
|
||||
//
|
||||
// This file is part of iTop.
|
||||
//
|
||||
// iTop is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// iTop is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with iTop. If not, see <http://www.gnu.org/licenses/>
|
||||
|
||||
|
||||
/**
|
||||
* Tasks performed in the background
|
||||
*
|
||||
* @copyright Copyright (C) 2017 Combodo SARL
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
|
||||
class ObsolescenceDateUpdater implements iBackgroundProcess
|
||||
{
|
||||
public function GetPeriodicity()
|
||||
{
|
||||
return MetaModel::GetConfig()->Get('obsolescence.date_update_interval'); // 10 mn
|
||||
}
|
||||
|
||||
public function Process($iUnixTimeLimit)
|
||||
{
|
||||
$iCountSet = 0;
|
||||
$iCountReset = 0;
|
||||
$iClasses = 0;
|
||||
foreach (MetaModel::EnumObsoletableClasses() as $sClass)
|
||||
{
|
||||
$oObsoletedToday = new DBObjectSearch($sClass);
|
||||
$oObsoletedToday->AddCondition('obsolescence_flag', 1, '=');
|
||||
$oObsoletedToday->AddCondition('obsolescence_date', null, '=');
|
||||
$sToday = date(AttributeDate::GetSQLFormat());
|
||||
$iCountSet += MetaModel::BulkUpdate($oObsoletedToday, array('obsolescence_date' => $sToday));
|
||||
|
||||
$oObsoletedToday = new DBObjectSearch($sClass);
|
||||
$oObsoletedToday->AddCondition('obsolescence_flag', 1, '!=');
|
||||
$oObsoletedToday->AddCondition('obsolescence_date', null, '!=');
|
||||
$iCountReset += MetaModel::BulkUpdate($oObsoletedToday, array('obsolescence_date' => null));
|
||||
}
|
||||
echo "Obsolescence date updated (classes: $iClasses ; set: $iCountSet ; reset: $iCountReset)\n";
|
||||
}
|
||||
}
|
||||
@@ -929,7 +929,7 @@ class Config
|
||||
'source_of_value' => '',
|
||||
'show_in_conf_sample' => false,
|
||||
),
|
||||
'show_obsolete_data' => array(
|
||||
'obsolescence.show_obsolete_data' => array(
|
||||
'type' => 'bool',
|
||||
'description' => 'Default value for the user preference "show obsolete data"',
|
||||
'default' => false,
|
||||
@@ -937,6 +937,14 @@ class Config
|
||||
'source_of_value' => '',
|
||||
'show_in_conf_sample' => false,
|
||||
),
|
||||
'obsolescence.date_update_interval' => array(
|
||||
'type' => 'integer',
|
||||
'description' => 'Delay in seconds between two refreshes of the obsolescence dates.',
|
||||
'default' => 600,
|
||||
'value' => 600,
|
||||
'source_of_value' => '',
|
||||
'show_in_conf_sample' => false,
|
||||
),
|
||||
);
|
||||
|
||||
public function IsProperty($sPropCode)
|
||||
|
||||
@@ -2554,13 +2554,14 @@ abstract class MetaModel
|
||||
}
|
||||
return $aRes;
|
||||
}
|
||||
public static function EnumObsoletableClasses()
|
||||
public static function EnumObsoletableClasses($bRootClassesOnly = true)
|
||||
{
|
||||
$aRes = array();
|
||||
foreach (self::GetClasses() as $sClass)
|
||||
{
|
||||
if (self::IsObsoletable($sClass))
|
||||
{
|
||||
if ($bRootClassesOnly && !static::IsRootClass($sClass)) continue;
|
||||
$aRes[] = $sClass;
|
||||
}
|
||||
}
|
||||
@@ -4868,6 +4869,11 @@ abstract class MetaModel
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param DBObjectSearch $oFilter
|
||||
* @param array $aValues array of attcode => value
|
||||
* @return int Modified objects
|
||||
*/
|
||||
public static function BulkUpdate(DBObjectSearch $oFilter, array $aValues)
|
||||
{
|
||||
// $aValues is an array of $sAttCode => $value
|
||||
@@ -4876,6 +4882,7 @@ abstract class MetaModel
|
||||
{
|
||||
CMDBSource::Query($sSQL);
|
||||
}
|
||||
return CMDBSource::AffectedRows();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -90,7 +90,7 @@ function DisplayPreferences($oP)
|
||||
$iDefaultPageSize = appUserPreferences::GetPref('default_page_size', MetaModel::GetConfig()->GetMinDisplayLimit());
|
||||
$oP->add('<p>'.Dict::Format('UI:Favorites:Default_X_ItemsPerPage', '<input id="default_page_size" name="default_page_size" type="text" size="3" value="'.$iDefaultPageSize.'"/><span id="v_default_page_size"></span>').'</p>');
|
||||
|
||||
$bDefaultShow = appUserPreferences::GetPref('show_obsolete_data', MetaModel::GetConfig()->Get('show_obsolete_data'));
|
||||
$bDefaultShow = appUserPreferences::GetPref('show_obsolete_data', MetaModel::GetConfig()->Get('obsolescence.show_obsolete_data'));
|
||||
$sSelected = $bDefaultShow ? ' checked="checked"' : '';
|
||||
$oP->add(
|
||||
'<p>'
|
||||
|
||||
@@ -29,6 +29,7 @@ require_once(APPROOT.'/application/application.inc.php');
|
||||
require_once(APPROOT.'/application/nicewebpage.class.inc.php');
|
||||
require_once(APPROOT.'/application/webpage.class.inc.php');
|
||||
require_once(APPROOT.'/application/clipage.class.inc.php');
|
||||
require_once(APPROOT.'/core/background.inc.php');
|
||||
|
||||
$sConfigFile = APPCONF.ITOP_DEFAULT_ENV.'/'.ITOP_CONFIG_FILE;
|
||||
if (!file_exists($sConfigFile))
|
||||
|
||||
Reference in New Issue
Block a user