@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.

Make buildPagingClauseFromMultipleColumns() safer

Summary: Ref T7803. Reduce the amount of code we're trusting to build SQL queries.

Test Plan:
- Paged through results in Maniphest, Differential and Diffusion.
- Some of the NULLable groups in Maniphest are a bit funky but this was preexisting.

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T7803

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

+68 -31
+6 -3
src/applications/differential/query/DifferentialRevisionQuery.php
··· 896 896 return $default; 897 897 case self::ORDER_MODIFIED: 898 898 $columns[] = array( 899 - 'name' => 'r.dateModified', 899 + 'table' => 'r', 900 + 'column' => 'dateModified', 900 901 'value' => $cursor->getDateModified(), 901 902 'type' => 'int', 902 903 ); 903 904 break; 904 905 case self::ORDER_PATH_MODIFIED: 905 906 $columns[] = array( 906 - 'name' => 'p.epoch', 907 + 'table' => 'p', 908 + 'column' => 'epoch', 907 909 'value' => $cursor->getDateCreated(), 908 910 'type' => 'int', 909 911 ); ··· 911 913 } 912 914 913 915 $columns[] = array( 914 - 'name' => 'r.id', 916 + 'table' => 'r', 917 + 'column' => 'id', 915 918 'value' => $cursor->getID(), 916 919 'type' => 'int', 917 920 );
+28 -16
src/applications/maniphest/query/ManiphestTaskQuery.php
··· 1005 1005 break; 1006 1006 case self::GROUP_PRIORITY: 1007 1007 $columns[] = array( 1008 - 'name' => 'task.priority', 1008 + 'table' => 'task', 1009 + 'column' => 'priority', 1009 1010 'value' => (int)$group_id, 1010 1011 'type' => 'int', 1011 1012 ); 1012 1013 break; 1013 1014 case self::GROUP_OWNER: 1014 1015 $columns[] = array( 1015 - 'name' => '(task.ownerOrdering IS NULL)', 1016 - 'value' => (int)(strlen($group_id) ? 0 : 1), 1017 - 'type' => 'int', 1016 + 'table' => 'task', 1017 + 'column' => 'ownerOrdering', 1018 + 'value' => strlen($group_id), 1019 + 'type' => 'null', 1018 1020 ); 1019 1021 if ($group_id) { 1020 1022 $paging_users = id(new PhabricatorPeopleQuery()) ··· 1025 1027 return null; 1026 1028 } 1027 1029 $columns[] = array( 1028 - 'name' => 'task.ownerOrdering', 1030 + 'table' => 'task', 1031 + 'column' => 'ownerOrdering', 1029 1032 'value' => head($paging_users)->getUsername(), 1030 1033 'type' => 'string', 1031 1034 'reverse' => true, ··· 1034 1037 break; 1035 1038 case self::GROUP_STATUS: 1036 1039 $columns[] = array( 1037 - 'name' => 'task.status', 1040 + 'table' => 'task', 1041 + 'column' => 'status', 1038 1042 'value' => $group_id, 1039 1043 'type' => 'string', 1040 1044 ); 1041 1045 break; 1042 1046 case self::GROUP_PROJECT: 1043 1047 $columns[] = array( 1044 - 'name' => '(projectGroupName.indexedObjectName IS NULL)', 1045 - 'value' => (int)(strlen($group_id) ? 0 : 1), 1046 - 'type' => 'int', 1048 + 'table' => 'projectGroupName', 1049 + 'column' => 'indexedObjectName', 1050 + 'value' => strlen($group_id), 1051 + 'type' => 'null', 1047 1052 ); 1048 1053 if ($group_id) { 1049 1054 $paging_projects = id(new PhabricatorProjectQuery()) ··· 1054 1059 return null; 1055 1060 } 1056 1061 $columns[] = array( 1057 - 'name' => 'projectGroupName.indexedObjectName', 1062 + 'table' => 'projectGroupName', 1063 + 'column' => 'indexedObjectName', 1058 1064 'value' => head($paging_projects)->getName(), 1059 1065 'type' => 'string', 1060 1066 'reverse' => true, ··· 1073 1079 case self::ORDER_PRIORITY: 1074 1080 if ($this->groupBy != self::GROUP_PRIORITY) { 1075 1081 $columns[] = array( 1076 - 'name' => 'task.priority', 1082 + 'table' => 'task', 1083 + 'column' => 'priority', 1077 1084 'value' => (int)$cursor->getPriority(), 1078 1085 'type' => 'int', 1079 1086 ); 1080 1087 } 1081 1088 $columns[] = array( 1082 - 'name' => 'task.subpriority', 1089 + 'table' => 'task', 1090 + 'column' => 'subpriority', 1083 1091 'value' => $cursor->getSubpriority(), 1084 1092 'type' => 'float', 1085 1093 ); 1086 1094 $columns[] = array( 1087 - 'name' => 'task.dateModified', 1095 + 'table' => 'task', 1096 + 'column' => 'dateModified', 1088 1097 'value' => (int)$cursor->getDateModified(), 1089 1098 'type' => 'int', 1090 1099 ); ··· 1094 1103 break; 1095 1104 case self::ORDER_MODIFIED: 1096 1105 $columns[] = array( 1097 - 'name' => 'task.dateModified', 1106 + 'table' => 'task', 1107 + 'column' => 'dateModified', 1098 1108 'value' => (int)$cursor->getDateModified(), 1099 1109 'type' => 'int', 1100 1110 ); 1101 1111 break; 1102 1112 case self::ORDER_TITLE: 1103 1113 $columns[] = array( 1104 - 'name' => 'task.title', 1114 + 'table' => 'task', 1115 + 'column' => 'title', 1105 1116 'value' => $cursor->getTitle(), 1106 1117 'type' => 'string', 1107 1118 ); ··· 1112 1123 } 1113 1124 1114 1125 $columns[] = array( 1115 - 'name' => 'task.id', 1126 + 'table' => 'task', 1127 + 'column' => 'id', 1116 1128 'value' => $cursor->getID(), 1117 1129 'type' => 'int', 1118 1130 );
+10 -5
src/applications/repository/query/PhabricatorRepositoryQuery.php
··· 383 383 } 384 384 385 385 $id_column = array( 386 - 'name' => 'r.id', 386 + 'table' => 'r', 387 + 'column' => 'id', 387 388 'type' => 'int', 388 389 'value' => $cursor->getID(), 389 390 ); ··· 396 397 return null; 397 398 } 398 399 $columns[] = array( 399 - 'name' => 's.epoch', 400 + 'table' => 's', 401 + 'column' => 'epoch', 400 402 'type' => 'int', 401 403 'value' => $commit->getEpoch(), 402 404 ); ··· 404 406 break; 405 407 case self::ORDER_CALLSIGN: 406 408 $columns[] = array( 407 - 'name' => 'r.callsign', 409 + 'table' => 'r', 410 + 'column' => 'callsign', 408 411 'type' => 'string', 409 412 'value' => $cursor->getCallsign(), 410 413 'reverse' => true, ··· 412 415 break; 413 416 case self::ORDER_NAME: 414 417 $columns[] = array( 415 - 'name' => 'r.name', 418 + 'table' => 'r', 419 + 'column' => 'name', 416 420 'type' => 'string', 417 421 'value' => $cursor->getName(), 418 422 'reverse' => true, ··· 421 425 break; 422 426 case self::ORDER_SIZE: 423 427 $columns[] = array( 424 - 'name' => 's.size', 428 + 'table' => 's', 429 + 'column' => 'size', 425 430 'type' => 'int', 426 431 'value' => $cursor->getCommitCount(), 427 432 );
+24 -7
src/infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php
··· 181 181 * $conn_r, 182 182 * array( 183 183 * array( 184 - * 'name' => 'title', 184 + * 'table' => 't', 185 + * 'column' => 'title', 185 186 * 'type' => 'string', 186 187 * 'value' => $cursor->getTitle(), 187 188 * 'reverse' => true, 188 189 * ), 189 190 * array( 190 - * 'name' => 'id', 191 + * 'table' => 't', 192 + * 'column' => 'id', 191 193 * 'type' => 'int', 192 194 * 'value' => $cursor->getID(), 193 195 * ), ··· 212 214 PhutilTypeSpec::checkMap( 213 215 $column, 214 216 array( 215 - 'name' => 'string', 217 + 'table' => 'optional string', 218 + 'column' => 'string', 216 219 'value' => 'wild', 217 220 'type' => 'string', 218 221 'reverse' => 'optional bool', ··· 231 234 $accumulated = array(); 232 235 $last_key = last_key($columns); 233 236 foreach ($columns as $key => $column) { 234 - $name = $column['name']; 235 - 236 237 $type = $column['type']; 237 238 switch ($type) { 239 + case 'null': 240 + $value = qsprintf($conn, '%d', ($column['value'] ? 0 : 1)); 241 + break; 238 242 case 'int': 239 243 $value = qsprintf($conn, '%d', $column['value']); 240 244 break; ··· 252 256 $reverse = ($is_query_reversed xor $is_column_reversed); 253 257 254 258 $clause = $accumulated; 259 + 260 + $table_name = idx($column, 'table'); 261 + $column_name = $column['column']; 262 + if ($table_name !== null) { 263 + $field = qsprintf($conn, '%T.%T', $table_name, $column_name); 264 + } else { 265 + $field = qsprintf($conn, '%T', $column_name); 266 + } 267 + 268 + if ($type == 'null') { 269 + $field = qsprintf($conn, '(%Q IS NULL)', $field); 270 + } 271 + 255 272 $clause[] = qsprintf( 256 273 $conn, 257 274 '%Q %Q %Q', 258 - $name, 275 + $field, 259 276 $reverse ? '>' : '<', 260 277 $value); 261 278 $clauses[] = '('.implode(') AND (', $clause).')'; ··· 263 280 $accumulated[] = qsprintf( 264 281 $conn, 265 282 '%Q = %Q', 266 - $name, 283 + $field, 267 284 $value); 268 285 } 269 286