Details
-
Type:
Bug
-
Status: Closed
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: None
-
Fix Version/s: 5.2.2
-
Component/s: None
-
Labels:None
Description
To reproduce:
- Install Domain Manager
- Uninstall all registrar modules
- Visit Billing > Services
- See error
PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ') AND `client_groups`.`company_id`='1' GROUP BY `services`.`id`)) AS `t_64614...' at line 1
This is caused by the following code block in app/models/services.php:
// Filter on type
if (isset($filters['type']) && !is_null($filters['type'])) {
// Build a list of all the registrar modules
$registrar_modules = [];
$modules = $this->ModuleManager->getInstalled(['type' => 'registrar']);
foreach ($modules as $module) {
$registrar_modules[] = $module->id;
}
// Filter by domains
if ($filters['type'] == 'domains') {
$this->Record->where('packages.module_id', 'in', $registrar_modules);
}
// Filter by services
if ($filters['type'] == 'services') {
$this->Record->where('packages.module_id', 'not in', $registrar_modules);
}
}
Which causes an error when $registrar_modules is empty.
A potential solution is to update to
// Filter on type
if (isset($filters['type']) && !is_null($filters['type'])) {
// Build a list of all the registrar modules
$registrar_modules = [];
$modules = $this->ModuleManager->getInstalled(['type' => 'registrar']);
foreach ($modules as $module) {
$registrar_modules[] = $module->id;
}
// Filter by domains
if ($filters['type'] == 'domains') {
$this->Record->where('packages.module_id', 'in', (empty($registrar_modules) ? [null] : $registrar_modules));
}
// Filter by services
if ($filters['type'] == 'services' && !empty($registrar_modules)) {
$this->Record->where('packages.module_id', 'not in', $registrar_modules);
}
}