Skip to content

Commit 570f64c

Browse files
rldhontgithub-actions[bot]
authored andcommitted
Fix the way to check if the lizmap_search is available
Instead of doing a `SELECT * FROM lizmap_search LIMIT 0;` to check if `lizmap_search` table / view / materialized view exists in the `search_path`
1 parent 15e8a89 commit 570f64c

File tree

1 file changed

+25
-10
lines changed

1 file changed

+25
-10
lines changed

lizmap/modules/lizmap/classes/lizmapFtsSearch.listener.php

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,20 +44,35 @@ protected function checkLizmapFts()
4444
return false;
4545
}
4646

47-
// Use a transaction to avoid: "ERROR: current transaction is aborted"
48-
// https://github.com/3liz/lizmap-web-client/issues/2008
49-
$cnx->beginTransaction();
47+
// Check if lizmap_search table / view / materialized view exists
48+
// in the search_path
49+
$sql = "
50+
SELECT EXISTS (
51+
SELECT FROM
52+
pg_catalog.pg_class c
53+
JOIN
54+
pg_catalog.pg_namespace n ON
55+
n.oid = c.relnamespace
56+
WHERE
57+
n.nspname = ANY(current_schemas(FALSE)) AND
58+
-- current_schemas(FALSE) returns the list of schemas in the search_path
59+
c.relname = 'lizmap_search' AND
60+
c.relkind = ANY(ARRAY['r', 'v', 'm', 'f', 'p'])
61+
-- r = ordinary table, v = view, m = materialized view, f = foreign table, p = partitioned
62+
) AS lizmap_search_exists;
63+
";
5064

51-
// Try to get data from lizmap_fts table / view / materialized view
5265
try {
53-
$cnx->query('SELECT * FROM lizmap_search LIMIT 0;');
54-
$cnx->commit();
55-
$ok = true;
66+
$res = $cnx->query($sql);
67+
foreach ($res as $r) {
68+
return $r->lizmap_search_exists;
69+
}
5670
} catch (Exception $e) {
57-
$cnx->rollback();
58-
$ok = false;
71+
jLog::logEx($e, 'error');
72+
73+
return false;
5974
}
6075

61-
return $ok;
76+
return false;
6277
}
6378
}

0 commit comments

Comments
 (0)