Skip to content

Commit

Permalink
fix(import): more explicit error message
Browse files Browse the repository at this point in the history
Signed-off-by: Thierry Bugier <tbugier@teclib.com>
  • Loading branch information
btry committed Jun 12, 2020
1 parent 475e190 commit 8bb3c3d
Show file tree
Hide file tree
Showing 12 changed files with 38 additions and 12 deletions.
7 changes: 6 additions & 1 deletion inc/condition.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ class PluginFormcreatorCondition extends CommonDBChild implements PluginFormcrea
const SHOW_CONDITION_QUESTION_VISIBLE = 7;
const SHOW_CONDITION_QUESTION_INVISIBLE = 8;

public static function getTypeName($nb = 0) {
return _n('Condition', 'Conditions', $nb, 'formcreator');
}


public function prepareInputForAdd($input) {
// generate a unique id
if (!isset($input['uuid'])
Expand Down Expand Up @@ -100,7 +105,7 @@ public static function import(PluginFormcreatorLinker $linker, $input = [], $con
global $DB;

if (!isset($input['uuid']) && !isset($input['id'])) {
throw new ImportFailureException('UUID or ID is mandatory');
throw new ImportFailureException(sprintf('UUID or ID is mandatory for %1$s', static::getTypeName(1)));
}

// restore key and FK
Expand Down
2 changes: 1 addition & 1 deletion inc/form.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1823,7 +1823,7 @@ public static function import(PluginFormcreatorLinker $linker, $input = [], $con
global $DB;

if (!isset($input['uuid']) && !isset($input['id'])) {
throw new ImportFailureException('UUID or ID is mandatory');
throw new ImportFailureException(sprintf('UUID or ID is mandatory for %1$s', static::getTypeName(1)));
}

$input['_skip_checks'] = true;
Expand Down
2 changes: 1 addition & 1 deletion inc/form_profile.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public static function showForForm(CommonDBTM $item, $withtemplate = '') {
*/
public static function import(PluginFormcreatorLinker $linker, $input = [], $containerId = 0) {
if (!isset($input['uuid']) && !isset($input['id'])) {
throw new ImportFailureException('UUID or ID is mandatory');
throw new ImportFailureException(sprintf('UUID or ID is mandatory for %1$s', static::getTypeName(1)));
}

$formFk = PluginFormcreatorForm::getForeignKeyField();
Expand Down
6 changes: 5 additions & 1 deletion inc/item_targetticket.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ class PluginFormcreatorItem_TargetTicket extends CommonDBRelation

static public $logs_for_item_1 = false;

public static function getTypeName($nb = 0) {
return _n('Composite ticket relation', 'Composite ticket relations', $nb, 'formcreator');
}

public function export($remove_uuid = false) {
if ($this->isNewItem()) {
return false;
Expand Down Expand Up @@ -88,7 +92,7 @@ public function export($remove_uuid = false) {

public static function import(PluginFormcreatorLinker $linker, $input = [], $containerId = 0) {
if (!isset($input['uuid']) && !isset($input['id'])) {
throw new ImportFailureException('UUID or ID is mandatory');
throw new ImportFailureException(sprintf('UUID or ID is mandatory for %1$s', static::getTypeName(1)));
}

$targetTicketFk = PluginFormcreatorTargetTicket::getForeignKeyField();
Expand Down
2 changes: 1 addition & 1 deletion inc/question.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -901,7 +901,7 @@ public static function import(PluginFormcreatorLinker $linker, $input = [], $con
global $DB;

if (!isset($input['uuid']) && !isset($input['id'])) {
throw new ImportFailureException('UUID or ID is mandatory');
throw new ImportFailureException(sprintf('UUID or ID is mandatory for %1$s', static::getTypeName(1)));
}

// restore key and FK
Expand Down
6 changes: 5 additions & 1 deletion inc/questiondependency.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ public function __construct(PluginFormcreatorFieldInterface $field, array $optio
$this->fieldtype = isset($options['fieldType']) ? $options['fieldType'] : [];
}

public static function getTypeName($nb = 0) {
return _n('Question dependency', 'Question dependencies', $nb, 'formcreator');
}

public function getParameterFormSize() {
return 0;
}
Expand Down Expand Up @@ -133,7 +137,7 @@ public static function import(PluginFormcreatorLinker $linker, $input = [], $con
global $DB;

if (!isset($input['uuid']) && !isset($input['id'])) {
throw new ImportFailureException('UUID or ID is mandatory');
throw new ImportFailureException(sprintf('UUID or ID is mandatory for %1$s', static::getTypeName(1)));
}

$questionFk = PluginFormcreatorQuestion::getForeignKeyField();
Expand Down
6 changes: 5 additions & 1 deletion inc/questionrange.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ class PluginFormcreatorQuestionRange

protected $domId = 'plugin_formcreator_questionRange';

public static function getTypeName($nb = 0) {
return _n('Question range', 'Question ranges', $nb, 'formcreator');
}

public function getParameterFormSize() {
return 0;
}
Expand Down Expand Up @@ -125,7 +129,7 @@ public static function import(PluginFormcreatorLinker $linker, $input = [], $con
global $DB;

if (!isset($input['uuid']) && !isset($input['id'])) {
throw new ImportFailureException('UUID or ID is mandatory');
throw new ImportFailureException(sprintf('UUID or ID is mandatory for %1$s', static::getTypeName(1)));
}

$questionFk = PluginFormcreatorQuestion::getForeignKeyField();
Expand Down
6 changes: 5 additions & 1 deletion inc/questionregex.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ class PluginFormcreatorQuestionRegex

protected $domId = 'plugin_formcreator_questionRegex';

public static function getTypeName($nb = 0) {
return _n('Question regular expression', 'Question regular expressions', $nb, 'formcreator');
}

public function getParameterFormSize() {
return 1;
}
Expand Down Expand Up @@ -120,7 +124,7 @@ public static function import(PluginFormcreatorLinker $linker, $input = [], $con
global $DB;

if (!isset($input['uuid']) && !isset($input['id'])) {
throw new ImportFailureException('UUID or ID is mandatory');
throw new ImportFailureException(sprintf('UUID or ID is mandatory for %1$s', static::getTypeName(1)));
}

$questionFk = PluginFormcreatorQuestion::getForeignKeyField();
Expand Down
2 changes: 1 addition & 1 deletion inc/section.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ public static function import(PluginFormcreatorLinker $linker, $input = [], $con
global $DB;

if (!isset($input['uuid']) && !isset($input['id'])) {
throw new ImportFailureException('UUID or ID is mandatory');
throw new ImportFailureException(sprintf('UUID or ID is mandatory for %1$s', static::getTypeName(1)));
}

// restore key and FK
Expand Down
7 changes: 6 additions & 1 deletion inc/target_actor.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ static function getEnumRole() {
// TODO : support ACTOR_ROLE_SUPPLIER
];
}

public static function getTypeName($nb = 0) {
return _n('Target actor', 'Target actors', $nb, 'formcreator');
}

public function prepareInputForAdd($input) {

// generate a unique id
Expand All @@ -92,7 +97,7 @@ public function prepareInputForAdd($input) {

public static function import(PluginFormcreatorLinker $linker, $input = [], $containerId = 0) {
if (!isset($input['uuid']) && !isset($input['id'])) {
throw new ImportFailureException('UUID or ID is mandatory');
throw new ImportFailureException(sprintf('UUID or ID is mandatory for %1$s', static::getTypeName(1)));
}

$input[static::$items_id] = $containerId;
Expand Down
2 changes: 1 addition & 1 deletion inc/targetchange.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public static function import(PluginFormcreatorLinker $linker, $input = [], $con
global $DB;

if (!isset($input['uuid']) && !isset($input['id'])) {
throw new ImportFailureException('UUID or ID is mandatory');
throw new ImportFailureException(sprintf('UUID or ID is mandatory for %1$s', static::getTypeName(1)));
}

$formFk = PluginFormcreatorForm::getForeignKeyField();
Expand Down
2 changes: 1 addition & 1 deletion inc/targetticket.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1030,7 +1030,7 @@ public static function import(PluginFormcreatorLinker $linker, $input = [], $con
global $DB;

if (!isset($input['uuid']) && !isset($input['id'])) {
throw new ImportFailureException('UUID or ID is mandatory');
throw new ImportFailureException(sprintf('UUID or ID is mandatory for %1$s', static::getTypeName(1)));
}

$formFk = PluginFormcreatorForm::getForeignKeyField();
Expand Down

0 comments on commit 8bb3c3d

Please sign in to comment.