" . __('Back') . '';
+ echo "
';
Html::popFooter();
}
diff --git a/front/ruletest.form.php b/front/ruletest.form.php
index e48a834..6235f3c 100644
--- a/front/ruletest.form.php
+++ b/front/ruletest.form.php
@@ -35,7 +35,7 @@
use GlpiPlugin\Example\RuleTestCollection;
-include('../../../inc/includes.php');
+include(__DIR__ . '/../../../inc/includes.php');
Session::checkLoginUser();
$rulecollection = new RuleTestCollection();
diff --git a/front/ruletest.php b/front/ruletest.php
index 16ea9e6..22dd6f1 100644
--- a/front/ruletest.php
+++ b/front/ruletest.php
@@ -35,7 +35,7 @@
use GlpiPlugin\Example\RuleTestCollection;
-include('../../../inc/includes.php');
+include(__DIR__ . '/../../../inc/includes.php');
Session::checkLoginUser();
$rulecollection = new RuleTestCollection();
diff --git a/hook.php b/hook.php
index 2484b2e..c7c5983 100644
--- a/hook.php
+++ b/hook.php
@@ -33,9 +33,7 @@
// Purpose of file:
// ----------------------------------------------------------------------
-use GlpiPlugin\Example\Dropdown;
use GlpiPlugin\Example\Example;
-use Dropdown as GlpiDropdown;
function plugin_change_profile_example()
{
@@ -54,7 +52,7 @@ function plugin_example_getDatabaseRelations()
function plugin_example_getDropdown()
{
// Table => Name
- return [Dropdown::class => __('Plugin Example Dropdown', 'example')];
+ return [Dropdown::class => __s('Plugin Example Dropdown', 'example')];
}
@@ -70,9 +68,8 @@ function plugin_example_getAddSearchOptions($itemtype)
$sopt[1001]['table'] = 'glpi_plugin_example_dropdowns';
$sopt[1001]['field'] = 'name';
$sopt[1001]['linkfield'] = 'plugin_example_dropdowns_id';
- $sopt[1001]['name'] = __('Example plugin', 'example');
+ $sopt[1001]['name'] = __s('Example plugin', 'example');
}
-
return $sopt;
}
@@ -86,10 +83,9 @@ function plugin_example_getAddSearchOptionsNew($itemtype)
'table' => 'glpi_plugin_example_dropdowns',
'field' => 'name',
'linkfield' => 'plugin_example_dropdowns_id',
- 'name' => __('Example plugin new', 'example'),
+ 'name' => __s('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;
}
@@ -212,7 +207,7 @@ function plugin_example_addWhere($link, $nott, $type, $ID, $val, $searchtype)
$table = $searchopt[$ID]['table'];
$field = $searchopt[$ID]['field'];
- $SEARCH = Search::makeTextSearch($val, $nott);
+ Search::makeTextSearch($val, $nott);
// Example of standard Where clause but use it ONLY for specific Where
// No need of the function if you do not have specific cases
@@ -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 '';
@@ -260,8 +255,6 @@ function plugin_example_addHaving($link, $nott, $type, $ID, $val, $num)
function plugin_example_addSelect($type, $ID, $num)
{
$searchopt = &Search::getOptions($type);
- $table = $searchopt[$ID]['table'];
- $field = $searchopt[$ID]['field'];
// Example of standard Select clause but use it ONLY for specific Select
// No need of the function if you do not have specific cases
@@ -276,8 +269,6 @@ function plugin_example_addSelect($type, $ID, $num)
function plugin_example_addOrderBy($type, $ID, $order, $key = 0)
{
$searchopt = &Search::getOptions($type);
- $table = $searchopt[$ID]['table'];
- $field = $searchopt[$ID]['field'];
// Example of standard OrderBy clause but use it ONLY for specific order by
// No need of the function if you do not have specific cases
@@ -299,7 +290,7 @@ function plugin_example_MassiveActions($type)
switch ($type) {
// New action for core and other plugin types : name = plugin_PLUGINNAME_actionname
case 'Computer':
- return [Example::class . MassiveAction::CLASS_ACTION_SEPARATOR . 'DoIt' => __('plugin_example_DoIt', 'example')];
+ return [Example::class . MassiveAction::CLASS_ACTION_SEPARATOR . 'DoIt' => __s('plugin_example_DoIt', 'example')];
// Actions for types provided by the plugin are included inside the classes
}
@@ -316,13 +307,12 @@ function plugin_example_MassiveActionsFieldsDisplay($options = [])
$table = $options['options']['table'];
$field = $options['options']['field'];
- $linkfield = $options['options']['linkfield'];
if ($table == getTableForItemType($options['itemtype'])) {
// Table fields
switch ($table . '.' . $field) {
case 'glpi_plugin_example_examples.serial':
- echo __('Not really specific - Just for example', 'example');
+ echo __s('Not really specific - Just for example', 'example');
// Dropdown::showYesNo($linkfield);
// Need to return true if specific display
@@ -332,13 +322,12 @@ function plugin_example_MassiveActionsFieldsDisplay($options = [])
// Linked Fields
switch ($table . '.' . $field) {
case 'glpi_plugin_example_dropdowns.name':
- echo __('Not really specific - Just for example', 'example');
+ echo __s('Not really specific - Just for example', 'example');
// Need to return true if specific display
return true;
}
}
-
// Need to return false on non display item
return false;
}
@@ -355,8 +344,8 @@ function plugin_example_searchOptionsValues($options = [])
// Table fields
switch ($table . '.' . $field) {
case 'glpi_plugin_example_examples.serial':
- echo __('Not really specific - Use your own dropdown - Just for example', 'example');
- GlpiDropdown::show(
+ echo __s('Not really specific - Use your own dropdown - Just for example', 'example');
+ Dropdown::show(
getItemTypeForTable($options['searchoption']['table']),
['value' => $options['value'],
'name' => $options['name'],
@@ -382,14 +371,14 @@ function plugin_pre_item_update_example($item)
}
$item->input['comment'] .= addslashes("\nUpdate: ".date('r'));
*/
- Session::addMessageAfterRedirect(__('Pre Update Computer Hook', 'example'), true);
+ Session::addMessageAfterRedirect(__s('Pre Update Computer Hook', 'example'), true);
}
// Hook done on update item case
function plugin_item_update_example($item)
{
- Session::addMessageAfterRedirect(sprintf(__('Update Computer Hook (%s)', 'example'), implode(',', $item->updates)), true);
+ Session::addMessageAfterRedirect(sprintf(__s('Update Computer Hook (%s)', 'example'), implode(',', $item->updates)), true);
return true;
}
@@ -399,7 +388,7 @@ function plugin_item_update_example($item)
function plugin_item_empty_example($item)
{
if (empty($_SESSION['Already displayed "Empty Computer Hook"'])) {
- Session::addMessageAfterRedirect(__('Empty Computer Hook', 'example'), true);
+ Session::addMessageAfterRedirect(__s('Empty Computer Hook', 'example'), true);
$_SESSION['Already displayed "Empty Computer Hook"'] = true;
}
@@ -411,14 +400,14 @@ function plugin_item_empty_example($item)
function plugin_pre_item_delete_example($object)
{
// Manipulate data if needed
- Session::addMessageAfterRedirect(__('Pre Delete Computer Hook', 'example'), true);
+ Session::addMessageAfterRedirect(__s('Pre Delete Computer Hook', 'example'), true);
}
// Hook done on delete item case
function plugin_item_delete_example($object)
{
- Session::addMessageAfterRedirect(__('Delete Computer Hook', 'example'), true);
+ Session::addMessageAfterRedirect(__s('Delete Computer Hook', 'example'), true);
return true;
}
@@ -428,14 +417,14 @@ function plugin_item_delete_example($object)
function plugin_pre_item_purge_example($object)
{
// Manipulate data if needed
- Session::addMessageAfterRedirect(__('Pre Purge Computer Hook', 'example'), true);
+ Session::addMessageAfterRedirect(__s('Pre Purge Computer Hook', 'example'), true);
}
// Hook done on purge item case
function plugin_item_purge_example($object)
{
- Session::addMessageAfterRedirect(__('Purge Computer Hook', 'example'), true);
+ Session::addMessageAfterRedirect(__s('Purge Computer Hook', 'example'), true);
return true;
}
@@ -445,7 +434,7 @@ function plugin_item_purge_example($object)
function plugin_pre_item_restore_example($item)
{
// Manipulate data if needed
- Session::addMessageAfterRedirect(__('Pre Restore Computer Hook', 'example'));
+ Session::addMessageAfterRedirect(__s('Pre Restore Computer Hook', 'example'));
}
@@ -453,14 +442,14 @@ function plugin_pre_item_restore_example($item)
function plugin_pre_item_restore_example2($item)
{
// Manipulate data if needed
- Session::addMessageAfterRedirect(__('Pre Restore Phone Hook', 'example'));
+ Session::addMessageAfterRedirect(__s('Pre Restore Phone Hook', 'example'));
}
// Hook done on restore item case
function plugin_item_restore_example($item)
{
- Session::addMessageAfterRedirect(__('Restore Computer Hook', 'example'));
+ Session::addMessageAfterRedirect(__s('Restore Computer Hook', 'example'));
return true;
}
@@ -471,7 +460,7 @@ function plugin_item_transfer_example($parm)
{
//TRANS: %1$s is the source type, %2$d is the source ID, %3$d is the destination ID
Session::addMessageAfterRedirect(sprintf(
- __('Transfer Computer Hook %1$s %2$d -> %3$d', 'example'),
+ __s('Transfer Computer Hook %1$s %2$d -> %3$d', 'example'),
$parm['type'],
$parm['id'],
$parm['newID'],
@@ -551,7 +540,7 @@ function plugin_example_install()
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET={$default_charset} COLLATE={$default_collation} ROW_FORMAT=DYNAMIC;";
- $DB->query($query) or die('error creating glpi_plugin_example_examples ' . $DB->error());
+ $DB->doQuery($query);
$query = "INSERT INTO `glpi_plugin_example_examples`
(`id`, `name`, `serial`, `plugin_example_dropdowns_id`, `is_deleted`,
@@ -559,7 +548,7 @@ function plugin_example_install()
VALUES (1, 'example 1', 'serial 1', 1, 0, 0, NULL),
(2, 'example 2', 'serial 2', 2, 0, 0, NULL),
(3, 'example 3', 'serial 3', 1, 0, 0, NULL)";
- $DB->query($query) or die('error populate glpi_plugin_example ' . $DB->error());
+ $DB->doQuery($query);
}
if (!$DB->tableExists('glpi_plugin_example_dropdowns')) {
@@ -571,14 +560,14 @@ function plugin_example_install()
KEY `name` (`name`)
) ENGINE=InnoDB DEFAULT CHARSET={$default_charset} COLLATE={$default_collation} ROW_FORMAT=DYNAMIC;";
- $DB->query($query) or die('error creating glpi_plugin_example_dropdowns' . $DB->error());
+ $DB->doQuery($query);
$query = "INSERT INTO `glpi_plugin_example_dropdowns`
(`id`, `name`, `comment`)
VALUES (1, 'dp 1', 'comment 1'),
(2, 'dp2', 'comment 2')";
- $DB->query($query) or die('error populate glpi_plugin_example_dropdowns' . $DB->error());
+ $DB->doQuery($query);
}
if (!$DB->tableExists('glpi_plugin_example_devicecameras')) {
@@ -592,7 +581,7 @@ function plugin_example_install()
KEY `manufacturers_id` (`manufacturers_id`)
) ENGINE=InnoDB DEFAULT CHARSET={$default_charset} COLLATE={$default_collation} ROW_FORMAT=DYNAMIC;";
- $DB->query($query) or die('error creating glpi_plugin_example_examples ' . $DB->error());
+ $DB->doQuery($query);
}
if (!$DB->tableExists('glpi_plugin_example_items_devicecameras')) {
@@ -610,13 +599,12 @@ function plugin_example_install()
KEY `is_dynamic` (`is_dynamic`)
) ENGINE=InnoDB DEFAULT CHARSET={$default_charset} COLLATE={$default_collation} ROW_FORMAT=DYNAMIC;";
- $DB->query($query) or die('error creating glpi_plugin_example_examples ' . $DB->error());
+ $DB->doQuery($query);
}
// To be called for each task the plugin manage
// task in class
CronTask::Register(Example::class, 'Sample', DAY_TIMESTAMP, ['param' => 50]);
-
return true;
}
@@ -645,28 +633,28 @@ function plugin_example_uninstall()
// Old version tables
if ($DB->tableExists('glpi_dropdown_plugin_example')) {
$query = 'DROP TABLE `glpi_dropdown_plugin_example`';
- $DB->query($query) or die('error deleting glpi_dropdown_plugin_example');
+ $DB->doQuery($query);
}
if ($DB->tableExists('glpi_plugin_example')) {
$query = 'DROP TABLE `glpi_plugin_example`';
- $DB->query($query) or die('error deleting glpi_plugin_example');
+ $DB->doQuery($query);
}
// Current version tables
if ($DB->tableExists('glpi_plugin_example_example')) {
$query = 'DROP TABLE `glpi_plugin_example_example`';
- $DB->query($query) or die('error deleting glpi_plugin_example_example');
+ $DB->doQuery($query);
}
if ($DB->tableExists('glpi_plugin_example_dropdowns')) {
$query = 'DROP TABLE `glpi_plugin_example_dropdowns`;';
- $DB->query($query) or die('error deleting glpi_plugin_example_dropdowns');
+ $DB->doQuery($query);
}
if ($DB->tableExists('glpi_plugin_example_devicecameras')) {
$query = 'DROP TABLE `glpi_plugin_example_devicecameras`;';
- $DB->query($query) or die('error deleting glpi_plugin_example_devicecameras');
+ $DB->doQuery($query);
}
if ($DB->tableExists('glpi_plugin_example_items_devicecameras')) {
$query = 'DROP TABLE `glpi_plugin_example_items_devicecameras`;';
- $DB->query($query) or die('error deleting glpi_plugin_example_items_devicecameras');
+ $DB->doQuery($query);
}
return true;
@@ -683,13 +671,13 @@ function plugin_example_AssignToTicket($types)
function plugin_example_get_events(NotificationTargetTicket $target)
{
- $target->events['plugin_example'] = __('Example event', 'example');
+ $target->events['plugin_example'] = __s('Example event', 'example');
}
function plugin_example_get_datas(NotificationTargetTicket $target)
{
- $target->data['##ticket.example##'] = __('Example datas', 'example');
+ $target->data['##ticket.example##'] = __s('Example datas', 'example');
}
@@ -710,7 +698,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 +711,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)
{
@@ -736,6 +724,7 @@ function plugin_example_Status($param)
// Do checks (no check for example)
$ok = true;
echo 'example plugin: example';
+
if ($ok) {
echo '_OK';
} else {
@@ -744,7 +733,6 @@ function plugin_example_Status($param)
$param['ok'] = false;
}
echo "\n";
-
return $param;
}
@@ -752,7 +740,7 @@ function plugin_example_display_central()
{
echo "
";
echo " ";
- echo __('Plugin example displays on central page', 'example');
+ echo __s('Plugin example displays on central page', 'example');
echo ' ';
echo ' |
---|
';
}
@@ -760,21 +748,20 @@ function plugin_example_display_central()
function plugin_example_display_login()
{
echo "
";
- echo __('Plugin example displays on login page', 'example');
+ echo __s('Plugin example displays on login page', 'example');
echo '
';
}
function plugin_example_infocom_hook($params)
{
echo "
";
- echo __('Plugin example displays on central page', 'example');
+ echo __s('Plugin example displays on central page', 'example');
echo ' |
---|
';
}
function plugin_example_filter_actors(array $params = []): array
{
$itemtype = $params['params']['itemtype'];
- $items_id = $params['params']['items_id'];
// remove users_id = 1 for assignee list
if ($itemtype == 'Ticket' && $params['params']['actortype'] == 'assign') {
@@ -790,12 +777,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;
diff --git a/phpstan.neon b/phpstan.neon
new file mode 100644
index 0000000..8cf33ad
--- /dev/null
+++ b/phpstan.neon
@@ -0,0 +1,19 @@
+parameters:
+ parallel:
+ maximumNumberOfProcesses: 2
+ level: 5
+ paths:
+ - front
+ - src
+ - hook.php
+ - report.php
+ - setup.php
+ - stat.php
+ scanDirectories:
+ - ../../inc
+ - ../../src
+ - ../../front
+ bootstrapFiles:
+ - ../../stubs/glpi_constants.php
+ - ../../vendor/autoload.php
+
diff --git a/psalm.xml b/psalm.xml
new file mode 100644
index 0000000..7958e23
--- /dev/null
+++ b/psalm.xml
@@ -0,0 +1,24 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/rector.php b/rector.php
new file mode 100644
index 0000000..5b24fa4
--- /dev/null
+++ b/rector.php
@@ -0,0 +1,97 @@
+.
+ * -------------------------------------------------------------------------
+ * @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
+ * -------------------------------------------------------------------------
+ */
+
+require_once __DIR__ . '/../../src/Plugin.php';
+
+use Rector\Caching\ValueObject\Storage\FileCacheStorage;
+use Rector\CodeQuality\Rector as CodeQuality;
+use Rector\Config\RectorConfig;
+use Rector\DeadCode\Rector as DeadCode;
+use Rector\ValueObject\PhpVersion;
+
+return RectorConfig::configure()
+ ->withPaths([
+ __DIR__ . '/front',
+ __DIR__ . '/src',
+ ])
+ ->withPhpVersion(PhpVersion::PHP_82)
+ ->withCache(
+ cacheClass: FileCacheStorage::class,
+ cacheDirectory: sys_get_temp_dir() . '/example-rector',
+ )
+ ->withRootFiles()
+ ->withParallel(timeoutSeconds: 300)
+ ->withImportNames(removeUnusedImports: true)
+ ->withRules([
+ CodeQuality\Assign\CombinedAssignRector::class,
+ CodeQuality\BooleanAnd\RemoveUselessIsObjectCheckRector::class,
+ CodeQuality\BooleanAnd\SimplifyEmptyArrayCheckRector::class,
+ CodeQuality\BooleanNot\ReplaceMultipleBooleanNotRector::class,
+ CodeQuality\Catch_\ThrowWithPreviousExceptionRector::class,
+ CodeQuality\Empty_\SimplifyEmptyCheckOnEmptyArrayRector::class,
+ CodeQuality\Expression\InlineIfToExplicitIfRector::class,
+ CodeQuality\Expression\TernaryFalseExpressionToIfRector::class,
+ CodeQuality\For_\ForRepeatedCountToOwnVariableRector::class,
+ CodeQuality\Foreach_\ForeachItemsAssignToEmptyArrayToAssignRector::class,
+ CodeQuality\Foreach_\ForeachToInArrayRector::class,
+ CodeQuality\Foreach_\SimplifyForeachToCoalescingRector::class,
+ CodeQuality\Foreach_\UnusedForeachValueToArrayKeysRector::class,
+ CodeQuality\FuncCall\ChangeArrayPushToArrayAssignRector::class,
+ CodeQuality\FuncCall\CompactToVariablesRector::class,
+ CodeQuality\FuncCall\InlineIsAInstanceOfRector::class,
+ CodeQuality\FuncCall\IsAWithStringWithThirdArgumentRector::class,
+ CodeQuality\FuncCall\RemoveSoleValueSprintfRector::class,
+ CodeQuality\FuncCall\SetTypeToCastRector::class,
+ CodeQuality\FuncCall\SimplifyFuncGetArgsCountRector::class,
+ CodeQuality\FuncCall\SimplifyInArrayValuesRector::class,
+ CodeQuality\FuncCall\SimplifyStrposLowerRector::class,
+ CodeQuality\FuncCall\UnwrapSprintfOneArgumentRector::class,
+ CodeQuality\Identical\BooleanNotIdenticalToNotIdenticalRector::class,
+ CodeQuality\Identical\SimplifyArraySearchRector::class,
+ CodeQuality\Identical\SimplifyConditionsRector::class,
+ CodeQuality\Identical\StrlenZeroToIdenticalEmptyStringRector::class,
+ CodeQuality\If_\CombineIfRector::class,
+ CodeQuality\If_\CompleteMissingIfElseBracketRector::class,
+ CodeQuality\If_\ConsecutiveNullCompareReturnsToNullCoalesceQueueRector::class,
+ CodeQuality\If_\ExplicitBoolCompareRector::class,
+ CodeQuality\If_\ShortenElseIfRector::class,
+ CodeQuality\If_\SimplifyIfElseToTernaryRector::class,
+ CodeQuality\If_\SimplifyIfNotNullReturnRector::class,
+ CodeQuality\If_\SimplifyIfNullableReturnRector::class,
+ CodeQuality\If_\SimplifyIfReturnBoolRector::class,
+ CodeQuality\Include_\AbsolutizeRequireAndIncludePathRector::class,
+ CodeQuality\LogicalAnd\AndAssignsToSeparateLinesRector::class,
+ CodeQuality\LogicalAnd\LogicalToBooleanRector::class,
+ CodeQuality\NotEqual\CommonNotEqualRector::class,
+ CodeQuality\Ternary\UnnecessaryTernaryExpressionRector::class,
+ DeadCode\Assign\RemoveUnusedVariableAssignRector::class,
+ ])
+ ->withPhpSets(php74: true) // apply PHP sets up to PHP 7.4
+;
diff --git a/setup.php b/setup.php
index 8d71794..7a24a49 100644
--- a/setup.php
+++ b/setup.php
@@ -27,24 +27,24 @@
* @link https://github.com/pluginsGLPI/example
* -------------------------------------------------------------------------
*/
-
use Glpi\Plugin\Hooks;
use GlpiPlugin\Example\Computer;
use GlpiPlugin\Example\Config;
-use GlpiPlugin\Example\Dropdown;
use GlpiPlugin\Example\DeviceCamera;
+use GlpiPlugin\Example\Dropdown;
use GlpiPlugin\Example\Example;
use GlpiPlugin\Example\Filters\ComputerModelFilter;
use GlpiPlugin\Example\ItemForm;
+use GlpiPlugin\Example\Profile;
use GlpiPlugin\Example\RuleTestCollection;
use GlpiPlugin\Example\Showtabitem;
-define('PLUGIN_EXAMPLE_VERSION', '0.0.1');
+define('PLUGIN_EXAMPLE_VERSION', '0.1.0');
// 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.
@@ -86,13 +86,11 @@ function plugin_init_example()
['device_types' => true],
);
- if (version_compare(GLPI_VERSION, '9.1', 'ge')) {
- if (class_exists(Example::class)) {
- Link::registerTag(Example::$tags);
- }
+ if (version_compare(GLPI_VERSION, '9.1', 'ge') && class_exists(Example::class)) {
+ Link::registerTag(Example::$tags);
}
// Display a menu entry ?
- Plugin::registerClass(\GlpiPlugin\Example\Profile::class, ['addtabon' => ['Profile']]);
+ Plugin::registerClass(Profile::class, ['addtabon' => ['Profile']]);
if (Example::canView()) { // Right set in change_profile hook
$PLUGIN_HOOKS['menu_toadd']['example'] = ['plugins' => Example::class,
'tools' => Example::class];
@@ -250,9 +248,6 @@ function plugin_init_example()
$PLUGIN_HOOKS['status']['example'] = 'plugin_example_Status';
- // CSRF compliance : All actions must be done via POST and forms closed by Html::closeForm();
- $PLUGIN_HOOKS[Hooks::CSRF_COMPLIANT]['example'] = true;
-
$PLUGIN_HOOKS[Hooks::DISPLAY_CENTRAL]['example'] = 'plugin_example_display_central';
$PLUGIN_HOOKS[Hooks::DISPLAY_LOGIN]['example'] = 'plugin_example_display_login';
$PLUGIN_HOOKS[Hooks::INFOCOM]['example'] = 'plugin_example_infocom_hook';
@@ -267,11 +262,8 @@ function plugin_init_example()
$PLUGIN_HOOKS[Hooks::PRE_ITEM_FORM]['example'] = [ItemForm::class, 'preItemForm'];
$PLUGIN_HOOKS[Hooks::POST_ITEM_FORM]['example'] = [ItemForm::class, 'postItemForm'];
- //TODO: remove check when GLPI 11.0.0 is released
- if (version_compare(GLPI_VERSION, '11.0.0', 'ge')) {
- $PLUGIN_HOOKS[Hooks::PRE_ITIL_INFO_SECTION]['example'] = [ItemForm::class, 'preSection'];
- $PLUGIN_HOOKS[Hooks::POST_ITIL_INFO_SECTION]['example'] = [ItemForm::class, 'postSection'];
- }
+ $PLUGIN_HOOKS[Hooks::PRE_ITIL_INFO_SECTION]['example'] = [ItemForm::class, 'preSection'];
+ $PLUGIN_HOOKS[Hooks::POST_ITIL_INFO_SECTION]['example'] = [ItemForm::class, 'postSection'];
// Add new actions to timeline
$PLUGIN_HOOKS[Hooks::TIMELINE_ACTIONS]['example'] = [
@@ -297,11 +289,8 @@ function plugin_init_example()
ComputerModelFilter::class,
];
- //TODO: remove check when GLPI 11.0.0 is released
- if (version_compare(GLPI_VERSION, '11.0.0', 'ge')) {
- // Icon in the impact analysis
- $PLUGIN_HOOKS[Hooks::SET_ITEM_IMPACT_ICON]['example'] = 'plugin_example_set_impact_icon';
- }
+ // Icon in the impact analysis
+ $PLUGIN_HOOKS[Hooks::SET_ITEM_IMPACT_ICON]['example'] = 'plugin_example_set_impact_icon';
}
@@ -337,11 +326,7 @@ function plugin_version_example()
*/
function plugin_example_check_prerequisites()
{
- if (false) {
- return false;
- }
-
- return true;
+ return !false;
}
/**
@@ -358,8 +343,7 @@ function plugin_example_check_config($verbose = false)
}
if ($verbose) {
- echo __('Installed / not configured', 'example');
+ echo __s('Installed / not configured', 'example');
}
-
return false;
}
diff --git a/src/Child.php b/src/Child.php
index b2960c8..e58a8b4 100644
--- a/src/Child.php
+++ b/src/Child.php
@@ -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());
diff --git a/src/Computer.php b/src/Computer.php
index 31a4cd5..efe4e63 100644
--- a/src/Computer.php
+++ b/src/Computer.php
@@ -37,23 +37,17 @@ 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()
{
echo '
';
echo '';
- echo '' . __('More information') . ' | ';
+ echo '' . __s('More information') . ' | ';
echo '
';
echo '';
echo '';
- echo __('Test successful');
+ echo __s('Test successful');
echo ' | ';
echo '
';
echo '
';
@@ -71,7 +65,7 @@ class Computer extends CommonDBTM
public static function add_default_where($in)
{
- list($itemtype, $condition) = $in;
+ [$itemtype, $condition] = $in;
if ($itemtype == 'Computer') {
$table = getTableForItemType($itemtype);
$condition .= ' (' . $table . '.groups_id NOT IN (' . implode(',', $_SESSION['glpigroups']) . '))';
diff --git a/src/Config.php b/src/Config.php
index baf00b3..9f1f602 100644
--- a/src/Config.php
+++ b/src/Config.php
@@ -44,10 +44,8 @@ class Config extends CommonDBTM
public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0)
{
- if (!$withtemplate) {
- if ($item->getType() == 'Config') {
- return __('Example plugin');
- }
+ if (!$withtemplate && $item->getType() == 'Config') {
+ return __s('Example plugin');
}
return '';
@@ -73,10 +71,10 @@ class Config extends CommonDBTM
echo "