Issue 4610: The query is simplified and shouldn't fail again

This commit is contained in:
Michael 2018-03-17 07:50:49 +00:00
parent c7dc3f94c9
commit 8053172398
1 changed files with 46 additions and 49 deletions

View File

@ -37,7 +37,10 @@ class GContact
*/
public static function searchByName($search, $mode = '')
{
if ($search) {
if (empty($search)) {
return [];
}
// check supported networks
if (Config::get('system', 'diaspora_enabled')) {
$diaspora = NETWORK_DIASPORA;
@ -60,33 +63,27 @@ class GContact
$search .= "%";
$results = q(
"SELECT `contact`.`id` AS `cid`, `gcontact`.`url`, `gcontact`.`name`, `gcontact`.`nick`, `gcontact`.`photo`,
`gcontact`.`network`, `gcontact`.`keywords`, `gcontact`.`addr`, `gcontact`.`community`
FROM `gcontact`
LEFT JOIN `contact` ON `contact`.`nurl` = `gcontact`.`nurl`
AND `contact`.`uid` = %d AND NOT `contact`.`blocked`
AND NOT `contact`.`pending` AND `contact`.`rel` IN ('%s', '%s')
WHERE (`contact`.`id` > 0 OR (NOT `gcontact`.`hide` AND `gcontact`.`network` IN ('%s', '%s', '%s') AND
((`gcontact`.`last_contact` >= `gcontact`.`last_failure`) OR
(`gcontact`.`updated` >= `gcontact`.`last_failure`)))) AND
(`gcontact`.`addr` LIKE '%s' OR `gcontact`.`name` LIKE '%s' OR `gcontact`.`nick` LIKE '%s') $extra_sql
GROUP BY `gcontact`.`nurl`
ORDER BY `gcontact`.`nurl` DESC
LIMIT 1000",
intval(local_user()),
dbesc(CONTACT_IS_SHARING),
dbesc(CONTACT_IS_FRIEND),
dbesc(NETWORK_DFRN),
dbesc($ostatus),
dbesc($diaspora),
dbesc(escape_tags($search)),
dbesc(escape_tags($search)),
dbesc(escape_tags($search))
$results = dba::p("SELECT `nurl` FROM `gcontact`
WHERE NOT `hide` AND `network` IN (?, ?, ?) AND
((`last_contact` >= `last_failure`) OR (`updated` >= `last_failure`)) AND
(`addr` LIKE ? OR `name` LIKE ? OR `nick` LIKE ?) $extra_sql
GROUP BY `nurl` ORDER BY `nurl` DESC LIMIT 1000",
NETWORK_DFRN, $ostatus, $diaspora, $search, $search, $search
);
return $results;
$gcontacts = [];
while ($result = dba::fetch($results)) {
$urlparts = parse_url($result["nurl"]);
// Ignore results that look strange.
// For historic reasons the gcontact table does contain some garbage.
if (!empty($urlparts['query']) || !empty($urlparts['fragment'])) {
continue;
}
$gcontacts[] = Contact::getDetailsByURL($result["nurl"], local_user());
}
return $gcontacts;
}
/**