Commit ae1bc497 authored by Johan Cwiklinski's avatar Johan Cwiklinski
Browse files

Merge branch '9.5/bugfixes'

parents 47cd2189 b6cb3549
......@@ -41,6 +41,12 @@ include ('../inc/includes.php');
Session::checkCentralAccess();
$contractsupplier = new Contract_Supplier();
if (isset($_POST["add"])) {
if (!isset($_POST['contracts_id']) || empty($_POST['contracts_id'])) {
$message = sprintf(__('Mandatory fields are not filled. Please correct: %s'),
_n('Contract', 'Contract', 1));
Session::addMessageAfterRedirect($message, false, ERROR);
Html::back();
}
$contractsupplier->check(-1, CREATE, $_POST);
if (isset($_POST["contracts_id"]) && ($_POST["contracts_id"] > 0)
......
......@@ -33,6 +33,12 @@
include ('../inc/includes.php');
global $CFG_GLPI;
if ((int)$CFG_GLPI['use_anonymous_helpdesk'] === 0) {
Html::redirect($CFG_GLPI["root_doc"] . "/front/central.php");
}
echo "<!DOCTYPE html>";
echo "<html lang=\"{$CFG_GLPI["languages"][$_SESSION['glpilanguage']][3]}\">";
?>
......
......@@ -40,7 +40,13 @@ if (Session::getCurrentInterface() == "helpdesk") {
Html::header(Ticket::getTypeName(Session::getPluralNumber()), '', "helpdesk", "ticket");
}
echo Html::manageRefreshPage();
$callback = <<<JS
if ($('div[role="dialog"]:visible').length === 0) {
window.location.reload();
}
JS;
echo Html::manageRefreshPage(false, $callback);
if ($default = Glpi\Dashboard\Grid::getDefaultDashboardForMenu('mini_ticket', true)) {
$dashboard = new Glpi\Dashboard\Grid($default, 33, 2, 'mini_core');
......
......@@ -286,6 +286,12 @@ class DBmysqlIterator implements Iterator, Countable {
// WHERE criteria list
if (!empty($crit)) {
$this->sql .= " WHERE ".$this->analyseCrit($crit);
if ($where) {
trigger_error(
'Criteria found both inside and outside "WHERE" key. Some of them will be ignored',
E_USER_WARNING
);
}
} else if ($where) {
$this->sql .= " WHERE ".$this->analyseCrit($where);
}
......
......@@ -186,4 +186,12 @@ class Pdu_Plug extends CommonDBRelation {
}
}
}
function getForbiddenStandardMassiveAction() {
$forbidden = parent::getForbiddenStandardMassiveAction();
$forbidden[] = 'CommonDBConnexity:affect';
$forbidden[] = 'CommonDBConnexity:unaffect';
return $forbidden;
}
}
......@@ -1564,42 +1564,43 @@ class Transfer extends CommonDBTM {
function transferItemSoftwares($itemtype, $ID) {
global $DB;
if (isset($this->noneedtobe_transfer['SoftwareVersion']) && count($this->noneedtobe_transfer['SoftwareVersion'])) {
// Get Installed version
$criteria = [
'FROM' => 'glpi_items_softwareversions',
'WHERE' => [
'items_id' => $ID,
'itemtype' => $itemtype,
'NOT' => [
'softwareversions_id' => $this->noneedtobe_transfer['SoftwareVersion'],
]
]
];
$iterator = $DB->request($criteria);
// Get Installed version
$criteria = [
'FROM' => 'glpi_items_softwareversions',
'WHERE' => [
'items_id' => $ID,
'itemtype' => $itemtype,
]
];
while ($data = $iterator->next()) {
if ($this->options['keep_software']) {
$newversID = $this->copySingleVersion($data['softwareversions_id']);
if (count($this->noneedtobe_transfer['SoftwareVersion'] ?? [])) {
$criteria['WHERE']['NOT'] = [
'softwareversions_id' => $this->noneedtobe_transfer['SoftwareVersion'],
];
}
if (($newversID > 0)
&& ($newversID != $data['softwareversions_id'])) {
$DB->update(
'glpi_items_softwareversions', [
'softwareversions_id' => $newversID
], [
'id' => $data['id']
]
);
}
$iterator = $DB->request($criteria);
} else { // Do not keep
// Delete inst software for item
$DB->delete('glpi_items_softwareversions', ['id' => $data['id']]);
while ($data = $iterator->next()) {
if ($this->options['keep_software']) {
$newversID = $this->copySingleVersion($data['softwareversions_id']);
if (($newversID > 0)
&& ($newversID != $data['softwareversions_id'])) {
$DB->update(
'glpi_items_softwareversions', [
'softwareversions_id' => $newversID
], [
'id' => $data['id']
]
);
}
} // each installed version
}
} else { // Do not keep
// Delete inst software for item
$DB->delete('glpi_items_softwareversions', ['id' => $data['id']]);
}
} // each installed version
// Affected licenses
if ($this->options['keep_software']) {
......
......@@ -533,7 +533,7 @@ class Computer extends DbTestCase {
$computer,
[$cid]
);
$transfer->moveItems(['Computer' => [$cid]], $entities_id, [$cid]);
$transfer->moveItems(['Computer' => [$cid]], $entities_id, [$cid, 'keep_software' => 1]);
unset($_SESSION['glpitransfer_list']);
$this->boolean($computer->getFromDB($cid))->isTrue();
......
......@@ -32,7 +32,11 @@
namespace tests\units;
use Computer;
use DbTestCase;
use Item_SoftwareVersion;
use Software;
use SoftwareVersion;
/* Test for inc/transfer.class.php */
......@@ -250,4 +254,145 @@ class Transfer extends DbTestCase {
$this->integer((int)$rec['entities_id'])->isidenticalTo($dentity);
}
}
protected function testKeepSoftwareOptionProvider(): array {
$test_entity = getItemByTypeName('Entity', '_test_root_entity', true);
// Create test computers
$computers_to_create = [
'test_transfer_pc_1',
'test_transfer_pc_2',
'test_transfer_pc_3',
'test_transfer_pc_4',
];
foreach ($computers_to_create as $computer_name) {
$computer = new Computer();
$computers_id = $computer->add([
'name' => $computer_name,
'entities_id' => $test_entity,
]);
$this->integer($computers_id)->isGreaterThan(0);
}
// Create test softwares
$softwares_to_create = [
'test_transfer_software_1',
'test_transfer_software_2',
'test_transfer_software_3',
];
foreach ($softwares_to_create as $software_name) {
$software = new Software();
$softwares_id = $software->add([
'name' => $software_name,
'entities_id' => $test_entity,
]);
$this->integer($softwares_id)->isGreaterThan(0);
}
// Create test software versions
$software_versions_to_create = [
'test_transfer_software_1' => ['V1', 'V2'],
'test_transfer_software_2' => ['V1', 'V2'],
'test_transfer_software_3' => ['V1', 'V2'],
];
foreach ($software_versions_to_create as $software_name => $versions) {
foreach ($versions as $version) {
$softwareversion = new SoftwareVersion();
$softwareversions_id = $softwareversion->add([
'name' => $software_name . '::' . $version,
'softwares_id' => getItemByTypeName('Software', $software_name, true),
'entities_id' => $test_entity,
]);
$this->integer($softwareversions_id)->isGreaterThan(0);
}
}
// Link softwares and computers
$item_softwareversion_ids = [];
$item_softwareversion_to_create = [
'test_transfer_pc_1' => ['test_transfer_software_1::V1', 'test_transfer_software_2::V1'],
'test_transfer_pc_2' => ['test_transfer_software_1::V2', 'test_transfer_software_2::V2'],
'test_transfer_pc_3' => ['test_transfer_software_2::V1', 'test_transfer_software_3::V2'],
'test_transfer_pc_4' => ['test_transfer_software_1::V2', 'test_transfer_software_3::V1'],
];
foreach ($item_softwareversion_to_create as $computer_name => $versions) {
foreach ($versions as $version) {
$item_softwareversion = new Item_SoftwareVersion();
$item_softwareversions_id = $item_softwareversion->add([
'items_id' => getItemByTypeName('Computer', $computer_name, true),
'itemtype' => 'Computer',
'softwareversions_id' => getItemByTypeName('SoftwareVersion', $version, true),
'entities_id' => $test_entity,
]);
$this->integer($item_softwareversions_id)->isGreaterThan(0);
$item_softwareversion_ids[] = $item_softwareversions_id;
}
}
return [
[
'items' => [
'Computer' => [
getItemByTypeName('Computer', 'test_transfer_pc_1', true),
getItemByTypeName('Computer', 'test_transfer_pc_2', true),
]
],
'entities_id_destination' => $test_entity,
'transfer_options' => ['keep_software' => 1],
'expected_softwares_after_transfer' => [
'Computer' => [
getItemByTypeName('Computer', 'test_transfer_pc_1', true) => [
$item_softwareversion_ids[0],
$item_softwareversion_ids[1]
],
getItemByTypeName('Computer', 'test_transfer_pc_2', true) => [
$item_softwareversion_ids[2],
$item_softwareversion_ids[3]
],
]
]
],
[
'items' => [
'Computer' => [
getItemByTypeName('Computer', 'test_transfer_pc_3', true),
getItemByTypeName('Computer', 'test_transfer_pc_4', true),
]
],
'entities_id_destination' => $test_entity,
'transfer_options' => ['keep_software' => 0],
'expected_softwares_after_transfer' => [
'Computer' => [
getItemByTypeName('Computer', 'test_transfer_pc_3', true) => [],
getItemByTypeName('Computer', 'test_transfer_pc_4', true) => [],
]
]
]
];
}
/**
* @dataProvider testKeepSoftwareOptionProvider
*/
public function testKeepSoftwareOption(
array $items,
int $entities_id_destination,
array $transfer_options,
array $expected_softwares_after_transfer
): void {
$tranfer = new \Transfer();
$tranfer->moveItems($items, $entities_id_destination, $transfer_options);
foreach ($items as $itemtype => $ids) {
foreach ($ids as $id) {
$item_softwareversion = new Item_SoftwareVersion();
$data = $item_softwareversion->find([
'items_id' => $id,
'itemtype' => $itemtype
]);
$found_ids = array_column($data, 'id');
$this->array($found_ids)->isEqualTo($expected_softwares_after_transfer[$itemtype][$id]);
}
}
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment