@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Continue making application fixes to Phabricator for changes to %Q semantics

Summary: Depends on D19789. Ref T13217. Continue updating things to use the new %Q-flavored conversions instead of smushing a bunch of strings together.

Test Plan: Browsed around, far fewer errors. These changes are largely mechanical in nature.

Reviewers: amckinley

Reviewed By: amckinley

Maniphest Tasks: T13217

Differential Revision: https://secure.phabricator.com/D19790

+119 -84
+4 -4
src/applications/auth/engine/PhabricatorAuthSessionEngine.php
··· 809 809 } 810 810 811 811 if ($cache_selects) { 812 - $cache_selects = ', '.implode(', ', $cache_selects); 812 + $cache_selects = qsprintf($conn, ', %LQ', $cache_selects); 813 813 } else { 814 - $cache_selects = ''; 814 + $cache_selects = qsprintf($conn, ''); 815 815 } 816 816 817 817 if ($cache_joins) { 818 - $cache_joins = implode(' ', $cache_joins); 818 + $cache_joins = qsprintf($conn, '%LJ', $cache_joins); 819 819 } else { 820 - $cache_joins = ''; 820 + $cache_joins = qsprintf($conn, ''); 821 821 } 822 822 823 823 return array($cache_selects, $cache_joins, $cache_map, $types_map);
+1 -1
src/applications/auth/query/PhabricatorAuthSSHKeyQuery.php
··· 111 111 $key->getType(), 112 112 $key->getHash()); 113 113 } 114 - $where[] = implode(' OR ', $sql); 114 + $where[] = qsprintf($conn, '%LO', $sql); 115 115 } 116 116 117 117 if ($this->isActive !== null) {
-1
src/applications/calendar/query/PhabricatorCalendarEventQuery.php
··· 513 513 return 'PhabricatorCalendarApplication'; 514 514 } 515 515 516 - 517 516 protected function willFilterPage(array $events) { 518 517 $instance_of_event_phids = array(); 519 518 $recurring_events = array();
+23 -9
src/applications/differential/query/DifferentialRevisionQuery.php
··· 453 453 454 454 private function loadData() { 455 455 $table = $this->newResultObject(); 456 - $conn_r = $table->establishConnection('r'); 456 + $conn = $table->establishConnection('r'); 457 457 458 458 $selects = array(); 459 459 ··· 469 469 $this->authors = array_merge($basic_authors, $this->responsibles); 470 470 471 471 $this->reviewers = $basic_reviewers; 472 - $selects[] = $this->buildSelectStatement($conn_r); 472 + $selects[] = $this->buildSelectStatement($conn); 473 473 474 474 // Build the query where the responsible users are reviewers, or 475 475 // projects they are members of are reviewers. 476 476 $this->authors = $basic_authors; 477 477 $this->reviewers = array_merge($basic_reviewers, $this->responsibles); 478 - $selects[] = $this->buildSelectStatement($conn_r); 478 + $selects[] = $this->buildSelectStatement($conn); 479 479 480 480 // Put everything back like it was. 481 481 $this->authors = $basic_authors; ··· 486 486 throw $ex; 487 487 } 488 488 } else { 489 - $selects[] = $this->buildSelectStatement($conn_r); 489 + $selects[] = $this->buildSelectStatement($conn); 490 490 } 491 491 492 492 if (count($selects) > 1) { 493 + $unions = null; 494 + foreach ($selects as $select) { 495 + if (!$unions) { 496 + $unions = $select; 497 + continue; 498 + } 499 + 500 + $unions = qsprintf( 501 + $conn, 502 + '%Q UNION DISTINCT %Q', 503 + $unions, 504 + $select); 505 + } 506 + 493 507 $query = qsprintf( 494 - $conn_r, 508 + $conn, 495 509 '%Q %Q %Q', 496 - implode(' UNION DISTINCT ', $selects), 497 - $this->buildOrderClause($conn_r, true), 498 - $this->buildLimitClause($conn_r)); 510 + $unions, 511 + $this->buildOrderClause($conn, true), 512 + $this->buildLimitClause($conn)); 499 513 } else { 500 514 $query = head($selects); 501 515 } 502 516 503 - return queryfx_all($conn_r, '%Q', $query); 517 + return queryfx_all($conn, '%Q', $query); 504 518 } 505 519 506 520 private function buildSelectStatement(AphrontDatabaseConnection $conn_r) {
+24 -23
src/applications/maniphest/editor/ManiphestTransactionEditor.php
··· 471 471 // be worth evaluating is to use "CASE". Another approach is to disable 472 472 // strict mode for this query. 473 473 474 + $default_str = qsprintf($conn, '%s', ''); 475 + $default_int = qsprintf($conn, '%d', 0); 476 + 474 477 $extra_columns = array( 475 - 'phid' => '""', 476 - 'authorPHID' => '""', 477 - 'status' => '""', 478 - 'priority' => 0, 479 - 'title' => '""', 480 - 'description' => '""', 481 - 'dateCreated' => 0, 482 - 'dateModified' => 0, 483 - 'mailKey' => '""', 484 - 'viewPolicy' => '""', 485 - 'editPolicy' => '""', 486 - 'ownerOrdering' => '""', 487 - 'spacePHID' => '""', 488 - 'bridgedObjectPHID' => '""', 489 - 'properties' => '""', 490 - 'points' => 0, 491 - 'subtype' => '""', 478 + 'phid' => $default_str, 479 + 'authorPHID' => $default_str, 480 + 'status' => $default_str, 481 + 'priority' => $default_int, 482 + 'title' => $default_str, 483 + 'description' => $default_str, 484 + 'dateCreated' => $default_int, 485 + 'dateModified' => $default_int, 486 + 'mailKey' => $default_str, 487 + 'viewPolicy' => $default_str, 488 + 'editPolicy' => $default_str, 489 + 'ownerOrdering' => $default_str, 490 + 'spacePHID' => $default_str, 491 + 'bridgedObjectPHID' => $default_str, 492 + 'properties' => $default_str, 493 + 'points' => $default_int, 494 + 'subtype' => $default_str, 492 495 ); 493 - 494 - $defaults = implode(', ', $extra_columns); 495 496 496 497 $sql = array(); 497 498 $offset = 0; ··· 520 521 521 522 $sql[] = qsprintf( 522 523 $conn, 523 - '(%d, %Q, %f)', 524 + '(%d, %LQ, %f)', 524 525 $id, 525 - $defaults, 526 + $extra_columns, 526 527 $subpriority); 527 528 528 529 $offset++; ··· 531 532 foreach (PhabricatorLiskDAO::chunkSQL($sql) as $chunk) { 532 533 queryfx( 533 534 $conn, 534 - 'INSERT INTO %T (id, %Q, subpriority) VALUES %LQ 535 + 'INSERT INTO %T (id, %LC, subpriority) VALUES %LQ 535 536 ON DUPLICATE KEY UPDATE subpriority = VALUES(subpriority)', 536 537 $task->getTableName(), 537 - implode(', ', array_keys($extra_columns)), 538 + array_keys($extra_columns), 538 539 $chunk); 539 540 } 540 541
+8 -8
src/applications/maniphest/query/ManiphestTaskQuery.php
··· 237 237 238 238 $where = $this->buildWhereClause($conn); 239 239 240 - $group_column = ''; 240 + $group_column = qsprintf($conn, ''); 241 241 switch ($this->groupBy) { 242 242 case self::GROUP_PROJECT: 243 243 $group_column = qsprintf( ··· 601 601 } 602 602 603 603 if (!$subclause) { 604 - return ''; 604 + return qsprintf($conn, ''); 605 605 } 606 606 607 - return '('.implode(') OR (', $subclause).')'; 607 + return qsprintf($conn, '%LO', $subclause); 608 608 } 609 609 610 610 protected function buildJoinClauseParts(AphrontDatabaseConnection $conn) { ··· 736 736 return $joins; 737 737 } 738 738 739 - protected function buildGroupClause(AphrontDatabaseConnection $conn_r) { 739 + protected function buildGroupClause(AphrontDatabaseConnection $conn) { 740 740 $joined_multiple_rows = 741 741 ($this->hasOpenParents !== null) || 742 742 ($this->hasOpenSubtasks !== null) || ··· 750 750 // task IDs. 751 751 if ($joined_multiple_rows) { 752 752 if ($joined_project_name) { 753 - return 'GROUP BY task.phid, projectGroup.dst'; 753 + return qsprintf($conn, 'GROUP BY task.phid, projectGroup.dst'); 754 754 } else { 755 - return 'GROUP BY task.phid'; 755 + return qsprintf($conn, 'GROUP BY task.phid'); 756 756 } 757 - } else { 758 - return ''; 759 757 } 758 + 759 + return qsprintf($conn, ''); 760 760 } 761 761 762 762
+2 -2
src/applications/people/storage/PhabricatorUser.php
··· 663 663 if ($sql) { 664 664 queryfx( 665 665 $conn_w, 666 - 'INSERT INTO %T (userID, token) VALUES %Q', 666 + 'INSERT INTO %T (userID, token) VALUES %LQ', 667 667 $table, 668 - implode(', ', $sql)); 668 + $sql); 669 669 } 670 670 } 671 671
+8 -2
src/infrastructure/cluster/PhabricatorDatabaseRef.php
··· 557 557 $conn = $this->newManagementConnection(); 558 558 559 559 try { 560 - $value = queryfx_one($conn, 'SELECT @@%Q', $key); 561 - $value = $value['@@'.$key]; 560 + $value = queryfx_one($conn, 'SELECT @@%C', $key); 561 + 562 + // NOTE: Although MySQL allows us to escape configuration values as if 563 + // they are column names, the escaping is included in the column name 564 + // of the return value: if we select "@@`x`", we get back a column named 565 + // "@@`x`", not "@@x" as we might expect. 566 + $value = head($value); 567 + 562 568 } catch (AphrontQueryException $ex) { 563 569 $value = null; 564 570 }
+5 -5
src/infrastructure/edges/editor/PhabricatorEdgeEditor.php
··· 275 275 $conn_w->openTransaction(); 276 276 $this->openTransactions[] = $conn_w; 277 277 278 - foreach (array_chunk($sql, 256) as $chunk) { 278 + foreach (PhabricatorLiskDAO::chunkSQL($sql) as $chunk) { 279 279 queryfx( 280 280 $conn_w, 281 281 'INSERT INTO %T (src, type, dst, dateCreated, seq, dataID) 282 - VALUES %Q ON DUPLICATE KEY UPDATE dataID = VALUES(dataID)', 282 + VALUES %LQ ON DUPLICATE KEY UPDATE dataID = VALUES(dataID)', 283 283 PhabricatorEdgeConfig::TABLE_NAME_EDGE, 284 - implode(', ', $chunk)); 284 + $chunk); 285 285 } 286 286 } 287 287 } ··· 320 320 foreach (array_chunk($sql, 256) as $chunk) { 321 321 queryfx( 322 322 $conn_w, 323 - 'DELETE FROM %T WHERE (%Q)', 323 + 'DELETE FROM %T WHERE %LO', 324 324 PhabricatorEdgeConfig::TABLE_NAME_EDGE, 325 - implode(' OR ', $chunk)); 325 + $chunk); 326 326 } 327 327 } 328 328 }
+3 -3
src/infrastructure/edges/query/PhabricatorEdgeQuery.php
··· 322 322 /** 323 323 * @task internal 324 324 */ 325 - private function buildOrderClause($conn_r) { 325 + private function buildOrderClause(AphrontDatabaseConnection $conn) { 326 326 if ($this->order == self::ORDER_NEWEST_FIRST) { 327 - return 'ORDER BY edge.dateCreated DESC, edge.seq DESC'; 327 + return qsprintf($conn, 'ORDER BY edge.dateCreated DESC, edge.seq DESC'); 328 328 } else { 329 - return 'ORDER BY edge.dateCreated ASC, edge.seq ASC'; 329 + return qsprintf($conn, 'ORDER BY edge.dateCreated ASC, edge.seq ASC'); 330 330 } 331 331 } 332 332
+24 -21
src/infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php
··· 123 123 AphrontDatabaseConnection $conn, 124 124 $table_name) { 125 125 126 + $table_alias = $this->getPrimaryTableAlias(); 127 + if ($table_alias === null) { 128 + $table_alias = qsprintf($conn, ''); 129 + } else { 130 + $table_alias = qsprintf($conn, '%T', $table_alias); 131 + } 132 + 126 133 return qsprintf( 127 134 $conn, 128 135 '%Q FROM %T %Q %Q %Q %Q %Q %Q %Q', 129 136 $this->buildSelectClause($conn), 130 137 $table_name, 131 - (string)$this->getPrimaryTableAlias(), 138 + $table_alias, 132 139 $this->buildJoinClause($conn), 133 140 $this->buildWhereClause($conn), 134 141 $this->buildGroupClause($conn), ··· 425 432 } else { 426 433 // No paging is being applied to this query so we do not need to 427 434 // construct a paging clause. 428 - return ''; 435 + return qsprintf($conn, ''); 429 436 } 430 437 431 438 $keys = array(); ··· 655 662 $conn, 656 663 '%Q %Q %Q', 657 664 $field, 658 - $reverse ? '>' : '<', 665 + $reverse ? qsprintf($conn, '>') : qsprintf($conn, '<'), 659 666 $value); 660 667 } 661 668 662 669 if ($parts) { 663 - if (count($parts) > 1) { 664 - $clause[] = '('.implode(') OR (', $parts).')'; 665 - } else { 666 - $clause[] = head($parts); 667 - } 670 + $clause[] = qsprintf($conn, '%LO', $parts); 668 671 } 669 672 670 673 if ($clause) { 671 - if (count($clause) > 1) { 672 - $clauses[] = '('.implode(') AND (', $clause).')'; 673 - } else { 674 - $clauses[] = head($clause); 675 - } 674 + $clauses[] = qsprintf($conn, '%LA', $clause); 676 675 } 677 676 678 677 if ($value === null) { ··· 689 688 } 690 689 } 691 690 692 - return '('.implode(') OR (', $clauses).')'; 691 + if ($clauses) { 692 + return qsprintf($conn, '%LO', $clauses); 693 + } 694 + 695 + return qsprintf($conn, ''); 693 696 } 694 697 695 698 ··· 1315 1318 return qsprintf( 1316 1319 $conn, 1317 1320 'GROUP BY %Q', 1318 - $this->getApplicationSearchObjectPHIDColumn()); 1321 + $this->getApplicationSearchObjectPHIDColumn($conn)); 1319 1322 } else { 1320 1323 return qsprintf($conn, ''); 1321 1324 } ··· 1339 1342 $alias = $constraint['alias']; 1340 1343 $index = $constraint['index']; 1341 1344 $cond = $constraint['cond']; 1342 - $phid_column = $this->getApplicationSearchObjectPHIDColumn(); 1345 + $phid_column = $this->getApplicationSearchObjectPHIDColumn($conn); 1343 1346 switch ($cond) { 1344 1347 case '=': 1345 1348 // Figure out whether we need to do a LEFT JOIN or not. We need to 1346 1349 // LEFT JOIN if we're going to select "IS NULL" rows. 1347 - $join_type = 'JOIN'; 1350 + $join_type = qsprintf($conn, 'JOIN'); 1348 1351 foreach ($constraint['constraints'] as $query_constraint) { 1349 1352 $op = $query_constraint->getOperator(); 1350 1353 if ($op === PhabricatorQueryConstraint::OPERATOR_NULL) { 1351 - $join_type = 'LEFT JOIN'; 1354 + $join_type = qsprintf($conn, 'LEFT JOIN'); 1352 1355 break; 1353 1356 } 1354 1357 } ··· 2437 2440 // this to a LEFT join. We'll use WHERE to select matching rows 2438 2441 // later. 2439 2442 if ($has_null) { 2440 - $join_type = 'LEFT'; 2443 + $join_type = qsprintf($conn, 'LEFT'); 2441 2444 } else { 2442 - $join_type = ''; 2445 + $join_type = qsprintf($conn, ''); 2443 2446 } 2444 2447 2445 2448 $joins[] = qsprintf( ··· 2912 2915 if ($alias) { 2913 2916 $col = qsprintf($conn, '%T.spacePHID', $alias); 2914 2917 } else { 2915 - $col = 'spacePHID'; 2918 + $col = qsprintf($conn, 'spacePHID'); 2916 2919 } 2917 2920 2918 2921 if ($space_phids && $include_null) {
+17 -5
src/infrastructure/storage/lisk/LiskDAO.php
··· 1149 1149 $map[$key] = qsprintf($conn, '%C = %ns', $key, $value); 1150 1150 } 1151 1151 } 1152 - $map = implode(', ', $map); 1153 1152 1154 1153 $id = $this->getID(); 1155 1154 $conn->query( 1156 - 'UPDATE %R SET %Q WHERE %C = '.(is_int($id) ? '%d' : '%s'), 1155 + 'UPDATE %R SET %LQ WHERE %C = '.(is_int($id) ? '%d' : '%s'), 1157 1156 $this, 1158 1157 $map, 1159 1158 $this->getIDKeyForUse(), ··· 1255 1254 $parameter_exception); 1256 1255 } 1257 1256 } 1258 - $data = implode(', ', $data); 1257 + 1258 + switch ($mode) { 1259 + case 'INSERT': 1260 + $verb = qsprintf($conn, 'INSERT'); 1261 + break; 1262 + case 'REPLACE': 1263 + $verb = qsprintf($conn, 'REPLACE'); 1264 + break; 1265 + default: 1266 + throw new Exception( 1267 + pht( 1268 + 'Insert mode verb "%s" is not recognized, use INSERT or REPLACE.', 1269 + $mode)); 1270 + } 1259 1271 1260 1272 $conn->query( 1261 - '%Q INTO %R (%LC) VALUES (%Q)', 1262 - $mode, 1273 + '%Q INTO %R (%LC) VALUES (%LQ)', 1274 + $verb, 1263 1275 $this, 1264 1276 $columns, 1265 1277 $data);