Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom Asset Type and Model Dictionaries #17669

Merged
merged 7 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 3 additions & 69 deletions .phpstan-baseline.php
Original file line number Diff line number Diff line change
@@ -1,72 +1,6 @@
<?php declare(strict_types = 1);

$ignoreErrors = [];
$ignoreErrors[] = [
// identifier: classConstant.nonObject
'message' => '#^Cannot access constant class on object\\|false\\.$#',
'count' => 6,
'path' => __DIR__ . '/front/asset/asset.form.php',
];
$ignoreErrors[] = [
// identifier: staticProperty.nonObject
'message' => '#^Cannot access static property \\$rightname on object\\|false\\.$#',
'count' => 1,
'path' => __DIR__ . '/front/asset/asset.form.php',
];
$ignoreErrors[] = [
// identifier: method.nonObject
'message' => '#^Cannot call method add\\(\\) on object\\|false\\.$#',
'count' => 1,
'path' => __DIR__ . '/front/asset/asset.form.php',
];
$ignoreErrors[] = [
// identifier: method.nonObject
'message' => '#^Cannot call method check\\(\\) on object\\|false\\.$#',
'count' => 5,
'path' => __DIR__ . '/front/asset/asset.form.php',
];
$ignoreErrors[] = [
// identifier: method.nonObject
'message' => '#^Cannot call method delete\\(\\) on object\\|false\\.$#',
'count' => 2,
'path' => __DIR__ . '/front/asset/asset.form.php',
];
$ignoreErrors[] = [
// identifier: method.nonObject
'message' => '#^Cannot call method getLinkURL\\(\\) on object\\|false\\.$#',
'count' => 1,
'path' => __DIR__ . '/front/asset/asset.form.php',
];
$ignoreErrors[] = [
// identifier: method.nonObject
'message' => '#^Cannot call method redirectToList\\(\\) on object\\|false\\.$#',
'count' => 3,
'path' => __DIR__ . '/front/asset/asset.form.php',
];
$ignoreErrors[] = [
// identifier: method.nonObject
'message' => '#^Cannot call method restore\\(\\) on object\\|false\\.$#',
'count' => 1,
'path' => __DIR__ . '/front/asset/asset.form.php',
];
$ignoreErrors[] = [
// identifier: method.nonObject
'message' => '#^Cannot call method update\\(\\) on object\\|false\\.$#',
'count' => 1,
'path' => __DIR__ . '/front/asset/asset.form.php',
];
$ignoreErrors[] = [
// identifier: staticMethod.nonObject
'message' => '#^Cannot call static method displayFullPageForItem\\(\\) on object\\|false\\.$#',
'count' => 1,
'path' => __DIR__ . '/front/asset/asset.form.php',
];
$ignoreErrors[] = [
// identifier: staticMethod.nonObject
'message' => '#^Cannot call static method getDefinition\\(\\) on object\\|false\\.$#',
'count' => 1,
'path' => __DIR__ . '/front/asset/asset.form.php',
];
$ignoreErrors[] = [
// identifier: booleanOr.alwaysFalse
'message' => '#^Result of \\|\\| is always false\\.$#',
Expand Down Expand Up @@ -2001,7 +1935,7 @@
];
$ignoreErrors[] = [
// identifier: return.type
'message' => '#^Method Glpi\\\\Asset\\\\Asset\\:\\:getById\\(\\) should return static\\(Glpi\\\\Asset\\\\Asset\\)\\|false but returns object\\.$#',
'message' => '#^Method Glpi\\\\Asset\\\\Asset\\:\\:getById\\(\\) should return static\\(Glpi\\\\Asset\\\\Asset\\)\\|false but returns Glpi\\\\Asset\\\\Asset\\.$#',
'count' => 1,
'path' => __DIR__ . '/src/Glpi/Asset/Asset.php',
];
Expand All @@ -2019,13 +1953,13 @@
];
$ignoreErrors[] = [
// identifier: return.type
'message' => '#^Method Glpi\\\\Asset\\\\AssetModel\\:\\:getById\\(\\) should return static\\(Glpi\\\\Asset\\\\AssetModel\\)\\|false but returns object\\.$#',
'message' => '#^Method Glpi\\\\Asset\\\\AssetModel\\:\\:getById\\(\\) should return static\\(Glpi\\\\Asset\\\\AssetModel\\)\\|false but returns Glpi\\\\Asset\\\\AssetModel\\.$#',
'count' => 1,
'path' => __DIR__ . '/src/Glpi/Asset/AssetModel.php',
];
$ignoreErrors[] = [
// identifier: return.type
'message' => '#^Method Glpi\\\\Asset\\\\AssetType\\:\\:getById\\(\\) should return static\\(Glpi\\\\Asset\\\\AssetType\\)\\|false but returns object\\.$#',
'message' => '#^Method Glpi\\\\Asset\\\\AssetType\\:\\:getById\\(\\) should return static\\(Glpi\\\\Asset\\\\AssetType\\)\\|false but returns Glpi\\\\Asset\\\\AssetType\\.$#',
'count' => 1,
'path' => __DIR__ . '/src/Glpi/Asset/AssetType.php',
];
Expand Down
3 changes: 3 additions & 0 deletions front/asset/asset.form.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@

if (array_key_exists('id', $_REQUEST) && !Asset::isNewId($_REQUEST['id'])) {
$asset = Asset::getById($_REQUEST['id']);
if ($asset === false) {
$asset = null;
}
} else {
$definition = new AssetDefinition();
$classname = array_key_exists('class', $_GET) && $definition->getFromDBBySystemName((string)$_GET['class'])
Expand Down
51 changes: 51 additions & 0 deletions front/asset/ruledictionarymodel.form.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

/**
* ---------------------------------------------------------------------
*
* GLPI - Gestionnaire Libre de Parc Informatique
*
* http://glpi-project.org
*
* @copyright 2015-2024 Teclib' and contributors.
* @copyright 2003-2014 by the INDEPNET Development Team.
* @licence https://www.gnu.org/licenses/gpl-3.0.html
*
* ---------------------------------------------------------------------
*
* LICENSE
*
* This file is part of GLPI.
*
* 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, either version 3 of the License, or
* (at your option) any later version.
*
* 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, see <https://www.gnu.org/licenses/>.
*
* ---------------------------------------------------------------------
*/

use Glpi\Asset\AssetDefinition;
use Glpi\Http\Response;

$definition = new AssetDefinition();
$classname = array_key_exists('class', $_GET) && $definition->getFromDBBySystemName((string)$_GET['class'])
? $definition->getAssetClassName()
: null;

if ($classname === null || !class_exists($classname)) {
Response::sendError(400, 'Bad request', Response::CONTENT_TYPE_TEXT_HTML);
}

$rulecollection_class = $definition->getAssetModelDictionaryCollectionClassName();
$rulecollection = new $rulecollection_class();

include(GLPI_ROOT . "/front/rule.common.form.php");
51 changes: 51 additions & 0 deletions front/asset/ruledictionarymodel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

/**
* ---------------------------------------------------------------------
*
* GLPI - Gestionnaire Libre de Parc Informatique
*
* http://glpi-project.org
*
* @copyright 2015-2024 Teclib' and contributors.
* @copyright 2003-2014 by the INDEPNET Development Team.
* @licence https://www.gnu.org/licenses/gpl-3.0.html
*
* ---------------------------------------------------------------------
*
* LICENSE
*
* This file is part of GLPI.
*
* 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, either version 3 of the License, or
* (at your option) any later version.
*
* 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, see <https://www.gnu.org/licenses/>.
*
* ---------------------------------------------------------------------
*/

use Glpi\Asset\AssetDefinition;
use Glpi\Http\Response;

$definition = new AssetDefinition();
$classname = array_key_exists('class', $_GET) && $definition->getFromDBBySystemName((string)$_GET['class'])
? $definition->getAssetClassName()
: null;

if ($classname === null || !class_exists($classname)) {
Response::sendError(400, 'Bad request', Response::CONTENT_TYPE_TEXT_HTML);
}

$rulecollection_class = $definition->getAssetModelDictionaryCollectionClassName();
$rulecollection = new $rulecollection_class();

include(GLPI_ROOT . "/front/rule.common.php");
51 changes: 51 additions & 0 deletions front/asset/ruledictionarytype.form.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

/**
* ---------------------------------------------------------------------
*
* GLPI - Gestionnaire Libre de Parc Informatique
*
* http://glpi-project.org
*
* @copyright 2015-2024 Teclib' and contributors.
* @copyright 2003-2014 by the INDEPNET Development Team.
* @licence https://www.gnu.org/licenses/gpl-3.0.html
*
* ---------------------------------------------------------------------
*
* LICENSE
*
* This file is part of GLPI.
*
* 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, either version 3 of the License, or
* (at your option) any later version.
*
* 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, see <https://www.gnu.org/licenses/>.
*
* ---------------------------------------------------------------------
*/

use Glpi\Asset\AssetDefinition;
use Glpi\Http\Response;

$definition = new AssetDefinition();
$classname = array_key_exists('class', $_GET) && $definition->getFromDBBySystemName((string)$_GET['class'])
? $definition->getAssetClassName()
: null;

if ($classname === null || !class_exists($classname)) {
Response::sendError(400, 'Bad request', Response::CONTENT_TYPE_TEXT_HTML);
}

$rulecollection_class = $definition->getAssetTypeDictionaryCollectionClassName();
$rulecollection = new $rulecollection_class();

include(GLPI_ROOT . "/front/rule.common.form.php");
51 changes: 51 additions & 0 deletions front/asset/ruledictionarytype.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

/**
* ---------------------------------------------------------------------
*
* GLPI - Gestionnaire Libre de Parc Informatique
*
* http://glpi-project.org
*
* @copyright 2015-2024 Teclib' and contributors.
* @copyright 2003-2014 by the INDEPNET Development Team.
* @licence https://www.gnu.org/licenses/gpl-3.0.html
*
* ---------------------------------------------------------------------
*
* LICENSE
*
* This file is part of GLPI.
*
* 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, either version 3 of the License, or
* (at your option) any later version.
*
* 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, see <https://www.gnu.org/licenses/>.
*
* ---------------------------------------------------------------------
*/

use Glpi\Asset\AssetDefinition;
use Glpi\Http\Response;

$definition = new AssetDefinition();
$classname = array_key_exists('class', $_GET) && $definition->getFromDBBySystemName((string)$_GET['class'])
? $definition->getAssetClassName()
: null;

if ($classname === null || !class_exists($classname)) {
Response::sendError(400, 'Bad request', Response::CONTENT_TYPE_TEXT_HTML);
}

$rulecollection_class = $definition->getAssetTypeDictionaryCollectionClassName();
$rulecollection = new $rulecollection_class();

include(GLPI_ROOT . "/front/rule.common.php");
2 changes: 1 addition & 1 deletion front/rule.common.form.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
"setup",
sprintf(__('%1$s adds the item %2$s'), $_SESSION["glpiname"], $newID)
);
Html::redirect($_SERVER['HTTP_REFERER'] . "?id=$newID");
Html::redirect($rule->getFormURLWithID($newID));
} else if (isset($_POST["purge"])) {
$rulecollection->checkGlobal(PURGE);
$rulecollection->deleteRuleOrder($_POST["ranking"]);
Expand Down
Loading
Loading