Skip to content

Commit

Permalink
CS
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrienClairembault committed Feb 21, 2024
1 parent 4743427 commit 0c64d1d
Show file tree
Hide file tree
Showing 129 changed files with 11,790 additions and 11,102 deletions.
4 changes: 3 additions & 1 deletion .phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
<rule ref="PSR12">
<exclude name="Generic.Files.LineLength" />
<exclude name="PSR1.Classes.ClassDeclaration.MissingNamespace" />

<!-- Plugin specific rules to bypass checks that we can't change without BC -->
<exclude name="Squiz.Classes.ValidClassName"/>
</rule>
<rule ref="Generic.Arrays.ArrayIndent"></rule>
</ruleset>

8 changes: 5 additions & 3 deletions ajax/dropdownSelectModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,18 @@

Session::checkCentralAccess();

if (isset($_SESSION['datainjection']['models_id'])
&& $_SESSION['datainjection']['models_id']!=$_POST['models_id']
if (
isset($_SESSION['datainjection']['models_id'])
&& $_SESSION['datainjection']['models_id'] != $_POST['models_id']
) {
PluginDatainjectionModel::cleanSessionVariables();
}

$_SESSION['datainjection']['step'] = PluginDatainjectionClientInjection::STEP_UPLOAD;
$model = new PluginDatainjectionModel();

if (($_POST['models_id'] > 0)
if (
($_POST['models_id'] > 0)
&& $model->can($_POST['models_id'], READ)
) {
PluginDatainjectionInfo::showAdditionalInformationsForm($model);
Expand Down
97 changes: 50 additions & 47 deletions front/clientinjection.form.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,70 +33,73 @@
Session::checkRight("plugin_datainjection_use", READ);

Html::header(
__('Data injection', 'datainjection'), $_SERVER["PHP_SELF"],
"tools", "plugindatainjectionmenu", "client"
__('Data injection', 'datainjection'),
$_SERVER["PHP_SELF"],
"tools",
"plugindatainjectionmenu",
"client"
);

if (isset($_SESSION['datainjection']['go'])) {
$model = unserialize($_SESSION['datainjection']['currentmodel']);
PluginDatainjectionClientInjection::showInjectionForm($model, $_SESSION['glpiactive_entity']);

} else if (isset($_POST['upload'])) {
$model = new PluginDatainjectionModel();
$model->can($_POST['id'], READ);
$_SESSION['datainjection']['infos'] = (isset($_POST['info'])?$_POST['info']:[]);
$model = new PluginDatainjectionModel();
$model->can($_POST['id'], READ);
$_SESSION['datainjection']['infos'] = (isset($_POST['info']) ? $_POST['info'] : []);

//If additional informations provided : check if mandatory infos are present
if (!$model->checkMandatoryFields($_SESSION['datainjection']['infos'])) {
Session::addMessageAfterRedirect(
__('One mandatory field is not filled', 'datainjection'),
true, ERROR, true
);

} else if (isset($_FILES['filename']['name'])
&& $_FILES['filename']['name']
if (!$model->checkMandatoryFields($_SESSION['datainjection']['infos'])) {
Session::addMessageAfterRedirect(
__('One mandatory field is not filled', 'datainjection'),
true,
ERROR,
true
);
} else if (
isset($_FILES['filename']['name'])
&& $_FILES['filename']['name']
&& $_FILES['filename']['tmp_name']
&& !$_FILES['filename']['error']
&& $_FILES['filename']['size']) {

//Read file using automatic encoding detection, and do not delete file once readed
$options = [
'file_encoding' => $_POST['file_encoding'],
'mode' => PluginDatainjectionModel::PROCESS,
'delete_file' => false
];
$response = $model->processUploadedFile($options);
$model->cleanData();
&& $_FILES['filename']['size']
) {
//Read file using automatic encoding detection, and do not delete file once readed
$options = [
'file_encoding' => $_POST['file_encoding'],
'mode' => PluginDatainjectionModel::PROCESS,
'delete_file' => false
];
$response = $model->processUploadedFile($options);
$model->cleanData();

if ($response) {
//File uploaded successfully and matches the given model : switch to the import tab
$_SESSION['datainjection']['file_name'] = $_FILES['filename']['name'];
$_SESSION['datainjection']['step'] = PluginDatainjectionClientInjection::STEP_PROCESS;
//Store model in session for injection
$_SESSION['datainjection']['currentmodel'] = serialize($model);
$_SESSION['datainjection']['go'] = true;
} else {
//Got back to the file upload page
$_SESSION['datainjection']['step'] = PluginDatainjectionClientInjection::STEP_UPLOAD;
}

} else {
Session::addMessageAfterRedirect(
__('The file could not be found', 'datainjection'),
true, ERROR, true
);
}
if ($response) {
//File uploaded successfully and matches the given model : switch to the import tab
$_SESSION['datainjection']['file_name'] = $_FILES['filename']['name'];
$_SESSION['datainjection']['step'] = PluginDatainjectionClientInjection::STEP_PROCESS;
//Store model in session for injection
$_SESSION['datainjection']['currentmodel'] = serialize($model);
$_SESSION['datainjection']['go'] = true;
} else {
//Got back to the file upload page
$_SESSION['datainjection']['step'] = PluginDatainjectionClientInjection::STEP_UPLOAD;
}
} else {
Session::addMessageAfterRedirect(
__('The file could not be found', 'datainjection'),
true,
ERROR,
true
);
}

Html::back();
} else if (isset($_POST['finish']) || isset($_POST['cancel'])) {

PluginDatainjectionSession::removeParams();
Html::redirect(Toolbox::getItemTypeFormURL('PluginDatainjectionClientInjection'));

} else {
if (isset($_GET['id'])) { // Allow link to a model
PluginDatainjectionSession::setParam('models_id', $_GET['id']);
}
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
18 changes: 7 additions & 11 deletions front/info.form.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,17 @@

/* Update mappings */
if (isset($_POST["update"])) {

PluginDatainjectionInfo::manageInfos($_POST['models_id'], $_POST);

} else if (isset($_POST["delete"])) {

$info = new PluginDatainjectionInfo();
foreach ($_POST["item"] as $key => $val) {
$input = ['id' => $key];
if ($val == 1) {
$info->check($key, UPDATE);
$info->delete($input);
}
}
foreach ($_POST["item"] as $key => $val) {
$input = ['id' => $key];
if ($val == 1) {
$info->check($key, UPDATE);
$info->delete($input);
}
}
Html::back();

}

Session::setActiveTab('PluginDatainjectionModel', 'PluginDatainjectionModel$5');
Expand Down
82 changes: 42 additions & 40 deletions front/mapping.form.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,51 +35,53 @@
$at_least_one_mandatory = false;
$mapping = new PluginDatainjectionMapping();

foreach ($_POST['data'] as $id => $mapping_infos) {
$mapping_infos['id'] = $id;
foreach ($_POST['data'] as $id => $mapping_infos) {
$mapping_infos['id'] = $id;

//If no field selected, reset other values
if ($mapping_infos['value'] == PluginDatainjectionInjectionType::NO_VALUE) {
$mapping_infos['itemtype'] = PluginDatainjectionInjectionType::NO_VALUE;
$mapping_infos['is_mandatory'] = 0;
//If no field selected, reset other values
if ($mapping_infos['value'] == PluginDatainjectionInjectionType::NO_VALUE) {
$mapping_infos['itemtype'] = PluginDatainjectionInjectionType::NO_VALUE;
$mapping_infos['is_mandatory'] = 0;
} else {
$mapping_infos['is_mandatory'] = (isset($mapping_infos['is_mandatory']) ? 1 : 0);
}

} else {
$mapping_infos['is_mandatory'] = (isset($mapping_infos['is_mandatory'])?1:0);
}
if ($mapping_infos['is_mandatory']) {
$at_least_one_mandatory = true;
}

if ($mapping_infos['is_mandatory']) {
$at_least_one_mandatory = true;
}
$mapping->update($mapping_infos);
}

$mapping->update($mapping_infos);
}
if (!$at_least_one_mandatory) {
Session::addMessageAfterRedirect(
__(
'One link field must be selected: it will be used to check if data already exists',
'datainjection'
),
true,
ERROR,
true
);
} else {
$model = new PluginDatainjectionModel();
$model->getFromDB($_POST['models_id']);

if (!$at_least_one_mandatory) {
Session::addMessageAfterRedirect(
__(
'One link field must be selected: it will be used to check if data already exists',
'datainjection'
), true, ERROR, true
);
} else {
$model = new PluginDatainjectionModel();
$model->getFromDB($_POST['models_id']);

if ($model->fields['step'] != PluginDatainjectionModel::READY_TO_USE_STEP) {
PluginDatainjectionModel::changeStep(
$_POST['models_id'],
PluginDatainjectionModel::OTHERS_STEP
);
Session::setActiveTab('PluginDatainjectionModel', 'PluginDatainjectionModel$5');
Session::addMessageAfterRedirect(
__(
"This step allows you to add informations not present in the file. You'll be asked for theses informations while using the model.",
'datainjection'
)
);
}
unset($_SESSION['datainjection']['lines']);
}
if ($model->fields['step'] != PluginDatainjectionModel::READY_TO_USE_STEP) {
PluginDatainjectionModel::changeStep(
$_POST['models_id'],
PluginDatainjectionModel::OTHERS_STEP
);
Session::setActiveTab('PluginDatainjectionModel', 'PluginDatainjectionModel$5');
Session::addMessageAfterRedirect(
__(
"This step allows you to add informations not present in the file. You'll be asked for theses informations while using the model.",
'datainjection'
)
);
}
unset($_SESSION['datainjection']['lines']);
}
}

Html::back();
54 changes: 28 additions & 26 deletions front/model.form.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,12 @@

//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");
} else if (isset($_POST["delete"])) {
/* delete */
$model->check($_POST['id'], DELETE);
$model->delete($_POST);
$model->redirectToList();

} else if (isset($_POST["update"])) {
/* update */
//Update model
Expand All @@ -65,33 +63,34 @@
$specific_model = PluginDatainjectionModel::getInstance('csv');
$specific_model->saveFields($_POST);
Html::back();

} else if (isset($_POST["validate"])) {
/* update order */
$model->check($_POST['id'], UPDATE);
$model->switchReadyToUse();
Html::back();

} else if (isset($_POST['upload'])) {
if (!empty($_FILES)) {
$model->check($_POST['id'], UPDATE);

if ($model->processUploadedFile(
[
'file_encoding' => 'csv',
'mode' => PluginDatainjectionModel::CREATION
]
)) {
Session::setActiveTab('PluginDatainjectionModel', 'PluginDatainjectionModel$4');
} else {
Session::addMessageAfterRedirect(
__('The file could not be found', 'datainjection'),
true, ERROR, true
);
}
}
if (!empty($_FILES)) {
$model->check($_POST['id'], UPDATE);

if (
$model->processUploadedFile(
[
'file_encoding' => 'csv',
'mode' => PluginDatainjectionModel::CREATION
]
)
) {
Session::setActiveTab('PluginDatainjectionModel', 'PluginDatainjectionModel$4');
} else {
Session::addMessageAfterRedirect(
__('The file could not be found', 'datainjection'),
true,
ERROR,
true
);
}
}
Html::back();

} else if (isset($_GET['sample'])) {
$model->check($_GET['sample'], READ);
$modeltype = PluginDatainjectionModel::getInstance($model->getField('filetype'));
Expand All @@ -101,10 +100,13 @@
}

Html::header(
PluginDatainjectionModel::getTypeName(), '',
"tools", "plugindatainjectionmenu", "model"
PluginDatainjectionModel::getTypeName(),
'',
"tools",
"plugindatainjectionmenu",
"model"
);

$model->display(['id' =>$_GET["id"]]);
$model->display(['id' => $_GET["id"]]);

Html::footer();
7 changes: 5 additions & 2 deletions front/model.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,11 @@
require '../../../inc/includes.php';

Html::header(
PluginDatainjectionModel::getTypeName(), '', "tools",
"plugindatainjectionmenu", "model"
PluginDatainjectionModel::getTypeName(),
'',
"tools",
"plugindatainjectionmenu",
"model"
);

$model = new PluginDatainjectionModel();
Expand Down
Loading

0 comments on commit 0c64d1d

Please sign in to comment.