|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * --------------------------------------------------------------------- |
| 4 | + * Formcreator is a plugin which allows creation of custom forms of |
| 5 | + * easy access. |
| 6 | + * --------------------------------------------------------------------- |
| 7 | + * LICENSE |
| 8 | + * |
| 9 | + * This file is part of Formcreator. |
| 10 | + * |
| 11 | + * Formcreator is free software; you can redistribute it and/or modify |
| 12 | + * it under the terms of the GNU General Public License as published by |
| 13 | + * the Free Software Foundation; either version 2 of the License, or |
| 14 | + * (at your option) any later version. |
| 15 | + * |
| 16 | + * Formcreator is distributed in the hope that it will be useful, |
| 17 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | + * GNU General Public License for more details. |
| 20 | + * |
| 21 | + * You should have received a copy of the GNU General Public License |
| 22 | + * along with Formcreator. If not, see <http://www.gnu.org/licenses/>. |
| 23 | + * --------------------------------------------------------------------- |
| 24 | + * @copyright Copyright © 2011 - 2021 Teclib' |
| 25 | + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ |
| 26 | + * @link https://github.com/pluginsGLPI/formcreator/ |
| 27 | + * @link https://pluginsglpi.github.io/formcreator/ |
| 28 | + * @link http://plugins.glpi-project.org/#/plugin/formcreator |
| 29 | + * --------------------------------------------------------------------- |
| 30 | + */ |
| 31 | + |
| 32 | +use Glpi\RichText\RichText; |
| 33 | +use Glpi\Toolbox\Sanitizer; |
| 34 | + |
| 35 | +class PluginFormcreatorUpgradeTo2_13_6 { |
| 36 | + /** @var Migration */ |
| 37 | + protected $migration; |
| 38 | + |
| 39 | + public function isResyncIssuesRequired() { |
| 40 | + return false; |
| 41 | + } |
| 42 | + |
| 43 | + /** |
| 44 | + * @param Migration $migration |
| 45 | + */ |
| 46 | + public function upgrade(Migration $migration) { |
| 47 | + $this->migration = $migration; |
| 48 | + $this->migrateToRichText(); |
| 49 | + } |
| 50 | + |
| 51 | + public function migrateToRichText() { |
| 52 | + global $DB; |
| 53 | + |
| 54 | + $tables = [ |
| 55 | + 'glpi_plugin_formcreator_targetchanges' => [ |
| 56 | + 'content', |
| 57 | + 'impactcontent', |
| 58 | + 'controlistcontent', |
| 59 | + 'rolloutplancontent', |
| 60 | + 'backoutplancontent', |
| 61 | + 'checklistcontent', |
| 62 | + ], |
| 63 | + 'glpi_plugin_formcreator_targetproblems' => [ |
| 64 | + 'content', |
| 65 | + 'impactcontent', |
| 66 | + 'causecontent', |
| 67 | + 'symptomcontent', |
| 68 | + ], |
| 69 | + ]; |
| 70 | + |
| 71 | + foreach ($tables as $table => $fields) { |
| 72 | + $request = [ |
| 73 | + 'SELECT' => ['id'] + $fields, |
| 74 | + 'FROM' => $table |
| 75 | + ]; |
| 76 | + foreach ($DB->request($request) as $row) { |
| 77 | + foreach ($fields as $field) { |
| 78 | + $row[$field] = RichText::getSafeHtml($row[$field]); |
| 79 | + $row[$field] = Sanitizer::dbEscape($row[$field]); |
| 80 | + } |
| 81 | + $DB->update($table, $row, ['id' => $row['id']]); |
| 82 | + } |
| 83 | + } |
| 84 | + } |
| 85 | +} |
0 commit comments