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
2 changes: 1 addition & 1 deletion ajax/field_specific_fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@
$field->fields['default_value'] = '';
}

$default_value = $multiple ? json_decode($field->fields['default_value']) : $field->fields['default_value'];
$default_value = $multiple ? json_decode((string) $field->fields['default_value']) : $field->fields['default_value'];
Dropdown::show(
$itemtype,
[
Expand Down
67 changes: 34 additions & 33 deletions composer.lock

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

16 changes: 7 additions & 9 deletions inc/container.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,7 @@ public static function installBaseData(Migration $migration, $version)
PRIMARY KEY (`id`),
KEY `entities_id` (`entities_id`)
) ENGINE=InnoDB DEFAULT CHARSET={$default_charset} COLLATE={$default_collation} ROW_FORMAT=DYNAMIC;";
if (!$DB->doQuery($query)) {
throw new RuntimeException('Error creating plugin_fields_containers table: ' . $DB->error());
}
$DB->doQuery($query);
}

// multiple itemtype for one container
Expand Down Expand Up @@ -750,7 +748,7 @@ public static function create($fields)

public static function generateTemplate($fields)
{
$itemtypes = strlen((string) $fields['itemtypes']) > 0
$itemtypes = (string) $fields['itemtypes'] !== ''
? PluginFieldsToolbox::decodeJSONItemtypes($fields['itemtypes'], true)
: [];
foreach ($itemtypes as $itemtype) {
Expand Down Expand Up @@ -1175,7 +1173,7 @@ public static function getEntries($type = 'tab', $full = false): array
if (!in_array($item['entities_id'], $_SESSION['glpiactiveentities'])) {
if ($item['is_recursive'] == 1) {
$entities = getSonsOf('glpi_entities', $item['entities_id']);
if (count(array_intersect($entities, $_SESSION['glpiactiveentities'])) == 0) {
if (array_intersect($entities, $_SESSION['glpiactiveentities']) === []) {
continue;
}
} else {
Expand Down Expand Up @@ -1261,7 +1259,7 @@ public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0)
// needs to check if entity of item is in hierachy of $tab_name
foreach ($container->find(['is_active' => 1, 'name' => $tab_name]) as $data) {
$dataitemtypes = PluginFieldsToolbox::decodeJSONItemtypes($data['itemtypes']);
if (in_array($item::class, $dataitemtypes) != false) {
if (in_array($item::class, $dataitemtypes)) {
$entities = [$data['entities_id']];
if ($data['is_recursive']) {
$entities = getSonsOf(getTableForItemType('Entity'), $data['entities_id']);
Expand Down Expand Up @@ -1294,7 +1292,7 @@ public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $
$container = new self();
if ($container->getFromDB($tabnum)) {
$dataitemtypes = PluginFieldsToolbox::decodeJSONItemtypes($container->fields['itemtypes']);
if (in_array($item::class, $dataitemtypes) != false) {
if (in_array($item::class, $dataitemtypes)) {
return PluginFieldsField::showForTabContainer($container->fields['id'], $item);
}
}
Expand Down Expand Up @@ -1723,7 +1721,7 @@ public static function findContainer($itemtype, $type = 'tab', $subtype = '')

foreach ($itemtypes as $data) {
$dataitemtypes = PluginFieldsToolbox::decodeJSONItemtypes($data['itemtypes']);
if (in_array($itemtype, $dataitemtypes) != false) {
if (in_array($itemtype, $dataitemtypes)) {
$id = $data['id'];
}
}
Expand Down Expand Up @@ -1785,7 +1783,7 @@ public static function preItemUpdate(CommonDBTM $item)
//update data
$container = new self();
if (
count($data) == 0
count($data) === 0
|| $container->updateFieldsValues($data, $item->getType(), isset($_REQUEST['massiveaction']))
) {
$item->input['date_mod'] = $_SESSION['glpi_currenttime'];
Expand Down
8 changes: 3 additions & 5 deletions inc/field.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,7 @@ public static function installBaseData(Migration $migration, $version)
KEY `is_active` (`is_active`),
KEY `is_readonly` (`is_readonly`)
) ENGINE=InnoDB DEFAULT CHARSET={$default_charset} COLLATE={$default_collation} ROW_FORMAT=DYNAMIC;";
if (!$DB->doQuery($query)) {
throw new RuntimeException('Error creating plugin_fields_fields table: ' . $DB->error());
}
$DB->doQuery($query);
}

$migration->displayMessage('Updating ' . $table);
Expand Down Expand Up @@ -630,7 +628,7 @@ public function showSummary($container)
. sprintf("<a href='javascript:viewAddField%s%d();'>", $cID, $rand);
echo __('Add a new field', 'fields') . '</a></div><br>';

if (count($iterator) == 0) {
if (count($iterator) === 0) {
echo "<table class='tab_cadre_fixe'><tr class='tab_bg_2'>";
echo "<th class='b'>" . __('No field for this block', 'fields') . '</th></tr></table>';
} else {
Expand Down Expand Up @@ -975,7 +973,7 @@ public static function showForTab($params)
$itemtypes = PluginFieldsContainer::getUsedItemtypes($type, true);

//if no dom containers defined for this itemtype, do nothing (in_array case insensitive)
if (!in_array(strtolower((string) $item::getType()), array_map('strtolower', $itemtypes))) {
if (!in_array(strtolower((string) $item::getType()), array_map(strtolower(...), $itemtypes))) {
return;
}

Expand Down
4 changes: 1 addition & 3 deletions inc/labeltranslation.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,7 @@ public static function installBaseData(Migration $migration, $version)
KEY `language` (`language`),
UNIQUE KEY `unicity` (`itemtype`, `items_id`, `language`)
) ENGINE=InnoDB DEFAULT CHARSET={$default_charset} COLLATE={$default_collation} ROW_FORMAT=DYNAMIC;";
if (!$DB->doQuery($query)) {
throw new RuntimeException('Error creating plugin_fields_labeltranslations table: ' . $DB->error());
}
$DB->doQuery($query);
}

if ($DB->fieldExists($table, 'plugin_fields_itemtype')) {
Expand Down
4 changes: 1 addition & 3 deletions inc/profile.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,7 @@ public static function installBaseData(Migration $migration, $version)
KEY `profiles_id` (`profiles_id`),
KEY `plugin_fields_containers_id` (`plugin_fields_containers_id`)
) ENGINE=InnoDB DEFAULT CHARSET={$default_charset} COLLATE={$default_collation} ROW_FORMAT=DYNAMIC;";
if (!$DB->doQuery($query)) {
throw new RuntimeException('Error creating plugin_fields_profiles table: ' . $DB->error());
}
$DB->doQuery($query);
}

return true;
Expand Down
4 changes: 1 addition & 3 deletions inc/statusoverride.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,7 @@ public static function installBaseData(Migration $migration, $version)
PRIMARY KEY (`id`),
KEY `plugin_fields_fields_id` (`plugin_fields_fields_id`)
) ENGINE=InnoDB DEFAULT CHARSET={$default_charset} COLLATE={$default_collation} ROW_FORMAT=DYNAMIC;";
if (!$DB->doQuery($query)) {
throw new RuntimeException('Error creating plugin_fields_statusoverrides table: ' . $DB->error());
}
$DB->doQuery($query);
}

return true;
Expand Down
2 changes: 1 addition & 1 deletion inc/toolbox.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function getSystemNameFromLabel($label)
$name = preg_replace('/[^\da-z]/i', '', $name);

// 3. if empty, uses a random number
if (strlen((string) $name) == 0) {
if ((string) (string) $name === '') {
$name = random_int(0, mt_getrandmax());
}

Expand Down
4 changes: 2 additions & 2 deletions setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ function plugin_fields_checkFiles()
global $DB;

// Clean all existing files
array_map('unlink', glob(PLUGINFIELDS_DOC_DIR . '/*/*'));
array_map(unlink(...), glob(PLUGINFIELDS_DOC_DIR . '/*/*'));

// Regenerate dropdowns
if ($DB->tableExists(PluginFieldsField::getTable())) {
Expand Down Expand Up @@ -320,7 +320,7 @@ function plugin_fields_exportBlockAsYaml($container_id = null)
$container_obj = new PluginFieldsContainer();
$containers = $container_obj->find($where);
foreach ($containers as $container) {
$itemtypes = (strlen((string) $container['itemtypes']) > 0)
$itemtypes = ((string) $container['itemtypes'] !== '')
? PluginFieldsToolbox::decodeJSONItemtypes($container['itemtypes'], true)
: [];

Expand Down
1 change: 0 additions & 1 deletion tests/Units/FieldDestinationFieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,6 @@ private function sendFormAndAssertITILObjectAdditionalFields(
$itil_object = array_reduce(
$created_items,
fn(?CommonITILObject $carry, CommonITILObject $item) => $carry ?? ($item instanceof $itil_class ? $item : null),
null,
);
$this->assertNotNull($itil_object, sprintf('No created item of type %s found.', $itil_class));

Expand Down