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 CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]
## [UNRELEASED]

### Fixed

Expand Down
2 changes: 1 addition & 1 deletion ajax/dropdownChooseField.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
*/

// Direct access to file
if (strpos($_SERVER['PHP_SELF'], "dropdownChooseField.php")) {
if (strpos((string) $_SERVER['PHP_SELF'], "dropdownChooseField.php")) {
header("Content-Type: text/html; charset=UTF-8");
Html::header_nocache();
}
Expand Down
2 changes: 1 addition & 1 deletion ajax/dropdownMandatory.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
*/

// Direct access to file
if (strpos($_SERVER['PHP_SELF'], "dropdownMandatory.php")) {
if (strpos((string) $_SERVER['PHP_SELF'], "dropdownMandatory.php")) {
header("Content-Type: text/html; charset=UTF-8");
Html::header_nocache();
}
Expand Down
2 changes: 1 addition & 1 deletion ajax/dropdownSelectModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
*/

// Direct access to file
if (strpos($_SERVER['PHP_SELF'], "dropdownSelectModel.php")) {
if (strpos((string) $_SERVER['PHP_SELF'], "dropdownSelectModel.php")) {
header("Content-Type: text/html; charset=UTF-8");
Html::header_nocache();
}
Expand Down
2 changes: 1 addition & 1 deletion ajax/injection.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
*/

// Direct access to file
if (strpos($_SERVER['PHP_SELF'], "injection.php")) {
if (strpos((string) $_SERVER['PHP_SELF'], "injection.php")) {
header("Content-Type: text/html; charset=UTF-8");
Html::header_nocache();
}
Expand Down
2 changes: 1 addition & 1 deletion ajax/results.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
*/

// Direct access to file
if (strpos($_SERVER['PHP_SELF'], "results.php")) {
if (strpos((string) $_SERVER['PHP_SELF'], "results.php")) {
header("Content-Type: text/html; charset=UTF-8");
Html::header_nocache();
}
Expand Down
1 change: 1 addition & 0 deletions front/clientinjection.form.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
if (isset($_GET['id'])) { // Allow link to a model
PluginDatainjectionSession::setParam('models_id', $_GET['id']);
}

$clientInjection = new PluginDatainjectionClientInjection();
$clientInjection->title();
$clientInjection->showForm(0);
Expand Down
2 changes: 2 additions & 0 deletions front/info.form.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@
$info->delete($input);
}
}

Html::back();
}

Session::setActiveTab('PluginDatainjectionModel', 'PluginDatainjectionModel$5');
Html::back();
1 change: 1 addition & 0 deletions front/mapping.form.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
),
);
}

unset($_SESSION['datainjection']['lines']);
}
}
Expand Down
5 changes: 3 additions & 2 deletions front/model.form.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@

//Set display to the advanced options tab
Session::setActiveTab('PluginDatainjectionModel', 'PluginDatainjectionModel$3');
Html::redirect(Toolbox::getItemTypeFormURL('PluginDatainjectionModel') . "?id=$newID");
Html::redirect(Toolbox::getItemTypeFormURL('PluginDatainjectionModel') . ('?id=' . $newID));
} elseif (isset($_POST["delete"])) {
/* delete */
$model->check($_POST['id'], DELETE);
Expand All @@ -74,7 +74,7 @@
$model->switchReadyToUse();
Html::back();
} elseif (isset($_POST['upload'])) {
if (!empty($_FILES)) {
if ($_FILES !== []) {
$model->check($_POST['id'], UPDATE);

if (
Expand All @@ -95,6 +95,7 @@
);
}
}

Html::back();
} elseif (isset($_GET['sample'])) {
$model->check($_GET['sample'], READ);
Expand Down
22 changes: 14 additions & 8 deletions hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ function plugin_datainjection_migration_2158_2159(Migration $migration)
'glpi_plugin_datainjection_models',
'entities_id',
'entities_id',
"int {$default_key_sign} NOT NULL default '0'",
sprintf("int %s NOT NULL default '0'", $default_key_sign),
);

$migration->executeMigration();
Expand Down Expand Up @@ -404,7 +404,7 @@ function plugin_datainjection_update131_14()
'glpi_plugin_data_injection_models',
'user_id',
'FK_users',
"int {$default_key_sign} NOT NULL default '0'",
sprintf("int %s NOT NULL default '0'", $default_key_sign),
);
$migration->changeField(
'glpi_plugin_data_injection_models',
Expand Down Expand Up @@ -510,7 +510,7 @@ function plugin_datainjection_update170_20()
'glpi_plugin_datainjection_models',
'FK_entities',
'entities_id',
"int {$default_key_sign} NOT NULL default '0'",
sprintf("int %s NOT NULL default '0'", $default_key_sign),
);
$migration->changeField(
'glpi_plugin_datainjection_models',
Expand All @@ -522,7 +522,7 @@ function plugin_datainjection_update170_20()
'glpi_plugin_datainjection_models',
'FK_users',
'users_id',
"int {$default_key_sign} NOT NULL default '0'",
sprintf("int %s NOT NULL default '0'", $default_key_sign),
);
$migration->changeField(
'glpi_plugin_datainjection_models',
Expand All @@ -532,6 +532,7 @@ function plugin_datainjection_update170_20()
);

$migration->migrationOneTable('glpi_plugin_datainjection_models');

$query = "UPDATE `glpi_plugin_datainjection_models`
SET `step` = '5'";
$DB->doQuery($query);
Expand All @@ -551,7 +552,7 @@ function plugin_datainjection_update170_20()
'glpi_plugin_datainjection_modelcsvs',
'model_id',
'models_id',
"int {$default_key_sign} NOT NULL default '0'",
sprintf("int %s NOT NULL default '0'", $default_key_sign),
);
$migration->changeField(
'glpi_plugin_datainjection_modelcsvs',
Expand Down Expand Up @@ -585,7 +586,7 @@ function plugin_datainjection_update170_20()
'glpi_plugin_datainjection_mappings',
'model_id',
'models_id',
"int {$default_key_sign} NOT NULL default '0'",
sprintf("int %s NOT NULL default '0'", $default_key_sign),
);

$migration->changeField(
Expand All @@ -599,7 +600,7 @@ function plugin_datainjection_update170_20()
'glpi_plugin_datainjection_infos',
'model_id',
'models_id',
"int {$default_key_sign} NOT NULL default '0'",
sprintf("int %s NOT NULL default '0'", $default_key_sign),
);
$migration->changeField(
'glpi_plugin_datainjection_infos',
Expand Down Expand Up @@ -1854,6 +1855,7 @@ function plugin_datainjection_update170_20()
];

$foreignkeys = Plugin::doHookFunction("plugin_datainjection_migratefields", $foreignkeys);

$query = "SELECT `itemtype`, `value`
FROM `glpi_plugin_datainjection_mappings`
WHERE `itemtype` NOT IN ('none')
Expand Down Expand Up @@ -1908,6 +1910,7 @@ function plugin_datainjection_update210_220()
$DB->doQuery($query);
}
}

function plugin_datainjection_update220_230()
{
/** @var DBmysql $DB */
Expand Down Expand Up @@ -1942,7 +1945,7 @@ function plugin_datainjection_loadHook($hook_name, $params = [])
);
} elseif (isset($PLUGIN_HOOKS['plugin_types'])) {
//Browse all plugins
foreach ($PLUGIN_HOOKS['plugin_types'] as $type => $name) {
foreach ($PLUGIN_HOOKS['plugin_types'] as $name) {
Plugin::doOneHook($name, 'datainjection_' . $hook_name);
}
}
Expand Down Expand Up @@ -1988,6 +1991,7 @@ function plugin_datainjection_addDefaultWhere($itemtype)
foreach ($models as $model) {
$tab[] = $model['id'];
}

return "`glpi_plugin_datainjection_models`.`id` IN ('" . implode("','", $tab) . "')";
} else {
return "1 = 0"; //no model available -> force WHERE clause to get no result
Expand All @@ -1996,4 +2000,6 @@ function plugin_datainjection_addDefaultWhere($itemtype)
default:
break;
}

return null;
}
10 changes: 9 additions & 1 deletion inc/backend.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,19 @@
abstract class PluginDatainjectionBackend
{
protected $file = "";

protected $delimiter = "";

protected $encoding;

protected $errmsg;

protected $numberOfLines = 0;

public const ENCODING_ISO8859_1 = 0;

public const ENCODING_UFT8 = 1;

public const ENCODING_AUTO = 2;


Expand All @@ -67,6 +73,7 @@ public static function getHeader($injectionData, $header_present)
for ($i = 0; $i < $nb; $i++) {
$header[] = $i;
}

return $header;
}

Expand All @@ -83,7 +90,7 @@ public static function getInstance($type)
];

if (!isset($allowedBackends[$type])) {
throw new InvalidArgumentException("Unknown backend type: $type");
throw new InvalidArgumentException('Unknown backend type: ' . $type);
}

return new $allowedBackends[$type]();
Expand Down Expand Up @@ -118,6 +125,7 @@ public static function toUTF8($string)
if (!self::is_utf8($string)) {
return Toolbox::encodeInUtf8($string);
}

return $string;
}
}
26 changes: 12 additions & 14 deletions inc/backendcsv.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
class PluginDatainjectionBackendcsv extends PluginDatainjectionBackend implements PluginDatainjectionBackendInterface
{
private $isHeaderPresent = true;
private $file_handler = null;

private $file_handler;


public function __construct()
Expand Down Expand Up @@ -95,20 +96,14 @@ public static function parseLine($fic, $data, $encoding = 1)
$num = count($data);

for ($c = 0; $c < $num; $c++) {
$tmp = trim($data[$c]);
switch ($encoding) {
case PluginDatainjectionBackend::ENCODING_ISO8859_1:
$csv[0][] = $tmp === '' || $tmp === '0' ? Toolbox::encodeInUtf8($tmp) : $tmp;
break;

case PluginDatainjectionBackend::ENCODING_UFT8:
$csv[0][] = $tmp;
break;

default:
$csv[0][] = PluginDatainjectionBackend::toUTF8($tmp);
}
$tmp = trim((string) $data[$c]);
$csv[0][] = match ($encoding) {
PluginDatainjectionBackend::ENCODING_ISO8859_1 => $tmp === '' || $tmp === '0' ? Toolbox::encodeInUtf8($tmp) : $tmp,
PluginDatainjectionBackend::ENCODING_UFT8 => $tmp,
default => PluginDatainjectionBackend::toUTF8($tmp),
};
}

return $csv;
}

Expand Down Expand Up @@ -175,6 +170,7 @@ public function storeNumberOfLines()
}
}
}

fclose($fic);

if ($this->isHeaderPresent) {
Expand Down Expand Up @@ -229,13 +225,15 @@ public function getNextLine()
if ($data === false) {
return false;
}

$line = [];
if (
(count($data) > 1)
|| ($data[0] != PluginDatainjectionCommonInjectionLib::EMPTY_VALUE)
) {
$line = self::parseLine($this->file_handler, $data, $this->encoding);
}

return $line;
}

Expand Down
2 changes: 1 addition & 1 deletion inc/categoryinjection.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function connectedTo()

public function isNullable($field)
{
return !in_array($field, ['illustration']);
return $field != 'illustration';
}

/**
Expand Down
Loading