Skip to content

feat(UserStatsJobs): wire UserStatsJob to send stats to PSS via API client#18

Open
Arsalanulhaq wants to merge 2 commits intoas/dev/NSW-876-user-event-listenerfrom
as/dev/NSW-878-wire-user-stats-api
Open

feat(UserStatsJobs): wire UserStatsJob to send stats to PSS via API client#18
Arsalanulhaq wants to merge 2 commits intoas/dev/NSW-876-user-event-listenerfrom
as/dev/NSW-878-wire-user-stats-api

Conversation

@Arsalanulhaq
Copy link
Copy Markdown
Contributor

@Arsalanulhaq Arsalanulhaq commented May 5, 2026

Summary

  • Replaces the log-only payload in UserStatsJob with an actual HTTP PUT call to the NextcloudPSS service using ionos-ncpss-addons-api-client
  • Introduces ApiStatsClientService (factory) and PssConfigService (config reader) following the same pattern as the mail app's IONOS integration
  • Brand, extRef, and PSS credentials are read from system config keys (ncw_tools.pss.*)
  • Log statement is kept alongside the API call for observability
  • Errors are caught and logged without retrying (PSS has server-side idempotency)

Test plan

1. Set system config keys (inside the container)

occ config:system:set ncw_tools.pss.base_url --value='https://productivityqa.icaas.server.lan:10443/nextcloud'
occ config:system:set ncw_tools.pss.brand --value='IONOS'
occ config:system:set ncw_tools.pss.ext_ref --value='<extRef>'
occ config:system:set ncw_tools.pss.username --value='<username>'
occ config:system:set ncw_tools.pss.password --value='<password>'

2. Temporary code change required for local testing (self-signed cert)

PSS uses a self-signed certificate locally. Guzzle will reject it by default, so these two temporary changes are needed — do not commit:

lib/Service/PssConfigService.php — add:

public function getAllowInsecure(): bool {
    return $this->config->getSystemValueBool('ncw_tools.pss.allow_insecure', false);
}

lib/Service/ApiStatsClientService.php — change newClient() to:

public function newClient(bool $allowInsecure = false): Client {
    return new Client(['verify' => !$allowInsecure]);
}

lib/BackgroundJob/UserStatsJob.php — change the newClient() call to:

$client = $this->apiClientService->newClient($this->configService->getAllowInsecure());

Then set the config flag:

occ config:system:set ncw_tools.pss.allow_insecure --value=true --type=boolean

3. Trigger the flow

NC_PASS='MyLongPass99@dev' occ user:add --password-from-env testuser_$(date +%s)

4. Run the queued job

# Find the job ID (possibly the last created job-id)
occ background-job:list --output=json | jq

# Execute it
occ background-job:execute --force-execute <id>

5. Verify

# Check log for payload + no errors
grep 'User stats payload\|failed to push\|UserStatsJob' /var/www/html/data/nextcloud.log | tail -5

# Verify PSS received the stats
curl -k -u '<username>:<password>' -X GET \
  'https://productivityqa.icaas.server.lan:10443/nextcloud/config/IONOS?extRef=<extRef>' \
  -H 'accept: application/json'

The response should contain a `currentUsers` value matching the count from the log payload.

@Arsalanulhaq Arsalanulhaq force-pushed the as/dev/NSW-878-wire-user-stats-api branch 2 times, most recently from a273b83 to 8810d6e Compare May 6, 2026 10:34
@Arsalanulhaq Arsalanulhaq requested a review from Copilot May 6, 2026 10:49
Copy link
Copy Markdown

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 updates NCW ToolsUserStatsJob to push user-count stats to NextcloudPSS via the ionos-ncpss-addons-api-client, introducing small service wrappers for client creation and PSS config access.

Changes:

  • Replaced log-only behavior in UserStatsJob with an API call (updateStats) to PSS while keeping payload logging.
  • Added PssConfigService (system-config reader) and ApiStatsClientService (API client factory).
  • Added the new API client dependency to Composer and updated unit tests accordingly.

Reviewed changes

Copilot reviewed 7 out of 9 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
lib/BackgroundJob/UserStatsJob.php Builds a PSS stats request and performs the updateStats API call with error logging.
lib/Service/PssConfigService.php Reads PSS-related system config values used by the job.
lib/Service/ApiStatsClientService.php Constructs the Guzzle client and Stats API wrapper from the generated client library.
lib/AppInfo/Application.php Adds explicit vendor/autoload.php loading so the generated client classes resolve.
tests/unit/BackgroundJob/UserStatsJobTest.php Updates/extends unit tests to verify the API call and error logging behavior.
composer.json Adds the ionos-ncpss-addons-api-client repository + requirement; adjusts post-update bin behavior.
composer.lock Locks new dependency set (including Guzzle + PSR packages and the IONOS client).
psalm.xml Adds constructor references for Psalm’s container reflection setup.
.gitignore Ignores a local directory related to the API client repo.

Comment thread lib/AppInfo/Application.php Outdated
Comment thread lib/Service/ApiStatsClientService.php Outdated
Comment thread lib/BackgroundJob/UserStatsJob.php Outdated
Comment thread lib/BackgroundJob/UserStatsJob.php
Comment thread lib/Service/PssConfigService.php
Comment thread composer.json
@Arsalanulhaq Arsalanulhaq force-pushed the as/dev/NSW-876-user-event-listener branch from b88779b to f08c24c Compare May 6, 2026 14:23
@Arsalanulhaq Arsalanulhaq force-pushed the as/dev/NSW-878-wire-user-stats-api branch from ebc180d to e3d658d Compare May 6, 2026 14:30
Replaces the log-only payload with an actual HTTP PUT call to the
NextcloudPSS service using the ionos-ncpss-addons-api-client. Follows
the same factory + config-service pattern as the mail app's IONOS
integration (ApiStatsClientService, PssConfigService). Brand, extRef,
and PSS credentials are read from system config. The log statement is
kept alongside the API call for observability. Errors are caught and
logged without retrying.
- Guard vendor/autoload.php require_once with file_exists()
- Add connect/request timeouts to Guzzle client (5s/10s)
- Move DateTime construction inside try/catch
- Short-circuit on empty brand/extRef/baseUrl with error log
- Log error on empty username/password in PssConfigService
- Add dist section to composer.json to avoid requiring git at install time
- Add test for missing required PSS config early-exit path
@Arsalanulhaq Arsalanulhaq force-pushed the as/dev/NSW-878-wire-user-stats-api branch from e3d658d to d9f0fbb Compare May 6, 2026 14:36
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