Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
a47b074
feat(audience): add Action Scheduler action and logs helpers
chickenn00dle May 26, 2026
4962066
fix(audience): drop invalid LogEntry::get_log_id call
chickenn00dle May 26, 2026
79dbfec
feat(audience): add ownership check for per-integration AS actions
chickenn00dle May 26, 2026
3fe07bd
feat(audience): add REST endpoint for integration action detail
chickenn00dle May 26, 2026
b20fedf
fix(audience): normalize last_attempt_gmt to ISO 8601 in detail endpoint
chickenn00dle May 26, 2026
ef9b5c7
feat(audience): add REST endpoint to run a pending integration action
chickenn00dle May 26, 2026
0508cb9
chore(audience): clarify run-action concurrency behavior and drop dea…
chickenn00dle May 26, 2026
e0fbb15
feat(audience): add log details modal component
chickenn00dle May 26, 2026
5617ffa
refactor(audience): extract shared integration-logs constants
chickenn00dle May 26, 2026
8b1c111
feat(audience): add View details and Run now row actions to logs
chickenn00dle May 26, 2026
be269bb
chore(audience): drop dead non-empty-items guard on run-now action
chickenn00dle May 26, 2026
ec2f644
feat(audience): handle in-progress action status in logs view
chickenn00dle May 26, 2026
ead8216
fix(audience): show pointer cursor on integration log row actions
chickenn00dle May 26, 2026
aca9c6d
feat(audience): harden Run now flow and refine integration logs UX
chickenn00dle May 26, 2026
6161580
fix(audience): replace running notice via removeNotice before result
chickenn00dle May 29, 2026
2714a32
feat(audience): surface contact email in integration logs
chickenn00dle May 29, 2026
6eb6c7d
fix(audience): label complete status as Complete not Success
chickenn00dle May 29, 2026
ca60d16
fix(audience): resolve log contact email from user_id
chickenn00dle May 29, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions includes/class-action-scheduler.php
Original file line number Diff line number Diff line change
Expand Up @@ -405,4 +405,66 @@ public static function get_hooks() {

return $hooks;
}

/**
* Fetch a single ActionScheduler action by ID.
*
* Returns null when AS resolves the ID to a NullAction (action does not exist).
*
* @param int $action_id The action ID.
*
* @return \ActionScheduler_Action|null
*/
public static function get_action( $action_id ): ?\ActionScheduler_Action {
if ( ! self::is_available() ) {
return null;
}
$action = \ActionScheduler_Store::instance()->fetch_action( (int) $action_id );
if ( ! $action || $action instanceof \ActionScheduler_NullAction ) {
return null;
}
return $action;
}

/**
* Fetch per-action log entries for a single ActionScheduler action.
*
* Each entry is normalized to:
* [ 'date_gmt' => string, 'message' => string ]
*
* NullLogEntry sentinels are filtered out. Entries are sorted ascending
* by date. ActionScheduler_LogEntry does not expose the log-row PK, so
* consumers use the array index as a stable key.
*
* @param int $action_id The action ID.
*
* @return array<int,array{date_gmt:string,message:string}>
*/
public static function get_action_logs( $action_id ): array {
if ( ! self::is_available() || ! class_exists( '\ActionScheduler_Logger' ) ) {
return [];
}
$entries = \ActionScheduler_Logger::instance()->get_logs( (int) $action_id );
if ( empty( $entries ) ) {
return [];
}
$normalized = [];
foreach ( $entries as $entry ) {
if ( $entry instanceof \ActionScheduler_NullLogEntry ) {
continue;
}
$date = $entry->get_date();
$normalized[] = [
'date_gmt' => $date ? $date->format( 'Y-m-d\TH:i:s' ) : '',
'message' => (string) $entry->get_message(),
];
}
usort(
$normalized,
static function ( $a, $b ) {
return strcmp( $a['date_gmt'], $b['date_gmt'] );
}
);
return $normalized;
}
}
24 changes: 24 additions & 0 deletions includes/reader-activation/class-integrations.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,30 @@ public static function get_all_action_groups() {
return \Newspack\Action_Scheduler::get_groups_by_prefix( \Newspack\Action_Scheduler::GROUP_PREFIX . 'integration-' );
}

/**
* Get the AS action for the given ID if it belongs to the given integration.
*
* Combines existence + group-ownership checks so callers can do both in a
* single DB read. Returns null for missing actions and for actions in other
* groups — both cases the REST endpoints translate to a generic 404 so
* other-group actions can't be probed.
*
* @param int $action_id The AS action ID.
* @param string $integration_id The integration identifier.
*
* @return \ActionScheduler_Action|null
*/
public static function get_integration_action( $action_id, $integration_id ) {
$action = \Newspack\Action_Scheduler::get_action( (int) $action_id );
if ( ! $action ) {
return null;
}
if ( $action->get_group() !== self::get_action_group( $integration_id ) ) {
return null;
}
return $action;
}

/**
* Get ActionScheduler actions for Newspack integrations.
*
Expand Down
Loading
Loading