Skip to content

Commit b91bcd5

Browse files
committed
request #27166: Naming a field "id" breaks the report
Field names are now prefixed in the SQL query in order to avoid conflict with the static SQL columns we always retrieve. Change-Id: I7eaaf95e24f52f6e52647d679b5058bc09139b5f
1 parent 316405f commit b91bcd5

28 files changed

+76
-98
lines changed

Diff for: plugins/agiledashboard/include/AgileDashboard/FormElement/Burnup.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -285,8 +285,9 @@ public function getQueryFrom()
285285
{
286286
}
287287

288-
public function getQuerySelect()
288+
public function getQuerySelect(): string
289289
{
290+
return '';
290291
}
291292

292293
public function getRESTValue(PFUser $user, Tracker_Artifact_Changeset $changeset)

Diff for: plugins/testmanagement/include/TestManagement/Step/Execution/Field/StepExecution.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ public function getCriteriaWhere($criteria)
123123
return '';
124124
}
125125

126-
public function getQuerySelect()
126+
public function getQuerySelect(): string
127127
{
128128
return '';
129129
}

Diff for: plugins/tracker/include/Tracker/FormElement/Tracker_FormElement_Field.php

+12-6
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
// phpcs:ignore PSR1.Classes.ClassDeclaration.MissingNamespace, Squiz.Classes.ValidClassName.NotCamelCaps
4242
abstract class Tracker_FormElement_Field extends Tracker_FormElement implements Tracker_Report_Field, Tracker_FormElement_IAcceptFieldVisitor
4343
{
44+
public const PREFIX_NAME_SQL_COLUMN = 'user_defined_';
45+
4446
protected $has_errors = false;
4547

4648
/**
@@ -203,15 +205,19 @@ public function saveCriteriaValueFromXML(Tracker_Report_Criteria $criteria)
203205
$this->updateCriteriaValue($criteria, $value);
204206
}
205207

208+
final public function getQuerySelectName(): string
209+
{
210+
return \Tuleap\DB\DBFactory::getMainTuleapDBConnection()->getDB()->escapeIdentifier(self::PREFIX_NAME_SQL_COLUMN . $this->name);
211+
}
212+
206213
/**
207214
* Get the "select" statement to retrieve field values
208-
* @return string
209215
* @see getQueryFrom
210216
*/
211-
public function getQuerySelect()
217+
public function getQuerySelect(): string
212218
{
213219
$R = 'R_' . $this->id;
214-
return "$R.value_id AS `" . $this->name . "`";
220+
return "$R.value_id AS " . $this->getQuerySelectName();
215221
}
216222

217223
/**
@@ -229,15 +235,15 @@ public function getQueryFrom()
229235
/**
230236
* Get the "order by" statement to retrieve field values
231237
*/
232-
public function getQueryOrderby()
238+
public function getQueryOrderby(): string
233239
{
234-
return '`' . $this->name . '`';
240+
return $this->getQuerySelectName();
235241
}
236242

237243
/**
238244
* Get the "group by" statement to retrieve field values
239245
*/
240-
public function getQueryGroupby()
246+
public function getQueryGroupby(): string
241247
{
242248
$R = 'R_' . $this->id;
243249
return "$R.value_id";

Diff for: plugins/tracker/include/Tracker/FormElement/Tracker_FormElement_Field_Alphanum.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,8 @@ public function fetchAdvancedCriteriaValue($criteria)
7070
/**
7171
* Get the "group by" statement to retrieve field values
7272
*/
73-
public function getQueryGroupby()
73+
public function getQueryGroupby(): string
7474
{
75-
$R1 = 'R1_' . $this->id;
7675
$R2 = 'R2_' . $this->id;
7776
return "$R2.value";
7877
}

Diff for: plugins/tracker/include/Tracker/FormElement/Tracker_FormElement_Field_ArtifactId.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ public function getCriteriaWhere($criteria)
3838
return '';
3939
}
4040

41-
public function getQuerySelect()
41+
public function getQuerySelect(): string
4242
{
43-
return "a.id AS `" . $this->name . "`";
43+
return "a.id AS " . $this->getQuerySelectName();
4444
}
4545

4646
public function getQueryFrom()
@@ -51,7 +51,7 @@ public function getQueryFrom()
5151
/**
5252
* Get the "group by" statement to retrieve field values
5353
*/
54-
public function getQueryGroupby()
54+
public function getQueryGroupby(): string
5555
{
5656
return "a.id";
5757
}

Diff for: plugins/tracker/include/Tracker/FormElement/Tracker_FormElement_Field_ArtifactLink.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ public function getCriteriaWhere($criteria)
418418
return '';
419419
}
420420

421-
public function getQuerySelect()
421+
public function getQuerySelect(): string
422422
{
423423
return '';
424424
}

Diff for: plugins/tracker/include/Tracker/FormElement/Tracker_FormElement_Field_Burndown.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -447,8 +447,9 @@ public function getCriteriaWhere($criteria)
447447
{
448448
}
449449

450-
public function getQuerySelect()
450+
public function getQuerySelect(): string
451451
{
452+
return '';
452453
}
453454

454455
public function getQueryFrom()

Diff for: plugins/tracker/include/Tracker/FormElement/Tracker_FormElement_Field_Computed.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,7 @@ public function getCriteriaWhere($criteria)
627627
return '';
628628
}
629629

630-
public function getQuerySelect()
630+
public function getQuerySelect(): string
631631
{
632632
return '';
633633
}

Diff for: plugins/tracker/include/Tracker/FormElement/Tracker_FormElement_Field_CrossReferences.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ public function getCriteriaWhere($criteria)
139139
return '';
140140
}
141141

142-
public function getQuerySelect()
142+
public function getQuerySelect(): string
143143
{
144144
return '';
145145
}

Diff for: plugins/tracker/include/Tracker/FormElement/Tracker_FormElement_Field_Date.php

+3-5
Original file line numberDiff line numberDiff line change
@@ -413,11 +413,10 @@ public function getCriteriaWhere($criteria)
413413
return '';
414414
}
415415

416-
public function getQuerySelect()
416+
public function getQuerySelect(): string
417417
{
418-
$R1 = 'R1_' . $this->id;
419418
$R2 = 'R2_' . $this->id;
420-
return "$R2.value AS `" . $this->name . "`";
419+
return "$R2.value AS " . $this->getQuerySelectName();
421420
}
422421

423422
public function getQueryFrom()
@@ -432,9 +431,8 @@ public function getQueryFrom()
432431
/**
433432
* Get the "group by" statement to retrieve field values
434433
*/
435-
public function getQueryGroupby()
434+
public function getQueryGroupby(): string
436435
{
437-
$R1 = 'R1_' . $this->id;
438436
$R2 = 'R2_' . $this->id;
439437
return "$R2.value";
440438
}

Diff for: plugins/tracker/include/Tracker/FormElement/Tracker_FormElement_Field_File.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public function getCriteriaWhere($criteria)
6969
return '';
7070
}
7171

72-
public function getQuerySelect()
72+
public function getQuerySelect(): string
7373
{
7474
return '';
7575
}

Diff for: plugins/tracker/include/Tracker/FormElement/Tracker_FormElement_Field_LastModifiedBy.php

+3-8
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ public function getCriteriaWhere($criteria)
6767
return '';
6868
}
6969

70-
public function getQuerySelect()
70+
public function getQuerySelect(): string
7171
{
72-
return "c.submitted_by AS `" . $this->name . "`";
72+
return "c.submitted_by AS " . $this->getQuerySelectName();
7373
}
7474

7575
public function getQueryFrom()
@@ -84,16 +84,11 @@ public function getQueryFromAggregate()
8484
return " LEFT JOIN user AS $R2 ON ($R2.user_id = c.submitted_by ) ";
8585
}
8686

87-
public function getQueryGroupby()
87+
public function getQueryGroupby(): string
8888
{
8989
return '';
9090
}
9191

92-
public function getQueryOrderby()
93-
{
94-
return $this->name;
95-
}
96-
9792
public static function getFactoryLabel()
9893
{
9994
return dgettext('tuleap-tracker', 'Last Updated By');

Diff for: plugins/tracker/include/Tracker/FormElement/Tracker_FormElement_Field_LastUpdateDate.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,10 @@ public function getCriteriaWhere($criteria)
6868
return '';
6969
}
7070

71-
public function getQuerySelect()
71+
public function getQuerySelect(): string
7272
{
7373
//Last update date is stored in the changeset (the date of the changeset)
74-
return "c.submitted_on AS `" . $this->name . "`";
74+
return "c.submitted_on AS " . $this->getQuerySelectName();
7575
}
7676

7777
public function getQueryFrom()
@@ -83,7 +83,7 @@ public function getQueryFrom()
8383
/**
8484
* Get the "group by" statement to retrieve field values
8585
*/
86-
public function getQueryGroupby()
86+
public function getQueryGroupby(): string
8787
{
8888
//Last update date is stored in the changeset (the date of the changeset)
8989
return 'c.submitted_on';

Diff for: plugins/tracker/include/Tracker/FormElement/Tracker_FormElement_Field_List.php

+3-4
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,8 @@ public function getCriteriaWhere($criteria)
162162
*
163163
* @see getQueryFrom
164164
*
165-
* @return string
166165
*/
167-
public function getQuerySelect()
166+
public function getQuerySelect(): string
168167
{
169168
return $this->getBind()->getQuerySelect();
170169
}
@@ -205,15 +204,15 @@ public function getQueryFromWithDecorator()
205204
/**
206205
* Get the "order by" statement to retrieve field values
207206
*/
208-
public function getQueryOrderby()
207+
public function getQueryOrderby(): string
209208
{
210209
return $this->getBind()->getQueryOrderby();
211210
}
212211

213212
/**
214213
* Get the "group by" statement to retrieve field values
215214
*/
216-
public function getQueryGroupby()
215+
public function getQueryGroupby(): string
217216
{
218217
return $this->getBind()->getQueryGroupby();
219218
}

Diff for: plugins/tracker/include/Tracker/FormElement/Tracker_FormElement_Field_List_Bind.php

+3-4
Original file line numberDiff line numberDiff line change
@@ -326,10 +326,9 @@ protected function getIdsToSearch($criteria_value)
326326

327327
/**
328328
* Get the "select" statement to retrieve field values
329-
* @return string
330329
* @see getQueryFrom
331330
*/
332-
abstract public function getQuerySelect();
331+
abstract public function getQuerySelect(): string;
333332

334333
/**
335334
* Get the "select" statement to retrieve field values with their decorator if they exist
@@ -393,12 +392,12 @@ abstract public function getBindtableSqlFragment();
393392
/**
394393
* Get the "order by" statement to retrieve field values
395394
*/
396-
abstract public function getQueryOrderby();
395+
abstract public function getQueryOrderby(): string;
397396

398397
/**
399398
* Get the "group by" statement to retrieve field values
400399
*/
401-
abstract public function getQueryGroupby();
400+
abstract public function getQueryGroupby(): string;
402401

403402
public function getSelectOptionStyles($value_id)
404403
{

Diff for: plugins/tracker/include/Tracker/FormElement/Tracker_FormElement_Field_List_Bind_Null.php

+3-4
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,9 @@ public function getCriteriaWhere($criteria)
150150

151151
/**
152152
* Get the "select" statement to retrieve field values
153-
* @return string
154153
* @see getQueryFrom
155154
*/
156-
public function getQuerySelect()
155+
public function getQuerySelect(): string
157156
{
158157
return '';
159158
}
@@ -205,15 +204,15 @@ public function getBindtableSqlFragment()
205204
/**
206205
* Get the "order by" statement to retrieve field values
207206
*/
208-
public function getQueryOrderby()
207+
public function getQueryOrderby(): string
209208
{
210209
return '';
211210
}
212211

213212
/**
214213
* Get the "group by" statement to retrieve field values
215214
*/
216-
public function getQueryGroupby()
215+
public function getQueryGroupby(): string
217216
{
218217
return '';
219218
}

Diff for: plugins/tracker/include/Tracker/FormElement/Tracker_FormElement_Field_List_Bind_Static.php

+4-8
Original file line numberDiff line numberDiff line change
@@ -274,14 +274,12 @@ protected function getIdsToSearch($criteria_value)
274274

275275
/**
276276
* Get the "select" statement to retrieve field values
277-
* @return string
278277
* @see getQueryFrom
279278
*/
280-
public function getQuerySelect()
279+
public function getQuerySelect(): string
281280
{
282-
$R1 = 'R1_' . $this->field->id;
283281
$R2 = 'R2_' . $this->field->id;
284-
return "$R2.id AS `" . $this->field->name . "`";
282+
return "$R2.id AS " . $this->field->getQuerySelectName();
285283
}
286284

287285
/**
@@ -334,19 +332,17 @@ public function getQueryFromWithDecorator($changesetvalue_table = 'tracker_chang
334332
/**
335333
* Get the "order by" statement to retrieve field values
336334
*/
337-
public function getQueryOrderby()
335+
public function getQueryOrderby(): string
338336
{
339-
$R1 = 'R1_' . $this->field->id;
340337
$R2 = 'R2_' . $this->field->id;
341338
return $this->is_rank_alpha ? "$R2.label" : "$R2.rank";
342339
}
343340

344341
/**
345342
* Get the "group by" statement to retrieve field values
346343
*/
347-
public function getQueryGroupby()
344+
public function getQueryGroupby(): string
348345
{
349-
$R1 = 'R1_' . $this->field->id;
350346
$R2 = 'R2_' . $this->field->id;
351347
return "$R2.id";
352348
}

Diff for: plugins/tracker/include/Tracker/FormElement/Tracker_FormElement_Field_List_Bind_Ugroups.php

+4-10
Original file line numberDiff line numberDiff line change
@@ -225,15 +225,12 @@ public function getFieldData($submitted_value, $is_multiple)
225225

226226
/**
227227
* Get the "select" statement to retrieve field values
228-
* @return string
229228
* @see getQueryFrom
230229
*/
231-
public function getQuerySelect()
230+
public function getQuerySelect(): string
232231
{
233-
$R1 = 'R1_' . $this->field->id;
234232
$R2 = 'R2_' . $this->field->id;
235-
$R3 = 'R3_' . $this->field->id;
236-
return "$R2.id AS `" . $this->field->name . "`";
233+
return "$R2.id AS " . $this->field->getQuerySelectName();
237234
}
238235

239236
/**
@@ -265,20 +262,17 @@ public function getQueryFrom($changesetvalue_table = 'tracker_changeset_value_li
265262
/**
266263
* Get the "order by" statement to retrieve field values
267264
*/
268-
public function getQueryOrderby()
265+
public function getQueryOrderby(): string
269266
{
270-
$uh = UserHelper::instance();
271-
$R1 = 'R1_' . $this->field->id;
272267
$R2 = 'R2_' . $this->field->id;
273268
return "$R2.ugroup_id";
274269
}
275270

276271
/**
277272
* Get the "group by" statement to retrieve field values
278273
*/
279-
public function getQueryGroupby()
274+
public function getQueryGroupby(): string
280275
{
281-
$R1 = 'R1_' . $this->field->id;
282276
$R2 = 'R2_' . $this->field->id;
283277
return "$R2.id";
284278
}

0 commit comments

Comments
 (0)