Skip to content

Commit 73ad766

Browse files
committed
Qualify link list query aliases
1 parent ecd7412 commit 73ad766

File tree

1 file changed

+21
-16
lines changed

1 file changed

+21
-16
lines changed

liens-morts-detector-jlg/includes/class-blc-links-list-table.php

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,17 +1103,17 @@ public function prepare_items($data = null, $total_items_override = null) {
11031103
$params = [];
11041104

11051105
if (count($type_filter) === 1) {
1106-
$where[] = 'type = %s';
1106+
$where[] = "{$links_alias}.type = %s";
11071107
$params[] = $type_filter[0];
11081108
} else {
11091109
$type_placeholders = implode(',', array_fill(0, count($type_filter), '%s'));
1110-
$where[] = "type IN ($type_placeholders)";
1110+
$where[] = "{$links_alias}.type IN ($type_placeholders)";
11111111
$params = array_merge($params, $type_filter);
11121112
}
11131113

11141114
if ($search_term !== '') {
11151115
$like = '%' . $wpdb->esc_like($search_term) . '%';
1116-
$where[] = "(url LIKE %s OR anchor LIKE %s OR post_title LIKE %s)";
1116+
$where[] = "({$links_alias}.url LIKE %s OR {$links_alias}.anchor LIKE %s OR {$links_alias}.post_title LIKE %s)";
11171117
$params = array_merge($params, [$like, $like, $like]);
11181118
}
11191119

@@ -1123,28 +1123,28 @@ public function prepare_items($data = null, $total_items_override = null) {
11231123
}
11241124

11251125
if ($is_ignored_view) {
1126-
$where[] = 'ignored_at IS NOT NULL';
1126+
$where[] = "{$links_alias}.ignored_at IS NOT NULL";
11271127
} else {
1128-
$where[] = 'ignored_at IS NULL';
1128+
$where[] = "{$links_alias}.ignored_at IS NULL";
11291129
}
11301130

11311131
if ($current_view === 'internal') {
1132-
$where[] = "(is_internal = 1 OR (is_internal IS NULL AND {$internal_sql}))";
1132+
$where[] = "({$links_alias}.is_internal = 1 OR ({$links_alias}.is_internal IS NULL AND {$internal_sql}))";
11331133
$params = array_merge($params, $internal_params);
11341134
} elseif ($current_view === 'external') {
1135-
$external_clause = "(is_internal = 0 OR (is_internal IS NULL AND ({$external_sql} OR url IS NULL OR url = '')))";
1135+
$external_clause = "({$links_alias}.is_internal = 0 OR ({$links_alias}.is_internal IS NULL AND ({$external_sql} OR {$links_alias}.url IS NULL OR {$links_alias}.url = '')))";
11361136
$where[] = $external_clause;
11371137
$params = array_merge($params, $external_params);
11381138
}
11391139

1140-
$needs_recheck_clause = "(last_checked_at IS NULL OR last_checked_at = %s OR last_checked_at <= %s)";
1140+
$needs_recheck_clause = "({$links_alias}.last_checked_at IS NULL OR {$links_alias}.last_checked_at = %s OR {$links_alias}.last_checked_at <= %s)";
11411141

11421142
if ($current_view === 'status_404_410') {
1143-
$where[] = 'http_status IN (404, 410)';
1143+
$where[] = "{$links_alias}.http_status IN (404, 410)";
11441144
} elseif ($current_view === 'status_5xx') {
1145-
$where[] = '(http_status BETWEEN 500 AND 599)';
1145+
$where[] = "({$links_alias}.http_status BETWEEN 500 AND 599)";
11461146
} elseif ($current_view === 'status_redirects') {
1147-
$where[] = '(http_status BETWEEN 300 AND 399)';
1147+
$where[] = "({$links_alias}.http_status BETWEEN 300 AND 399)";
11481148
} elseif ($current_view === 'needs_recheck') {
11491149
$where[] = $needs_recheck_clause;
11501150
$params = array_merge($params, [$this->get_unchecked_sentinel_value(), $this->get_recheck_threshold_gmt()]);
@@ -1171,13 +1171,16 @@ public function prepare_items($data = null, $total_items_override = null) {
11711171
}
11721172

11731173
if ($db_column !== '') {
1174+
if (strpos($db_column, '.') === false) {
1175+
$db_column = "{$links_alias}.{$db_column}";
1176+
}
11741177
$whitelisted_columns[$column_key] = $db_column;
11751178
}
11761179
}
11771180

1178-
$whitelisted_columns['id'] = 'id';
1181+
$whitelisted_columns['id'] = "{$links_alias}.id";
11791182
if ($is_ignored_view) {
1180-
$whitelisted_columns['ignored_at'] = 'ignored_at';
1183+
$whitelisted_columns['ignored_at'] = "{$links_alias}.ignored_at";
11811184
}
11821185

11831186
$sort_request = $this->get_current_sort_request();
@@ -1188,13 +1191,15 @@ public function prepare_items($data = null, $total_items_override = null) {
11881191
$primary_order_column = $whitelisted_columns[$requested_orderby];
11891192
$order_clauses = [sprintf('%s %s', $primary_order_column, $order_direction)];
11901193

1191-
if ($primary_order_column !== 'id') {
1192-
$order_clauses[] = 'id DESC';
1194+
if ($primary_order_column !== "{$links_alias}.id") {
1195+
$order_clauses[] = "{$links_alias}.id DESC";
11931196
}
11941197

11951198
$order_by = implode(', ', $order_clauses);
11961199
} else {
1197-
$fallback_order = $is_ignored_view ? ['ignored_at DESC', 'id DESC'] : ['id DESC'];
1200+
$fallback_order = $is_ignored_view
1201+
? ["{$links_alias}.ignored_at DESC", "{$links_alias}.id DESC"]
1202+
: ["{$links_alias}.id DESC"];
11981203
$order_by = implode(', ', $fallback_order);
11991204
}
12001205

0 commit comments

Comments
 (0)