Skip to content

Check DB connectivity in occ status#199

Open
matsaur wants to merge 12 commits intoionos-devfrom
ms/dev/command_status_db_connection
Open

Check DB connectivity in occ status#199
matsaur wants to merge 12 commits intoionos-devfrom
ms/dev/command_status_db_connection

Conversation

@matsaur
Copy link

@matsaur matsaur commented Jan 26, 2026

To differentiate between non-existant database and connection errors, occ status will fail with a new error code

Add test coverage for the core status command including:
- Status output with installed/not installed state
- Maintenance mode detection and output
- Exit code functionality for normal and maintenance modes
- JSON output format verification

These tests provide a foundation for proper testing of the
OCC status command functionality.

Signed-off-by: Matthias Sauer <sauerm@strato.de>
Enhance the OCC status command to differentiate between database
connection states and provide proper error handling:

- Add database connection testing for installed instances
- Introduce new exit code 3 for database connection failures
- Add database status and error message to JSON output
- Include friendly error messages for different failure states
- Update tests to cover database connection scenarios

This change allows monitoring tools to distinguish between:
- Exit code 0: Normal operation
- Exit code 1: Maintenance mode
- Exit code 2: Upgrade needed
- Exit code 3: Database connection failed

Co-authored-by: GitHub Copilot
Signed-off-by: Matthias Sauer <sauerm@strato.de>
@matsaur matsaur requested a review from Copilot January 27, 2026 09:37
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR enhances the occ status command to include database connectivity checks, allowing it to differentiate between non-existent databases and connection errors through a new exit code (3) when using the --exit-code flag.

Changes:

  • Added database connectivity testing using SELECT 1 query when Nextcloud is installed
  • Introduced new exit code 3 for database connection failures in exit-code mode
  • Added user-friendly status messages for not installed, maintenance mode, and database connection failure states

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.

File Description
core/Command/Status.php Implements database connectivity check, adds new exit code 3 for connection failures, and includes friendly status messages in output
tests/Core/Command/StatusTest.php Comprehensive test suite covering database connection scenarios, exit codes, and output formatting

try {
$this->connection->executeQuery('SELECT 1');
$databaseStatus = 'connected';
} catch (\Exception $e) {
Copy link

Copilot AI Jan 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Catching the generic \Exception is too broad. Consider catching more specific database-related exceptions (e.g., \Doctrine\DBAL\Exception) to avoid masking unexpected errors.

Suggested change
} catch (\Exception $e) {
} catch (\Doctrine\DBAL\Exception $e) {

Copilot uses AI. Check for mistakes.
Copy link

Copilot AI commented Jan 27, 2026

@matsaur I've opened a new pull request, #202, to work on those changes. Once the pull request is ready, I'll request review from you.

Copy link

Copilot AI commented Jan 27, 2026

@matsaur I've opened a new pull request, #203, to work on those changes. Once the pull request is ready, I'll request review from you.

Copy link

Copilot AI commented Jan 27, 2026

@matsaur I've opened a new pull request, #204, to work on those changes. Once the pull request is ready, I'll request review from you.

matsaur and others added 7 commits January 27, 2026 10:41
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Matthias Sauer <151215545+matsaur@users.noreply.github.com>
Co-authored-by: matsaur <151215545+matsaur@users.noreply.github.com>
Co-authored-by: matsaur <151215545+matsaur@users.noreply.github.com>
Co-authored-by: matsaur <151215545+matsaur@users.noreply.github.com>
Remove trailing whitespace from Status.php blank line
…other-one

Remove trailing whitespace from Status.php
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants