Skip to content

Commit

Permalink
Feature/ci (#89)
Browse files Browse the repository at this point in the history
* Add CI

* phpcbf

* Visibility

* phpstan lvl 0

* phpstan lvl 1

* Fix CS
  • Loading branch information
trasher authored Nov 14, 2023
1 parent a79d9a1 commit f824361
Show file tree
Hide file tree
Showing 21 changed files with 4,329 additions and 3,711 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: "Continuous integration"

on:
push:
branches:
- "master"
tags:
- "*"
pull_request:
schedule:
- cron: "0 0 * * *"
workflow_dispatch:

jobs:
ci:
name: "GLPI ${{ matrix.glpi-version }} - php:${{ matrix.php-version }} - ${{ matrix.db-image }}"
strategy:
fail-fast: false
matrix:
include:
- {glpi-version: "10.0.x", php-version: "7.4", db-image: "mysql:5.7"}
- {glpi-version: "10.0.x", php-version: "8.0", db-image: "mysql:8.0"}
- {glpi-version: "10.0.x", php-version: "8.1", db-image: "mariadb:10.2"}
- {glpi-version: "10.0.x", php-version: "8.2", db-image: "mariadb:11.0"}
- {glpi-version: "10.0.x", php-version: "8.3-rc", db-image: "mysql:8.0"}
uses: "glpi-project/plugin-ci-workflows/.github/workflows/continuous-integration.yml@v1"
with:
plugin-key: "uninstall"
glpi-version: "${{ matrix.glpi-version }}"
php-version: "${{ matrix.php-version }}"
db-image: "${{ matrix.db-image }}"
17 changes: 17 additions & 0 deletions .phpcs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0"?>
<ruleset>
<file>.</file>
<exclude-pattern>/.git/</exclude-pattern>
<exclude-pattern type="relative">^vendor/</exclude-pattern>

<arg name="colors" />
<arg name="extensions" value="php" />
<arg value="p" />
<arg name="warning-severity" value="0" />

<rule ref="PSR12">
<exclude name="Generic.Files.LineLength" />
<exclude name="PSR1.Classes.ClassDeclaration.MissingNamespace" />
</rule>
<rule ref="Generic.Arrays.ArrayIndent"></rule>
</ruleset>
142 changes: 79 additions & 63 deletions ajax/dropdownReplaceFindDevice.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
* -------------------------------------------------------------------------
*/

include ('../../../inc/includes.php');
include('../../../inc/includes.php');

use Glpi\Toolbox\Sanitizer;

Expand All @@ -37,10 +37,16 @@

Session::checkRightsOr('uninstall:profile', [READ, PluginUninstallProfile::RIGHT_REPLACE]);

/**
* @var array $UNINSTALL_TYPES
* @var array $UNINSTALL_DIRECT_CONNECTIONS_TYPE
* @var array $CFG_GLPI
* @var DBmysql $DB
*/
global $UNINSTALL_TYPES, $UNINSTALL_DIRECT_CONNECTIONS_TYPE, $CFG_GLPI, $DB;

if (!in_array($_REQUEST['itemtype'], array_merge($UNINSTALL_TYPES, $UNINSTALL_DIRECT_CONNECTIONS_TYPE))) {
Html::displayErrorAndDie(__("You don't have permission to perform this action."));
Html::displayErrorAndDie(__("You don't have permission to perform this action."));
}

$itemtypeisplugin = isPluginItemType($_REQUEST['itemtype']);
Expand All @@ -52,106 +58,116 @@

$displaywith = false;
if (isset($_REQUEST['displaywith'])) {
if (is_array($_REQUEST['displaywith']) && count($_REQUEST['displaywith'])) {
$displaywith = true;
}
if (is_array($_REQUEST['displaywith']) && count($_REQUEST['displaywith'])) {
$displaywith = true;
}
}

$criteria = [
'FROM' => $table,
'WHERE' => []
'FROM' => $table,
'WHERE' => []
];

if ($item->isEntityAssign()) {
// allow opening ticket on recursive object (printer, software, ...)
$criteria['WHERE'] = getEntitiesRestrictCriteria($table, '', $_SESSION['glpiactiveentities'], $item->maybeRecursive());
$criteria['WHERE'] = getEntitiesRestrictCriteria($table, '', $_SESSION['glpiactiveentities'], $item->maybeRecursive());
}

if ($item->maybeDeleted()) {
$criteria['WHERE']['is_deleted'] = 0;
$criteria['WHERE']['is_deleted'] = 0;
}
if ($item->maybeTemplate()) {
$criteria['WHERE']['is_template'] = 0;
$criteria['WHERE']['is_template'] = 0;
}

if (isset($_REQUEST['searchText'])
if (
isset($_REQUEST['searchText'])
&& strlen($_REQUEST['searchText']) > 0
&& $_REQUEST['searchText'] != $CFG_GLPI["ajax_wildcard"]) {
&& $_REQUEST['searchText'] != $CFG_GLPI["ajax_wildcard"]
) {
// isset already makes sure the search value isn't null
$search_val = Search::makeTextSearchValue($_REQUEST['searchText']);
$critera['WHERE'][] = [
'OR' => [
'name' => ['LIKE', $search_val],
'id' => ['LIKE', $search_val],
'serial' => ['LIKE', $search_val],
'otherserial' => ['LIKE', $search_val]
]
];
$search_val = Search::makeTextSearchValue($_REQUEST['searchText']);
$critera['WHERE'][] = [
'OR' => [
'name' => ['LIKE', $search_val],
'id' => ['LIKE', $search_val],
'serial' => ['LIKE', $search_val],
'otherserial' => ['LIKE', $search_val]
]
];
}

//If software or plugins : filter to display only the objects that are allowed to be visible in Helpdesk
if (in_array($_REQUEST['itemtype'], $CFG_GLPI["helpdesk_visible_types"])) {
$criteria['WHERE']['is_helpdesk_visible'] = 1;
$criteria['WHERE']['is_helpdesk_visible'] = 1;
}

if (isset($_REQUEST['used'])) {
$used = $_REQUEST['used'];
$used = $_REQUEST['used'];

if (count($used)) {
$criteria['WHERE'][] = [
'NOT' => ["$table.id" => $used]
];
}
if (count($used)) {
$criteria['WHERE'][] = [
'NOT' => ["$table.id" => $used]
];
}
}

if (isset($_REQUEST['current_item']) && ($_REQUEST['current_item'] > 0)) {
$criteria['WHERE']['id'] = ['!=', $_REQUEST['current_item']];
$criteria['WHERE']['id'] = ['!=', $_REQUEST['current_item']];
}

$criteria['START'] = 0;
$criteria['LIMIT'] = $CFG_GLPI["dropdown_max"];
$criteria['ORDER'] = ['name'];

if (isset($_REQUEST['searchText'])
&& $_REQUEST['searchText'] == $CFG_GLPI["ajax_wildcard"]) {
unset($criteria['LIMIT']);
if (
isset($_REQUEST['searchText'])
&& $_REQUEST['searchText'] == $CFG_GLPI["ajax_wildcard"]
) {
unset($criteria['LIMIT']);
}

$it = $DB->request($criteria);
foreach ($it as $data) {
$outputval = Sanitizer::unsanitize($data["name"]);

if ($displaywith) {
foreach ($_REQUEST['displaywith'] as $key) {
if (isset($data[$key])) {
$withoutput = $data[$key];
if (isForeignKeyField($key)) {
$withoutput = Dropdown::getDropdownName(getTableNameForForeignKeyField($key),
$data[$key]);
}
if ((strlen($withoutput) > 0) && ($withoutput != '&nbsp;')) {
$outputval = sprintf(__('%1$s - %2$s'), $outputval, $withoutput);
$outputval = Sanitizer::unsanitize($data["name"]);

if ($displaywith) {
foreach ($_REQUEST['displaywith'] as $key) {
if (isset($data[$key])) {
$withoutput = $data[$key];
if (isForeignKeyField($key)) {
$withoutput = Dropdown::getDropdownName(
getTableNameForForeignKeyField($key),
$data[$key]
);
}
if ((strlen($withoutput) > 0) && ($withoutput != '&nbsp;')) {
$outputval = sprintf(__('%1$s - %2$s'), $outputval, $withoutput);
}
}
}
}
}
$ID = $data['id'];
$addcomment = "";
$title = $outputval;
if (isset($data["comment"])) {
$addcomment .= $data["comment"];
$title = sprintf(__('%1$s - %2$s'), $title, $addcomment);
}
if ($_SESSION["glpiis_ids_visible"]
|| (strlen($outputval) == 0)) {
$outputval = sprintf(__('%1$s (%2$s)'), $outputval, $ID);
}
array_push($options, ['id' => $ID,
'text' => $outputval,
'title' => $title]);
$count++;
}
}
$ID = $data['id'];
$addcomment = "";
$title = $outputval;
if (isset($data["comment"])) {
$addcomment .= $data["comment"];
$title = sprintf(__('%1$s - %2$s'), $title, $addcomment);
}
if (
$_SESSION["glpiis_ids_visible"]
|| (strlen($outputval) == 0)
) {
$outputval = sprintf(__('%1$s (%2$s)'), $outputval, $ID);
}
array_push($options, ['id' => $ID,
'text' => $outputval,
'title' => $title
]);
$count++;
}


echo json_encode(['results' => $options,
'count' => $count]);
'count' => $count
]);
28 changes: 17 additions & 11 deletions ajax/locations.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,26 @@
* -------------------------------------------------------------------------
*/

include ('../../../inc/includes.php');
include('../../../inc/includes.php');
header("Content-Type: text/html; charset=UTF-8");
Html::header_nocache();

Session::checkRightsOr('uninstall:profile', [READ, PluginUninstallProfile::RIGHT_REPLACE]);

if (Session::haveRight(PluginUninstallUninstall::$rightname, READ)
&& $_POST['templates_id']) {
$location = PluginUninstallPreference::getLocationByUserByEntity($_POST["users_id"],
$_POST["templates_id"],
$_POST["entity"]);
Location::dropdown(['value' => ($location == '' ? 0 : $location),
'comments' => 1,
'entity' => $_POST["entity"],
'toadd' => [-1 => __('Keep previous location', 'uninstall'),
0 => __('Empty location', 'uninstall')]]);
if (
Session::haveRight(PluginUninstallUninstall::$rightname, READ)
&& $_POST['templates_id']
) {
$location = PluginUninstallPreference::getLocationByUserByEntity(
$_POST["users_id"],
$_POST["templates_id"],
$_POST["entity"]
);
Location::dropdown(['value' => ($location == '' ? 0 : $location),
'comments' => 1,
'entity' => $_POST["entity"],
'toadd' => [-1 => __('Keep previous location', 'uninstall'),
0 => __('Empty location', 'uninstall')
]
]);
}
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
"php": ">=7.4"
},
"require-dev": {
"glpi-project/tools": "^0.6"
"glpi-project/tools": "^0.7.1",
"phpstan/phpstan": "^1.10",
"squizlabs/php_codesniffer": "^3.7"
},
"config": {
"optimize-autoloader": true,
Expand Down
Loading

0 comments on commit f824361

Please sign in to comment.