Skip to content

Remove all PUE related CRONs on Site Kit reset and before Site Kit is setup #11805

@zutigrm

Description

@zutigrm

Feature Description

Currently we are not unscheduling/removing Email Reporting CRON's when FF is disabled. Also it seems Email Reporting CRON's are added even before SIte Kit is setup


Do not alter or remove anything below. The following sections will be managed by moderators only.

Acceptance criteria

  • When proactiveUserEngagement feature flag is disabled all Email Reporting CRON's are removed
  • When Site Kit is not set up, no Email Reporting CRON should be scheduled - Email reports should only be scheduled, at minimum, once Site Kit is set up.
  • When Site Kit is reset all Email Reporting CRONs are removed

Implementation Brief

  • Perform cleanup when the proactiveUserEngagement feature flag is disabled: during plugin bootstrap where proactiveUserEngagement is checked (in Plugin::register where Feature_Flags::enabled( 'proactiveUserEngagement' ) gates Email Reporting), add a branch for the disabled path that instantiates Email_Reporting_Scheduler (with Frequency_Planner) and calls unschedule_all() to clear googlesitekit_email_reporting_* cron hooks. This ensures any previously queued events are removed because the feature is no longer registered.
  • Gate scheduling on setup completion: inject Authentication into the Email_Reporting class (pass it from Plugin::register alongside existing dependencies) and guard the scheduling logic in Email_Reporting::register() with $this->authentication->is_setup_completed(). If setup is incomplete, short-circuit before scheduling, and proactively call $this->scheduler->unschedule_all() to clean up any existing events.
  • Preserve enable/disable toggle behavior: keep the existing is_email_reporting_enabled() checks, but require both "email reporting enabled" and "setup complete" before scheduling. If either is false (flag off, toggle off, or setup incomplete), ensure unschedule_all() runs so no cron remains registered.

Test Coverage

  • Extend integration tests in tests/phpunit/integration/Core/Email_Reporting to verify:
    • When proactiveUserEngagement is disabled, any pre-scheduled email reporting cron events are removed via scheduler cleanup;
    • When Authentication::is_setup_completed() returns false, no new email reporting events are scheduled and existing ones are cleared.

QA Brief

  • Verify that before setting up the Site Kit there are no email_reporting_* related CRONS (If previously there are some stale CRONs, remove them and reload the page, verify they are not being added)

  • Setup Site Kit
  • Verify that email reporting CRONs are added - as Email reporting setting is enabled by default

  • Go to Settings > Admin Settings and disable Email Reporting
  • Verify that Email Reporting CRONs have been removed

  • Go to Settings > Admin Settings and reset Site Kit
  • Verify that Email Reporting CRONs are removed

Changelog entry

  • Update the uninstall script to unregister all email reporting events when the plugin is unininstalled.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P0High priorityPHPTeam SIssues for Squad 1Type: EnhancementImprovement of an existing feature

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions