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 CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

### Fixed

- Fix `json_decode` using class with namespace
- Fix drag and drop
- Increased the maximum length of the language column to support longer locale codes

Expand Down
2 changes: 1 addition & 1 deletion hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ function plugin_datainjection_populate_fields()
$container = new PluginFieldsContainer();
$found = $container->find(['is_active' => 1]);
foreach ($found as $values) {
$types = json_decode($values['itemtypes']);
$types = PluginFieldsToolbox::decodeJSONItemtypes($values['itemtypes']);

foreach ($types as $type) {
$classname = PluginFieldsContainer::getClassname($type, $values['name'], 'Injection');
Expand Down
30 changes: 15 additions & 15 deletions inc/container.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ public static function installBaseData(Migration $migration, $version)
foreach ($result as $type) {
$migration_genericobject_itemtype[$type['itemtype']] = [
'genericobject_itemtype' => $type['itemtype'],
'itemtype' => 'Glpi\CustomAsset\\' . $type['name'] . 'Asset',
'itemtype' => 'Glpi\\\\CustomAsset\\\\' . $type['name'] . 'Asset',
'genericobject_name' => $type['name'],
'name' => $type['name'] . 'Asset',
];
Expand All @@ -191,7 +191,7 @@ public static function installBaseData(Migration $migration, $version)
$container_class = new self();
foreach ($result as $container) {
self::generateTemplate($container);
foreach (json_decode($container['itemtypes']) as $itemtype) {
foreach (PluginFieldsToolbox::decodeJSONItemtypes($container['itemtypes']) as $itemtype) {
$classname = self::getClassname($itemtype, $container["name"]);
$old_table = $classname::getTable();
// Rename genericobject container table
Expand Down Expand Up @@ -239,7 +239,7 @@ public static function installUserData(Migration $migration, $version)
foreach ($containers as $container) {
$itemtypes = [];
if (!empty($container['itemtypes'])) {
$decoded = json_decode($container['itemtypes'], true);
$decoded = PluginFieldsToolbox::decodeJSONItemtypes($container['itemtypes'], true);
if (is_array($decoded)) {
$itemtypes = $decoded;
}
Expand Down Expand Up @@ -290,7 +290,7 @@ public static function installUserData(Migration $migration, $version)

// Update container name
$new_name = $toolbox->getSystemNameFromLabel($container['label']);
foreach (json_decode($container['itemtypes']) as $itemtype) {
foreach (PluginFieldsToolbox::decodeJSONItemtypes($container['itemtypes']) as $itemtype) {
while (strlen(getTableForItemType(self::getClassname($itemtype, $new_name))) > 64) {
// limit tables names to 64 chars (MySQL limit)
$new_name = substr($new_name, 0, -1);
Expand All @@ -304,7 +304,7 @@ public static function installUserData(Migration $migration, $version)
);

// Rename container tables and itemtype if needed
foreach (json_decode($container['itemtypes']) as $itemtype) {
foreach (PluginFieldsToolbox::decodeJSONItemtypes($container['itemtypes']) as $itemtype) {
$migration->renameItemtype(
self::getClassname($itemtype, $old_name),
self::getClassname($itemtype, $new_name),
Expand Down Expand Up @@ -640,7 +640,7 @@ public function prepareInputForAdd($input)
$found = $this->find(['type' => 'dom']);
if (count($found) > 0) {
foreach (array_column($found, 'itemtypes') as $founditemtypes) {
foreach (json_decode($founditemtypes) as $founditemtype) {
foreach (PluginFieldsToolbox::decodeJSONItemtypes($founditemtypes) as $founditemtype) {
if (in_array($founditemtype, $input['itemtypes'])) {
Session::AddMessageAfterRedirect(__("You cannot add several blocks with type 'Insertion in the form' on same object", 'fields'), false, ERROR);

Expand All @@ -656,7 +656,7 @@ public function prepareInputForAdd($input)
$found = $this->find(['type' => 'domtab', 'subtype' => $input['subtype']]);
if (count($found) > 0) {
foreach (array_column($found, 'itemtypes') as $founditemtypes) {
foreach (json_decode($founditemtypes) as $founditemtype) {
foreach (PluginFieldsToolbox::decodeJSONItemtypes($founditemtypes) as $founditemtype) {
if (in_array($founditemtype, $input['itemtypes'])) {
Session::AddMessageAfterRedirect(__("You cannot add several blocks with type 'Insertion in the form of a specific tab' on same object tab", 'fields'), false, ERROR);

Expand Down Expand Up @@ -688,7 +688,7 @@ public function prepareInputForAdd($input)
$found = $this->find(['name' => $input['name']]);
if (count($found) > 0) {
foreach (array_column($found, 'itemtypes') as $founditemtypes) {
foreach (json_decode($founditemtypes) as $founditemtype) {
foreach (PluginFieldsToolbox::decodeJSONItemtypes($founditemtypes) as $founditemtype) {
if (in_array($founditemtype, $input['itemtypes'])) {
Session::AddMessageAfterRedirect(__('You cannot add several blocs with identical name on same object', 'fields'), false, ERROR);

Expand Down Expand Up @@ -781,7 +781,7 @@ public function pre_deleteItem()

$_SESSION['delete_container'] = true;

foreach (json_decode($this->fields['itemtypes']) as $itemtype) {
foreach (PluginFieldsToolbox::decodeJSONItemtypes($this->fields['itemtypes']) as $itemtype) {
$classname = self::getClassname($itemtype, $this->fields['name']);
$sysname = self::getSystemName($itemtype, $this->fields['name']);
$class_filename = $sysname . '.class.php';
Expand Down Expand Up @@ -843,7 +843,7 @@ public static function preItemPurge($item)
$containers = new self();
$founded_containers = $containers->find();
foreach ($founded_containers as $container) {
$itemtypes = json_decode($container['itemtypes']);
$itemtypes = PluginFieldsToolbox::decodeJSONItemtypes($container['itemtypes']);
if (in_array($itemtype, $itemtypes)) {
$classname = 'PluginFields' . $itemtype . getSingular($container['name']);
$classname = preg_replace('/s{2}$/i', 's', $classname); // in case name ends with 'ss' remove last 's'
Expand Down Expand Up @@ -928,7 +928,7 @@ public function showForm($ID, $options = [])
echo '<td>' . __('Associated item type') . ' : </td>';
echo '<td>';
if ($ID > 0) {
$types = json_decode($this->fields['itemtypes']);
$types = PluginFieldsToolbox::decodeJSONItemtypes($this->fields['itemtypes']);
$obj = '';
$count = count($types);
$i = 1;
Expand Down Expand Up @@ -969,7 +969,7 @@ public function showForm($ID, $options = [])
echo '<td>';
echo "&nbsp;<span id='subtype_$rand'></span>";
if ($ID > 0 && !empty($this->fields['subtype'])) {
$itemtypes = json_decode($this->fields['itemtypes'], true);
$itemtypes = PluginFieldsToolbox::decodeJSONItemtypes($this->fields['itemtypes'], true);
$itemtype = array_shift($itemtypes);
$dbu = new DbUtils();
$item = $dbu->getItemForItemtype($itemtype);
Expand Down Expand Up @@ -1234,7 +1234,7 @@ public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0)
foreach ($itemtypes[$item->getType()] as $tab_name => $tab_label) {
// 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 = json_decode($data['itemtypes']);
$dataitemtypes = PluginFieldsToolbox::decodeJSONItemtypes($data['itemtypes']);
if (in_array(get_class($item), $dataitemtypes) != false) {
$entities = [$data['entities_id']];
if ($data['is_recursive']) {
Expand Down Expand Up @@ -1266,7 +1266,7 @@ public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $
//retrieve container for current tab
$container = new self();
if ($container->getFromDB($tabnum)) {
$dataitemtypes = json_decode($container->fields['itemtypes']);
$dataitemtypes = PluginFieldsToolbox::decodeJSONItemtypes($container->fields['itemtypes']);
if (in_array(get_class($item), $dataitemtypes) != false) {
return PluginFieldsField::showForTabContainer($container->fields['id'], $item);
}
Expand Down Expand Up @@ -2243,7 +2243,7 @@ public function prepareInputForClone($input)
if (array_key_exists('itemtypes', $input) && !empty($input['itemtypes'])) {
// $input has been transformed with `Toolbox::addslashes_deep()`, and `self::prepareInputForAdd()`
// is expecting an array, so it have to be unslashed then json decoded.
$input['itemtypes'] = json_decode($input['itemtypes']);
$input['itemtypes'] = PluginFieldsToolbox::decodeJSONItemtypes($input['itemtypes']);
} else {
unset($input['itemtypes']);
}
Expand Down
8 changes: 4 additions & 4 deletions inc/field.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ public function prepareInputForAdd($input)
if ($input['type'] !== 'header') {
$container_obj = new PluginFieldsContainer();
$container_obj->getFromDB($input['plugin_fields_containers_id']);
foreach (json_decode($container_obj->fields['itemtypes']) as $itemtype) {
foreach (PluginFieldsToolbox::decodeJSONItemtypes($container_obj->fields['itemtypes']) as $itemtype) {
$classname = PluginFieldsContainer::getClassname($itemtype, $container_obj->fields['name']);
$classname::addField(
$input['name'],
Expand Down Expand Up @@ -354,7 +354,7 @@ public function pre_deleteItem()
$container_obj = new PluginFieldsContainer();
$container_obj->getFromDB($this->fields['plugin_fields_containers_id']);

foreach (json_decode($container_obj->fields['itemtypes']) as $itemtype) {
foreach (PluginFieldsToolbox::decodeJSONItemtypes($container_obj->fields['itemtypes']) as $itemtype) {
$so = PluginFieldsContainer::getAddSearchOptions($itemtype, $this->fields['plugin_fields_containers_id']);
foreach ($so as $so_id => $so_value) {
if ($this->fields['type'] == 'glpi_item') {
Expand All @@ -380,7 +380,7 @@ public function pre_deleteItem()
&& !isset($_SESSION['uninstall_fields'])
&& !isset($_SESSION['delete_container'])
) {
foreach (json_decode($container_obj->fields['itemtypes']) as $itemtype) {
foreach (PluginFieldsToolbox::decodeJSONItemtypes($container_obj->fields['itemtypes']) as $itemtype) {
$classname = PluginFieldsContainer::getClassname($itemtype, $container_obj->fields['name']);
$classname::removeField($this->fields['name'], $this->fields['type']);
}
Expand All @@ -400,7 +400,7 @@ public function pre_deleteItem()

$use_by_another = false;
foreach ($all_container as $container_fields) {
foreach (json_decode($container_fields['itemtypes']) as $itemtype) {
foreach (PluginFieldsToolbox::decodeJSONItemtypes($container_fields['itemtypes']) as $itemtype) {
$dropdown_classname = PluginFieldsDropdown::getClassname($this->fields['name']);
$classname = PluginFieldsContainer::getClassname($itemtype, $container_fields['name']);
$dropdown_fk = getForeignKeyFieldForItemType($dropdown_classname);
Expand Down
2 changes: 1 addition & 1 deletion setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ function plugin_fields_exportBlockAsYaml($container_id = null)
$containers = $container_obj->find($where);
foreach ($containers as $container) {
$itemtypes = (strlen($container['itemtypes']) > 0)
? json_decode($container['itemtypes'], true)
? PluginFieldsToolbox::decodeJSONItemtypes($container['itemtypes'], true)
: [];

foreach ($itemtypes as $itemtype) {
Expand Down