|
@@ -3227,6 +3227,52 @@ class FirewallMiddleware extends Middleware
|
3227
|
3227
|
}
|
3228
|
3228
|
}
|
3229
|
3229
|
|
|
3230
|
+// file: src/Tqdev/PhpCrudApi/Middleware/JoinLimitsMiddleware.php
|
|
3231
|
+
|
|
3232
|
+class JoinLimitsMiddleware extends Middleware
|
|
3233
|
+{
|
|
3234
|
+ private $reflection;
|
|
3235
|
+
|
|
3236
|
+ public function __construct(Router $router, Responder $responder, array $properties, ReflectionService $reflection)
|
|
3237
|
+ {
|
|
3238
|
+ parent::__construct($router, $responder, $properties);
|
|
3239
|
+ $this->reflection = $reflection;
|
|
3240
|
+ $this->utils = new RequestUtils($reflection);
|
|
3241
|
+ }
|
|
3242
|
+
|
|
3243
|
+ public function handle(Request $request): Response
|
|
3244
|
+ {
|
|
3245
|
+ $operation = $this->utils->getOperation($request);
|
|
3246
|
+ $params = $request->getParams();
|
|
3247
|
+ if (in_array($operation, ['read', 'list']) && isset($params['join'])) {
|
|
3248
|
+ $maxDepth = (int) $this->getProperty('depth', '3');
|
|
3249
|
+ $maxTables = (int) $this->getProperty('tables', '10');
|
|
3250
|
+ $maxRecords = (int) $this->getProperty('records', '1000');
|
|
3251
|
+ $tableCount = 0;
|
|
3252
|
+ $joinPaths = array();
|
|
3253
|
+ for ($i = 0; $i < count($params['join']); $i++) {
|
|
3254
|
+ $joinPath = array();
|
|
3255
|
+ $tables = explode(',', $params['join'][$i]);
|
|
3256
|
+ for ($depth = 0; $depth < min($maxDepth, count($tables)); $depth++) {
|
|
3257
|
+ array_push($joinPath, $table);
|
|
3258
|
+ $tableCount += 1;
|
|
3259
|
+ if ($tableCount == $maxTables) {
|
|
3260
|
+ break;
|
|
3261
|
+ }
|
|
3262
|
+ }
|
|
3263
|
+ array_push($joinPaths, $joinPath);
|
|
3264
|
+ if ($tableCount == $maxTables) {
|
|
3265
|
+ break;
|
|
3266
|
+ }
|
|
3267
|
+ }
|
|
3268
|
+ $params['join'] = $joinPaths;
|
|
3269
|
+ $request->setParams($params);
|
|
3270
|
+ VariableStore::set("joinLimits.maxRecords", $maxRecords);
|
|
3271
|
+ }
|
|
3272
|
+ return $this->next->handle($request);
|
|
3273
|
+ }
|
|
3274
|
+}
|
|
3275
|
+
|
3230
|
3276
|
// file: src/Tqdev/PhpCrudApi/Middleware/JwtAuthMiddleware.php
|
3231
|
3277
|
|
3232
|
3278
|
class JwtAuthMiddleware extends Middleware
|
|
@@ -5021,7 +5067,8 @@ class RelationJoiner
|
5021
|
5067
|
$conditions[] = new ColumnCondition($fk, 'in', $pkValueKeys);
|
5022
|
5068
|
}
|
5023
|
5069
|
$condition = OrCondition::fromArray($conditions);
|
5024
|
|
- foreach ($db->selectAll($t2, $columnNames, $condition, array(), 0, -1) as $record) {
|
|
5070
|
+ $limit = VariableStore::get("joinLimits.maxRecords") ?: -1;
|
|
5071
|
+ foreach ($db->selectAll($t2, $columnNames, $condition, array(), 0, $limit) as $record) {
|
5025
|
5072
|
$records[] = $record;
|
5026
|
5073
|
}
|
5027
|
5074
|
}
|
|
@@ -5067,7 +5114,8 @@ class RelationJoiner
|
5067
|
5114
|
$pkIds = implode(',', array_keys($pkValues));
|
5068
|
5115
|
$condition = new ColumnCondition($t3->getColumn($fk1Name), 'in', $pkIds);
|
5069
|
5116
|
|
5070
|
|
- $records = $db->selectAll($t3, $columnNames, $condition, array(), 0, -1);
|
|
5117
|
+ $limit = VariableStore::get("joinLimits.maxRecords") ?: -1;
|
|
5118
|
+ $records = $db->selectAll($t3, $columnNames, $condition, array(), 0, $limit);
|
5071
|
5119
|
foreach ($records as $record) {
|
5072
|
5120
|
$val1 = $record[$fk1Name];
|
5073
|
5121
|
$val2 = $record[$fk2Name];
|
|
@@ -5219,6 +5267,9 @@ class Api
|
5219
|
5267
|
case 'pageLimits':
|
5220
|
5268
|
new PageLimitsMiddleware($router, $responder, $properties, $reflection);
|
5221
|
5269
|
break;
|
|
5270
|
+ case 'joinLimits':
|
|
5271
|
+ new JoinLimitsMiddleware($router, $responder, $properties, $reflection);
|
|
5272
|
+ break;
|
5222
|
5273
|
case 'customization':
|
5223
|
5274
|
new CustomizationMiddleware($router, $responder, $properties, $reflection);
|
5224
|
5275
|
break;
|