Finish 1.0.0

This commit is contained in:
Pierre Goiffon
2019-01-18 17:28:22 +01:00
10 changed files with 388 additions and 392 deletions

9
.gitflow Normal file
View File

@@ -0,0 +1,9 @@
[gitflow "branch"]
master = master
develop = develop
[gitflow "prefix"]
feature = feature/
release = release/
hotfix = hotfix/
versiontag =
support = support/

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
/.idea/**

View File

@@ -1,5 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<itop_design xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.3">
<!--
@copyright Copyright (C) 2010-2019 Combodo SARL
@license https://www.combodo.com/documentation/combodo-software-license.html
-->
<classes>
<class id="ExpirationRule" _delta="define">
<parent>cmdbAbstractObject</parent>
@@ -25,12 +29,12 @@
<default_value/>
<is_null_allowed>false</is_null_allowed>
</field>
<field id="description" xsi:type="AttributeText">
<sql>description</sql>
<default_value/>
<is_null_allowed>true</is_null_allowed>
<format>html</format>
</field>
<field id="description" xsi:type="AttributeText">
<sql>description</sql>
<default_value/>
<is_null_allowed>true</is_null_allowed>
<format>html</format>
</field>
<field id="class" xsi:type="AttributeString">
<sql>class</sql>
<default_value/>
@@ -282,7 +286,7 @@
$oBlock->Display($oPage, 'rel_preview_rule_'.$this->GetKey(), $aParams);
}]]></code>
</method>
</methods>
</methods>
<presentation>
<list>
<items>

View File

@@ -1,28 +1,16 @@
<?php
// Copyright (C) 2012-2018 Combodo SARL
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; version 3 of the License.
//
// This program 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 General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
/**
* Localized data
*
* @copyright Copyright (C) 2010-2019 Combodo SARL
* @license https://www.combodo.com/documentation/combodo-software-license.html
*
* @author Erwan Taloc <erwan.taloc@combodo.com>
* @author Romain Quetiez <romain.quetiez@combodo.com>
* @author Denis Flaven <denis.flaven@combodo.com>
* @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
* @author Vincent Dumas <vincent.dumas@combodo.com>
* @license http://www.opensource.org/licenses/gpl-3.0.html LGPL
*/
// ExpirationRule

View File

@@ -1,28 +1,16 @@
<?php
// Copyright (C) 2012-2018 Combodo SARL
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; version 3 of the License.
//
// This program 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 General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
/**
* Localized data
*
* @copyright Copyright (C) 2010-2019 Combodo SARL
* @license https://www.combodo.com/documentation/combodo-software-license.html
*
* @author Erwan Taloc <erwan.taloc@combodo.com>
* @author Romain Quetiez <romain.quetiez@combodo.com>
* @author Denis Flaven <denis.flaven@combodo.com>
* @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
* @author Vincent Dumas <vincent.dumas@combodo.com>
* @license http://www.opensource.org/licenses/gpl-3.0.html LGPL
*/
// ExpirationRule

View File

@@ -1,28 +1,16 @@
<?php
// Copyright (C) 2012-2018 Combodo SARL
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; version 3 of the License.
//
// This program 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 General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
/**
* Localized data
*
* @copyright Copyright (C) 2010-2019 Combodo SARL
* @license https://www.combodo.com/documentation/combodo-software-license.html
*
* @author Erwan Taloc <erwan.taloc@combodo.com>
* @author Romain Quetiez <romain.quetiez@combodo.com>
* @author Denis Flaven <denis.flaven@combodo.com>
* @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
* @author Vincent Dumas <vincent.dumas@combodo.com>
* @license http://www.opensource.org/licenses/gpl-3.0.html LGPL
*/
// ClosingRule

View File

@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<licenses>
<license>
<product>Notify on expiration</product>
<author>2010-2019 Combodo SARL</author>
<license_type>Combodo Software License</license_type>
<text><![CDATA[
<h3>Combodo Software License</h3>
<p>Version 1.0</p>
<p>Copyright (c) 2018 Combodo SARL. All rights reserved.</p>
<p>Redistribution and use in source and binary forms, with or without modification, of this software is permitted provided that the following conditions are met:</p>
<ol>
<li>Combodo grants you a non-exclusive, non-sublicensable and non-transferable license to install and use the software for your own business purposes, in accordance with this agreement, the documentation and all laws.</li>
<li>Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.</li>
<li>Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.</li>
<li>The redistribution of the software covered by this license is limited to the individual or the company who purchased the software and its affiliates.</li>
<li>You cannot rent, lease, distribute, sell, sublicense, or transfer the software.</li>
<li>The use of the software is <b>limited to only one set of production data</b> (i.e. only one instance of iTop managing production data).</li>
<li>In the context of this license, the interaction with the installed software across a computer network is not considered as a redistribution.</li>
<li>Combodo SARL may publish revised and/or new versions of the license from time to time. Each version will be given a distinguishing version number.</li>
Once covered code has been published under a particular version of the license, you may always continue to use it under the terms of that version. You may also choose to use such covered code under the terms of any subsequent version of the license published by Combodo SARL. No one other than Combodo SARL has the right to modify the terms applicable to covered code created under this License.</li>
</ol>
<p>THIS SOFTWARE IS PROVIDED BY COMBODO SARL “AS IS” AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL COMBODO SARL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
For more information on Combodo SARL, please see <a href="https://www.combodo.com">https://www.combodo.com</a>.</p>
]]></text>
</license>
</licenses>

View File

@@ -1,29 +1,15 @@
<?php
// Copyright (C) 2012-2018 Combodo SARL
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; version 3 of the License.
//
// This program 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 General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
/**
* Module combodo-notify-on-expiration
*
* @copyright Copyright (C) 2010-2019 Combodo SARL
* @license https://www.combodo.com/documentation/combodo-software-license.html
*
* @author Erwan Taloc <erwan.taloc@combodo.com>
* @author Romain Quetiez <romain.quetiez@combodo.com>
* @author Denis Flaven <denis.flaven@combodo.com>
* @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
* @author Vincent Dumas <vincent.dumas@combodo.com>
* @license http://www.opensource.org/licenses/gpl-3.0.html LGPL
*/
@@ -33,10 +19,11 @@
class NotifyOnExpiration implements iScheduledProcess
{
const MODULE_CODE = 'combodo-notify-on-expiration';
const MODULE_SETTING_ENABLED = 'enabled';
const MODULE_SETTING_DEBUG = 'debug';
const MODULE_SETTING_WEEKDAYS = 'week_days';
const MODULE_SETTING_TIME = 'time';
const KEY_MODULE_SETTING_ENABLED = 'enabled';
const KEY_MODULE_SETTING_DEBUG = 'debug';
const KEY_MODULE_SETTING_WEEKDAYS = 'week_days';
const KEY_MODULE_SETTING_TIME = 'time';
const DEFAULT_MODULE_SETTING_ENABLED = true;
const DEFAULT_MODULE_SETTING_DEBUG = false;
@@ -50,17 +37,20 @@ class NotifyOnExpiration implements iScheduledProcess
*/
function __construct()
{
$this->bDebug = (bool) MetaModel::GetModuleSetting(static::MODULE_CODE, static::MODULE_SETTING_DEBUG, static::DEFAULT_MODULE_SETTING_DEBUG);
$this->bDebug = (bool)MetaModel::GetModuleSetting(static::MODULE_CODE, static::KEY_MODULE_SETTING_DEBUG,
static::DEFAULT_MODULE_SETTING_DEBUG);
}
/**
* Gives the exact time at which the process must be run next time
*
* @return \DateTime
* @throws \CoreUnexpectedValue
*/
public function GetNextOccurrence()
{
$bEnabled = MetaModel::GetConfig()->GetModuleSetting(static::MODULE_CODE, static::MODULE_SETTING_ENABLED, static::DEFAULT_MODULE_SETTING_ENABLED);
$bEnabled = MetaModel::GetConfig()->GetModuleSetting(static::MODULE_CODE, static::KEY_MODULE_SETTING_ENABLED,
static::DEFAULT_MODULE_SETTING_ENABLED);
if (!$bEnabled)
{
$oRet = new DateTime('3000-01-01');
@@ -73,14 +63,15 @@ class NotifyOnExpiration implements iScheduledProcess
// 2nd - Find the next active week day
//
$sRunTime = MetaModel::GetConfig()->GetModuleSetting(static::MODULE_CODE, static::MODULE_SETTING_TIME, static::DEFAULT_MODULE_SETTING_TIME);
$sRunTime = MetaModel::GetConfig()->GetModuleSetting(static::MODULE_CODE, static::KEY_MODULE_SETTING_TIME,
static::DEFAULT_MODULE_SETTING_TIME);
if (!preg_match('/^([01]?\d|2[0-3]):[0-5]?\d(:[0-5]?\d)?$/', $sRunTime, $aMatches))
{
throw new Exception(static::MODULE_CODE.": wrong format for setting 'time' (found '$sRunTime')");
throw new CoreUnexpectedValue(static::MODULE_CODE.": wrong format for setting 'time' (found '$sRunTime')");
}
$oNow = new DateTime();
$iNextPos = false;
for ($iDay = $oNow->format('N') ; $iDay <= 7 ; $iDay++)
for ($iDay = $oNow->format('N'); $iDay <= 7; $iDay++)
{
$iNextPos = array_search($iDay, $aDays);
if ($iNextPos !== false)
@@ -111,13 +102,21 @@ class NotifyOnExpiration implements iScheduledProcess
$oRet = clone $oNow;
$oRet->modify('+'.$iMove.' days');
}
$oRet->setTime((int)$aMatches[1], (int) $aMatches[2]);
$oRet->setTime((int)$aMatches[1], (int)$aMatches[2]);
}
return $oRet;
}
/**
* @inheritdoc
*
* @throws \CoreException
* @throws \CoreUnexpectedValue
* @throws \MissingQueryArgument
* @throws \MySQLException
* @throws \MySQLHasGoneAwayException
* @throws \OQLException
*/
public function Process($iTimeLimit)
{
@@ -133,7 +132,7 @@ class NotifyOnExpiration implements iScheduledProcess
$this->Trace('Processing '.$oRulesSet->Count().' active expiration rules...');
$iTotalProcessedObjectsCount = 0;
while($oRule = $oRulesSet->Fetch())
while ($oRule = $oRulesSet->Fetch())
{
$iRuleProcessedObjectsCount = 0;
$this->Trace('Processing rule "'.$oRule->Get('friendlyname').'" (#'.$oRule->GetKey().')...');
@@ -150,13 +149,13 @@ class NotifyOnExpiration implements iScheduledProcess
// Prepare the Rule information to be passed to the notification
$aRuleContext = $oRule->ToArgs('rule');
// Get applicable Triggers for this object class
// Get applicable Triggers for this object class
$sClassList = implode("', '", MetaModel::EnumParentClasses($sClass, ENUM_PARENT_CLASSES_ALL));
$oTriggerSet = new DBObjectSet(DBObjectSearch::FromOQL("SELECT TriggerOnExpirationRule AS t WHERE t.target_class IN ('$sClassList')"));
$oSet = new DBObjectSet($oSearch);
$this->Trace('|- Objects:');
/** @var $oToTrigger DBObject */
/** @var DBObject $oToTrigger */
while ((time() < $iTimeLimit) && $oToTrigger = $oSet->Fetch())
{
// Catching exceptions so the process don't get stucked on this object
@@ -168,11 +167,12 @@ class NotifyOnExpiration implements iScheduledProcess
// Combine the current object :this and :rule to be available in the notification
$aContext = $oToTrigger->ToArgs('this');
$aContext = array_merge($aContext, $aRuleContext);
/** @var TriggerOnExpirationRule $oTrigger */
while ($oTrigger = $oTriggerSet->Fetch())
{
$oTrigger->DoActivate($aContext);
}
// The same set of Triggers is reused for each object returned by the Rule as they all belongs to the same class
// The same set of Triggers is reused for each object returned by the Rule as they all belongs to the same class
$oTriggerSet->Rewind();
$iRuleProcessedObjectsCount++;
@@ -184,7 +184,7 @@ class NotifyOnExpiration implements iScheduledProcess
} // Trigger was NOT applied because of an exception, which is NOT normal
catch (Exception $e)
{
$aReport['not_triggered'][] = $oToClose->Get('friendlyname');
$aReport['not_triggered'][] = $oToTrigger->Get('friendlyname');
$this->Trace('| |- [KO] /!\\ '.$sClass.' #'.$oToTrigger->GetKey().' exception raised! Error message: '.$e->getMessage());
}
@@ -197,14 +197,14 @@ class NotifyOnExpiration implements iScheduledProcess
$this->Trace('Stopped because time limit exceeded!');
}
}
catch(Exception $e)
catch (Exception $e)
{
$this->Trace('Skipping rule as there was an exception! ('.$e->getMessage().')');
}
}
// Report
if($aReport['reached_deadline'] === 0)
if ($aReport['reached_deadline'] === 0)
{
return 'No object to process';
}
@@ -213,17 +213,18 @@ class NotifyOnExpiration implements iScheduledProcess
$iClosedCount = count($aReport['triggered']);
$iNotClosedCount = count($aReport['not_triggered']);
$sReport = $aReport['reached_deadline'] . " objects reached triggering date";
$sReport = $aReport['reached_deadline']." objects reached triggering date";
$sReport .= " - ".$iClosedCount." were triggered";
if($iClosedCount > 0)
if ($iClosedCount > 0)
{
$sReport .= " (".implode(", ", $aReport['triggered']).")";
}
$sReport .= " - ".$iNotClosedCount." were not triggered";
if($iNotClosedCount > 0)
if ($iNotClosedCount > 0)
{
$sReport .= " (".implode(", ", $aReport['not_triggered']).")";
}
return $sReport;
}
}
@@ -234,12 +235,22 @@ class NotifyOnExpiration implements iScheduledProcess
* Note: This comes from itop-backup scheduled task.
*
* @returns array of int (monday = 1)
* @throws \CoreUnexpectedValue
*/
public function InterpretWeekDays()
{
static $aWEEKDAYTON = array('monday' => 1, 'tuesday' => 2, 'wednesday' => 3, 'thursday' => 4, 'friday' => 5, 'saturday' => 6, 'sunday' => 7);
static $aWEEKDAYTON = array(
'monday' => 1,
'tuesday' => 2,
'wednesday' => 3,
'thursday' => 4,
'friday' => 5,
'saturday' => 6,
'sunday' => 7,
);
$aDays = array();
$sWeekDays = MetaModel::GetConfig()->GetModuleSetting(static::MODULE_CODE, static::MODULE_SETTING_WEEKDAYS, static::DEFAULT_MODULE_SETTING_WEEKDAYS);
$sWeekDays = MetaModel::GetConfig()->GetModuleSetting(static::MODULE_CODE, static::KEY_MODULE_SETTING_WEEKDAYS,
static::DEFAULT_MODULE_SETTING_WEEKDAYS);
if ($sWeekDays != '')
{
$aWeekDaysRaw = explode(',', $sWeekDays);
@@ -252,16 +263,17 @@ class NotifyOnExpiration implements iScheduledProcess
}
else
{
throw new Exception(static::MODULE_CODE.": wrong format for setting 'week_days' (found '$sWeekDay')");
throw new CoreUnexpectedValue(static::MODULE_CODE.": wrong format for setting 'week_days' (found '$sWeekDay')");
}
}
}
if (count($aDays) == 0)
{
throw new Exception(static::MODULE_CODE.": missing setting 'week_days'");
throw new CoreUnexpectedValue(static::MODULE_CODE.": missing setting 'week_days'");
}
$aDays = array_unique($aDays);
sort($aDays);
return $aDays;
}

View File

@@ -1,22 +1,14 @@
<?php
// Copyright (C) 2012-2018 Combodo SARL
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; version 3 of the License.
//
// This program 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 General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
/**
*
* @copyright Copyright (C) 2010-2019 Combodo SARL
* @license https://www.combodo.com/documentation/combodo-software-license.html
*
*/
SetupWebPage::AddModule(
__FILE__, // Path to the current file, all other file names are relative to the directory containing this file
'combodo-notify-on-expiration/0.1.0',
'combodo-notify-on-expiration/1.0.0',
array(
// Identification
//
@@ -35,7 +27,6 @@ SetupWebPage::AddModule(
// Components
//
'datamodel' => array(
'model.combodo-notify-on-expiration.php',
'main.combodo-notify-on-expiration.php',
'triggerexpirationrule.class.inc.php',
),

View File

@@ -1,21 +1,9 @@
<?php
// Copyright (C) 2012-2016 Combodo SARL
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation; version 3 of the License.
//
// This program 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 General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
/**
* @copyright Copyright (C) 2012-2016 Combodo SARL
* @license http://opensource.org/licenses/AGPL-3.0
*
* @copyright Copyright (C) 2010-2019 Combodo SARL
* @license https://www.combodo.com/documentation/combodo-software-license.html
*
*/
/**