db; $sql = 'SELECT * FROM pg_catalog.pg_tables where tableowner=:tableowner'; $res = $this->fetchAssoc($sql, [':tableowner' => $db['user']]); if ($res == null) { return false; } $tables = [ $this->pdo->prefix() . 'category' => false, $this->pdo->prefix() . 'feed' => false, $this->pdo->prefix() . 'entry' => false, $this->pdo->prefix() . 'entrytmp' => false, $this->pdo->prefix() . 'tag' => false, $this->pdo->prefix() . 'entrytag' => false, ]; foreach ($res as $value) { $tables[array_pop($value)] = true; } return count(array_keys($tables, true, true)) === count($tables); } /** @return array */ #[\Override] public function getSchema(string $table): array { $sql = <<<'SQL' SELECT column_name AS field, data_type AS type, column_default AS default, is_nullable AS null FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = :table_name SQL; $res = $this->fetchAssoc($sql, [':table_name' => $this->pdo->prefix() . $table]); return $res == null ? [] : $this->listDaoToSchema($res); } /** * @param array $dao * @return array{'name':string,'type':string,'notnull':bool,'default':mixed} */ #[\Override] public function daoToSchema(array $dao): array { return [ 'name' => (string)($dao['field']), 'type' => strtolower((string)($dao['type'])), 'notnull' => (bool)$dao['null'], 'default' => $dao['default'], ]; } #[\Override] public function size(bool $all = false): int { if ($all) { $db = FreshRSS_Context::systemConf()->db; $res = $this->fetchColumn('SELECT pg_database_size(:base)', 0, [':base' => $db['base']]); } else { $sql = <<pdo->prefix()}category`') + pg_total_relation_size('`{$this->pdo->prefix()}feed`') + pg_total_relation_size('`{$this->pdo->prefix()}entry`') + pg_total_relation_size('`{$this->pdo->prefix()}entrytmp`') + pg_total_relation_size('`{$this->pdo->prefix()}tag`') + pg_total_relation_size('`{$this->pdo->prefix()}entrytag`') SQL; $res = $this->fetchColumn($sql, 0); } return (int)($res[0] ?? -1); } #[\Override] public function optimize(): bool { $ok = true; $tables = ['category', 'feed', 'entry', 'entrytmp', 'tag', 'entrytag']; foreach ($tables as $table) { $sql = 'VACUUM `_' . $table . '`'; if ($this->pdo->exec($sql) === false) { $ok = false; $info = $this->pdo->errorInfo(); Minz_Log::warning(__METHOD__ . ' error: ' . $sql . ' : ' . json_encode($info)); } } return $ok; } }