mirror of
https://github.com/Combodo/iTop.git
synced 2026-05-16 05:48:47 +02:00
Merge branch 'split-file_bulkchange.class.inc.php' into feature/2535-split_file
This commit is contained in:
File diff suppressed because it is too large
Load Diff
1074
core/bulkchange/BulkChange.php
Normal file
1074
core/bulkchange/BulkChange.php
Normal file
File diff suppressed because it is too large
Load Diff
82
core/bulkchange/CellChangeSpec.php
Normal file
82
core/bulkchange/CellChangeSpec.php
Normal file
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* CellChangeSpec
|
||||
* A series of classes, keeping the information about a given cell: could it be changed or not (and why)?
|
||||
*
|
||||
* @package iTopORM
|
||||
*/
|
||||
abstract class CellChangeSpec
|
||||
{
|
||||
protected $m_proposedValue;
|
||||
protected $m_sOql; // in case of ambiguity
|
||||
|
||||
public function __construct($proposedValue, $sOql = '')
|
||||
{
|
||||
$this->m_proposedValue = $proposedValue;
|
||||
$this->m_sOql = $sOql;
|
||||
}
|
||||
|
||||
public function GetPureValue()
|
||||
{
|
||||
// Todo - distinguish both values
|
||||
return $this->m_proposedValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Exception
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function GetCLIValue(bool $bLocalizedValues = false): string
|
||||
{
|
||||
if (is_object($this->m_proposedValue)) {
|
||||
if ($this->m_proposedValue instanceof ReportValue) {
|
||||
return $this->m_proposedValue->GetAsCSV($bLocalizedValues, ',', '"');
|
||||
}
|
||||
throw new Exception('Unexpected class : ' . get_class($this->m_proposedValue));
|
||||
}
|
||||
return $this->m_proposedValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Exception
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function GetHTMLValue(bool $bLocalizedValues = false): string
|
||||
{
|
||||
if (is_object($this->m_proposedValue)) {
|
||||
if ($this->m_proposedValue instanceof ReportValue) {
|
||||
return $this->m_proposedValue->GetAsHTML($bLocalizedValues);
|
||||
}
|
||||
throw new Exception('Unexpected class : ' . get_class($this->m_proposedValue));
|
||||
}
|
||||
return utils::EscapeHtml($this->m_proposedValue);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @since 3.1.0 N°5305
|
||||
*/
|
||||
public function SetDisplayableValue(string $sDisplayableValue)
|
||||
{
|
||||
$this->m_proposedValue = $sDisplayableValue;
|
||||
}
|
||||
|
||||
public function GetOql()
|
||||
{
|
||||
return $this->m_sOql;
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function GetCLIValueAndDescription(): string
|
||||
{
|
||||
return sprintf("%s%s",
|
||||
$this->GetCLIValue(),
|
||||
$this->GetDescription()
|
||||
);
|
||||
}
|
||||
|
||||
abstract public function GetDescription();
|
||||
}
|
||||
43
core/bulkchange/CellStatus_Ambiguous.php
Normal file
43
core/bulkchange/CellStatus_Ambiguous.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
class CellStatus_Ambiguous extends CellStatus_Issue
|
||||
{
|
||||
protected $m_iCount;
|
||||
/**
|
||||
* @since 3.1.0 N°5305
|
||||
* @var string
|
||||
*/
|
||||
protected $sSerializedSearch;
|
||||
|
||||
/**
|
||||
* @param $previousValue
|
||||
* @param int $iCount
|
||||
* @param string $sSerializedSearch
|
||||
*
|
||||
* @since 3.1.0 N°5305
|
||||
*
|
||||
*/
|
||||
public function __construct($previousValue, $iCount, $sSerializedSearch)
|
||||
{
|
||||
$this->m_iCount = $iCount;
|
||||
$this->sSerializedSearch = $sSerializedSearch;
|
||||
parent::__construct(null, $previousValue, '');
|
||||
}
|
||||
|
||||
public function GetDescription()
|
||||
{
|
||||
$sCount = $this->m_iCount;
|
||||
return Dict::Format('UI:CSVReport-Value-Ambiguous', $sCount);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
* @since 3.1.0 N°5305
|
||||
*/
|
||||
public function GetSearchLinkUrl()
|
||||
{
|
||||
return sprintf("UI.php?operation=search&filter=%s",
|
||||
rawurlencode($this->sSerializedSearch ?? "")
|
||||
);
|
||||
}
|
||||
}
|
||||
47
core/bulkchange/CellStatus_Issue.php
Normal file
47
core/bulkchange/CellStatus_Issue.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
class CellStatus_Issue extends CellStatus_Modify
|
||||
{
|
||||
protected $m_sReason;
|
||||
|
||||
public function __construct($proposedValue, $previousValue, $sReason)
|
||||
{
|
||||
$this->m_sReason = $sReason;
|
||||
parent::__construct($proposedValue, $previousValue);
|
||||
}
|
||||
|
||||
public function GetCLIValue(bool $bLocalizedValues = false): string
|
||||
{
|
||||
if (is_null($this->m_proposedValue)) {
|
||||
return Dict::Format('UI:CSVReport-Value-SetIssue');
|
||||
}
|
||||
return Dict::Format('UI:CSVReport-Value-ChangeIssue', $this->m_proposedValue);
|
||||
}
|
||||
|
||||
public function GetHTMLValue(bool $bLocalizedValues = false): string
|
||||
{
|
||||
if (is_null($this->m_proposedValue)) {
|
||||
return Dict::Format('UI:CSVReport-Value-SetIssue');
|
||||
}
|
||||
if ($this->m_proposedValue instanceof ReportValue) {
|
||||
return Dict::Format('UI:CSVReport-Value-ChangeIssue', $this->m_proposedValue->GetAsHTML($bLocalizedValues));
|
||||
}
|
||||
return Dict::Format('UI:CSVReport-Value-ChangeIssue', utils::EscapeHtml($this->m_proposedValue));
|
||||
}
|
||||
|
||||
public function GetDescription()
|
||||
{
|
||||
return $this->m_sReason;
|
||||
}
|
||||
|
||||
/*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function GetCLIValueAndDescription(): string
|
||||
{
|
||||
return sprintf("%s. %s",
|
||||
$this->GetCLIValue(),
|
||||
$this->GetDescription()
|
||||
);
|
||||
}
|
||||
}
|
||||
23
core/bulkchange/CellStatus_Modify.php
Normal file
23
core/bulkchange/CellStatus_Modify.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
class CellStatus_Modify extends CellChangeSpec
|
||||
{
|
||||
protected $m_previousValue;
|
||||
|
||||
public function __construct($proposedValue, $previousValue = null)
|
||||
{
|
||||
// Unused (could be costly to know -see the case of reconciliation on ext keys)
|
||||
//$this->m_previousValue = $previousValue;
|
||||
parent::__construct($proposedValue);
|
||||
}
|
||||
|
||||
public function GetDescription()
|
||||
{
|
||||
return Dict::S('UI:CSVReport-Value-Modified');
|
||||
}
|
||||
|
||||
//public function GetPreviousValue()
|
||||
//{
|
||||
// return $this->m_previousValue;
|
||||
//}
|
||||
}
|
||||
14
core/bulkchange/CellStatus_NullIssue.php
Normal file
14
core/bulkchange/CellStatus_NullIssue.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
class CellStatus_NullIssue extends CellStatus_Issue
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct(null, null, null);
|
||||
}
|
||||
|
||||
public function GetDescription()
|
||||
{
|
||||
return Dict::S('UI:CSVReport-Value-Missing');
|
||||
}
|
||||
}
|
||||
91
core/bulkchange/CellStatus_SearchIssue.php
Normal file
91
core/bulkchange/CellStatus_SearchIssue.php
Normal file
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
|
||||
class CellStatus_SearchIssue extends CellStatus_Issue
|
||||
{
|
||||
/** @var string|null $m_sAllowedValues */
|
||||
private $m_sAllowedValues;
|
||||
|
||||
/**
|
||||
* @since 3.1.0 N°5305
|
||||
* @var string $sSerializedSearch
|
||||
*/
|
||||
private $sSerializedSearch;
|
||||
|
||||
/** @var string|null $m_sTargetClass */
|
||||
private $m_sTargetClass;
|
||||
|
||||
/**
|
||||
* @since 3.1.0 N°5305
|
||||
* @var string $sAllowedValuesSearch
|
||||
*/
|
||||
private $sAllowedValuesSearch;
|
||||
|
||||
/**
|
||||
* CellStatus_SearchIssue constructor.
|
||||
* @param string $sOql : main message
|
||||
* @param string $sReason : main message
|
||||
* @param null $sClass : used for additional message that provides allowed values for current class $sClass
|
||||
* @param null $sAllowedValues : used for additional message that provides allowed values $sAllowedValues for current class
|
||||
* @param string|null $sAllowedValuesSearch : used to search all allowed values
|
||||
* @since 3.1.0 N°5305
|
||||
*
|
||||
*/
|
||||
public function __construct($sSerializedSearch, $sReason, $sClass = null, $sAllowedValues = null, string $sAllowedValuesSearch = null)
|
||||
{
|
||||
parent::__construct(null, null, $sReason);
|
||||
$this->sSerializedSearch = $sSerializedSearch;
|
||||
$this->m_sAllowedValues = $sAllowedValues;
|
||||
$this->m_sTargetClass = $sClass;
|
||||
$this->sAllowedValuesSearch = $sAllowedValuesSearch;
|
||||
}
|
||||
|
||||
public function GetCLIValue(bool $bLocalizedValues = false): string
|
||||
{
|
||||
if (null === $this->m_sReason) {
|
||||
return Dict::Format('UI:CSVReport-Value-NoMatch', '');
|
||||
}
|
||||
|
||||
return $this->m_sReason;
|
||||
}
|
||||
|
||||
public function GetHTMLValue(bool $bLocalizedValues = false): string
|
||||
{
|
||||
if (null === $this->m_sReason) {
|
||||
return Dict::Format('UI:CSVReport-Value-NoMatch', '');
|
||||
}
|
||||
|
||||
return utils::EscapeHtml($this->m_sReason);
|
||||
}
|
||||
|
||||
public function GetDescription()
|
||||
{
|
||||
if (\utils::IsNullOrEmptyString($this->m_sAllowedValues) ||
|
||||
\utils::IsNullOrEmptyString($this->m_sTargetClass)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return Dict::Format('UI:CSVReport-Value-NoMatch-PossibleValues', $this->m_sTargetClass, $this->m_sAllowedValues);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
* @since 3.1.0 N°5305
|
||||
*/
|
||||
public function GetSearchLinkUrl()
|
||||
{
|
||||
return sprintf("UI.php?operation=search&filter=%s",
|
||||
rawurlencode($this->sSerializedSearch ?? "")
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null|string
|
||||
* @since 3.1.0 N°5305
|
||||
*/
|
||||
public function GetAllowedValuesLinkUrl(): ?string
|
||||
{
|
||||
return sprintf("UI.php?operation=search&filter=%s",
|
||||
rawurlencode($this->sAllowedValuesSearch ?? "")
|
||||
);
|
||||
}
|
||||
}
|
||||
9
core/bulkchange/CellStatus_Void.php
Normal file
9
core/bulkchange/CellStatus_Void.php
Normal file
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
class CellStatus_Void extends CellChangeSpec
|
||||
{
|
||||
public function GetDescription()
|
||||
{
|
||||
return '';
|
||||
}
|
||||
}
|
||||
32
core/bulkchange/ReportValue.php
Normal file
32
core/bulkchange/ReportValue.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Class to differ formatting depending on the caller
|
||||
*/
|
||||
class ReportValue
|
||||
{
|
||||
/**
|
||||
* @param DBObject $oObject
|
||||
* @param string $sAttCode
|
||||
* @param bool $bOriginal
|
||||
*/
|
||||
public function __construct(protected DBObject $oObject, protected string $sAttCode, protected bool $bOriginal)
|
||||
{
|
||||
}
|
||||
|
||||
public function GetAsHTML(bool $bLocalizedValues)
|
||||
{
|
||||
if ($this->bOriginal) {
|
||||
return $this->oObject->GetOriginalAsHTML($this->sAttCode, $bLocalizedValues);
|
||||
}
|
||||
return $this->oObject->GetAsHTML($this->sAttCode, $bLocalizedValues);
|
||||
}
|
||||
|
||||
public function GetAsCSV(bool $bLocalizedValues, string $sCsvSep, string $sCsvDelimiter)
|
||||
{
|
||||
if ($this->bOriginal) {
|
||||
return $this->oObject->GetOriginalAsCSV($this->sAttCode, $sCsvSep, $sCsvDelimiter, $bLocalizedValues);
|
||||
}
|
||||
return $this->oObject->GetAsCSV($this->sAttCode, $sCsvSep, $sCsvDelimiter, $bLocalizedValues);
|
||||
}
|
||||
}
|
||||
16
core/bulkchange/RowStatus.php
Normal file
16
core/bulkchange/RowStatus.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* RowStatus
|
||||
* A series of classes, keeping the information about a given row: could it be changed or not (and why)?
|
||||
*
|
||||
* @package iTopORM
|
||||
*/
|
||||
abstract class RowStatus
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
abstract public function GetDescription();
|
||||
}
|
||||
9
core/bulkchange/RowStatus_Disappeared.php
Normal file
9
core/bulkchange/RowStatus_Disappeared.php
Normal file
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
class RowStatus_Disappeared extends RowStatus_Modify
|
||||
{
|
||||
public function GetDescription()
|
||||
{
|
||||
return Dict::Format('UI:CSVReport-Row-Disappeared', $this->m_iChanged);
|
||||
}
|
||||
}
|
||||
22
core/bulkchange/RowStatus_Error.php
Normal file
22
core/bulkchange/RowStatus_Error.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* class dedicated to testability
|
||||
* not used/ignored in csv imports UI/CLI
|
||||
* @since 3.1.0 N°5305
|
||||
*/
|
||||
class RowStatus_Error extends RowStatus
|
||||
{
|
||||
/** @var string */
|
||||
protected $m_sError;
|
||||
|
||||
public function __construct($sError)
|
||||
{
|
||||
$this->m_sError = $sError;
|
||||
}
|
||||
|
||||
public function GetDescription()
|
||||
{
|
||||
return $this->m_sError;
|
||||
}
|
||||
}
|
||||
16
core/bulkchange/RowStatus_Issue.php
Normal file
16
core/bulkchange/RowStatus_Issue.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
class RowStatus_Issue extends RowStatus
|
||||
{
|
||||
protected $m_sReason;
|
||||
|
||||
public function __construct($sReason)
|
||||
{
|
||||
$this->m_sReason = $sReason;
|
||||
}
|
||||
|
||||
public function GetDescription()
|
||||
{
|
||||
return Dict::Format('UI:CSVReport-Row-Issue', $this->m_sReason);
|
||||
}
|
||||
}
|
||||
16
core/bulkchange/RowStatus_Modify.php
Normal file
16
core/bulkchange/RowStatus_Modify.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
class RowStatus_Modify extends RowStatus
|
||||
{
|
||||
protected $m_iChanged;
|
||||
|
||||
public function __construct($iChanged)
|
||||
{
|
||||
$this->m_iChanged = $iChanged;
|
||||
}
|
||||
|
||||
public function GetDescription()
|
||||
{
|
||||
return Dict::Format('UI:CSVReport-Row-Updated', $this->m_iChanged);
|
||||
}
|
||||
}
|
||||
9
core/bulkchange/RowStatus_NewObj.php
Normal file
9
core/bulkchange/RowStatus_NewObj.php
Normal file
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
class RowStatus_NewObj extends RowStatus
|
||||
{
|
||||
public function GetDescription()
|
||||
{
|
||||
return Dict::S('UI:CSVReport-Row-Created');
|
||||
}
|
||||
}
|
||||
9
core/bulkchange/RowStatus_NoChange.php
Normal file
9
core/bulkchange/RowStatus_NoChange.php
Normal file
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
class RowStatus_NoChange extends RowStatus
|
||||
{
|
||||
public function GetDescription()
|
||||
{
|
||||
return Dict::S('UI:CSVReport-Row-Unchanged');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user