Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ dist/
vendor/
.gh_token
*.min.*
var/
9 changes: 5 additions & 4 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@

$finder = Finder::create()
->in(__DIR__)
->name('*.php');
->name('*.php')
->ignoreVCSIgnored(true);

$config = new Config();

$rules = [
'@PER-CS2.0' => true,
'trailing_comma_in_multiline' => ['elements' => ['arguments', 'array_destructuring', 'arrays']], // For PHP 7.4 compatibility
'@PER-CS' => true, // Latest PER rules.
];

return $config
->setRules($rules)
->setFinder($finder)
->setUsingCache(false);
->setCacheFile(__DIR__ . '/var/php-cs-fixer/.php-cs-fixer.cache')
;
9 changes: 4 additions & 5 deletions ajax/agent.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,12 @@
$agent = new Agent();
if (!$agent->getFromDB($_POST['id'])) {
throw new NotFoundHttpException();
};
}

$answer = [];

switch ($_POST['action']) {
case PluginDatabaseinventoryInventoryAction::MA_PARTIAL:
$answer = PluginDatabaseinventoryInventoryAction::runPartialInventory($agent);
break;
if ($_POST['action'] === PluginDatabaseinventoryInventoryAction::MA_PARTIAL) {
$answer = PluginDatabaseinventoryInventoryAction::runPartialInventory($agent);
}

echo json_encode($answer);
Expand Down
16 changes: 10 additions & 6 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions front/computergroup.form.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
Html::redirect($computergroup->getLinkURL());
}
}

Html::back();
} elseif (isset($_POST['add_staticcomputer'])) {
if (!$_POST['computers_id']) {
Expand All @@ -81,6 +82,7 @@
Html::redirect($computergroup->getLinkURL());
}
}

Html::back();
} elseif (isset($_POST['purge'])) {
// purge a computergroup
Expand All @@ -95,6 +97,7 @@
sprintf(__s('%s purges an item'), $_SESSION['glpiname']),
);
}

$computergroup->redirectToList();
} elseif (isset($_POST['update'])) {
// update a computergroup
Expand Down Expand Up @@ -143,5 +146,6 @@
} else {
$computergroup->display($_GET);
}

Html::footer();
}
3 changes: 3 additions & 0 deletions front/credential.form.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
Html::redirect($credential->getLinkURL());
}
}

Html::back();
} elseif (isset($_POST['purge'])) {
// purge a credential
Expand All @@ -72,6 +73,7 @@
sprintf(__s('%s purges an item'), $_SESSION['glpiname']),
);
}

$credential->redirectToList();
} elseif (isset($_POST['update'])) {
// update a credential
Expand All @@ -95,5 +97,6 @@
} else {
$credential->display($_GET);
}

Html::footer();
}
5 changes: 5 additions & 0 deletions front/databaseparam.form.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
Html::redirect($databaseparam->getLinkURL());
}
}

Html::back();
} elseif (isset($_POST['add_credential'])) {
// add credential
Expand All @@ -78,6 +79,7 @@
Html::redirect($databaseparam->getLinkURL());
}
}

Html::back();
} elseif (isset($_POST['add_computergroup'])) {
// add computer group
Expand All @@ -96,6 +98,7 @@
Html::redirect($databaseparam->getLinkURL());
}
}

Html::back();
} elseif (isset($_POST['purge'])) {
// purge a databaseparam
Expand All @@ -110,6 +113,7 @@
sprintf(__s('%s purges an item'), $_SESSION['glpiname']),
);
}

$databaseparam->redirectToList();
} elseif (isset($_POST['update'])) {
// update a databaseparam
Expand All @@ -133,5 +137,6 @@
} else {
$databaseparam->display($_GET);
}

Html::footer();
}
2 changes: 2 additions & 0 deletions hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ function plugin_databaseinventory_install()
}
}
}

$migration->executeMigration();

return true;
Expand All @@ -79,6 +80,7 @@ function plugin_databaseinventory_uninstall()
}
}
}

$migration->executeMigration();

return true;
Expand Down
8 changes: 4 additions & 4 deletions inc/computergroup.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
class PluginDatabaseinventoryComputerGroup extends CommonDBTM
{
public $dohistory = true;

public static $rightname = 'database_inventory';

public static function getTypeName($nb = 0)
Expand Down Expand Up @@ -220,9 +221,8 @@ public function countStaticItem()
];

$iterator = $DB->request($params);
$count = count($iterator);

return $count;
return count($iterator);
}

public static function install(Migration $migration)
Expand All @@ -236,9 +236,9 @@ public static function install(Migration $migration)

$table = self::getTable();
if (!$DB->tableExists($table)) {
$migration->displayMessage("Installing $table");
$migration->displayMessage('Installing ' . $table);
$query = <<<SQL
CREATE TABLE IF NOT EXISTS `$table` (
CREATE TABLE IF NOT EXISTS `{$table}` (
`id` int {$default_key_sign} NOT NULL AUTO_INCREMENT,
`name` varchar(255) DEFAULT NULL,
`comment` text,
Expand Down
37 changes: 17 additions & 20 deletions inc/computergroupdynamic.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public static function getSpecificValueToDisplay($field, $values, array $options
if (!is_array($values)) {
$values = [$field => $values];
}

switch ($field) {
case 'search':
$count = 0;
Expand All @@ -91,7 +92,7 @@ public static function getSpecificValueToDisplay($field, $values, array $options
global $CFG_GLPI;
$value = ' ';
$out = ' ';
if (!str_contains($values['id'], Search::NULLVALUE)) {
if (!str_contains((string) $values['id'], Search::NULLVALUE)) {
$search_params = Search::manageParams('Computer', unserialize($values['search']));
$data = Search::prepareDatasForSearch('Computer', $search_params);
Search::constructSQL($data);
Expand Down Expand Up @@ -120,6 +121,7 @@ public static function getSpecificValueToDisplay($field, $values, array $options
foreach ($values as $v) {
$value .= $v . $line_delimiter;
}

$value = preg_replace('/' . Search::LBBR . '/', '<br>', $value);
$value = preg_replace('/' . Search::LBHR . '/', '<hr>', $value);
$value = '<div class="fup-popup">' . $value . '</div>';
Expand Down Expand Up @@ -147,12 +149,8 @@ public static function getSpecificValueToDisplay($field, $values, array $options

public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0)
{
if ($item instanceof PluginDatabaseinventoryComputerGroup) {
switch ($tabnum) {
case 1:
self::showForItem($item);
break;
}
if ($item instanceof PluginDatabaseinventoryComputerGroup && $tabnum === 1) {
self::showForItem($item);
}

return true;
Expand All @@ -164,9 +162,8 @@ private function countDynamicItems()
$data = Search::prepareDatasForSearch('Computer', $search_params);
Search::constructSQL($data);
Search::constructData($data);
$count = $data['data']['totalcount'];

return $count;
return $data['data']['totalcount'];
}

public function isDynamicSearchMatchComputer(Computer $computer)
Expand All @@ -183,13 +180,13 @@ public function isDynamicSearchMatchComputer(Computer $computer)
if (!isset($_SESSION['glpiname'])) {
$_SESSION['glpiname'] = 'databaseinventory_plugin';
}

$search_params = Search::manageParams('Computer', $search);
$data = Search::prepareDatasForSearch('Computer', $search_params);
Search::constructSQL($data);
Search::constructData($data);
$count = $data['data']['totalcount'];

return $count;
return $data['data']['totalcount'];
}

private static function showForItem(PluginDatabaseinventoryComputerGroup $computergroup)
Expand All @@ -204,16 +201,16 @@ private static function showForItem(PluginDatabaseinventoryComputerGroup $comput
$firsttime = true;
// load dynamic search criteria from DB if exist
$computergroup_dynamic = new self();
if (
$computergroup_dynamic->getFromDBByCrit([
'plugin_databaseinventory_computergroups_id' => $ID,
])
) {
$p = $search_params = Search::manageParams('Computer', unserialize($computergroup_dynamic->fields['search']));
if ($computergroup_dynamic->getFromDBByCrit([
'plugin_databaseinventory_computergroups_id' => $ID,
])) {
$p = Search::manageParams('Computer', unserialize($computergroup_dynamic->fields['search']));
$search_params = $p;
$firsttime = false;
} else {
// retrieve filter value from search if exist and reset it
$p = $search_params = Search::manageParams('Computer', $_GET);
$p = Search::manageParams('Computer', $_GET);
$search_params = $p;
if (isset($_SESSION['glpisearch']['Computer'])) {
unset($_SESSION['glpisearch']['Computer']);
}
Expand Down Expand Up @@ -268,9 +265,9 @@ public static function install(Migration $migration)

$table = self::getTable();
if (!$DB->tableExists($table)) {
$migration->displayMessage("Installing $table");
$migration->displayMessage('Installing ' . $table);
$query = <<<SQL
CREATE TABLE IF NOT EXISTS `$table` (
CREATE TABLE IF NOT EXISTS `{$table}` (
`id` int {$default_key_sign} NOT NULL AUTO_INCREMENT,
`plugin_databaseinventory_computergroups_id` int {$default_key_sign} NOT NULL DEFAULT '0',
`search` text,
Expand Down
18 changes: 10 additions & 8 deletions inc/computergroupstatic.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,17 @@ class PluginDatabaseinventoryComputerGroupStatic extends CommonDBRelation
{
// From CommonDBRelation
public static $itemtype_1 = 'PluginDatabaseinventoryComputerGroup';

public static $items_id_1 = 'plugin_databaseinventory_computergroups_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 = 'database_inventory';
Expand Down Expand Up @@ -105,12 +110,8 @@ public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0)

public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0)
{
if ($item instanceof PluginDatabaseinventoryComputerGroup) {
switch ($tabnum) {
case 1:
self::showForItem($item);
break;
}
if ($item instanceof PluginDatabaseinventoryComputerGroup && $tabnum === 1) {
self::showForItem($item);
}

return true;
Expand Down Expand Up @@ -146,6 +147,7 @@ private static function showForItem(PluginDatabaseinventoryComputerGroup $comput
];
}
}

TemplateRenderer::getInstance()->display(
'@databaseinventory/computergroupstatic.html.twig',
[
Expand Down Expand Up @@ -173,9 +175,9 @@ public static function install(Migration $migration)

$table = self::getTable();
if (!$DB->tableExists($table)) {
$migration->displayMessage("Installing $table");
$migration->displayMessage('Installing ' . $table);
$query = <<<SQL
CREATE TABLE IF NOT EXISTS `$table` (
CREATE TABLE IF NOT EXISTS `{$table}` (
`id` int {$default_key_sign} NOT NULL AUTO_INCREMENT,
`plugin_databaseinventory_computergroups_id` int {$default_key_sign} NOT NULL DEFAULT '0',
`computers_id` int {$default_key_sign} NOT NULL DEFAULT '0',
Expand Down
Loading