Merge branch 'split-file_bulkchange.class.inc.php' into feature/2535-split_file

This commit is contained in:
anne-catherine
2025-09-02 16:46:15 +00:00
17 changed files with 1512 additions and 1673 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View 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();
}

View 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 ?? "")
);
}
}

View 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()
);
}
}

View 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;
//}
}

View 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');
}
}

View 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 ?? "")
);
}
}

View File

@@ -0,0 +1,9 @@
<?php
class CellStatus_Void extends CellChangeSpec
{
public function GetDescription()
{
return '';
}
}

View 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);
}
}

View 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();
}

View 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);
}
}

View 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;
}
}

View 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);
}
}

View 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);
}
}

View File

@@ -0,0 +1,9 @@
<?php
class RowStatus_NewObj extends RowStatus
{
public function GetDescription()
{
return Dict::S('UI:CSVReport-Row-Created');
}
}

View File

@@ -0,0 +1,9 @@
<?php
class RowStatus_NoChange extends RowStatus
{
public function GetDescription()
{
return Dict::S('UI:CSVReport-Row-Unchanged');
}
}