Skip to content

Commit

Permalink
fix(targetchange,targetproblem): several fields must use rich text
Browse files Browse the repository at this point in the history
  • Loading branch information
btry committed Mar 31, 2023
1 parent e32ab28 commit cf24aa1
Show file tree
Hide file tree
Showing 6 changed files with 449 additions and 11 deletions.
1 change: 1 addition & 0 deletions install/install.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class PluginFormcreatorInstall {
'2.13.1' => '2.13.3',
'2.13.3' => '2.13.4',
'2.13.4' => '2.13.5',
'2.13.5' => '2.13.6',
];

protected bool $resyncIssues = false;
Expand Down
352 changes: 352 additions & 0 deletions install/mysql/plugin_formcreator_2.13.6_empty.sql

Large diffs are not rendered by default.

85 changes: 85 additions & 0 deletions install/upgrade_to_2.13.6.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?php
/**
* ---------------------------------------------------------------------
* Formcreator is a plugin which allows creation of custom forms of
* easy access.
* ---------------------------------------------------------------------
* LICENSE
*
* This file is part of Formcreator.
*
* Formcreator is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* Formcreator is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Formcreator. If not, see <http://www.gnu.org/licenses/>.
* ---------------------------------------------------------------------
* @copyright Copyright © 2011 - 2021 Teclib'
* @license http://www.gnu.org/licenses/gpl.txt GPLv3+
* @link https://github.com/pluginsGLPI/formcreator/
* @link https://pluginsglpi.github.io/formcreator/
* @link http://plugins.glpi-project.org/#/plugin/formcreator
* ---------------------------------------------------------------------
*/

use Glpi\RichText\RichText;
use Glpi\Toolbox\Sanitizer;

class PluginFormcreatorUpgradeTo2_13_6 {
/** @var Migration */
protected $migration;

public function isResyncIssuesRequired() {
return false;
}

/**
* @param Migration $migration
*/
public function upgrade(Migration $migration) {
$this->migration = $migration;
$this->migrateToRichText();
}

public function migrateToRichText() {
global $DB;

$tables = [
'glpi_plugin_formcreator_targetchanges' => [
'content',
'impactcontent',
'controlistcontent',
'rolloutplancontent',
'backoutplancontent',
'checklistcontent',
],
'glpi_plugin_formcreator_targetproblems' => [
'content',
'impactcontent',
'causecontent',
'symptomcontent',
],
];

foreach ($tables as $table => $fields) {
$request = [
'SELECT' => ['id'] + $fields,
'FROM' => $table
];
foreach ($DB->request($request) as $row) {
foreach ($fields as $field) {
$row[$field] = RichText::getSafeHtml($row[$field]);
$row[$field] = Sanitizer::dbEscape($row[$field]);
}
$DB->update($table, $row, ['id' => $row['id']]);
}
}
}
}
2 changes: 1 addition & 1 deletion setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

global $CFG_GLPI;
// Version of the plugin (major.minor.bugfix)
define('PLUGIN_FORMCREATOR_VERSION', '2.13.5');
define('PLUGIN_FORMCREATOR_VERSION', '2.13.6-dev');
// Schema version of this version (major.minor only)
define('PLUGIN_FORMCREATOR_SCHEMA_VERSION', '2.13');
// is or is not an official release of the plugin
Expand Down
12 changes: 6 additions & 6 deletions templates/pages/targetchange.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@
{ required: true, full_width: true }
) }}

{{ fields.textareaField('content', item.fields['content'], __('Description', 'formcreator'), { full_width: true }) }}
{{ fields.textareaField('content', item.fields['content'], __('Description', 'formcreator'), { enable_richtext: true, full_width: true }) }}

{{ fields.textareaField('impactcontent', item.fields['impactcontent'], __('Impacts'), { full_width: true }) }}
{{ fields.textareaField('impactcontent', item.fields['impactcontent'], __('Impacts'), { enable_richtext: true, full_width: true }) }}

{{ fields.textareaField('controlistcontent', item.fields['controlistcontent'], __('Control list'), { full_width: true }) }}
{{ fields.textareaField('controlistcontent', item.fields['controlistcontent'], __('Control list'), { enable_richtext: true, full_width: true }) }}

{{ fields.textareaField('rolloutplancontent', item.fields['rolloutplancontent'], __('Deployment plan'), { full_width: true }) }}
{{ fields.textareaField('rolloutplancontent', item.fields['rolloutplancontent'], __('Deployment plan'), { enable_richtext: true, full_width: true }) }}

{{ fields.textareaField('backoutplancontent', item.fields['backoutplancontent'], __('Backup plan'), { full_width: true }) }}
{{ fields.textareaField('backoutplancontent', item.fields['backoutplancontent'], __('Backup plan'), { enable_richtext: true, full_width: true }) }}

{{ fields.textareaField('checklistcontent', item.fields['checklistcontent'], __('Checklist'), { full_width: true }) }}
{{ fields.textareaField('checklistcontent', item.fields['checklistcontent'], __('Checklist'), { enable_richtext: true, full_width: true }) }}
{% endblock %}
8 changes: 4 additions & 4 deletions templates/pages/targetproblem.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@
{ required: true, full_width: true }
) }}

{{ fields.textareaField('content', item.fields['content'], __('Description', 'formcreator'), { full_width: true }) }}
{{ fields.textareaField('content', item.fields['content'], __('Description', 'formcreator'), { enable_richtext: true, full_width: true }) }}

{{ fields.textareaField('impactcontent', item.fields['impactcontent'], __('Impacts'), { full_width: true }) }}
{{ fields.textareaField('impactcontent', item.fields['impactcontent'], __('Impacts'), { enable_richtext: true, full_width: true }) }}

{{ fields.textareaField('causecontent', item.fields['causecontent'], __('Cause'), { full_width: true }) }}
{{ fields.textareaField('causecontent', item.fields['causecontent'], __('Cause'), { enable_richtext: true, full_width: true }) }}

{{ fields.textareaField('symptomcontent', item.fields['symptomcontent'], __('Symptom'), { full_width: true }) }}
{{ fields.textareaField('symptomcontent', item.fields['symptomcontent'], __('Symptom'), { enable_richtext: true, full_width: true }) }}
{% endblock %}

0 comments on commit cf24aa1

Please sign in to comment.