Skip to content

Commit

Permalink
add CI (#372)
Browse files Browse the repository at this point in the history
* add CI

* add CI

* composer

* phpcbf

* phpcs

* phpstan

* disable phpstan
  • Loading branch information
Rom1-B authored Feb 23, 2024
1 parent 1c1abf0 commit a40daa1
Show file tree
Hide file tree
Showing 85 changed files with 14,047 additions and 12,312 deletions.
44 changes: 44 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@

module.exports = {
"root": true,
"ignorePatterns": [
"/node_modules/*",
"/vendor/*",
],
"env": {
"browser": true,
"es6": true,
"jquery": true,
},
"extends": "eslint:recommended",
"globals": {
"CFG_GLPI": true,
"GLPI_PLUGINS_PATH": true,
"__": true,
"_n": true,
"_x": true,
"_nx": true
},
"parserOptions": {
"ecmaVersion": 8,
},
"plugins": [
"@stylistic/js",
],
"rules": {
"no-console": ["error", {"allow": ["warn", "error"]}],
"no-unused-vars": ["error", {"vars": "local"}],
"@stylistic/js/eol-last": ["error", "always"],
"@stylistic/js/indent": ["error", 4],
"@stylistic/js/linebreak-style": ["error", "unix"],
"@stylistic/js/semi": ["error", "always"],
},
"overrides": [
{
"files": [".eslintrc.js"],
"env": {
"node": true
}
},
],
};
35 changes: 35 additions & 0 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: "Continuous integration"

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

concurrency:
group: "${{ github.workflow }}-${{ github.ref }}"
cancel-in-progress: true

jobs:
generate-ci-matrix:
name: "Generate CI matrix"
uses: "glpi-project/plugin-ci-workflows/.github/workflows/generate-ci-matrix.yml@v1"
with:
glpi-version: "10.0.x"
ci:
name: "GLPI ${{ matrix.glpi-version }} - php:${{ matrix.php-version }} - ${{ matrix.db-image }}"
needs: "generate-ci-matrix"
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.generate-ci-matrix.outputs.matrix) }}
uses: "glpi-project/plugin-ci-workflows/.github/workflows/continuous-integration.yml@v1"
with:
plugin-key: "order"
glpi-version: "${{ matrix.glpi-version }}"
php-version: "${{ matrix.php-version }}"
db-image: "${{ matrix.db-image }}"
19 changes: 19 additions & 0 deletions .phpcs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0"?>
<ruleset>
<file>.</file>
<exclude-pattern>/.git/</exclude-pattern>
<exclude-pattern type="relative">^node_modules/</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" />
<exclude name="PSR1.Methods.CamelCapsMethodName.NotCamelCaps" />
</rule>
<rule ref="Generic.Arrays.ArrayIndent"></rule>
</ruleset>
26 changes: 13 additions & 13 deletions ajax/billactions.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,27 +28,27 @@
* -------------------------------------------------------------------------
*/

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

header("Content-Type: text/html; charset=UTF-8");

Html::header_nocache();

if (!defined('GLPI_ROOT')) {
die("Can not acces directly to this file");
die("Can not acces directly to this file");
}

if (isset($_POST["action"])) {
switch ($_POST["action"]) {
case "bill":
echo "&nbsp;";
echo Html::hidden('plugin_order_orders_id', ['value' => $_POST["plugin_order_orders_id"]]);
PluginOrderBill::Dropdown([
'condition' => ['plugin_order_orders_id' => $_POST['plugin_order_orders_id']],
]);
break;
}
switch ($_POST["action"]) {
case "bill":
echo "&nbsp;";
echo Html::hidden('plugin_order_orders_id', ['value' => $_POST["plugin_order_orders_id"]]);
PluginOrderBill::Dropdown([
'condition' => ['plugin_order_orders_id' => $_POST['plugin_order_orders_id']],
]);
break;
}

PluginOrderBillState::Dropdown(['comments' => true]);
echo "&nbsp;<input type='submit' name='action' class='submit' value='"._sx('button', 'Post')."'>";
PluginOrderBillState::Dropdown(['comments' => true]);
echo "&nbsp;<input type='submit' name='action' class='submit' value='" . _sx('button', 'Post') . "'>";
}
59 changes: 33 additions & 26 deletions ajax/dropdownReference.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,17 @@
* -------------------------------------------------------------------------
*/

include_once ("../../../inc/includes.php");
/** @var DBmysql $DB */
global $DB;

include_once("../../../inc/includes.php");

Session::checkCentralAccess();

// Make a select box for references
if (isset($_POST["itemtype"])) {
$entity_restrict = getEntitiesRestrictRequest("AND", 'r', '', $_POST['entities_id'], 1);
$query = "SELECT s.`plugin_order_references_id` as id, s.`price_taxfree`, s.`reference_code`, r.`name`
$entity_restrict = getEntitiesRestrictRequest("AND", 'r', '', $_POST['entities_id'], 1);
$query = "SELECT s.`plugin_order_references_id` as id, s.`price_taxfree`, s.`reference_code`, r.`name`
FROM `glpi_plugin_order_references_suppliers` s
LEFT JOIN `glpi_plugin_order_references` r
ON (s.`plugin_order_references_id` = r.`id`
Expand All @@ -45,31 +48,35 @@
AND r.`itemtype` = '{$_POST['itemtype']}'
$entity_restrict
ORDER BY s.`reference_code`";
$result = $DB->query($query);
$number = $DB->numrows($result);
$values = [0 => Dropdown::EMPTY_VALUE];
if ($number) {
while ($data = $DB->fetchAssoc($result)) {
$values[$data['id']] = $data['name']." - ".$data['reference_code'];
}
}
Dropdown::showFromArray($_POST['fieldname'], $values,
['rand' => $_POST['rand'], 'width' => '100%']);
Ajax::updateItemOnSelectEvent('dropdown_plugin_order_references_id' . $_POST['rand'],
'show_priceht',
'../ajax/dropdownReference.php',
[
'reference_id' => '__VALUE__',
'suppliers_id' => $_POST['suppliers_id'],
]);

$result = $DB->query($query);
$number = $DB->numrows($result);
$values = [0 => Dropdown::EMPTY_VALUE];
if ($number) {
while ($data = $DB->fetchAssoc($result)) {
$values[$data['id']] = $data['name'] . " - " . $data['reference_code'];
}
}
Dropdown::showFromArray(
$_POST['fieldname'],
$values,
['rand' => $_POST['rand'], 'width' => '100%']
);
Ajax::updateItemOnSelectEvent(
'dropdown_plugin_order_references_id' . $_POST['rand'],
'show_priceht',
'../ajax/dropdownReference.php',
[
'reference_id' => '__VALUE__',
'suppliers_id' => $_POST['suppliers_id'],
]
);
} else if (isset($_POST['reference_id'])) {
// Get price
$query = "SELECT `price_taxfree`
$query = "SELECT `price_taxfree`
FROM `glpi_plugin_order_references_suppliers`
WHERE `plugin_order_references_id` = '{$_POST['reference_id']}' AND suppliers_id = '{$_POST['suppliers_id']}'";
$result = $DB->query($query);
$price = $DB->result($result, 0, 'price_taxfree');
$price = Html::formatNumber($price, true);
echo "<input value='$price' type='number' class='form-control' step='".PLUGIN_ORDER_NUMBER_STEP."' name='price' class='decimal' min='0' />";
$result = $DB->query($query);
$price = $DB->result($result, 0, 'price_taxfree');
$price = Html::formatNumber($price, true);
echo "<input value='$price' type='number' class='form-control' step='" . PLUGIN_ORDER_NUMBER_STEP . "' name='price' class='decimal' min='0' />";
}
30 changes: 16 additions & 14 deletions ajax/dropdownSupplier.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,31 +28,33 @@
* -------------------------------------------------------------------------
*/

/** @var \DBmysql $DB */
global $DB;

if (strpos($_SERVER['PHP_SELF'], "dropdownSupplier.php")) {
include ("../../../inc/includes.php");
header("Content-Type: text/html; charset=UTF-8");
Html::header_nocache();
include("../../../inc/includes.php");
header("Content-Type: text/html; charset=UTF-8");
Html::header_nocache();
}

Session::checkCentralAccess();

// Make a select box
if (isset($_POST["suppliers_id"])) {

// Make a select box
$query = "SELECT c.`id`, c.`name`, c.`firstname`
$query = "SELECT c.`id`, c.`name`, c.`firstname`
FROM `glpi_contacts` c
LEFT JOIN `glpi_contacts_suppliers` s ON (s.`contacts_id` = c.`id`)
WHERE s.`suppliers_id` = '{$_POST['suppliers_id']}'
ORDER BY c.`name`";
$result = $DB->query($query);
$number = $DB->numrows($result);
$result = $DB->query($query);
$number = $DB->numrows($result);

$values = [0 => Dropdown::EMPTY_VALUE];
if ($number) {
while ($data = $DB->fetchAssoc($result)) {
$values[$data['id']] = formatUserName('', '', $data['name'], $data['firstname']);
}
}
Dropdown::showFromArray($_POST['fieldname'], $values);
$values = [0 => Dropdown::EMPTY_VALUE];
if ($number) {
while ($data = $DB->fetchAssoc($result)) {
$values[$data['id']] = formatUserName('', '', $data['name'], $data['firstname']);
}
}
Dropdown::showFromArray($_POST['fieldname'], $values);
}
38 changes: 19 additions & 19 deletions ajax/inputnumber.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,33 +34,33 @@

use Glpi\Toolbox\Sanitizer;

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

header("Content-Type: text/html; charset=UTF-8");
Html::header_nocache();
Session::checkLoginUser();

if (isset($_POST['name'])) {
$step = 1;
if (!isset($_REQUEST['force_integer'])) {
$step = PLUGIN_ORDER_NUMBER_STEP;
}
$step = 1;
if (!isset($_REQUEST['force_integer'])) {
$step = PLUGIN_ORDER_NUMBER_STEP;
}

$class = "";
if (isset($_REQUEST['class'])) {
$class = "class='".$_REQUEST['class']."'";
}
$class = "";
if (isset($_REQUEST['class'])) {
$class = "class='" . $_REQUEST['class'] . "'";
}

$min = 0;
if (isset($_REQUEST['min'])) {
if (isset($_REQUEST['force_integer']) && $_REQUEST['force_integer']) {
$min = (int)$_REQUEST['min'];
} else {
$min = (float)$_REQUEST['min'];
}
}
$min = 0;
if (isset($_REQUEST['min'])) {
if (isset($_REQUEST['force_integer']) && $_REQUEST['force_integer']) {
$min = (int)$_REQUEST['min'];
} else {
$min = (float)$_REQUEST['min'];
}
}

$data = Html::cleanInputText(Sanitizer::sanitize(rawurldecode(stripslashes($_POST["data"]))));
$data = Html::cleanInputText(Sanitizer::sanitize(rawurldecode(stripslashes($_POST["data"]))));

echo "<input type='number' class='form-control' step='$step' min='$min' name='".$_POST['name']."' value='$data' $class>";
echo "<input type='number' class='form-control' step='$step' min='$min' name='" . $_POST['name'] . "' value='$data' $class>";
}
Loading

0 comments on commit a40daa1

Please sign in to comment.