| @@ -111,8 +111,43 @@ | ||
| 111 | 111 | return $this->execute($sql, [$now, absint($minAgeMinutes), $now, absint($maxAgeHours), absint($limit)])->getResult(); |
| 112 | 112 | } |
| 113 | 113 | |
| 114 | 114 | /** |
| 115 | + * Newest still-queued workflow row of an entry, for callers that hold the | |
| 116 | + * entry id but not the queue log id (the payment endpoints). | |
| 117 | + * | |
| 118 | + * @return object|null row with id and response_obj | |
| 119 | + */ | |
| 120 | + public function latestQueuedWorkflowByEntry($entryID) | |
| 121 | + { | |
| 122 | + $sql = "SELECT ld.id, ld.response_obj | |
| 123 | + FROM `{$this->app_db->prefix}bitforms_form_log_details` ld | |
| 124 | + JOIN `{$this->app_db->prefix}bitforms_form_entry_log` el ON el.id = ld.log_id | |
| 125 | + WHERE el.form_entry_id = %d | |
| 126 | + AND ld.integration_id = 0 | |
| 127 | + AND ld.response_type = 'queued' | |
| 128 | + ORDER BY ld.id DESC | |
| 129 | + LIMIT 1"; | |
| 130 | + $rows = $this->execute($sql, [absint($entryID)])->getResult(); | |
| 131 | + | |
| 132 | + return is_wp_error($rows) || empty($rows) ? null : $rows[0]; | |
| 133 | + } | |
| 134 | + | |
| 135 | + /** | |
| 136 | + * Patch a queued row's payload. The 'queued' condition keeps it off rows a | |
| 137 | + * trigger or the reclaim cron has already claimed. | |
| 138 | + * | |
| 139 | + * @return mixed rows affected, or WP_Error | |
| 140 | + */ | |
| 141 | + public function updateQueuedWorkflowResponse($queueLogId, array $responseObj) | |
| 142 | + { | |
| 143 | + return $this->update( | |
| 144 | + ['response_obj' => wp_json_encode($responseObj)], | |
| 145 | + ['id' => absint($queueLogId), 'response_type' => 'queued'] | |
| 146 | + ); | |
| 147 | + } | |
| 148 | + | |
| 149 | + /** | |
| 115 | 150 | * Latest execution per integration of a form: last run time plus the |
| 116 | 151 | * response_type of that newest log row. integration_id 0 (workflow queue) excluded. |
| 117 | 152 | */ |
| 118 | 153 | public function getIntegrationLastRuns($formId) |