@@ -53,6 +53,7 @@ protected function execute(InputInterface $input, OutputInterface $output) {
53
53
54
54
$ this ->fixBadForm_1 ($ input , $ output );
55
55
$ this ->fixBadForm_2 ($ input , $ output );
56
+ $ this ->fixBadForm_3 ($ input , $ output );
56
57
57
58
$ output ->writeln ('<info>Done.</info> ' );
58
59
return 0 ;
@@ -62,8 +63,6 @@ protected function execute(InputInterface $input, OutputInterface $output) {
62
63
* fix HTML tags double encoded
63
64
* <p> => <p> => &lt;p&gt;
64
65
*
65
- * @param InputInterface $input
66
- * @param OutputInterface $output
67
66
* @return void
68
67
*/
69
68
protected function fixBadForm_1 (InputInterface $ input , OutputInterface $ output ) {
@@ -102,7 +101,7 @@ protected function fixBadForm_1(InputInterface $input, OutputInterface $output)
102
101
return 0 ;
103
102
}
104
103
105
- $ output ->write ("<info>-> Found $ count tickets to clean</info> " );
104
+ $ output ->write ("<info>-> Found $ count tickets to clean (double encoded < and > signs) </info> " );
106
105
$ output ->writeln ("" );
107
106
$ output ->write ("<info>-> Cleaning tickets...</info> " );
108
107
$ output ->writeln ("" );
@@ -130,10 +129,8 @@ protected function fixBadForm_1(InputInterface $input, OutputInterface $output)
130
129
}
131
130
132
131
/**
133
- * remove HTML tag <br />
132
+ * replace litteral HTML tag <br /> with <br />
134
133
*
135
- * @param InputInterface $input
136
- * @param OutputInterface $output
137
134
* @return void
138
135
*/
139
136
protected function fixBadForm_2 (InputInterface $ input , OutputInterface $ output ) {
@@ -142,7 +139,7 @@ protected function fixBadForm_2(InputInterface $input, OutputInterface $output)
142
139
// Search tickets having HTML tags <br />
143
140
$ itemTicketTable = Item_Ticket::getTable ();
144
141
$ ticketTable = Ticket::getTable ();
145
- $ pattern = 'br / ' ;
142
+ $ pattern = '< br /> ' ;
146
143
$ tickets = $ DB ->request ([
147
144
'SELECT ' => [$ ticketTable => [Ticket::getIndexName (), 'content ' ]],
148
145
'FROM ' => $ ticketTable ,
@@ -158,7 +155,7 @@ protected function fixBadForm_2(InputInterface $input, OutputInterface $output)
158
155
],
159
156
],
160
157
'WHERE ' => [
161
- "$ ticketTable.content " => ['LIKE ' , '% ' . $ pattern . '% ' ], // Matches bad encoding for '< '
158
+ "$ ticketTable.content " => ['LIKE ' , '% ' . $ pattern . '% ' ], // Matches bad encoding for 'br / '
162
159
],
163
160
]);
164
161
@@ -169,16 +166,89 @@ protected function fixBadForm_2(InputInterface $input, OutputInterface $output)
169
166
return 0 ;
170
167
}
171
168
172
- $ output ->write ("<info>-> Found $ count tickets to clean</info> " );
169
+ $ output ->write ("<info>-> Found $ count tickets to clean (literal BR tag) </info> " );
173
170
$ output ->writeln ("" );
174
171
$ output ->write ("<info>-> Cleaning tickets...</info> " );
175
172
$ output ->writeln ("" );
176
173
foreach ($ tickets as $ row ) {
177
174
$ pattern = [
178
175
'<br /> ' ,
179
176
];
177
+ // Determine if we mlust use legacy or new encoding
178
+ // @see Sanitizer::sanitize()
179
+ if (strpos ($ row ['content ' ], '< ' ) !== false && strpos ($ row ['content ' ], '#60; ' ) === false ) {
180
+ $ replace = [
181
+ '<br /> ' ,
182
+ ];
183
+ } else if (strpos ($ row ['content ' ], '#60 ' ) !== false && strpos ($ row ['content ' ], '< ' ) === false ) {
184
+ $ replace = [
185
+ '<br /> ' ,
186
+ ];
187
+ }
188
+ $ row ['content ' ] = str_replace ($ pattern , $ replace , $ row ['content ' ]);
189
+ // Direct write to the table to avoid alteration of other fields
190
+ $ DB ->update (
191
+ $ ticketTable ,
192
+ [
193
+ 'content ' => $ DB ->escape ($ row ['content ' ])
194
+ ],
195
+ [
196
+ 'id ' => $ row ['id ' ],
197
+ ]
198
+ );
199
+ }
200
+ }
201
+
202
+ /**
203
+ * replace litteral HTML tag > with #38;
204
+ * This may happen when a question gives the path to an item of a CommonTreeObject
205
+ * entities, locations, ...
206
+ *
207
+ * @return void
208
+ */
209
+ protected function fixBadForm_3 (InputInterface $ input , OutputInterface $ output ) {
210
+ global $ DB ;
211
+
212
+ // Search tickets having HTML tags <br />
213
+ $ itemTicketTable = Item_Ticket::getTable ();
214
+ $ ticketTable = Ticket::getTable ();
215
+ $ pattern = ' > ' ; // greater than sign with a space before and after
216
+ $ tickets = $ DB ->request ([
217
+ 'SELECT ' => [$ ticketTable => [Ticket::getIndexName (), 'content ' ]],
218
+ 'FROM ' => $ ticketTable ,
219
+ 'INNER JOIN ' => [
220
+ $ itemTicketTable => [
221
+ 'FKEY ' => [
222
+ $ ticketTable => Ticket::getIndexName (),
223
+ $ itemTicketTable => Ticket::getForeignKeyField (),
224
+ ],
225
+ 'AND ' => [
226
+ "$ itemTicketTable.itemtype " => PluginFormcreatorFormAnswer::getType (),
227
+ ]
228
+ ],
229
+ ],
230
+ 'WHERE ' => [
231
+ "$ ticketTable.content " => ['LIKE ' , '% ' . $ pattern . '% ' ],
232
+ ],
233
+ ]);
234
+
235
+ $ count = $ tickets ->count ();
236
+ if ($ count < 1 ) {
237
+ $ output ->writeln ('<info>-> No ticket to fix.</info> ' );
238
+ $ output ->writeln ("" );
239
+ return 0 ;
240
+ }
241
+
242
+ $ output ->write ("<info>-> Found $ count tickets to clean (litteral > sign)</info> " );
243
+ $ output ->writeln ("" );
244
+ $ output ->write ("<info>-> Cleaning tickets...</info> " );
245
+ $ output ->writeln ("" );
246
+ foreach ($ tickets as $ row ) {
247
+ $ pattern = [
248
+ ' > ' ,
249
+ ];
180
250
$ replace = [
181
- '<br /> ' ,
251
+ ' #38; ' ,
182
252
];
183
253
$ row ['content ' ] = str_replace ($ pattern , $ replace , $ row ['content ' ]);
184
254
// Direct write to the table to avoid alteration of other fields
0 commit comments