Feature GLP11

This commit is contained in:
Stanislas
2025-06-26 16:16:43 +02:00
parent eea539b601
commit d16f837062
15 changed files with 394 additions and 380 deletions

View File

@@ -1,16 +1,26 @@
{
"require": {
"php": ">=7.4"
"php": ">=8.2"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.75",
"glpi-project/tools": "^0.7.5"
"friendsoftwig/twigcs": "^6.1",
"glpi-project/tools": "^0.7.5",
"php-parallel-lint/php-parallel-lint": "^1.4"
},
"config": {
"optimize-autoloader": true,
"platform": {
"php": "7.4.0"
"php": "8.2.99"
},
"sort-packages": true
"sort-packages": true,
"allow-plugins": {
"phpstan/extension-installer": true
}
},
"autoload-dev": {
"psr-4": {
"Glpi\\Tools\\": "../../tools/src/"
}
}
}

611
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -33,9 +33,7 @@
// Purpose of file:
// ----------------------------------------------------------------------
use GlpiPlugin\Example\Dropdown;
use GlpiPlugin\Example\Example;
use Dropdown as GlpiDropdown;
function plugin_change_profile_example()
{
@@ -72,7 +70,6 @@ function plugin_example_getAddSearchOptions($itemtype)
$sopt[1001]['linkfield'] = 'plugin_example_dropdowns_id';
$sopt[1001]['name'] = __('Example plugin', 'example');
}
return $sopt;
}
@@ -89,7 +86,6 @@ function plugin_example_getAddSearchOptionsNew($itemtype)
'name' => __('Example plugin new', 'example'),
];
}
return $options;
}
@@ -201,7 +197,6 @@ function plugin_example_forceGroupBy($type)
// Force add GROUP BY IN REQUEST
return true;
}
return false;
}
@@ -250,7 +245,7 @@ function plugin_example_addHaving($link, $nott, $type, $ID, $val, $num)
$ADD = " OR ITEM_$num IS NULL";
}
return " $LINK ( ITEM_" . $num . $SEARCH . " $ADD ) ";
return " $link ( ITEM_" . $num . $SEARCH . " $ADD ) ";
}
return '';
@@ -338,7 +333,6 @@ function plugin_example_MassiveActionsFieldsDisplay($options = [])
return true;
}
}
// Need to return false on non display item
return false;
}
@@ -616,7 +610,6 @@ function plugin_example_install()
// To be called for each task the plugin manage
// task in class
CronTask::Register(Example::class, 'Sample', DAY_TIMESTAMP, ['param' => 50]);
return true;
}
@@ -710,7 +703,7 @@ function plugin_example_postinit()
*
* @param $datas array
*
* @return un tableau
* @return array
**/
function plugin_retrieve_more_data_from_ldap_example(array $datas)
{
@@ -723,7 +716,7 @@ function plugin_retrieve_more_data_from_ldap_example(array $datas)
*
* @param $fields array
*
* @return un tableau
* @return array
**/
function plugin_retrieve_more_field_from_ldap_example($fields)
{
@@ -744,7 +737,6 @@ function plugin_example_Status($param)
$param['ok'] = false;
}
echo "\n";
return $param;
}
@@ -790,12 +782,15 @@ function plugin_example_filter_actors(array $params = []): array
function plugin_example_set_impact_icon(array $params)
{
/** @var array $CFG_GLPI */
global $CFG_GLPI;
$itemtype = $params['itemtype'];
$items_id = $params['items_id'];
$item = getItemForItemtype($itemtype);
if ($item instanceof Computer && $item->getFromDB($items_id)) {
return Plugin::getWebDir('example', true, false) . '/public/computer_icon.svg';
return $CFG_GLPI['root_doc'] . '/plugins/example/public/computer_icon.svg';
}
return null;

View File

@@ -42,9 +42,9 @@ use GlpiPlugin\Example\Showtabitem;
define('PLUGIN_EXAMPLE_VERSION', '0.0.1');
// Minimal GLPI version, inclusive
define('PLUGIN_EXAMPLE_MIN_GLPI', '10.0.0');
define('PLUGIN_EXAMPLE_MIN_GLPI', '11.0.0');
// Maximum GLPI version, exclusive
define('PLUGIN_EXAMPLE_MAX_GLPI', '10.0.99');
define('PLUGIN_EXAMPLE_MAX_GLPI', '11.0.99');
/**
* Init hooks of the plugin.
@@ -340,7 +340,6 @@ function plugin_example_check_prerequisites()
if (false) {
return false;
}
return true;
}
@@ -360,6 +359,5 @@ function plugin_example_check_config($verbose = false)
if ($verbose) {
echo __('Installed / not configured', 'example');
}
return false;
}

View File

@@ -59,25 +59,25 @@ class Child extends CommonDBChild
// - CommonDBConnexity::HAVE_SAME_RIGHT_ON_ITEM we must have at least update right
// on the item
// * $mustBeAttached: some CommonDBChild can be free, without any parent.
public static function canCreate()
public static function canCreate(): bool
{
return (Session::haveRight('internet', UPDATE)
&& parent::canCreate());
}
public static function canView()
public static function canView(): bool
{
return (Session::haveRight('internet', READ)
&& parent::canView());
}
public static function canUpdate()
public static function canUpdate(): bool
{
return (Session::haveRight('internet', UPDATE)
&& parent::canUpdate());
}
public static function canDelete()
public static function canDelete(): bool
{
return (Session::haveRight('internet', DELETE)
&& parent::canDelete());

View File

@@ -37,12 +37,6 @@ namespace GlpiPlugin\Example;
use CommonDBTM;
// Class of the defined type
if (!defined('GLPI_ROOT')) {
die("Sorry. You can't access directly to this file");
}
class Computer extends CommonDBTM
{
public static function showInfo()

View File

@@ -37,12 +37,6 @@ namespace GlpiPlugin\Example;
use CommonDevice;
// Class of the defined type
if (!defined('GLPI_ROOT')) {
die("Sorry. You can't access directly to this file");
}
/// Class DeviceCamera
class DeviceCamera extends CommonDevice
{

View File

@@ -1,30 +1,31 @@
<?php
/*
-------------------------------------------------------------------------
GLPI - Gestionnaire Libre de Parc Informatique
Copyright (C) 2003-2011 by the INDEPNET Development Team.
http://indepnet.net/ http://glpi-project.org
-------------------------------------------------------------------------
LICENSE
This file is part of GLPI.
GLPI 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 2 of the License, or
(at your option) any later version.
GLPI 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 GLPI. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
/**
* -------------------------------------------------------------------------
* Example plugin for GLPI
* -------------------------------------------------------------------------
*
* LICENSE
*
* This file is part of Example.
*
* Example 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 2 of the License, or
* (at your option) any later version.
*
* Example 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 Example. If not, see <http://www.gnu.org/licenses/>.
* -------------------------------------------------------------------------
* @copyright Copyright (C) 2006-2022 by Example plugin team.
* @license GPLv2 https://www.gnu.org/licenses/gpl-2.0.html
* @link https://github.com/pluginsGLPI/example
* -------------------------------------------------------------------------
*/
/**
@@ -57,10 +58,9 @@ along with GLPI. If not, see <http://www.gnu.org/licenses/>.
namespace GlpiPlugin\Example;
use Document as GlpiDocument;
if (!defined('GLPI_ROOT')) {
die("Sorry. You can't access this file directly");
}
use Exception;
use Glpi\Exception\Http\NotFoundHttpException;
use Sabre\DAV\Exception\BadRequest;
class Document extends GlpiDocument
{

View File

@@ -38,6 +38,7 @@ namespace GlpiPlugin\Example;
use CommonDBTM;
use CommonGLPI;
use Computer;
use DBmysql;
use Html;
use Log;
use MassiveAction;
@@ -487,7 +488,7 @@ class Example extends CommonDBTM
parent::processMassiveActionsForOneItemtype($ma, $item, $ids);
}
public static function generateLinkContents($link, CommonDBTM $item)
public static function generateLinkContents($link, CommonDBTM $item, bool $safe_url = true)
{
if (strstr($link, '[EXAMPLE_ID]')) {
$link = str_replace('[EXAMPLE_ID]', $item->getID(), $link);

View File

@@ -48,6 +48,7 @@ class ComputerModelFilter extends AbstractFilter
public static function canBeApplied(string $table): bool
{
/** @var DBmysql $DB */
global $DB;
return $DB->fieldExists($table, ComputerModel::getForeignKeyField());

View File

@@ -40,10 +40,6 @@ namespace GlpiPlugin\Example;
use GlpiPlugin\Example\DeviceCamera;
use Item_Devices;
if (!defined('GLPI_ROOT')) {
die("Sorry. You can't access directly to this file");
}
/**
* Relation between item and devices
**/

View File

@@ -32,10 +32,6 @@ namespace GlpiPlugin\Example;
use NotificationTarget;
if (!defined('GLPI_ROOT')) {
die("Sorry. You can't access directly to this file");
}
// Class NotificationTarget
class NotificationTargetExample extends NotificationTarget
{
@@ -46,8 +42,6 @@ class NotificationTargetExample extends NotificationTarget
public function addDataForTemplate($event, $options = [])
{
global $DB, $CFG_GLPI;
$this->data['##example.name##'] = __('Example', 'example');
}
}

View File

@@ -34,17 +34,27 @@ use CommonGLPI;
use Html;
use Session;
final class Profile extends \Profile
class Profile extends \Profile
{
public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0)
{
return __('Example plugin');
if (
$item instanceof \Profile
&& $item->getField('id')
) {
return self::createTabEntry(__('Example plugin'));
}
return '';
}
public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0)
{
$profile = new self();
$profile->showFormExample($item->getID());
if ($item instanceof self) {
$profile = new self();
$profile->showFormExample($item->getID());
}
return true;
}
public function showFormExample(int $profiles_id): void

View File

@@ -37,11 +37,6 @@ namespace GlpiPlugin\Example;
use Rule;
if (!defined('GLPI_ROOT')) {
die("Sorry. You can't access directly to this file");
}
/**
* Rule class store all informations about a GLPI rule :
* - description

View File

@@ -37,11 +37,6 @@ namespace GlpiPlugin\Example;
use RuleCollection;
if (!defined('GLPI_ROOT')) {
die("Sorry. You can't access directly to this file");
}
class RuleTestCollection extends RuleCollection
{
// From RuleCollection