Skip to content

feat(event-module): implement Event_Module::boot()#105

Merged
MathieuLamiot merged 1 commit into
developfrom
feat/event-module-95
May 19, 2026
Merged

feat(event-module): implement Event_Module::boot()#105
MathieuLamiot merged 1 commit into
developfrom
feat/event-module-95

Conversation

@MathieuLamiot

Copy link
Copy Markdown
Owner

Description

Moves event tracking initialisation, the public extensibility API call, and the `sybgo/track-events` Ability registration out of `Sybgo::init_event_tracking()` and `init_abilities()` into `Event_Module::boot()`, making the event-domain wiring independently testable as a named method.

Closes #95

Type of change

Detailed scenario

What was tested

Behaviour is identical to develop — the same hooks, API, and ability are registered; only the location of that wiring changed. Manual verification on a local wp-env install:

  1. Activated the plugin — no fatal errors, all admin pages loaded normally.
  2. Ran wp cron event list | grep sybgo — all four cron events present and scheduled as before.
  3. Ran wp cron event run sybgo_freeze_weekly_report — weekly report frozen successfully; event tracking continued writing rows to wp_sybgo_events before and after the freeze.
  4. Navigated to WP Admin → Dashboard — widget showed current-week event counts, confirming Event_Tracker is still active.

How to test

  1. Check out feat/event-module-95 and run composer dump-autoload inside wp-plugin/.
  2. Boot wp-env: cd tests/e2e && npx wp-env start.
  3. Run unit tests: cd wp-plugin && vendor/bin/phpunit --testsuite=Unit — 4 new EventModuleTest tests pass; 5 pre-existing DashboardWidgetTest errors (unrelated, present on develop too).
  4. Publish a post via WP Admin or wp post create --post_title="Test" --post_status=publish.
  5. Verify the event was tracked: wp db query "SELECT event_type FROM wp_sybgo_events ORDER BY id DESC LIMIT 1" — should show post_published.
  6. Run wp cron event run sybgo_freeze_weekly_report and confirm the report freezes without PHP errors in the debug log.

Affected Features & Quality Assurance Scope

Event tracking, the public extensibility API (sybgo_init_api), and the sybgo/track-events Ability are affected — behaviour unchanged but wired from a new location. All other plugin features are untouched.

Technical description

Event_Module::boot() now:

  1. Calls Factory::create_event_repository() and create_aggregated_event_repository(), constructs Event_Tracker, calls init() on it, and stores it via Factory::set_event_tracker().
  2. Calls sybgo_init_api($event_repo) to expose the public extension API.
  3. Schedules a closure on add_action('init', …, 5) that calls Ability_Manager::register('sybgo/track-events', …) with the translated label and description. Priority 5 ensures registration runs before Ability_Manager::init(), which is now deferred to add_action('init', …, 20) inside Sybgo::init().

The init action deferral preserves the fix for the WP 6.7+ textdomain early-loading bug: calling __() during plugins_loaded before the text domain is loaded triggers _doing_it_wrong()trigger_error() → captured by Error_Tracker, polluting aggregated event counts.

Sybgo::init_event_tracking() is deleted (dead code after extraction). init_abilities() now only handles sybgo/generate-summary, which will move to AI_Module in #98.

See wp-plugin/docs/development.md — Feature Module Architecture section.

New dependencies

None.

Risks

None identified. The ability registration timing (priority 5 → priority 20 on init) is the only subtle change; it preserves the existing WP7 deferral fix and is covered by EventModuleTest::test_boot_registers_track_events_on_init_hook_priority_5.

Mandatory Checklist

Code validation

  • I validated all the Acceptance Criteria. If possible, provide screenshots or videos.
  • I triggered all changed lines of code at least once without new errors/warnings/notices.
  • I implemented built-in tests to cover the new/changed code.

Code style

  • I wrote a self-explanatory code about what it does.
  • I protected entry points against unexpected inputs.
  • I did not introduce unnecessary complexity.
  • Output messages (errors, notices, logs) are explicit enough for users to understand the issue and are actionable.

Unticked items justification

None.

Additional Checks

  • In the case of complex code, I wrote comments to explain it.
  • When possible, I prepared ways to observe the implemented system (logs, data, etc.)
  • I added error handling logic when using functions that could throw errors (HTTP/API request, filesystem, etc.)

Base automatically changed from feat/modules-scaffold-94 to develop May 19, 2026 10:53
…API, ability (#95)

Moves event tracking init, sybgo_init_api(), and sybgo/track-events ability
registration from Sybgo::init_event_tracking() and init_abilities() into
Event_Module::boot(). Ability registration is deferred to the 'init' hook at
priority 5; Ability_Manager::init() is scheduled at priority 20 so it captures
all module-registered abilities. Adds EventModuleTest covering tracker storage,
API side-effect, and deferred ability registration.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@MathieuLamiot MathieuLamiot force-pushed the feat/event-module-95 branch from 2be7ce4 to 4cf8474 Compare May 19, 2026 12:08
@MathieuLamiot MathieuLamiot merged commit 063907f into develop May 19, 2026
15 checks passed
@MathieuLamiot MathieuLamiot deleted the feat/event-module-95 branch May 19, 2026 12:18
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.

Implement Event_Module: event tracking, API init, track-events ability

1 participant