Skip to content

Commit 66a0337

Browse files
committed
fix(form): SQL errors when counting available forms
Signed-off-by: Thierry Bugier <[email protected]>
1 parent 04e6df0 commit 66a0337

File tree

1 file changed

+20
-29
lines changed

1 file changed

+20
-29
lines changed

inc/form.class.php

Lines changed: 20 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1922,37 +1922,28 @@ public static function countAvailableForm() {
19221922
if ($DB->tableExists($formTable)
19231923
&& $DB->tableExists($formProfileTable)
19241924
&& isset($_SESSION['glpiactiveprofile']['id'])) {
1925-
$entitiesRestrict = (new DBUtils())->getEntitiesRestrictCriteria(
1926-
$formTable, '', '', true, false
1927-
);
1928-
$result = $DB->request([
1929-
'SELECT' => ['COUNT' => ["$formTable.id"]],
1930-
'FROM' => $formTable,
1931-
'WHERE' => [
1932-
"$formTable.is_active" => '1',
1933-
"$formTable.is_deleted" => '0',
1934-
$entitiesRestrict,
1935-
[
1936-
'OR' => [
1937-
"$formTable.language" => ['0', '', null],
1938-
"$formTable.language" => $_SESSION['glpilanguage']
1939-
]
1940-
],
1941-
[
1942-
'OR' => [
1943-
"$formTable.access_rights" => ['<>', PluginFormcreatorForm::ACCESS_RESTRICTED],
1944-
"$formTable.'id'" => new QuerySubQuery([
1945-
'SELECT' => $formFk,
1946-
'FROM' => $formProfileTable,
1947-
'WHERE' => [
1948-
'profiles_id' => $_SESSION['glpiactiveprofile']['id']
1949-
]
1950-
]),
1925+
$nb = (new DBUtils())->countElementsInTableForMyEntities(
1926+
$formTable,
1927+
[
1928+
'WHERE' => [
1929+
"$formTable.is_active" => '1',
1930+
"$formTable.is_deleted" => '0',
1931+
"$formTable.language" => [$_SESSION['glpilanguage'], '0', '', null],
1932+
[
1933+
'OR' => [
1934+
"$formTable.access_rights" => ['<>', PluginFormcreatorForm::ACCESS_RESTRICTED],
1935+
"$formTable.id" => new QuerySubQuery([
1936+
'SELECT' => $formFk,
1937+
'FROM' => $formProfileTable,
1938+
'WHERE' => [
1939+
'profiles_id' => $_SESSION['glpiactiveprofile']['id']
1940+
]
1941+
]),
1942+
],
19511943
],
19521944
],
1953-
],
1954-
]);
1955-
list($nb) = $result->next();
1945+
]
1946+
);
19561947
}
19571948

19581949
return $nb;

0 commit comments

Comments
 (0)