Skip to content

Commit

Permalink
Merge branch 'release/2.7.0-beta.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
btry committed Jan 16, 2019
2 parents b9d0828 + 1e3af94 commit d2b33b9
Show file tree
Hide file tree
Showing 54 changed files with 1,704 additions and 568 deletions.
12 changes: 7 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,37 +6,39 @@ env:
- CS=7.2
- DBNAME=glpitest
- OLDDBNAME=glpiupgradetest
- AFTER_SUCCESS_BRANCH=9.3/bugfixes
- AFTER_SUCCESS_BRANCH=9.4/bugfixes
matrix:
- GLPI_BRANCH=9.3.0
- GLPI_BRANCH=9.3/bugfixes
- GLPI_BRANCH=master
- GLPI_BRANCH=9.4/bugfixes
# - GLPI_BRANCH=master

php:
- 5.6
- 7.0
- 7.1
- 7.2
- 7.3
- nightly

matrix:
allow_failures:
- php: nightly
- env: GLPI_BRANCH=master
# - env: GLPI_BRANCH=master

before_script:
- "./tests/before_script.sh"

script:
- if [ "${TRAVIS_PHP_VERSION:0:3}" = "$CS" ] && [ "$GLPI_BRANCH" = "$AFTER_SUCCESS_BRANCH" ]; then COVERAGE="--nccfc CommonTreeDropdown CommonDropdown CommonDBTM CommonGLPI"; else COVERAGE="-ncc"; fi
- if [ -e ../../scripts/cliinstall.php ] ; then php ../../scripts/cliinstall.php --db=$OLDDBNAME --user=root --tests ; fi
- if [ -e ../../tools/cliinstall.php ] ; then php ../../tools/cliinstall.php --db=$OLDDBNAME --user=root --tests ; fi
- if [ -e ../../bin/console ] ; then php ../../bin/console glpi:database:install --db-name=$OLDDBNAME --db-user=root --config-dir=../../tests --no-interaction --force; fi
- mysql -u root $OLDDBNAME < tests/plugin_formcreator_empty_2.5.0.sql
- mysql -u root $OLDDBNAME < tests/plugin_formcreator_config_2.5.0.sql
- php scripts/cliinstall.php --tests
- rm ../../tests/config_db.php
- if [ -e ../../scripts/cliinstall.php ] ; then php ../../scripts/cliinstall.php --db=$DBNAME --user=root --tests ; fi
- if [ -e ../../tools/cliinstall.php ] ; then php ../../tools/cliinstall.php --db=$DBNAME --user=root --tests ; fi
- if [ -e ../../bin/console ] ; then php ../../bin/console glpi:database:install --db-name=$DBNAME --db-user=root --config-dir=../../tests --no-interaction --force; fi
- vendor/bin/atoum -ft -bf tests/bootstrap.php -d tests/suite-install -ncc
- vendor/bin/atoum -ft -bf tests/bootstrap.php -d tests/suite-integration $COVERAGE
- vendor/bin/atoum -ft -bf tests/bootstrap.php -d tests/suite-unit $COVERAGE
Expand Down
24 changes: 24 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
<a name="2.7.0-beta.2"></a>
# [2.7.0-beta.2](https://github.com/pluginsglpi/formcreator/compare/v2.7.0-beta.1...v2.7.0-beta.2) (2019-01-16)


### Bug Fixes

* **descriptionfield:** show / hide did not work ([04f1695](https://github.com/pluginsglpi/formcreator/commit/04f1695))
* **form:** access rights checking ([e05e20b](https://github.com/pluginsglpi/formcreator/commit/e05e20b))
* **formanswer:** empty list of answers ([2478b2c](https://github.com/pluginsglpi/formcreator/commit/2478b2c))
* **formanswer:** missing right check ([bdac689](https://github.com/pluginsglpi/formcreator/commit/bdac689))
* **install:** create tables before filling them ([#1234](https://github.com/pluginsglpi/formcreator/issues/1234)) ([c08e299](https://github.com/pluginsglpi/formcreator/commit/c08e299))
* **install:** update relation ([09c0101](https://github.com/pluginsglpi/formcreator/commit/09c0101))
* **issue:** fix filtered searches of issues ([9bda871](https://github.com/pluginsglpi/formcreator/commit/9bda871))
* **targetTicket:** generation of ticket ([8355480](https://github.com/pluginsglpi/formcreator/commit/8355480))
* **textfield:** abuse escaping ([167c43f](https://github.com/pluginsglpi/formcreator/commit/167c43f))
* **urgencyfield:** default value ([1849e61](https://github.com/pluginsglpi/formcreator/commit/1849e61))


### Features

* **targetticket:** compatibility with GLPI 9.4 ([6afe5fe](https://github.com/pluginsglpi/formcreator/commit/6afe5fe))



<a name="2.7.0-beta.1"></a>
# [2.7.0-beta.1](https://github.com/pluginsglpi/formcreator/compare/v2.6.4...v2.7.0-beta.1) (2018-12-05)

Expand Down
4 changes: 4 additions & 0 deletions front/formanswer.form.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@

// Show target ticket form
} else {
$formanswer->getFromDB(intval((int) $_GET['id']));
if (!$formanswer->checkEntity()) {
Html::displayRightError();
}
if (plugin_formcreator_replaceHelpdesk()) {
PluginFormcreatorWizard::header(__('Service catalog', 'formcreator'));
} else {
Expand Down
14 changes: 8 additions & 6 deletions front/formdisplay.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,14 @@
}

if ($form->fields['access_rights'] == PluginFormcreatorForm::ACCESS_RESTRICTED) {
$form_profile = new PluginFormcreatorForm_Profile();
$formId = $form->getID();
$activeProfileId = $_SESSION['glpiactiveprofile']['id'];
$rows = $form_profile->find("profiles_id = '$activeProfileId'
AND plugin_formcreator_forms_id = '$formId'", "", "1");
if (count($rows) == 0) {
$iterator = $DB->request(PluginFormcreatorForm_Profile::getTable(), [
'WHERE' => [
'profiles_id' => $_SESSION['glpiactiveprofile']['id'],
'plugin_formcreator_forms_id' => $form->getID()
],
'LIMIT' => 1
]);
if (count($iterator) == 0) {
Html::displayRightError();
exit();
}
Expand Down
28 changes: 18 additions & 10 deletions front/targetchange.form.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,17 @@
if (!$plugin->isActivated('formcreator')) {
Html::displayNotFoundError();
}
$targetticket = new PluginFormcreatorTargetChange();
$targetchange = new PluginFormcreatorTargetChange();

// Edit an existing target change
if (isset($_POST["update"])) {
$target = new PluginFormcreatorTarget();
$found = $target->find('items_id = ' . (int) $_POST['id']);
$found = array_shift($found);
$target->update(['id' => $found['id'], 'name' => $_POST['name']]);
$targetticket->update($_POST);
$DB->update(PluginFormcreatorTarget::getTable(), [
'name' => $_POST['name']
], [
'items_id' => (int) $_POST['id'],
'itemtype' => 'PluginFormcreatorTargetChange'
]);
$targetchange->update($_POST);
Html::back();

} else if (isset($_POST['actor_role'])) {
Expand Down Expand Up @@ -84,17 +86,23 @@
);

$itemtype = "PluginFormcreatorTargetChange";
$target = new PluginFormcreatorTarget;
$found = $target->find("itemtype = '$itemtype' AND items_id = " . (int) $_REQUEST['id']);
$first = array_shift($found);
$iterator = $DB->request([
'SELECT' => ['plugin_formcreator_forms_id'],
'FROM' => PluginFormcreatorTarget::getTable(),
'WHERE' => [
'itemtype' => $itemtype,
'items_id' => (int) $_REQUEST['id'],
]
]);
$first = $iterator->next();
$form = new PluginFormcreatorForm;
$form->getFromDB($first['plugin_formcreator_forms_id']);

$_SESSION['glpilisttitle'][$itemtype] = sprintf(__('%1$s = %2$s'),
$form->getTypeName(1), $form->getName());
$_SESSION['glpilisturl'][$itemtype] = $form->getFormURL()."?id=".$form->getID();

$targetticket->display($_REQUEST);
$targetchange->display($_REQUEST);

Html::footer();
}
12 changes: 9 additions & 3 deletions front/targetticket.form.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,15 @@
);

$itemtype = "PluginFormcreatorTargetTicket";
$target = new PluginFormcreatorTarget;
$found = $target->find("itemtype = '$itemtype' AND items_id = " . (int) $_REQUEST['id']);
$first = array_shift($found);
$iterator = $DB->request([
'SELECT' => ['plugin_formcreator_forms_id'],
'FROM' => PluginFormcreatorTarget::getTable(),
'WHERE' => [
'itemtype' => $itemtype,
'items_id' => (int) $_REQUEST['id'],
]
]);
$first = $iterator->next();
$form = new PluginFormcreatorForm;
$form->getFromDB($first['plugin_formcreator_forms_id']);

Expand Down
32 changes: 25 additions & 7 deletions hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,9 @@ function plugin_formcreator_addDefaultWhere($itemtype) {
case PluginFormcreatorFormAnswer::class:
if (isset($_SESSION['formcreator']['form_search_answers'])
&& $_SESSION['formcreator']['form_search_answers']) {
$condition = "`$table`.`".PluginFormcreatorFormAnswer::$items_id."` = ".
// Context is displaying the answers for a given form
$formFk = PluginFormcreatorForm::getForeignKeyField();
$condition = "`$table`.`$formFk` = ".
$_SESSION['formcreator']['form_search_answers'];
} else {
$condition = plugin_formcreator_getCondition($itemtype);
Expand Down Expand Up @@ -334,13 +336,21 @@ function plugin_formcreator_hook_update_ticket(CommonDBTM $item) {
}

function plugin_formcreator_hook_delete_ticket(CommonDBTM $item) {
global $DB;

if ($item instanceof Ticket) {
$id = $item->getID();

// mark formanswers as deleted
$item_ticket = new Item_Ticket();
$rows = $item_ticket->find("`itemtype` = 'PluginFormcreatorFormAnswer' AND `tickets_id` = '$id'");
foreach ($rows as $row) {
$iterator = $DB->request([
'SELECT' => ['id'],
'FROM' => Item_Ticket::getTable(),
'WHERE' => [
'itemtype' => 'PluginFormcreatorFormAnswer',
'tickets_id' => $id,
]
]);
foreach ($iterator as $row) {
$form_answer = new PluginFormcreatorFormAnswer();
$form_answer->update([
'id' => $row['id'],
Expand All @@ -358,13 +368,21 @@ function plugin_formcreator_hook_delete_ticket(CommonDBTM $item) {
}

function plugin_formcreator_hook_restore_ticket(CommonDBTM $item) {
global $DB;

if ($item instanceof Ticket) {
$id = $item->getID();

// Restore deletes form_answers
$item_ticket = new Item_Ticket();
$rows = $item_ticket->find("`itemtype` = 'PluginFormcreatorFormAnswer' AND `tickets_id` = '$id'");
foreach ($rows as $row) {
$iterator = $DB->request([
'SELECT' => ['id'],
'FROM' => Item_Ticket::getTable(),
'WHERE' => [
'itemtype' => 'PluginFormcreatorFormAnswer',
'tickets_id' => $id,
]
]);
foreach ($iterator as $row) {
$form_answer = new PluginFormcreatorFormAnswer();
$form_answer->update([
'id' => $row['id'],
Expand Down
32 changes: 24 additions & 8 deletions inc/category.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,18 +80,19 @@ public function getAdditionalFields() {
* @return array Tree of form categories as nested array
*/
public static function getCategoryTree($rootId = 0, $helpdeskHome = false) {
global $DB;

$cat_table = PluginFormcreatorCategory::getTable();
$form_table = PluginFormcreatorForm::getTable();
$table_fp = PluginFormcreatorForm_Profile::getTable();
$helpdesk = '';
if ($helpdeskHome) {
$helpdesk = "AND $form_table.`helpdesk_home` = 1";
} else {
$helpdesk = '';
}

$query_faqs = KnowbaseItem::getListRequest([
'faq' => '1',
'contains' => ''
'faq' => '1',
'contains' => ''
]);

// Selects categories containing forms or sub-categories
Expand All @@ -118,20 +119,35 @@ public static function getCategoryTree($rootId = 0, $helpdeskHome = false) {
AND `faqs`.`knowbaseitemcategories_id` <> '0'
) > 0";

$formCategory = new self();
if ($rootId == 0) {
$items = $formCategory->find("`level`='1' AND ($where)", '`name`');
$query = "SELECT *
FROM $cat_table
WHERE `level` = '1'
AND ($where)
ORDER BY `name`";
$name = '';
$parent = 0;
} else {
$items = $formCategory->find("`plugin_formcreator_categories_id`='$rootId' AND ($where)",
'`name`');
$query = "SELECT *
FROM $cat_table
WHERE `plugin_formcreator_categories_id` = '$rootId'
AND ($where)
ORDER BY `name`";
$formCategory = new self();
$formCategory->getFromDB($rootId);
$name = $formCategory->getField('name');
$parent = $formCategory->getField('plugin_formcreator_categories_id');
}

$items = [];
if ($result = $DB->query($query)) {
if ($DB->numrows($result)) {
while ($item = $DB->fetch_assoc($result)) {
$items[$item['id']] = $item;
}
}
}

// No sub-categories, then return
if (count($items) == 0) {
return [
Expand Down
18 changes: 13 additions & 5 deletions inc/common.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,22 @@ public static function getFormcreatorRequestTypeId() {
/**
* Get the maximum value of a column for a given itemtype
* @param CommonDBTM $item
* @param string $condition
* @param array $condition
* @param string $fieldName
* @return NULL|integer
*/
public static function getMax(CommonDBTM $item, $condition, $fieldName) {
$rows = $item->find($condition, "`$fieldName` DESC", '1');
$line = array_pop($rows);
if ($line === null) {
public static function getMax(CommonDBTM $item, array $condition, $fieldName) {
global $DB;

$line = $DB->request([
'SELECT' => [$fieldName],
'FROM' => $item::getTable(),
'WHERE' => $condition,
'ORDER' => "$fieldName DESC",
'LIMIT' => 1
])->next();

if ($line === false) {
return null;
}
return (int) $line[$fieldName];
Expand Down
14 changes: 13 additions & 1 deletion inc/composite.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,21 @@ public function addTarget(PluginFormcreatorTargetBase $target, CommonDBTM $gener
}

public function buildCompositeRelations() {
global $DB;

if (isset($this->targets['PluginFormcreatorTargetTicket'])) {
foreach ($this->targets['PluginFormcreatorTargetTicket'] as $targetId => $generatedObject) {
$rows = $this->item_targetTicket->find("`plugin_formcreator_targettickets_id` = '$targetId'");
$rows = $DB->request([
'SELECT' => [
'itemtype',
'items_id',
'link'
],
'FROM' => $this->item_targetTicket->getTable(),
'WHERE' => [
'plugin_formcreator_targettickets_id' => $targetId
]
]);
foreach ($rows as $row) {
switch ($row['itemtype']) {
case 'Ticket':
Expand Down
2 changes: 0 additions & 2 deletions inc/entityconfig.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ class PluginFormcreatorEntityconfig extends CommonDBTM {
public $dohistory = true;

public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) {

$tabNames = [];
if (!$withtemplate) {
if ($item->getType() == 'Entity') {
Expand All @@ -62,7 +61,6 @@ public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) {
}

public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0) {

if ($item->getType() == 'Entity') {
$config = new self();
$config->showFormForEntity($item);
Expand Down
4 changes: 2 additions & 2 deletions inc/fields/checkboxesfield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,13 @@ private function isValidValue($value) {
if (!$parameters['range']->isNewItem()) {
$rangeMin = $parameters['range']->fields['range_min'];
$rangeMax = $parameters['range']->fields['range_max'];
if (strlen($rangeMin) > 0 && count($value) < $rangeMin) {
if ($rangeMin > 0 && count($value) < $rangeMin) {
$message = sprintf(__('The following question needs of at least %d answers', 'formcreator'), $rangeMin);
Session::addMessageAfterRedirect($message . ' ' . $this->getLabel(), false, ERROR);
return false;
}

if (strlen($rangeMax) > 0 && count($value) > $rangeMax) {
if ($rangeMax > 0 && count($value) > $rangeMax) {
$message = sprintf(__('The following question does not accept more than %d answers', 'formcreator'), $rangeMax);
Session::addMessageAfterRedirect($message . ' ' . $this->getLabel(), false, ERROR);
return false;
Expand Down
2 changes: 1 addition & 1 deletion inc/fields/descriptionfield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function isPrerequisites() {
}

public function show($canEdit = true) {
echo '<div class="description_field form-group" id="form-group-formcreator_field_' . $this->fields['id'] . '">';
echo '<div class="description_field form-group" id="form-group-field-' . $this->fields['id'] . '">';
echo nl2br(html_entity_decode($this->fields['description']));
echo '</div>' . PHP_EOL;
}
Expand Down
Loading

0 comments on commit d2b33b9

Please sign in to comment.