diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml
index b199cd5..b4c8afc 100644
--- a/.github/workflows/continuous-integration.yml
+++ b/.github/workflows/continuous-integration.yml
@@ -18,11 +18,9 @@ jobs:
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"}
+ - {glpi-version: "10.1.x", php-version: "8.1", db-image: "mariadb:10.5"}
+ - {glpi-version: "10.1.x", php-version: "8.2", db-image: "mariadb:11.0"}
+ - {glpi-version: "10.1.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: "deploy"
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index 1e794b5..b7a3960 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -17,7 +17,7 @@ jobs:
uses: "actions/checkout@v4"
- name: "Build package"
id: "build-package"
- uses: "glpi-project/tools/github-actions/build-package@0.7.1"
+ uses: "glpi-project/tools/github-actions/build-package@0.7.2"
with:
plugin-version: ${{ env.tag_name }}
- name: "Create release"
diff --git a/.phpcs.xml b/.phpcs.xml
index 7cc76ed..3728aea 100644
--- a/.phpcs.xml
+++ b/.phpcs.xml
@@ -13,6 +13,7 @@
+
diff --git a/ajax/package.php b/ajax/package.php
index 57e2cf0..c1591b8 100644
--- a/ajax/package.php
+++ b/ajax/package.php
@@ -30,28 +30,28 @@
namespace GlpiPlugin\Deploy;
-include ("../../../inc/includes.php");
+include("../../../inc/includes.php");
\Session::checkLoginUser();
switch (($_POST['action'] ?? "")) {
case "add_check":
- Package_Check::showAdd((int) ($_POST['plugin_deploy_packages_id'] ?? 0));
+ PackageCheck::showAdd((int) ($_POST['plugin_deploy_packages_id'] ?? 0));
break;
case "edit_check":
- Package_Check::showEdit((int) ($_POST['id'] ?? 0));
+ PackageCheck::showEdit((int) ($_POST['id'] ?? 0));
break;
case "add_file":
- Package_File::showAdd((int) ($_POST['plugin_deploy_packages_id'] ?? 0));
+ PackageFile::showAdd((int) ($_POST['plugin_deploy_packages_id'] ?? 0));
break;
case "edit_file":
- Package_File::showEdit((int) ($_POST['id'] ?? 0));
+ PackageFile::showEdit((int) ($_POST['id'] ?? 0));
break;
case "add_action":
- Package_Action::showAdd((int) ($_POST['plugin_deploy_packages_id'] ?? 0));
+ PackageAction::showAdd((int) ($_POST['plugin_deploy_packages_id'] ?? 0));
break;
case "edit_action":
- Package_Action::showEdit((int) ($_POST['id'] ?? 0));
+ PackageAction::showEdit((int) ($_POST['id'] ?? 0));
break;
case "move_subitem":
Package::moveSubitem(
diff --git a/composer.json b/composer.json
index ab641f3..a6f5c7a 100644
--- a/composer.json
+++ b/composer.json
@@ -1,9 +1,9 @@
{
"require": {
- "php": ">=7.4"
+ "php": ">=8.1"
},
"require-dev": {
- "glpi-project/tools": "^0.7.1",
+ "glpi-project/tools": "^0.7.2",
"php-parallel-lint/php-parallel-lint": "^1.3",
"phpstan/extension-installer": "^1.3",
"phpstan/phpstan": "^1.10",
@@ -13,7 +13,7 @@
"config": {
"optimize-autoloader": true,
"platform": {
- "php": "7.4.0"
+ "php": "8.1"
},
"sort-packages": true,
"allow-plugins": {
diff --git a/front/computer/group.form.php b/front/computer/group.form.php
index 83a06c0..4575c52 100644
--- a/front/computer/group.form.php
+++ b/front/computer/group.form.php
@@ -34,108 +34,127 @@
use Html;
use Session;
-include ('../../../../inc/includes.php');
+include('../../../../inc/includes.php');
Session::checkRight("computer_group", READ);
if (!isset($_GET["id"])) {
- $_GET["id"] = "";
+ $_GET["id"] = "";
}
if (!isset($_GET["withtemplate"])) {
- $_GET["withtemplate"] = "";
+ $_GET["withtemplate"] = "";
}
$computergroup = new Group();
-$computergroupstatic = new Group_Static();
-$computergroup_dynamic = new Group_Dynamic();
+$computergroupstatic = new GroupStatic();
+$computergroup_dynamic = new GroupDynamic();
//Add a new computergroup
if (isset($_POST["add"])) {
- $computergroup->check(-1, CREATE, $_POST);
- if ($newID = $computergroup->add($_POST)) {
- Event::log($newID, "Group", 4, "inventory",
- sprintf(__('%1$s adds the item %2$s'), $_SESSION["glpiname"], $_POST["name"]));
-
- if ($_SESSION['glpibackcreated']) {
- Html::redirect($computergroup->getLinkURL());
- }
- }
- Html::back();
+ $computergroup->check(-1, CREATE, $_POST);
+ if ($newID = $computergroup->add($_POST)) {
+ Event::log(
+ $newID,
+ "Group",
+ 4,
+ "inventory",
+ sprintf(__('%1$s adds the item %2$s'), $_SESSION["glpiname"], $_POST["name"])
+ );
+
+ if ($_SESSION['glpibackcreated']) {
+ Html::redirect($computergroup->getLinkURL());
+ }
+ }
+ Html::back();
// purge a computergroup
}if (isset($_POST["add_staticcomputer"])) {
-
- if (!$_POST['computers_id']){
- Session::addMessageAfterRedirect(__('Please select a computer'), false, ERROR);
- Html::back();
- }
-
- $computergroupstatic->check(-1, CREATE, $_POST);
- if ($newID = $computergroupstatic->add($_POST)) {
- Event::log($newID, "Computer_Group_Static", 4, "inventory",
- sprintf(__('%1$s adds the item %2$s'), $_SESSION["glpiname"], $computergroupstatic::getTypeName(0)));
-
- if ($_SESSION['glpibackcreated']) {
- $computergroup->getFromDB($_POST['plugin_deploy_computers_groups_id']);
- Html::redirect($computergroup->getLinkURL());
- }
- }
- Html::back();
+ if (!$_POST['computers_id']) {
+ Session::addMessageAfterRedirect(__('Please select a computer'), false, ERROR);
+ Html::back();
+ }
+
+ $computergroupstatic->check(-1, CREATE, $_POST);
+ if ($newID = $computergroupstatic->add($_POST)) {
+ Event::log(
+ $newID,
+ "Computer_GroupStatic",
+ 4,
+ "inventory",
+ sprintf(__('%1$s adds the item %2$s'), $_SESSION["glpiname"], $computergroupstatic::getTypeName(0))
+ );
+
+ if ($_SESSION['glpibackcreated']) {
+ $computergroup->getFromDB($_POST['plugin_deploy_computers_groups_id']);
+ Html::redirect($computergroup->getLinkURL());
+ }
+ }
+ Html::back();
// purge a computergroup
} else if (isset($_POST["purge"])) {
- $computergroup->check($_POST['id'], PURGE);
- if ($computergroup->delete($_POST, 1)) {
- Event::log($_POST["id"], "Computer_Group", 4, "inventory",
- //TRANS: %s is the user login
- sprintf(__('%s purges an item'), $_SESSION["glpiname"]));
- }
- $computergroup->redirectToList();
+ $computergroup->check($_POST['id'], PURGE);
+ if ($computergroup->delete($_POST, 1)) {
+ Event::log(
+ $_POST["id"],
+ "Computer_Group",
+ 4,
+ "inventory",
+ //TRANS: %s is the user login
+ sprintf(__('%s purges an item'), $_SESSION["glpiname"])
+ );
+ }
+ $computergroup->redirectToList();
//update a computergroup
} else if (isset($_POST["update"])) {
- $computergroup->check($_POST['id'], UPDATE);
- $computergroup->update($_POST);
- Event::log($_POST["id"], "Computer_Group", 4, "inventory",
- //TRANS: %s is the user login
- sprintf(__('%s updates an item'), $_SESSION["glpiname"]));
- Html::back();
-
+ $computergroup->check($_POST['id'], UPDATE);
+ $computergroup->update($_POST);
+ Event::log(
+ $_POST["id"],
+ "Computer_Group",
+ 4,
+ "inventory",
+ //TRANS: %s is the user login
+ sprintf(__('%s updates an item'), $_SESSION["glpiname"])
+ );
+ Html::back();
} else {//print computergroup information
//save search parameters for dynamic group
- if (isset($_GET["save"])) {
- $input = ['plugin_deploy_computers_groups_id' => $_GET['plugin_deploy_computers_groups_id']];
- $search = serialize(['is_deleted' => isset($_GET['is_deleted']) ? $_GET['is_deleted'] : 0 ,
- 'as_map' => isset($_GET['as_map']) ? $_GET['as_map'] : 0,
- 'criteria' => $_GET['criteria'],
- 'metacriteria' => isset($_GET['metacriteria']) ? $_GET['metacriteria'] : []]);
-
- if (!$computergroup_dynamic->getFromDBByCrit($input)) {
- $input['search'] = $search;
- $computergroup_dynamic->add($input);
- } else {
- $input = $computergroup_dynamic->fields;
- $input['search'] = $search;
- $computergroup_dynamic->update($input);
- }
- }else if (isset($_GET["reset"])) {
- $computergroup_dynamic->deleteByCriteria(["plugin_deploy_computers_groups_id" => $_GET['id']]);
- }
-
-
- Html::header(
- Group::getTypeName(Session::getPluralNumber()),
- '',
- 'tools',
- 'glpiplugin\deploy\menu',
- 'computer_group'
- );
+ if (isset($_GET["save"])) {
+ $input = ['plugin_deploy_computers_groups_id' => $_GET['plugin_deploy_computers_groups_id']];
+ $search = serialize(['is_deleted' => isset($_GET['is_deleted']) ? $_GET['is_deleted'] : 0 ,
+ 'as_map' => isset($_GET['as_map']) ? $_GET['as_map'] : 0,
+ 'criteria' => $_GET['criteria'],
+ 'metacriteria' => isset($_GET['metacriteria']) ? $_GET['metacriteria'] : []
+ ]);
+
+ if (!$computergroup_dynamic->getFromDBByCrit($input)) {
+ $input['search'] = $search;
+ $computergroup_dynamic->add($input);
+ } else {
+ $input = $computergroup_dynamic->fields;
+ $input['search'] = $search;
+ $computergroup_dynamic->update($input);
+ }
+ } else if (isset($_GET["reset"])) {
+ $computergroup_dynamic->deleteByCriteria(["plugin_deploy_computers_groups_id" => $_GET['id']]);
+ }
+
+
+ Html::header(
+ Group::getTypeName(Session::getPluralNumber()),
+ '',
+ 'tools',
+ 'glpiplugin\deploy\menu',
+ 'computer_group'
+ );
//show computergroup form to add
- $computergroup->display([
- 'id' => (int) $_GET["id"],
- ]);
+ $computergroup->display([
+ 'id' => (int) $_GET["id"],
+ ]);
- Html::footer();
+ Html::footer();
}
diff --git a/front/computer/group.php b/front/computer/group.php
index bb8df08..c7ca6d6 100644
--- a/front/computer/group.php
+++ b/front/computer/group.php
@@ -28,14 +28,13 @@
* -------------------------------------------------------------------------
*/
-
namespace GlpiPlugin\Deploy\Computer;
use Html;
use Search;
use Session;
-include ('../../../../inc/includes.php');
+include('../../../../inc/includes.php');
Session::checkRight("computer_group", UPDATE);
diff --git a/front/package.form.php b/front/package.form.php
index 0d4062f..3aab27d 100644
--- a/front/package.form.php
+++ b/front/package.form.php
@@ -69,51 +69,51 @@
Html::back();
} else if (isset($_POST["add_file"])) {
unset($_POST['id']);
- $file = new Package_File();
+ $file = new PackageFile();
$file->add($_POST);
Html::back();
} else if (isset($_POST["edit_file"])) {
- $file = new Package_File();
+ $file = new PackageFile();
$file->update($_POST);
Html::back();
} else if (isset($_POST["delete_file"])) {
- $file = new Package_File();
+ $file = new PackageFile();
$file->delete($_POST);
Html::back();
} else if (isset($_GET["download_file"])) {
$file_id = (int)($_GET["file_id"] ?? 0);
- $file = new Package_File();
+ $file = new PackageFile();
$file->downloadFile($file_id);
Html::back();
} else if (isset($_POST["add_check"])) {
unset($_POST['id']);
- $check = new Package_Check();
+ $check = new PackageCheck();
$check->add($_POST);
Html::back();
} else if (isset($_POST["edit_check"])) {
- $check = new Package_Check();
+ $check = new PackageCheck();
$check->update($_POST);
Html::back();
} else if (isset($_POST["delete_check"])) {
- $check = new Package_Check();
+ $check = new PackageCheck();
$check->delete($_POST);
Html::back();
} else if (isset($_POST["add_action"])) {
unset($_POST['id']);
- $action = new Package_Action();
+ $action = new PackageAction();
$action->add($_POST);
Html::back();
} else if (isset($_POST["edit_action"])) {
- $action = new Package_Action();
+ $action = new PackageAction();
$action->update($_POST);
Html::back();
} else if (isset($_POST["delete_action"])) {
- $action = new Package_Action();
+ $action = new PackageAction();
$action->delete($_POST);
Html::back();
} else if (isset($_POST["add_target"])) {
if ($_POST['plugin_deploy_computers_groups_id'] > 0) {
- $package_target = new Package_Target();
+ $package_target = new PackageTarget();
$package_target->add($_POST);
}
Html::back();
diff --git a/hook.php b/hook.php
index 26f4526..a1bfc5d 100644
--- a/hook.php
+++ b/hook.php
@@ -1,13 +1,41 @@
.
+ * -------------------------------------------------------------------------
+ * @copyright Copyright (C) 2022-2024 by Deploy plugin team.
+ * @license GPLv3 https://www.gnu.org/licenses/gpl-3.0.html
+ * @link https://github.com/pluginsGLPI/deploy
+ * -------------------------------------------------------------------------
+ */
+
use GlpiPlugin\Deploy\Computer\Group;
-use GlpiPlugin\Deploy\Computer\Group_Dynamic;
-use GlpiPlugin\Deploy\Computer\Group_Static;
+use GlpiPlugin\Deploy\Computer\GroupDynamic;
+use GlpiPlugin\Deploy\Computer\GroupStatic;
use GlpiPlugin\Deploy\Package;
-use GlpiPlugin\Deploy\Package_Action;
-use GlpiPlugin\Deploy\Package_Check;
-use GlpiPlugin\Deploy\Package_File;
-use GlpiPlugin\Deploy\Package_Target;
+use GlpiPlugin\Deploy\PackageAction;
+use GlpiPlugin\Deploy\PackageCheck;
+use GlpiPlugin\Deploy\PackageFile;
+use GlpiPlugin\Deploy\PackageTarget;
use GlpiPlugin\Deploy\Profile;
use GlpiPlugin\Deploy\Repository;
@@ -44,16 +72,16 @@ function plugin_deploy_install()
$version = plugin_version_deploy();
$migration = new Migration($version['version']);
- Package_Action::install($migration);
- Package_Check::install($migration);
- Package_File::install($migration);
+ PackageAction::install($migration);
+ PackageCheck::install($migration);
+ PackageFile::install($migration);
Package::install($migration);
- Package_Target::install($migration);
+ PackageTarget::install($migration);
Profile::install($migration);
Repository::install($migration);
Group::install($migration);
- Group_Dynamic::install($migration);
- Group_Static::install($migration);
+ GroupDynamic::install($migration);
+ GroupStatic::install($migration);
return true;
}
@@ -67,14 +95,13 @@ function plugin_deploy_uninstall()
{
$migration = new Migration(PLUGIN_DEPLOY_VERSION);
- Package_Target::uninstall($migration);
+ PackageTarget::uninstall($migration);
Package::uninstall($migration);
Profile::uninstall($migration);
Repository::uninstall($migration);
Group::uninstall($migration);
- Group_Dynamic::uninstall($migration);
- Group_Static::uninstall($migration);
+ GroupDynamic::uninstall($migration);
+ GroupStatic::uninstall($migration);
return true;
}
-
diff --git a/phpstan.neon b/phpstan.neon
index 66335ca..788e872 100644
--- a/phpstan.neon
+++ b/phpstan.neon
@@ -7,7 +7,7 @@ parameters:
paths:
- ajax
- front
- - inc
+ - src
- hook.php
- setup.php
scanDirectories:
diff --git a/setup.php b/setup.php
index d7835a7..ea0f365 100644
--- a/setup.php
+++ b/setup.php
@@ -28,11 +28,10 @@
* -------------------------------------------------------------------------
*/
-
define('PLUGIN_DEPLOY_VERSION', '0.0.5');
define('PLUGIN_DEPLOY_REPOSITORY_PATH', GLPI_PLUGIN_DOC_DIR . "/deploy/repository");
-define('PLUGIN_DEPLOY_MANIFESTS_PATH', PLUGIN_DEPLOY_REPOSITORY_PATH . "/manifests");
-define('PLUGIN_DEPLOY_PARTS_PATH', PLUGIN_DEPLOY_REPOSITORY_PATH . "/parts");
+define('PLUGIN_DEPLOY_MANIFESTS_PATH', PLUGIN_DEPLOY_REPOSITORY_PATH . "/manifests");
+define('PLUGIN_DEPLOY_PARTS_PATH', PLUGIN_DEPLOY_REPOSITORY_PATH . "/parts");
define("PLUGIN_DEPLOY_MIN_GLPI", "10.1.0");
define("PLUGIN_DEPLOY_MAX_GLPI", "10.1.99");
@@ -44,6 +43,7 @@
*/
function plugin_init_deploy()
{
+ /** @var array $PLUGIN_HOOKS */
global $PLUGIN_HOOKS;
$PLUGIN_HOOKS['csrf_compliant']['deploy'] = true;
diff --git a/src/Computer/Group.php b/src/Computer/Group.php
index a4f4a1d..e7d2c20 100644
--- a/src/Computer/Group.php
+++ b/src/Computer/Group.php
@@ -40,178 +40,188 @@
class Group extends CommonDBTM
{
+ public $dohistory = true;
+ public static $rightname = 'computer_group';
- public $dohistory = true;
- public static $rightname = 'computer_group';
+ public static function getTypeName($nb = 0)
+ {
+ return _n('Computer Group', 'Computers Group', $nb, 'deploy');
+ }
- static function getTypeName($nb = 0) {
- return _n('Computer Group', 'Computers Group', $nb, 'deploy');
- }
-
- static function canCreate() {
- return Session::haveRight(static::$rightname, UPDATE);
- }
+ public static function canCreate()
+ {
+ return Session::haveRight(static::$rightname, UPDATE);
+ }
- static function canPurge() {
- return Session::haveRight(static::$rightname, UPDATE);
- }
+ public static function canPurge()
+ {
+ return Session::haveRight(static::$rightname, UPDATE);
+ }
- function defineTabs($options = []) {
- $ong = [];
- $this->addDefaultFormTab($ong)
- ->addStandardTab('GlpiPlugin\Deploy\Computer\Group_Dynamic', $ong, $options)
- ->addStandardTab('GlpiPlugin\Deploy\Computer\Group_Static', $ong, $options)
+ public function defineTabs($options = [])
+ {
+ $ong = [];
+ $this->addDefaultFormTab($ong)
+ ->addStandardTab('GlpiPlugin\Deploy\Computer\GroupDynamic', $ong, $options)
+ ->addStandardTab('GlpiPlugin\Deploy\Computer\GroupStatic', $ong, $options)
->addStandardTab('Log', $ong, $options);
- return $ong;
- }
-
- function rawSearchOptions() {
- $tab = parent::rawSearchOptions();
-
- $tab[] = [
- 'id' => '2',
- 'table' => $this->getTable(),
- 'field' => 'id',
- 'name' => __('ID'),
- 'massiveaction' => false, // implicit field is id
- 'datatype' => 'number'
- ];
-
- $tab[] = [
- 'id' => '3',
- 'table' => $this->getTable(),
- 'field' => 'comment',
- 'name' => __('Comment'),
- 'datatype' => 'text'
- ];
-
- $tab[] = [
- 'id' => '5',
- 'table' => Group_Dynamic::getTable(),
- 'field' => 'search',
- 'name' => __('Number of dynamics items', 'deploy'),
- 'nosearch' => true,
- 'massiveaction' => false,
- 'forcegroupby' => true,
- 'additionalfields' => ['id'],
- 'joinparams' => ['jointype' => 'child'],
- 'datatype' => 'specific',
- ];
-
- $tab[] = [
- 'id' => '6',
- 'table' => Group_Static::getTable(),
- 'field' => 'id',
- 'name' => __('Number of statics items', 'deploy'),
- 'forcegroupby' => true,
- 'usehaving' => true,
- 'nosearch' => true,
- 'datatype' => 'count',
- 'massiveaction' => false,
- 'joinparams' => ['jointype' => 'child'],
- ];
-
- $tab[] = [
- 'id' => '7',
- 'table' => Group_Dynamic::getTable(),
- 'field' => '_virtual_dynamic_list',
- 'name' => __('List of dynamics items', 'deploy'),
- 'massiveaction' => false,
- 'forcegroupby' => true,
- 'nosearch' => true,
- 'additionalfields' => ['id', 'search'],
- 'searchtype' => ['equals', 'notequals'],
- 'joinparams' => ['jointype' => 'child'],
- 'datatype' => 'specific',
- ];
-
- $tab[] = [
- 'id' => '8',
- 'table' => Computer::getTable(),
- 'field' => 'name',
- 'datatype' => 'itemlink',
- 'name' => __('List of statics items', 'deploy'),
- 'forcegroupby' => true,
- 'massiveaction' => false,
- 'joinparams' => [
- 'beforejoin' => [
- 'table' => Group_Static::getTable(),
- 'joinparams' => [
- 'jointype' => 'child',
- ]
+ return $ong;
+ }
+
+ public function rawSearchOptions()
+ {
+ $tab = parent::rawSearchOptions();
+
+ $tab[] = [
+ 'id' => '2',
+ 'table' => $this->getTable(),
+ 'field' => 'id',
+ 'name' => __('ID'),
+ 'massiveaction' => false, // implicit field is id
+ 'datatype' => 'number'
+ ];
+
+ $tab[] = [
+ 'id' => '3',
+ 'table' => $this->getTable(),
+ 'field' => 'comment',
+ 'name' => __('Comment'),
+ 'datatype' => 'text'
+ ];
+
+ $tab[] = [
+ 'id' => '5',
+ 'table' => GroupDynamic::getTable(),
+ 'field' => 'search',
+ 'name' => __('Number of dynamics items', 'deploy'),
+ 'nosearch' => true,
+ 'massiveaction' => false,
+ 'forcegroupby' => true,
+ 'additionalfields' => ['id'],
+ 'joinparams' => ['jointype' => 'child'],
+ 'datatype' => 'specific',
+ ];
+
+ $tab[] = [
+ 'id' => '6',
+ 'table' => GroupStatic::getTable(),
+ 'field' => 'id',
+ 'name' => __('Number of statics items', 'deploy'),
+ 'forcegroupby' => true,
+ 'usehaving' => true,
+ 'nosearch' => true,
+ 'datatype' => 'count',
+ 'massiveaction' => false,
+ 'joinparams' => ['jointype' => 'child'],
+ ];
+
+ $tab[] = [
+ 'id' => '7',
+ 'table' => GroupDynamic::getTable(),
+ 'field' => '_virtual_dynamic_list',
+ 'name' => __('List of dynamics items', 'deploy'),
+ 'massiveaction' => false,
+ 'forcegroupby' => true,
+ 'nosearch' => true,
+ 'additionalfields' => ['id', 'search'],
+ 'searchtype' => ['equals', 'notequals'],
+ 'joinparams' => ['jointype' => 'child'],
+ 'datatype' => 'specific',
+ ];
+
+ $tab[] = [
+ 'id' => '8',
+ 'table' => Computer::getTable(),
+ 'field' => 'name',
+ 'datatype' => 'itemlink',
+ 'name' => __('List of statics items', 'deploy'),
+ 'forcegroupby' => true,
+ 'massiveaction' => false,
+ 'joinparams' => [
+ 'beforejoin' => [
+ 'table' => GroupStatic::getTable(),
+ 'joinparams' => [
+ 'jointype' => 'child',
+ ]
+ ]
]
- ]
- ];
+ ];
- return $tab;
- }
+ return $tab;
+ }
- public function showForm($id, array $options = [])
- {
- if (!empty($id)) {
+ public function showForm($id, array $options = [])
+ {
+ if (!empty($id)) {
$this->getFromDB($id);
- } else {
+ } else {
$this->getEmpty();
- }
+ }
$this->initForm($id, $options);
TemplateRenderer::getInstance()->display('generic_show_form.html.twig', [
- 'item' => $this,
- 'params' => $options,
+ 'item' => $this,
+ 'params' => $options,
]);
return true;
- }
-
- function countDynamicItem() {
- global $DB;
- $count = 0;
-
- $params = [
- 'SELECT' => '*',
- 'FROM' => Group_Dynamic::getTable(),
- 'WHERE' => ['plugin_deploy_computers_groups_id' => $this->fields['id']],
- ];
-
- $iterator = $DB->request($params);
- foreach ($iterator as $computergroup_dynamic) {
- $params = unserialize($computergroup_dynamic['search']);
- $computers_params["reset"] = true;
- $search_params = Search::manageParams('Computer', $computers_params);
- $data = Search::prepareDatasForSearch('Computer', $search_params);
- Search::constructSQL($data);
- Search::constructData($data, true);
- $count += $data['data']['totalcount'];
- }
-
- return $count;
- }
-
-
- function countStaticItem() {
- global $DB;
- $count = 0;
-
- $params = [
- 'SELECT' => '*',
- 'FROM' => Group_Static::getTable(),
- 'WHERE' => ['plugin_deploy_computers_groups_id' => $this->fields['id']],
- ];
-
- $iterator = $DB->request($params);
- $count = count($iterator);
-
- return $count;
- }
-
-
- public static function install(Migration $migration) {
- global $DB;
- $table = self::getTable();
- if (!$DB->tableExists($table)) {
- $migration->displayMessage("Installing $table");
- $query = "CREATE TABLE IF NOT EXISTS `$table` (
+ }
+
+ public function countDynamicItem()
+ {
+ /** @var object $DB */
+ global $DB;
+ $count = 0;
+
+ $params = [
+ 'SELECT' => '*',
+ 'FROM' => GroupDynamic::getTable(),
+ 'WHERE' => ['plugin_deploy_computers_groups_id' => $this->fields['id']],
+ ];
+
+ $iterator = $DB->request($params);
+ foreach ($iterator as $computergroup_dynamic) {
+ $params = unserialize($computergroup_dynamic['search']);
+ $computers_params["reset"] = true;
+ $search_params = Search::manageParams('Computer', $computers_params);
+ $data = Search::prepareDatasForSearch('Computer', $search_params);
+ Search::constructSQL($data);
+ Search::constructData($data, true);
+ $count += $data['data']['totalcount'];
+ }
+
+ return $count;
+ }
+
+
+ public function countStaticItem()
+ {
+ /** @var object $DB */
+ global $DB;
+ $count = 0;
+
+ $params = [
+ 'SELECT' => '*',
+ 'FROM' => GroupStatic::getTable(),
+ 'WHERE' => ['plugin_deploy_computers_groups_id' => $this->fields['id']],
+ ];
+
+ $iterator = $DB->request($params);
+ $count = count($iterator);
+
+ return $count;
+ }
+
+
+ public static function install(Migration $migration)
+ {
+ /** @var object $DB */
+ global $DB;
+ $table = self::getTable();
+ if (!$DB->tableExists($table)) {
+ $migration->displayMessage("Installing $table");
+ $query = "CREATE TABLE IF NOT EXISTS `$table` (
`id` int unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`comment` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
@@ -223,49 +233,51 @@ public static function install(Migration $migration) {
KEY `date_creation` (`date_creation`),
KEY `date_mod` (`date_mod`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;";
- $DB->doQuery($query) or die($DB->error());
+ $DB->doQuery($query) or die($DB->error());
- // install default display preferences
+ // install default display preferences
// add display preferences
- $nb_display_pref = countElementsInTable(DisplayPreference::getTable(), [
- 'itemtype' => self::getType()
- ]);
- if ($nb_display_pref == 0) {
- $dp = new DisplayPreference;
- $i = 1;
- foreach ([3, 5, 6] as $id_so) {
- $dp->add([
- 'itemtype' => self::getType(),
- 'num' => $id_so,
- 'rank' => $i,
- 'users_id' => 0,
- ]);
- $i++;
- }
- }
- }
- }
-
+ $nb_display_pref = countElementsInTable(DisplayPreference::getTable(), [
+ 'itemtype' => self::getType()
+ ]);
+ if ($nb_display_pref == 0) {
+ $dp = new DisplayPreference();
+ $i = 1;
+ foreach ([3, 5, 6] as $id_so) {
+ $dp->add([
+ 'itemtype' => self::getType(),
+ 'num' => $id_so,
+ 'rank' => $i,
+ 'users_id' => 0,
+ ]);
+ $i++;
+ }
+ }
+ }
+ }
- public static function uninstall(Migration $migration) {
- global $DB;
- $table = self::getTable();
- $migration->displayMessage("Uninstalling $table");
- $migration->dropTable($table);
+ public static function uninstall(Migration $migration)
+ {
+ /** @var object $DB */
+ global $DB;
- $DB->doQuery("DELETE FROM `glpi_displaypreferences` WHERE `itemtype` = 'GlpiPlugin\\\Deploy\\\Computer\\\Group'");
- }
+ $table = self::getTable();
+ $migration->displayMessage("Uninstalling $table");
+ $migration->dropTable($table);
+ $DB->doQuery("DELETE FROM `glpi_displaypreferences` WHERE `itemtype` = 'GlpiPlugin\\\Deploy\\\Computer\\\Group'");
+ }
- static function getIcon() {
- return "fa-fw ti ti-device-laptop";
- }
+ public static function getIcon()
+ {
+ return "fa-fw ti ti-device-laptop";
+ }
- function post_purgeItem() {
+ public function post_purgeItem()
+ {
}
-
}
diff --git a/src/Computer/GroupDynamic.php b/src/Computer/GroupDynamic.php
new file mode 100644
index 0000000..adf1ca4
--- /dev/null
+++ b/src/Computer/GroupDynamic.php
@@ -0,0 +1,309 @@
+.
+ * -------------------------------------------------------------------------
+ * @copyright Copyright (C) 2022-2024 by Deploy plugin team.
+ * @license GPLv3 https://www.gnu.org/licenses/gpl-3.0.html
+ * @link https://github.com/pluginsGLPI/deploy
+ * -------------------------------------------------------------------------
+ */
+
+namespace GlpiPlugin\Deploy\Computer;
+
+use CommonDBTM;
+use CommonGLPI;
+use Computer;
+use Dropdown;
+use Html;
+use Migration;
+use Search;
+use Session;
+use Toolbox;
+
+class GroupDynamic extends CommonDBTM
+{
+ public static $rightname = 'computer_group';
+
+ public static function getTypeName($nb = 0)
+ {
+ return _n('Dynamic groups', 'Dynamic group', $nb, 'deploy');
+ }
+
+
+ public static function canCreate()
+ {
+ return Session::haveRight(static::$rightname, UPDATE);
+ }
+
+
+ public static function canPurge()
+ {
+ return Session::haveRight(static::$rightname, UPDATE);
+ }
+
+
+ public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0)
+ {
+
+ if (get_class($item) == Group::getType()) {
+ $count = 0;
+ $computergroup_dynamic = new self();
+ if (
+ $computergroup_dynamic->getFromDBByCrit([
+ 'plugin_deploy_computers_groups_id' => $item->getID()
+ ])
+ ) {
+ $count = $computergroup_dynamic->countDynamicItems();
+ }
+ $ong = [];
+ $ong[1] = self::createTabEntry(self::getTypeName(Session::getPluralNumber()), $count);
+ return $ong;
+ }
+ return '';
+ }
+
+
+ public static function getSpecificValueToDisplay($field, $values, array $options = [])
+ {
+
+ if (!is_array($values)) {
+ $values = [$field => $values];
+ }
+ Toolbox::logDebug($field);
+ switch ($field) {
+ case 'search':
+ $count = 0;
+ if (strpos($values['id'], Search::NULLVALUE) === false) {
+ $computergroup_dynamic = new GroupDynamic();
+ $computergroup_dynamic->getFromDB($values['id']);
+ $count = $computergroup_dynamic->countDynamicItems();
+ }
+ Toolbox::logDebug($count);
+ return ($count) ? $count : ' 0 ';
+
+ case '_virtual_dynamic_list':
+ /** @var array $CFG_GLPI */
+ global $CFG_GLPI;
+ $value = " ";
+ $out = " ";
+ if (strpos($values['id'], Search::NULLVALUE) === false) {
+ $computers_params = unserialize($values['search']);
+ $computers_params["reset"] = true;
+ $search_params = Search::manageParams('Computer', $computers_params);
+ $data = Search::prepareDatasForSearch('Computer', $search_params);
+ Search::constructSQL($data);
+ Search::constructData($data);
+
+ foreach ($data['data']['rows'] as $colvalue) {
+ $value .= "";
+ $value .= Dropdown::getDropdownName('glpi_computers', $colvalue['id']) . "" . Search::LBBR;
+ }
+ }
+
+ if (!preg_match('/' . Search::LBHR . '/', $value)) {
+ $values = preg_split('/' . Search::LBBR . '/i', $value);
+ $line_delimiter = '
';
+ } else {
+ $values = preg_split('/' . Search::LBHR . '/i', $value);
+ $line_delimiter = '
';
+ }
+
+ //move full list to tooltip if needed
+ if (
+ count($values) > 1
+ && Toolbox::strlen($value) > $CFG_GLPI['cut']
+ ) {
+ $value = '';
+ foreach ($values as $v) {
+ $value .= $v . $line_delimiter;
+ }
+ $value = preg_replace('/' . Search::LBBR . '/', '
', $value);
+ $value = preg_replace('/' . Search::LBHR . '/', '
', $value);
+ $value = '';
+ $valTip = " " . Html::showToolTip(
+ $value,
+ [
+ 'awesome-class' => 'fa-comments',
+ 'display' => false,
+ 'autoclose' => false,
+ 'onclick' => true
+ ]
+ );
+ $out .= $values[0] . $valTip;
+ } else {
+ $value = preg_replace('/' . Search::LBBR . '/', '
', $value);
+ $value = preg_replace('/' . Search::LBHR . '/', '
', $value);
+ $out .= $value;
+ }
+ return $out;
+ }
+ return '';
+ }
+
+
+ public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0)
+ {
+ switch ($tabnum) {
+ case 1:
+ self::showForItem($item);
+ break;
+ }
+ return true;
+ }
+
+
+ public function countDynamicItems()
+ {
+ $count = 0;
+ $computers_params = unserialize($this->fields['search']);
+ $computers_params["reset"] = true;
+ $search_params = Search::manageParams('Computer', $computers_params);
+ $data = Search::prepareDatasForSearch('Computer', $search_params);
+ Search::constructSQL($data);
+ Search::constructData($data, true);
+ $count = $data['data']['totalcount'];
+ return $count;
+ }
+
+ public function isDynamicSearchMatchComputer(Computer $computer)
+ {
+ $count = 0;
+
+ //add new criteria to force computer ID
+ $search = unserialize($this->fields['search']);
+ $search['criteria'][] = [
+ "link" => "AND",
+ "field" => 2, //computer ID
+ "searchtype" => 'contains',
+ "value" => $computer->fields['id'],
+ ];
+
+ $search["reset"] = true;
+ $search_params = Search::manageParams('Computer', $search);
+ $data = Search::prepareDatasForSearch('Computer', $search_params);
+ Search::constructSQL($data);
+ Search::constructData($data, true);
+ $count = $data['data']['totalcount'];
+ return $count;
+ }
+
+
+ public static function showForItem(Group $computergroup)
+ {
+
+ $ID = $computergroup->getField('id');
+ if (!$computergroup->can($ID, UPDATE)) {
+ return false;
+ }
+
+ $canedit = $computergroup->canEdit($ID);
+ if ($canedit) {
+ $firsttime = true;
+ //load dynamic search criteria from DB if exist
+ $computergroup_dynamic = new self();
+ if (
+ $computergroup_dynamic->getFromDBByCrit([
+ 'plugin_deploy_computers_groups_id' => $ID
+ ])
+ ) {
+ $computers_params = unserialize($computergroup_dynamic->fields['search']);
+ $computers_params["reset"] = true;
+ $p = $search_params = Search::manageParams('Computer', $computers_params);
+ $firsttime = false;
+ } else {
+ //retrieve filter value from search if exist and reset it
+ $_GET["reset"] = true;
+ $p = $search_params = Search::manageParams('Computer', $_GET);
+ if (isset($_SESSION['glpisearch']['Computer'])) {
+ unset($_SESSION['glpisearch']['Computer']);
+ }
+ }
+
+ //redirect to computergroup dynamic tab after saved search
+ $target = Group::getFormURLWithID($ID);
+ $target .= "&_glpi_tab=Computer_GroupDynamic$1";
+ $p['target'] = $target;
+ $p['addhidden'] = [
+ 'plugin_deploy_computers_groups_id' => $computergroup->getID(),
+ 'id' => $computergroup->getID(),
+ 'start' => 0
+ ];
+ $p['actionname'] = 'save';
+ $p['actionvalue'] = _sx('button', 'Save');
+ $p['showbookmark'] = false;
+ Search::showGenericSearch(Computer::getType(), $p);
+
+ //display result from search
+ if (!$firsttime) {
+ $data = Search::prepareDatasForSearch('Computer', $search_params);
+ Search::constructSQL($data);
+ Search::constructData($data);
+ $data['search']['target'] = $target;
+ $data['search']['showmassiveactions'] = false;
+ $data['search']['is_deleted'] = false;
+ Search::displayData($data);
+
+ //remove search header(trashbin / map switch)
+ echo Html::scriptBlock("
+ $(document).ready(
+ function() {
+ $('div.search-header').remove();
+ }
+ );
+ ");
+ }
+ }
+
+ return true;
+ }
+
+
+ public static function install(Migration $migration)
+ {
+ /** @var object $DB */
+ global $DB;
+ $table = self::getTable();
+ if (!$DB->tableExists($table)) {
+ $migration->displayMessage("Installing $table");
+ $query = "CREATE TABLE IF NOT EXISTS `$table` (
+ `id` int unsigned NOT NULL AUTO_INCREMENT,
+ `plugin_deploy_computers_groups_id` int unsigned NOT NULL DEFAULT '0',
+ `search` text,
+ PRIMARY KEY (`id`),
+ KEY `computergroups_id` (`plugin_deploy_computers_groups_id`)
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;";
+ $DB->doQuery($query) or die($DB->error());
+ }
+ }
+
+
+ public static function uninstall(Migration $migration)
+ {
+ /** @var object $DB */
+ global $DB;
+ $table = self::getTable();
+ if ($DB->tableExists($table)) {
+ $DB->doQuery("DROP TABLE IF EXISTS `" . self::getTable() . "`") or die($DB->error());
+ }
+ }
+}
diff --git a/src/Computer/GroupStatic.php b/src/Computer/GroupStatic.php
new file mode 100644
index 0000000..aff52ca
--- /dev/null
+++ b/src/Computer/GroupStatic.php
@@ -0,0 +1,224 @@
+.
+ * -------------------------------------------------------------------------
+ * @copyright Copyright (C) 2022-2024 by Deploy plugin team.
+ * @license GPLv3 https://www.gnu.org/licenses/gpl-3.0.html
+ * @link https://github.com/pluginsGLPI/deploy
+ * -------------------------------------------------------------------------
+ */
+
+ namespace GlpiPlugin\Deploy\Computer;
+
+use CommonDBRelation;
+use CommonGLPI;
+use Computer;
+use Dropdown;
+use Entity;
+use Glpi\Application\View\TemplateRenderer;
+use Html;
+use Migration;
+use Search;
+use Session;
+use Toolbox;
+
+class GroupStatic extends CommonDBRelation
+{
+ // From CommonDBRelation
+ public static $itemtype_1 = 'GlpiPlugin\Deploy\Computer\Group';
+ public static $items_id_1 = 'plugin_deploy_computers_groups_id';
+ public static $itemtype_2 = 'Computer';
+ public static $items_id_2 = 'computers_id';
+
+ public static $checkItem_2_Rights = self::DONT_CHECK_ITEM_RIGHTS;
+ public static $logs_for_item_2 = false;
+ public $auto_message_on_action = false;
+
+ public static $rightname = 'computer_group';
+
+
+ public static function getTypeName($nb = 0)
+ {
+ return _n('Static groups', 'Static group', $nb, 'deploy');
+ }
+
+
+ public static function canCreate()
+ {
+ return Session::haveRight(static::$rightname, UPDATE);
+ }
+
+
+ public function canCreateItem()
+ {
+ return Session::haveRight(static::$rightname, UPDATE);
+ }
+
+
+ public static function canPurge()
+ {
+ return Session::haveRight(static::$rightname, UPDATE);
+ return true;
+ }
+
+
+ public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0)
+ {
+ if (get_class($item) == Group::getType()) {
+ $count = 0;
+ $count = countElementsInTable(self::getTable(), ['plugin_deploy_computers_groups_id' => $item->getID()]);
+ $ong = [];
+ $ong[1] = self::createTabEntry(self::getTypeName(Session::getPluralNumber()), $count);
+ return $ong;
+ }
+ return '';
+ }
+
+
+ public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0)
+ {
+ switch ($tabnum) {
+ case 1:
+ self::showForItem($item);
+ break;
+ }
+ return true;
+ }
+
+
+ private static function getheadings(): array
+ {
+ return [
+ 'name' => __('Name'),
+ 'is_dynamic' => __('Automatic inventory'),
+ 'entities_id' => Entity::getTypeName(1),
+ 'serial' => __('Serial number'),
+ 'otherserial' => __('Inventory number'),
+ ];
+ }
+
+
+ public static function showForItem(Group $computergroup)
+ {
+ /** @var object $DB */
+ global $DB;
+
+ $ID = $computergroup->getField('id');
+ if (!$computergroup->can($ID, UPDATE)) {
+ return false;
+ }
+
+ $datas = [];
+ $used = [];
+ $params = [
+ 'SELECT' => '*',
+ 'FROM' => self::getTable(),
+ 'WHERE' => ['plugin_deploy_computers_groups_id' => $ID],
+ ];
+
+ $iterator = $DB->request($params);
+ foreach ($iterator as $data) {
+ $datas[] = $data;
+ $used [] = $data['computers_id'];
+ }
+
+ if ($computergroup->canAddItem('itemtype')) {
+ TemplateRenderer::getInstance()->display('@deploy/computer_group/computer_group_static.html.twig', [
+ 'form_action' => Toolbox::getItemTypeFormURL("GlpiPlugin\Deploy\Computer\Group"),
+ 'computers_groups_id' => $ID,
+ 'computer_used' => $used,
+ 'params' => [],
+ ]);
+ }
+
+ $canread = $computergroup->can($ID, READ);
+ $rows = [];
+ if ($canread) {
+ foreach ($datas as $data) {
+ $row = [];
+
+ $computer = new Computer();
+ $computer->getFromDB($data["computers_id"]);
+ $linkname = $computer->fields["name"];
+ $itemtype = Computer::getType();
+ if ($_SESSION["glpiis_ids_visible"] || empty($computer->fields["name"])) {
+ $linkname = sprintf(__('%1$s (%2$s)'), $linkname, $computer->fields["id"]);
+ }
+ $link = $itemtype::getFormURLWithID($computer->fields["id"]);
+ $name = "" . $linkname . "";
+
+ $row['name'] = $name;
+ $row['id'] = $data["id"];
+ $row['is_deleted'] = $computer->fields["is_deleted"];
+ $row['is_dynamic'] = Dropdown::getYesNo($computer->fields['is_dynamic']);
+ $row['entity'] = Dropdown::getDropdownName("glpi_entities", $computer->fields['entities_id']);
+ $row['serial'] = (isset($computer->fields["serial"]) ? "" . $computer->fields["serial"] . "" : "-");
+ $row['otherserial'] = (isset($computer->fields["otherserial"]) ? "" . $computer->fields["otherserial"] . "" : "-");
+ $rows[] = $row;
+ }
+
+ TemplateRenderer::getInstance()->display('@deploy/computer_group/computer_group_static_list.html.twig', [
+ 'subitem_type' => 'ComputerGroupStatic',
+ 'itemtype' => self::getType(),
+ 'plugin_deploy_computers_groups_id' => $ID,
+ 'count' => count($rows),
+ 'entries' => $rows,
+ 'none_found' => sprintf(__('No %s found', 'deploy'), self::getTypeName(Session::getPluralNumber())),
+ 'headings' => self::getheadings(),
+ ]);
+ }
+
+ return true;
+ }
+
+
+ public static function install(Migration $migration)
+ {
+ /** @var object $DB */
+ global $DB;
+ $table = self::getTable();
+ if (!$DB->tableExists($table)) {
+ $migration->displayMessage("Installing $table");
+ $query = "CREATE TABLE IF NOT EXISTS `$table` (
+ `id` int unsigned NOT NULL AUTO_INCREMENT,
+ `plugin_deploy_computers_groups_id` int unsigned NOT NULL DEFAULT '0',
+ `computers_id` int unsigned NOT NULL DEFAULT '0',
+ PRIMARY KEY (`id`),
+ KEY `computers_id` (`computers_id`),
+ KEY `computergroups_id` (`plugin_deploy_computers_groups_id`)
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;";
+ $DB->doQuery($query) or die($DB->error());
+ }
+ }
+
+
+ public static function uninstall(Migration $migration)
+ {
+ /** @var object $DB */
+ global $DB;
+ $table = self::getTable();
+ if ($DB->tableExists($table)) {
+ $DB->doQuery("DROP TABLE IF EXISTS `" . self::getTable() . "`") or die($DB->error());
+ }
+ }
+}
diff --git a/src/Computer/Group_Dynamic.php b/src/Computer/Group_Dynamic.php
deleted file mode 100644
index bd8b561..0000000
--- a/src/Computer/Group_Dynamic.php
+++ /dev/null
@@ -1,288 +0,0 @@
-.
- * -------------------------------------------------------------------------
- * @copyright Copyright (C) 2022-2024 by Deploy plugin team.
- * @license GPLv3 https://www.gnu.org/licenses/gpl-3.0.html
- * @link https://github.com/pluginsGLPI/deploy
- * -------------------------------------------------------------------------
- */
-
-namespace GlpiPlugin\Deploy\Computer;
-
-use CommonDBTM;
-use CommonGLPI;
-use Computer;
-use Dropdown;
-use Html;
-use Migration;
-use Search;
-use Session;
-use Toolbox;
-
-class Group_Dynamic extends CommonDBTM
-{
- static $rightname = 'computer_group';
-
- static function getTypeName($nb = 0) {
- return _n('Dynamic groups', 'Dynamic group', $nb, 'deploy');
- }
-
-
- static function canCreate() {
- return Session::haveRight(static::$rightname, UPDATE);
- }
-
-
- static function canPurge() {
- return Session::haveRight(static::$rightname, UPDATE);
- }
-
-
- function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) {
-
- if (get_class($item) == Group::getType()) {
- $count = 0;
- $computergroup_dynamic = new self();
- if ($computergroup_dynamic->getFromDBByCrit([
- 'plugin_deploy_computers_groups_id' => $item->getID()])) {
- $count = $computergroup_dynamic->countDynamicItems();
- }
- $ong = [];
- $ong[1] = self::createTabEntry(Self::getTypeName(Session::getPluralNumber()), $count);
- return $ong;
- }
- return '';
- }
-
-
- static function getSpecificValueToDisplay($field, $values, array $options = []) {
-
- if (!is_array($values)) {
- $values = [$field => $values];
- }
- Toolbox::logDebug($field);
- switch ($field) {
- case 'search' :
- $count = 0;
- if (strpos($values['id'], Search::NULLVALUE) === false ) {
- $computergroup_dynamic = new Group_Dynamic();
- $computergroup_dynamic->getFromDB($values['id']);
- $count = $computergroup_dynamic->countDynamicItems();
- }
- Toolbox::logDebug($count);
- return ($count) ? $count : ' 0 ';
-
- case '_virtual_dynamic_list' :
- global $CFG_GLPI;
- $value = " ";
- $out = " ";
- if (strpos($values['id'], Search::NULLVALUE) === false ) {
- $computers_params = unserialize($values['search']);
- $computers_params["reset"] = true;
- $search_params = Search::manageParams('Computer', $computers_params);
- $data = Search::prepareDatasForSearch('Computer', $search_params);
- Search::constructSQL($data);
- Search::constructData($data);
-
- foreach ($data['data']['rows'] as $colvalue) {
- $value .= "";
- $value .= Dropdown::getDropdownName('glpi_computers', $colvalue['id'])."".Search::LBBR;
- }
- }
-
- if (!preg_match('/'.Search::LBHR.'/', $value)) {
- $values = preg_split('/'.Search::LBBR.'/i', $value);
- $line_delimiter = '
';
- } else {
- $values = preg_split('/'.Search::LBHR.'/i', $value);
- $line_delimiter = '
';
- }
-
- //move full list to tooltip if needed
- if (count($values) > 1
- && Toolbox::strlen($value) > $CFG_GLPI['cut']) {
- $value = '';
- foreach ($values as $v) {
- $value .= $v.$line_delimiter;
- }
- $value = preg_replace('/'.Search::LBBR.'/', '
', $value);
- $value = preg_replace('/'.Search::LBHR.'/', '
', $value);
- $value = '';
- $valTip = " ".Html::showToolTip(
- $value, [
- 'awesome-class' => 'fa-comments',
- 'display' => false,
- 'autoclose' => false,
- 'onclick' => true
- ]
- );
- $out .= $values[0] . $valTip;
- } else {
- $value = preg_replace('/'.Search::LBBR.'/', '
', $value);
- $value = preg_replace('/'.Search::LBHR.'/', '
', $value);
- $out .= $value;
- }
- return $out;
- }
- return '';
- }
-
-
- static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0) {
- switch ($tabnum) {
- case 1 :
- self::showForItem($item);
- break;
- }
- return true;
- }
-
-
- function countDynamicItems(){
- $count = 0;
- $computers_params = unserialize($this->fields['search']);
- $computers_params["reset"] = true;
- $search_params = Search::manageParams('Computer', $computers_params);
- $data = Search::prepareDatasForSearch('Computer', $search_params);
- Search::constructSQL($data);
- Search::constructData($data, true);
- $count = $data['data']['totalcount'];
- return $count;
- }
-
- function isDynamicSearchMatchComputer(Computer $computer){
- $count = 0;
-
- //add new criteria to force computer ID
- $search = unserialize($this->fields['search']);
- $search['criteria'][] = [
- "link" => "AND",
- "field" => 2, //computer ID
- "searchtype" => 'contains',
- "value" => $computer->fields['id'],
- ];
-
- $search["reset"] = true;
- $search_params = Search::manageParams('Computer', $search);
- $data = Search::prepareDatasForSearch('Computer', $search_params);
- Search::constructSQL($data);
- Search::constructData($data, true);
- $count = $data['data']['totalcount'];
- return $count;
- }
-
-
- static function showForItem(Group $computergroup) {
-
- $ID = $computergroup->getField('id');
- if (!$computergroup->can($ID, UPDATE)) {
- return false;
- }
-
- $canedit = $computergroup->canEdit($ID);
- if ($canedit) {
-
- $firsttime = true;
- //load dynamic search criteria from DB if exist
- $computergroup_dynamic = new self();
- if ($computergroup_dynamic->getFromDBByCrit([
- 'plugin_deploy_computers_groups_id' => $ID
- ])) {
- $computers_params = unserialize($computergroup_dynamic->fields['search']);
- $computers_params["reset"] = true;
- $p = $search_params = Search::manageParams('Computer', $computers_params);
- $firsttime = false;
- }else{
- //retrieve filter value from search if exist and reset it
- $_GET["reset"] = true;
- $p = $search_params = Search::manageParams('Computer', $_GET);
- if (isset($_SESSION['glpisearch']['Computer'])) {
- unset($_SESSION['glpisearch']['Computer']);
- }
- }
-
- //redirect to computergroup dynamic tab after saved search
- $target = Group::getFormURLWithID($ID);
- $target .= "&_glpi_tab=Computer_Group_Dynamic$1";
- $p['target'] = $target;
- $p['addhidden'] = [
- 'plugin_deploy_computers_groups_id' => $computergroup->getID(),
- 'id' => $computergroup->getID(),
- 'start' => 0
- ];
- $p['actionname'] = 'save';
- $p['actionvalue'] = _sx('button', 'Save');
- $p['showbookmark'] = false;
- Search::showGenericSearch(Computer::getType(), $p);
-
- //display result from search
- if(!$firsttime) {
- $data = Search::prepareDatasForSearch('Computer', $search_params);
- Search::constructSQL($data);
- Search::constructData($data);
- $data['search']['target'] = $target;
- $data['search']['showmassiveactions'] = false;
- $data['search']['is_deleted'] = false;
- Search::displayData($data);
-
- //remove search header(trashbin / map switch)
- echo Html::scriptBlock("
- $(document).ready(
- function() {
- $('div.search-header').remove();
- }
- );
- ");
- }
- }
-
- return true;
- }
-
-
- public static function install(Migration $migration) {
- global $DB;
- $table = self::getTable();
- if (!$DB->tableExists($table)) {
- $migration->displayMessage("Installing $table");
- $query = "CREATE TABLE IF NOT EXISTS `$table` (
- `id` int unsigned NOT NULL AUTO_INCREMENT,
- `plugin_deploy_computers_groups_id` int unsigned NOT NULL DEFAULT '0',
- `search` text,
- PRIMARY KEY (`id`),
- KEY `computergroups_id` (`plugin_deploy_computers_groups_id`)
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;";
- $DB->doQuery($query) or die($DB->error());
- }
- }
-
-
- public static function uninstall(Migration $migration) {
- global $DB;
- $table = self::getTable();
- if ($DB->tableExists($table)) {
- $DB->doQuery("DROP TABLE IF EXISTS `".self::getTable()."`") or die ($DB->error());
- }
- }
-}
diff --git a/src/Computer/Group_Static.php b/src/Computer/Group_Static.php
deleted file mode 100644
index 8bf389a..0000000
--- a/src/Computer/Group_Static.php
+++ /dev/null
@@ -1,216 +0,0 @@
-.
- * -------------------------------------------------------------------------
- * @copyright Copyright (C) 2022-2024 by Deploy plugin team.
- * @license GPLv3 https://www.gnu.org/licenses/gpl-3.0.html
- * @link https://github.com/pluginsGLPI/deploy
- * -------------------------------------------------------------------------
- */
-
- namespace GlpiPlugin\Deploy\Computer;
-
-use CommonDBRelation;
-use CommonGLPI;
-use Computer;
-use Dropdown;
-use Entity;
-use Glpi\Application\View\TemplateRenderer;
-use Html;
-use Migration;
-use Search;
-use Session;
-use Toolbox;
-
-class Group_Static extends CommonDBRelation
-{
-
- // From CommonDBRelation
- static public $itemtype_1 = 'GlpiPlugin\Deploy\Computer\Group';
- static public $items_id_1 = 'plugin_deploy_computers_groups_id';
- static public $itemtype_2 = 'Computer';
- static public $items_id_2 = 'computers_id';
-
- static public $checkItem_2_Rights = self::DONT_CHECK_ITEM_RIGHTS;
- static public $logs_for_item_2 = false;
- public $auto_message_on_action = false;
-
- static $rightname = 'computer_group';
-
-
- static function getTypeName($nb = 0) {
- return _n('Static groups', 'Static group', $nb, 'deploy');
- }
-
-
- static function canCreate() {
- return Session::haveRight(static::$rightname, UPDATE);
- }
-
-
- function canCreateItem() {
- return Session::haveRight(static::$rightname, UPDATE);
- }
-
-
- static function canPurge() {
- return Session::haveRight(static::$rightname, UPDATE);
- return true;
- }
-
-
- function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) {
- if (get_class($item) == Group::getType()) {
- $count = 0;
- $count = countElementsInTable(self::getTable(), ['plugin_deploy_computers_groups_id' => $item->getID()]);
- $ong = [];
- $ong[1] = self::createTabEntry(Self::getTypeName(Session::getPluralNumber()), $count);
- return $ong;
- }
- return '';
- }
-
-
- static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0) {
- switch ($tabnum) {
- case 1 :
- self::showForItem($item);
- break;
- }
- return true;
- }
-
-
- private static function getheadings(): array
- {
- return [
- 'name' => __('Name'),
- 'is_dynamic' => __('Automatic inventory'),
- 'entities_id' => Entity::getTypeName(1),
- 'serial' => __('Serial number'),
- 'otherserial' => __('Inventory number'),
- ];
- }
-
-
- static function showForItem(Group $computergroup)
- {
- global $DB;
-
- $ID = $computergroup->getField('id');
- if (!$computergroup->can($ID, UPDATE)) {
- return false;
- }
-
- $datas = [];
- $used = [];
- $params = [
- 'SELECT' => '*',
- 'FROM' => self::getTable(),
- 'WHERE' => ['plugin_deploy_computers_groups_id' => $ID],
- ];
-
- $iterator = $DB->request($params);
- foreach ($iterator as $data) {
- $datas[] = $data;
- $used [] = $data['computers_id'];
- }
-
- if ($computergroup->canAddItem('itemtype')) {
- TemplateRenderer::getInstance()->display('@deploy/computer_group/computer_group_static.html.twig', [
- 'form_action' => Toolbox::getItemTypeFormURL("GlpiPlugin\Deploy\Computer\Group"),
- 'computers_groups_id' => $ID,
- 'computer_used' => $used,
- 'params' => [],
- ]);
- }
-
- $canread = $computergroup->can($ID, READ);
- $rows = [];
- if ($canread) {
- foreach ($datas as $data) {
- $row = [];
-
- $computer = new Computer();
- $computer->getFromDB($data["computers_id"]);
- $linkname = $computer->fields["name"];
- $itemtype = Computer::getType();
- if ($_SESSION["glpiis_ids_visible"] || empty($computer->fields["name"])) {
- $linkname = sprintf(__('%1$s (%2$s)'), $linkname, $computer->fields["id"]);
- }
- $link = $itemtype::getFormURLWithID($computer->fields["id"]);
- $name = "".$linkname."";
-
- $row['name'] = $name;
- $row['id'] = $data["id"];
- $row['is_deleted'] = $computer->fields["is_deleted"];
- $row['is_dynamic'] = Dropdown::getYesNo($computer->fields['is_dynamic']);
- $row['entity'] = Dropdown::getDropdownName("glpi_entities", $computer->fields['entities_id']);
- $row['serial'] = (isset($computer->fields["serial"])? "".$computer->fields["serial"]."" :"-");
- $row['otherserial'] = (isset($computer->fields["otherserial"])? "".$computer->fields["otherserial"]."" :"-");
- $rows[] = $row;
- }
-
- TemplateRenderer::getInstance()->display('@deploy/computer_group/computer_group_static_list.html.twig', [
- 'subitem_type' => 'ComputerGroupStatic',
- 'itemtype' => self::getType(),
- 'plugin_deploy_computers_groups_id' => $ID,
- 'count' => count($rows),
- 'entries' => $rows,
- 'none_found' => sprintf(__('No %s found', 'deploy'), self::getTypeName(Session::getPluralNumber())),
- 'headings' => self::getheadings(),
- ]);
-
- }
-
- return true;
- }
-
-
- public static function install(Migration $migration) {
- global $DB;
- $table = self::getTable();
- if (!$DB->tableExists($table)) {
- $migration->displayMessage("Installing $table");
- $query = "CREATE TABLE IF NOT EXISTS `$table` (
- `id` int unsigned NOT NULL AUTO_INCREMENT,
- `plugin_deploy_computers_groups_id` int unsigned NOT NULL DEFAULT '0',
- `computers_id` int unsigned NOT NULL DEFAULT '0',
- PRIMARY KEY (`id`),
- KEY `computers_id` (`computers_id`),
- KEY `computergroups_id` (`plugin_deploy_computers_groups_id`)
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;";
- $DB->doQuery($query) or die($DB->error());
- }
- }
-
-
- public static function uninstall(Migration $migration) {
- global $DB;
- $table = self::getTable();
- if ($DB->tableExists($table)) {
- $DB->doQuery("DROP TABLE IF EXISTS `".self::getTable()."`") or die ($DB->error());
- }
- }
-
-}
diff --git a/src/Menu.php b/src/Menu.php
index 04ad918..37e7d32 100644
--- a/src/Menu.php
+++ b/src/Menu.php
@@ -31,7 +31,7 @@
namespace GlpiPlugin\Deploy;
use GlpiPlugin\Deploy\Computer\Group;
-use \Session;
+use Session;
class Menu
{
@@ -47,7 +47,7 @@ public static function getIcon()
}
- static function getMenuContent()
+ public static function getMenuContent()
{
$menu = [];
@@ -99,7 +99,6 @@ static function getMenuContent()
$menu['options']['computer_group']['options']['add'] = Group::getFormURL(false);
$menu['options']['computer_group']['links']['add'] = Group::getFormURL(false);
}
-
}
if (count($menu)) {
diff --git a/src/Package.php b/src/Package.php
index ef56f7a..385e8e9 100644
--- a/src/Package.php
+++ b/src/Package.php
@@ -60,10 +60,10 @@ public function defineTabs($options = [])
$ong = [];
$this->addDefaultFormTab($ong)
- ->addStandardTab(Package_Check::getType(), $ong, $options)
- ->addStandardTab(Package_File::getType(), $ong, $options)
- ->addStandardTab(Package_Action::getType(), $ong, $options)
- ->addStandardTab(Package_Target::getType(), $ong, $options)
+ ->addStandardTab(PackageCheck::getType(), $ong, $options)
+ ->addStandardTab(PackageFile::getType(), $ong, $options)
+ ->addStandardTab(PackageAction::getType(), $ong, $options)
+ ->addStandardTab(PackageTarget::getType(), $ong, $options)
->addStandardTab(__CLASS__, $ong, $options);
return $ong;
@@ -79,9 +79,9 @@ public function showDebug()
public static function getJson(Package $package, bool $pretty_json = false): string
{
- $checks = Package_Check::getFormattedArrayForPackage($package);
- $files = Package_File::getFormattedArrayForPackage($package);
- $actions = Package_Action::getFormattedArrayForPackage($package);
+ $checks = PackageCheck::getFormattedArrayForPackage($package);
+ $files = PackageFile::getFormattedArrayForPackage($package);
+ $actions = PackageAction::getFormattedArrayForPackage($package);
$json_array = [
'jobs' => [
@@ -101,12 +101,12 @@ public static function moveSubitem(
int $ID,
int $ref_ID,
string $type = self::MOVE_AFTER
- ): bool
- {
+ ): bool {
+ /** @var object $DB */
global $DB;
$used_traits = class_uses($subitem_itemtype);
- if (!in_array("Package_Subitem", $used_traits)) {
+ if (!in_array("PackageSubitem", $used_traits)) {
return false;
}
@@ -244,7 +244,7 @@ public function cleanDBonPurge()
{
$this->deleteChildrenAndRelationsFromDb(
[
- Package_Target::class,
+ PackageTarget::class,
]
);
}
@@ -252,6 +252,7 @@ public function cleanDBonPurge()
public static function install(Migration $migration)
{
+ /** @var object $DB */
global $DB;
$table = self::getTable();
@@ -289,7 +290,7 @@ public static function install(Migration $migration)
'itemtype' => self::getType()
]);
if ($nb_display_pref == 0) {
- $dp = new DisplayPreference;
+ $dp = new DisplayPreference();
$i = 1;
foreach ([1, 80, 121, 19] as $id_so) {
$dp->add([
@@ -305,6 +306,7 @@ public static function install(Migration $migration)
public static function uninstall(Migration $migration)
{
+ /** @var object $DB */
global $DB;
$table = self::getTable();
diff --git a/src/Package_Action.php b/src/PackageAction.php
similarity index 86%
rename from src/Package_Action.php
rename to src/PackageAction.php
index a90ce09..70c5524 100644
--- a/src/Package_Action.php
+++ b/src/PackageAction.php
@@ -34,9 +34,9 @@
use DBConnection;
use Migration;
-class Package_Action extends CommonDBTM
+class PackageAction extends CommonDBTM
{
- use Package_Subitem;
+ use PackageSubitem;
public static $rightname = 'entity';
@@ -74,15 +74,15 @@ public static function getTypes(bool $with_icon = false): array
{
$base_icon = '';
return [
- SELF::ACTION_CMD => ($with_icon ? sprintf($base_icon, self::getTypeIconClass(SELF::ACTION_CMD)) : "")
+ self::ACTION_CMD => ($with_icon ? sprintf($base_icon, self::getTypeIconClass(self::ACTION_CMD)) : "")
. __('Run command', 'deploy'),
- SELF::ACTION_MOVE => ($with_icon ? sprintf($base_icon, self::getTypeIconClass(SELF::ACTION_MOVE)) : "")
+ self::ACTION_MOVE => ($with_icon ? sprintf($base_icon, self::getTypeIconClass(self::ACTION_MOVE)) : "")
. __('Move file', 'deploy'),
- SELF::ACTION_COPY => ($with_icon ? sprintf($base_icon, self::getTypeIconClass(SELF::ACTION_COPY)) : "")
+ self::ACTION_COPY => ($with_icon ? sprintf($base_icon, self::getTypeIconClass(self::ACTION_COPY)) : "")
. __('Copy file', 'deploy'),
- SELF::ACTION_DELETE => ($with_icon ? sprintf($base_icon, self::getTypeIconClass(SELF::ACTION_DELETE)) : "")
+ self::ACTION_DELETE => ($with_icon ? sprintf($base_icon, self::getTypeIconClass(self::ACTION_DELETE)) : "")
. __('Delete file', 'deploy'),
- SELF::ACTION_MKDIR => ($with_icon ? sprintf($base_icon, self::getTypeIconClass(SELF::ACTION_MKDIR)) : "")
+ self::ACTION_MKDIR => ($with_icon ? sprintf($base_icon, self::getTypeIconClass(self::ACTION_MKDIR)) : "")
. __('Create directory', 'deploy'),
];
}
@@ -91,15 +91,15 @@ public static function getTypes(bool $with_icon = false): array
public static function getTypeIconClass($type = ""): string
{
switch ($type) {
- case SELF::ACTION_CMD:
+ case self::ACTION_CMD:
return 'ti ti-terminal';
- case SELF::ACTION_MOVE:
+ case self::ACTION_MOVE:
return 'ti ti-drag-drop-2';
- case SELF::ACTION_COPY:
+ case self::ACTION_COPY:
return 'ti ti-copy';
- case SELF::ACTION_DELETE:
+ case self::ACTION_DELETE:
return 'ti ti-file-minus';
- case SELF::ACTION_MKDIR:
+ case self::ACTION_MKDIR:
return 'ti ti-folder-plus';
}
@@ -121,21 +121,21 @@ public static function getFormattedData(string $json = "", string $type = ""): s
switch ($type) {
case self::ACTION_CMD:
- $data_str = '' . $json_fields['exec']. '
';
+ $data_str = '' . $json_fields['exec'] . '
';
break;
case self::ACTION_MOVE:
case self::ACTION_COPY:
$data_str = sprintf(
__("From %s to %s", 'deploy'),
- '' .$json_fields['from']. '
',
- '' .$json_fields['to']. '
'
+ '' . $json_fields['from'] . '
',
+ '' . $json_fields['to'] . '
'
);
break;
case self::ACTION_DELETE:
- $data_str = '' . implode('
', $json_fields['list']). '
';
+ $data_str = '' . implode('
', $json_fields['list']) . '
';
break;
case self::ACTION_MKDIR:
- $data_str = '' . implode('
', $json_fields['list']). '
';
+ $data_str = '' . implode('
', $json_fields['list']) . '
';
break;
}
@@ -221,6 +221,7 @@ public static function getFormattedArrayForPackage(Package $package): array
public static function install(Migration $migration)
{
+ /** @var object $DB */
global $DB;
$table = self::getTable();
diff --git a/src/Package_Check.php b/src/PackageCheck.php
similarity index 98%
rename from src/Package_Check.php
rename to src/PackageCheck.php
index e5c0f7e..a1f2066 100644
--- a/src/Package_Check.php
+++ b/src/PackageCheck.php
@@ -34,9 +34,9 @@
use DBConnection;
use Migration;
-class Package_Check extends CommonDBTM
+class PackageCheck extends CommonDBTM
{
- use Package_Subitem;
+ use PackageSubitem;
public static $rightname = 'entity';
@@ -162,7 +162,7 @@ public static function getTypesWithValueField(): array
return [
self::WINKEYEQUALS => __("Value", 'deploy') . '',
self::WINKEYNOTEQUALS => __("Value", 'deploy') . '',
- self::WINVALUETYPE => __("Type of value", 'deploy'). '',
+ self::WINVALUETYPE => __("Type of value", 'deploy') . '',
self::FILESIZEGREATER => __("Size", 'deploy') . '',
self::FILESIZEEQUALS => __("Size", 'deploy') . '',
@@ -269,6 +269,7 @@ public function prepareInputForAdd($input)
public static function install(Migration $migration)
{
+ /** @var object $DB */
global $DB;
$table = self::getTable();
diff --git a/src/Package_File.php b/src/PackageFile.php
similarity index 94%
rename from src/Package_File.php
rename to src/PackageFile.php
index c0a8e9e..74abe39 100644
--- a/src/Package_File.php
+++ b/src/PackageFile.php
@@ -39,9 +39,9 @@
use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;
-class Package_File extends CommonDBTM
+class PackageFile extends CommonDBTM
{
- use Package_Subitem;
+ use PackageSubitem;
public static $rightname = 'entity';
@@ -75,9 +75,8 @@ private static function getheadings(): array
public function prepareInputForAdd($input)
{
- $repository = new Repository;
- switch ($input['upload_mode'])
- {
+ $repository = new Repository();
+ switch ($input['upload_mode']) {
case "from_computer":
$r_file = $repository->AddFileFromComputer();
$input = array_merge($input, $r_file->getDefinition());
@@ -107,7 +106,7 @@ public function pre_deleteItem()
// do not delete file in repository if it's also used in other packages
if (count($found_files) === 1) {
- $repository = new Repository;
+ $repository = new Repository();
$repository->deleteFile($this->fields['sha512']);
}
@@ -133,13 +132,12 @@ public static function getFilesTreeFromServer(): string
//the depth hasnt changed so just add another li
$li = $dom->createElement('li', $object->getFilename());
$li->setAttribute('id', $id);
- $li->setAttribute('data-json', '{"path": "'.$rel_path.'"}');
+ $li->setAttribute('data-json', '{"path": "' . $rel_path . '"}');
if ($object->isDir()) {
$li->setAttribute('class', 'folder');
}
$node->appendChild($li);
- }
- elseif ($dir_iterator->getDepth() > $depth) {
+ } elseif ($dir_iterator->getDepth() > $depth) {
//the depth increased, the last li is a non-empty folder
$li = $node->lastChild;
$ul = $dom->createElement('ul');
@@ -147,18 +145,17 @@ public static function getFilesTreeFromServer(): string
$li->setAttribute('id', $id);
$li->setAttribute('class', 'folder unselectable');
$new_li = $dom->createElement('li', $object->getFilename());
- $new_li->setAttribute('data-json', '{"path": "'.$rel_path.'"}');
+ $new_li->setAttribute('data-json', '{"path": "' . $rel_path . '"}');
$ul->appendChild($new_li);
$node = $ul;
- }
- else{
+ } else {
//the depth decreased, going up $difference directories
$difference = $depth - $dir_iterator->getDepth();
for ($i = 0; $i < $difference; $difference--) {
$node = $node->parentNode->parentNode;
}
$li = $dom->createElement('li', $object->getFilename());
- $li->setAttribute('data-json', '{"path": "'.$rel_path.'"}');
+ $li->setAttribute('data-json', '{"path": "' . $rel_path . '"}');
$li->setAttribute('id', $id);
if ($object->isDir()) {
$li->setAttribute('class', 'folder');
@@ -233,18 +230,18 @@ public static function getFormattedArrayForPackage(Package $package): array
return $files;
}
- public function downloadFile($file_id) {
+ public function downloadFile($file_id)
+ {
session_write_close(); // unlock session to ensure GLPI is still usable while huge file downloads is done in background
- $package_file = new Package_File();
+ $package_file = new PackageFile();
if ($file_id > 0 && $package_file->getFromDB($file_id)) {
-
$mimetype = $package_file->fields['mimetype'];
$filesize = $package_file->fields['filesize'];
$filename = $package_file->fields['filename'];
$sha512 = $package_file->fields['sha512'];
- $repository = new Repository_File(
+ $repository = new RepositoryFile(
$filename,
"",
$filesize,
@@ -291,12 +288,12 @@ public function downloadFile($file_id) {
} else {
Html::displayErrorAndDie(__('File not found', 'deploy'), true); // Not found
}
-
}
public static function install(Migration $migration)
{
+ /** @var object $DB */
global $DB;
$table = self::getTable();
diff --git a/src/Package_Subitem.php b/src/PackageSubitem.php
similarity index 97%
rename from src/Package_Subitem.php
rename to src/PackageSubitem.php
index 28cd821..bcd8ef6 100644
--- a/src/Package_Subitem.php
+++ b/src/PackageSubitem.php
@@ -37,7 +37,7 @@
use Migration;
use Session;
-trait Package_Subitem
+trait PackageSubitem
{
public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0)
{
@@ -55,6 +55,7 @@ public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $
if ($item->getType() == Package::class) {
self::showForPackage($item);
}
+ return true;
}
@@ -100,7 +101,7 @@ public static function showForPackage(Package $package)
public static function showAdd(int $plugin_deploy_packages_id = 0)
{
- $subitem_instance = new self;
+ $subitem_instance = new self();
$subitem_instance->getEmpty();
$subitem_instance->fields['plugin_deploy_packages_id'] = $plugin_deploy_packages_id;
TemplateRenderer::getInstance()->display('@deploy/package/subitem.form.html.twig', [
@@ -125,6 +126,7 @@ public static function showEdit(int $ID = 0)
public function getNextOrder(int $packages_id)
{
+ /** @var object $DB */
global $DB;
$iterator = $DB->request([
diff --git a/src/Package_Target.php b/src/PackageTarget.php
similarity index 94%
rename from src/Package_Target.php
rename to src/PackageTarget.php
index bdabe01..746e68f 100644
--- a/src/Package_Target.php
+++ b/src/PackageTarget.php
@@ -38,7 +38,7 @@
use Migration;
use Session;
-class Package_Target extends CommonDBRelation
+class PackageTarget extends CommonDBRelation
{
public static $itemtype_1 = Package::class;
public static $items_id_1 = "plugin_deploy_packages_id";
@@ -46,11 +46,11 @@ class Package_Target extends CommonDBRelation
public static $itemtype_2 = Group::class;
public static $items_id_2 = "plugin_deploy_computers_groups_id";
- static public $checkItem_2_Rights = self::DONT_CHECK_ITEM_RIGHTS;
- static public $logs_for_item_2 = false;
+ public static $checkItem_2_Rights = self::DONT_CHECK_ITEM_RIGHTS;
+ public static $logs_for_item_2 = false;
public $auto_message_on_action = false;
- static $rightname = 'computer_group';
+ public static $rightname = 'computer_group';
public static function getTypeName($nb = 0)
{
@@ -70,7 +70,7 @@ public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0)
switch ($item->getType()) {
case Package::class:
- return self::createTabEntry(self::getTypeName($number), $number, self::class, self::getIcon());
+ return self::createTabEntry(self::getTypeName($number), $number);
}
return parent::getTabNameForItem($item, $withtemplate);
@@ -90,6 +90,7 @@ public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $
public static function showForPackage(Package $package)
{
+ /** @var object $DB */
global $DB;
$iterator = $DB->request([
@@ -120,6 +121,7 @@ public static function showForPackage(Package $package)
public static function install(Migration $migration)
{
+ /** @var object $DB */
global $DB;
$table = self::getTable();
diff --git a/src/Profile.php b/src/Profile.php
index e75940e..e34c91f 100644
--- a/src/Profile.php
+++ b/src/Profile.php
@@ -38,75 +38,83 @@
use Profile as GlobalProfile;
use ProfileRight;
-class Profile extends GlobalProfile {
-
- public static $rightname = 'profile';
-
- static function getTypeName($nb = 0) {
- return __('Deploy', 'deploy');
- }
-
-
- static function getAllRights($all = false) {
- $rights = [
- ['itemtype' => Group::getType(),
- 'label' => Group::getTypeName(),
- 'field' => 'computer_group'
- ]
- ];
- return $rights;
- }
-
- function getTabNameForItem(CommonGLPI $item, $withtemplate=0) {
-
- if ($item->getType() == GlobalProfile::class) {
- return self::createTabEntry(self::getTypeName());
- }
- return '';
- }
-
-
- static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0) {
-
- if ($item instanceof GlobalProfile
- && $item->getField('id')) {
- return self::showForProfile($item->getID());
- }
- return true;
- }
-
-
- static function showForProfile($profiles_id = 0) {
- $canupdate = self::canUpdate();
- $profile = new GlobalProfile();
- $profile->getFromDB($profiles_id);
- echo "";
- }
- }
-
-
- /**
+class Profile extends GlobalProfile
+{
+ public static $rightname = 'profile';
+
+ public static function getTypeName($nb = 0)
+ {
+ return __('Deploy', 'deploy');
+ }
+
+
+ public static function getAllRights($all = false)
+ {
+ $rights = [
+ ['itemtype' => Group::getType(),
+ 'label' => Group::getTypeName(),
+ 'field' => 'computer_group'
+ ]
+ ];
+ return $rights;
+ }
+
+ public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0)
+ {
+
+ if ($item->getType() == GlobalProfile::class) {
+ return self::createTabEntry(self::getTypeName());
+ }
+ return '';
+ }
+
+
+ public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0)
+ {
+
+ if (
+ $item instanceof GlobalProfile
+ && $item->getField('id')
+ ) {
+ return self::showForProfile($item->getID());
+ }
+ return true;
+ }
+
+
+ public static function showForProfile($profiles_id = 0)
+ {
+ $canupdate = self::canUpdate();
+ $profile = new GlobalProfile();
+ $profile->getFromDB($profiles_id);
+ echo "";
+ }
+ }
+
+
+ /**
* @param $ID
*/
- static function createFirstAccess($ID) {
- self::addDefaultProfileInfos($ID, ['computer_group' => PURGE + CREATE + UPDATE + READ ], true);
- }
+ public static function createFirstAccess($ID)
+ {
+ self::addDefaultProfileInfos($ID, ['computer_group' => PURGE + CREATE + UPDATE + READ ], true);
+ }
/**
* @param $profiles_id
@@ -115,39 +123,50 @@ static function createFirstAccess($ID) {
*
* @internal param $profile
*/
- static function addDefaultProfileInfos($profiles_id, $rights, $drop_existing = false) {
-
- $profileRight = new ProfileRight();
- $dbu = new DbUtils();
- foreach ($rights as $right => $value) {
- if ($dbu->countElementsInTable('glpi_profilerights',
- ["profiles_id" => $profiles_id, "name" => $right]) && $drop_existing) {
- $profileRight->deleteByCriteria(['profiles_id' => $profiles_id, 'name' => $right]);
- }
- if (!$dbu->countElementsInTable('glpi_profilerights',
- ["profiles_id" => $profiles_id, "name" => $right])) {
- $plugin_right['profiles_id'] = $profiles_id;
- $plugin_right['name'] = $right;
- $plugin_right['rights'] = $value;
- $profileRight->add($plugin_right);
-
- //Add right to the current session
- $_SESSION['glpiactiveprofile'][$right] = $value;
- }
- }
- }
-
- public static function install(Migration $migration) {
- foreach (Profile::getAllRights() as $right) {
- ProfileRight::addProfileRights([$right['field']]);
- }
- self::createFirstAccess($_SESSION['glpiactiveprofile']['id']);
- return true;
- }
-
- public static function uninstall(Migration $migration) {
- foreach (Profile::getAllRights() as $right) {
- ProfileRight::deleteProfileRights([$right['field']]);
- }
- }
+ public static function addDefaultProfileInfos($profiles_id, $rights, $drop_existing = false)
+ {
+
+ $profileRight = new ProfileRight();
+ $dbu = new DbUtils();
+ foreach ($rights as $right => $value) {
+ if (
+ $dbu->countElementsInTable(
+ 'glpi_profilerights',
+ ["profiles_id" => $profiles_id, "name" => $right]
+ ) && $drop_existing
+ ) {
+ $profileRight->deleteByCriteria(['profiles_id' => $profiles_id, 'name' => $right]);
+ }
+ if (
+ !$dbu->countElementsInTable(
+ 'glpi_profilerights',
+ ["profiles_id" => $profiles_id, "name" => $right]
+ )
+ ) {
+ $plugin_right['profiles_id'] = $profiles_id;
+ $plugin_right['name'] = $right;
+ $plugin_right['rights'] = $value;
+ $profileRight->add($plugin_right);
+
+ //Add right to the current session
+ $_SESSION['glpiactiveprofile'][$right] = $value;
+ }
+ }
+ }
+
+ public static function install(Migration $migration)
+ {
+ foreach (Profile::getAllRights() as $right) {
+ ProfileRight::addProfileRights([$right['field']]);
+ }
+ self::createFirstAccess($_SESSION['glpiactiveprofile']['id']);
+ return true;
+ }
+
+ public static function uninstall(Migration $migration)
+ {
+ foreach (Profile::getAllRights() as $right) {
+ ProfileRight::deleteProfileRights([$right['field']]);
+ }
+ }
}
diff --git a/src/Repository.php b/src/Repository.php
index 631cd55..1bad88b 100644
--- a/src/Repository.php
+++ b/src/Repository.php
@@ -35,8 +35,7 @@
class Repository
{
-
- public function AddFileFromComputer(): Repository_File
+ public function AddFileFromComputer(): RepositoryFile
{
$filename = $_FILES['file']['name'] ?? "";
$tmp_name = $_FILES['file']['tmp_name'] ?? UPLOAD_ERR_NO_FILE;
@@ -75,26 +74,30 @@ public function AddFileFromComputer(): Repository_File
return false;
}
- if (false !== ($file = new Repository_File(
- $filename,
- $tmp_name,
- (int) $filesize,
- $mimetype,
- ))) {
+ if (
+ false !== ($file = new RepositoryFile(
+ $filename,
+ $tmp_name,
+ (int) $filesize,
+ $mimetype,
+ ))
+ ) {
$file->addToRepository();
}
return $file;
}
- public function addFileFromServer(string $path = ""): Repository_File
+ public function addFileFromServer(string $path = ""): RepositoryFile
{
- $tmp_name = GLPI_UPLOAD_DIR.$path;
- if (false !== ($file = new Repository_File(
- basename($tmp_name),
- $tmp_name,
- filesize($tmp_name),
- mime_content_type($tmp_name),
- ))) {
+ $tmp_name = GLPI_UPLOAD_DIR . $path;
+ if (
+ false !== ($file = new RepositoryFile(
+ basename($tmp_name),
+ $tmp_name,
+ filesize($tmp_name),
+ mime_content_type($tmp_name),
+ ))
+ ) {
$file->addToRepository();
}
return $file;
@@ -112,7 +115,7 @@ public function deleteFile(string $sha512 = ""): bool
// remove parts
$parts_sha512 = file($manifest_path);
foreach ($parts_sha512 as $part_sha512) {
- $part_relative_dir = Repository_File::getRelativePathBySha512($part_sha512, false);
+ $part_relative_dir = RepositoryFile::getRelativePathBySha512($part_sha512, false);
$part_absolute_dir = PLUGIN_DEPLOY_PARTS_PATH . "/$part_relative_dir";
$part_parent_dir = dirname($part_absolute_dir);
$part_path = trim($part_absolute_dir . $part_sha512);
@@ -135,7 +138,6 @@ public function deleteFile(string $sha512 = ""): bool
rmdir($part_parent_dir);
}
}
-
}
// remove manifest
diff --git a/src/Repository_File.php b/src/RepositoryFile.php
similarity index 94%
rename from src/Repository_File.php
rename to src/RepositoryFile.php
index cfccdbc..c2f7c1f 100644
--- a/src/Repository_File.php
+++ b/src/RepositoryFile.php
@@ -30,7 +30,7 @@
namespace GlpiPlugin\Deploy;
-class Repository_File
+class RepositoryFile
{
private $max_part_size = 1024 * 1024;
@@ -58,13 +58,14 @@ public function __construct(string $name = "", string $path = "", int $size = 0,
$this->short_sha512 = substr($this->sha512, 0, 8);
} else {
trigger_error(
- 'Repository_File __construct expects to get \'path\' or \'sha512\' arguments, both are missing !!',
+ 'RepositoryFile __construct expects to get \'path\' or \'sha512\' arguments, both are missing !!',
E_USER_WARNING
);
}
}
- public function addToRepository(): bool {
+ public function addToRepository(): bool
+ {
if (!$this->isFileExists()) {
if (!$this->saveParts() || !$this->savemanifest()) {
return false;
@@ -75,7 +76,8 @@ public function addToRepository(): bool {
}
- public function getDefinition(): array {
+ public function getDefinition(): array
+ {
return [
'filename' => $this->name,
'filesize' => $this->size,
@@ -85,7 +87,8 @@ public function getDefinition(): array {
];
}
- public function isFileExists(): bool {
+ public function isFileExists(): bool
+ {
// check a filename with sha512 exist in manifest path
if (!file_exists(PLUGIN_DEPLOY_MANIFESTS_PATH . "/{$this->sha512}")) {
return false;
@@ -113,7 +116,8 @@ public function isFileExists(): bool {
}
- private function saveParts(): bool {
+ private function saveParts(): bool
+ {
if (!($file_handle = fopen($this->path, 'rb'))) {
return false;
}
diff --git a/templates/package/action.form.html.twig b/templates/package/action.form.html.twig
index 2010af6..01bf39d 100644
--- a/templates/package/action.form.html.twig
+++ b/templates/package/action.form.html.twig
@@ -41,7 +41,7 @@
{% set type_select_field %}