diff --git a/lib/DatabaseStatistics.php b/lib/DatabaseStatistics.php index 3a8b896f..10408406 100644 --- a/lib/DatabaseStatistics.php +++ b/lib/DatabaseStatistics.php @@ -97,30 +97,11 @@ protected function databaseSize(): string { } break; case 'pgsql': - $sql = "SELECT proname - FROM pg_proc - WHERE proname = 'pg_database_size'"; - $result = $this->connection->executeQuery($sql); - $row = $result->fetch(); + $database = $this->config->getSystemValueString('dbname'); + $sql = 'SELECT pg_database_size(:dbname) as size'; + $result = $this->connection->executeQuery($sql, ['dbname' => $database]); + $database_size = $result->fetchOne(); $result->closeCursor(); - if ($row['proname'] === 'pg_database_size') { - $database = $this->config->getSystemValue('dbname'); - if (strpos($database, '.') !== false) { - [$database, ] = explode('.', $database); - } - $sql = "SELECT oid - FROM pg_database - WHERE datname = '$database'"; - $result = $this->connection->executeQuery($sql); - $row = $result->fetch(); - $result->closeCursor(); - $oid = $row['oid']; - $sql = 'SELECT pg_database_size(' . $oid . ') as size'; - $result = $this->connection->executeQuery($sql); - $row = $result->fetch(); - $result->closeCursor(); - $database_size = $row['size']; - } break; case 'oci': $sql = 'SELECT SUM(bytes) as dbsize diff --git a/lib/ShareStatistics.php b/lib/ShareStatistics.php index 6ec599e6..423bba81 100644 --- a/lib/ShareStatistics.php +++ b/lib/ShareStatistics.php @@ -59,10 +59,14 @@ protected function countEntries(string $tableName): int { $query->select($query->func()->count('*', 'num_entries')) ->from($tableName); $result = $query->executeQuery(); - $row = $result->fetch(); + $row = $result->fetchOne(); $result->closeCursor(); - return (int)$row['num_entries']; + if ($row === false) { + return 0; + } + + return (int)$row; } /** @@ -72,7 +76,7 @@ protected function countEntries(string $tableName): int { */ protected function countShares(int $type, bool $noPassword = false): int { $query = $this->connection->getQueryBuilder(); - $query->selectAlias($query->createFunction('COUNT(*)'), 'num_entries') + $query->select($query->func()->count('*', 'num_entries')) ->from('share') ->where($query->expr()->eq('share_type', $query->createNamedParameter($type))); @@ -81,9 +85,13 @@ protected function countShares(int $type, bool $noPassword = false): int { } $result = $query->executeQuery(); - $row = $result->fetch(); + $row = $result->fetchOne(); $result->closeCursor(); - return (int)$row['num_entries']; + if ($row === false) { + return 0; + } + + return (int)$row; } } diff --git a/lib/StorageStatistics.php b/lib/StorageStatistics.php index 0e14a759..5f17743d 100644 --- a/lib/StorageStatistics.php +++ b/lib/StorageStatistics.php @@ -95,9 +95,14 @@ protected function countStorages(string $type): int { $query->andWhere($query->expr()->notLike('id', $query->createNamedParameter('local::%'))); } $result = $query->executeQuery(); - $row = $result->fetch(); + $row = $result->fetchOne(); $result->closeCursor(); - return (int)$row['num_entries']; + + if ($row === false) { + return 0; + } + + return (int)$row; } public function updateAppDataStorageStats(): void {