Plugin Directory


Ignore:
Timestamp:
11/03/2026 11:52:29 PM (15 hours ago)
Author:
meumouse
Message:

Release 2.7.0

File:
1 edited

Legend:

Unmodified
Added
Removed
  • joinotify/trunk/admin/src/Core/Message_History.php

    r3771693 r3782814  
    245245     * Record a dispatched message.
    246246     *
    247      * @since 2.0.0
    248      * @version 2.4.1
     247     * The history is always on: it is what the retry queue, the delivery
     248     * webhook and the resend action all read back. A site that must not keep
     249     * a given message can still drop it through the `Should_Record` filter.
     250     *
     251     * A `resent_from` key (set through the dispatch context by a resend from
     252     * the history screen) is kept in the row's `meta`, and the row it points
     253     * at is marked as resent.
     254     *
     255     * @since 2.0.0
     256     * @version 2.7.0
    249257     * @param array<string,mixed> $entry Message fields. Recognized keys:
    250258     *        sender, receiver, message_type, media_type, content, media_url,
    251      *        meta, status, response_code, error, attempts, source, workflow_id.
     259     *        meta, status, response_code, error, attempts, source, workflow_id,
     260     *        resent_from.
    252261     * @return int|false Inserted row ID, or false when skipped/failed.
    253262     */
    254263    public static function record( $entry ) {
    255         if ( Admin::get_setting('enable_message_history') !== 'yes' ) {
    256             return false;
    257         }
    258 
    259264        if ( ! is_array( $entry ) ) {
    260265            return false;
    … …  
    285290        $message_type = isset( $entry['message_type'] ) ? sanitize_key( $entry['message_type'] ) : 'text';
    286291        $status = isset( $entry['status'] ) ? sanitize_key( $entry['status'] ) : 'failed';
     292        $resent_from = isset( $entry['resent_from'] ) ? absint( $entry['resent_from'] ) : 0;
     293
     294        if ( $resent_from > 0 ) {
     295            $entry['meta'] = array_merge( is_array( $entry['meta'] ?? null ) ? $entry['meta'] : array(), array(
     296                'resent_from' => $resent_from,
     297            ) );
     298        }
    287299
    288300        $data = array(
    … …  
    318330        $id = (int) $wpdb->insert_id;
    319331
     332        if ( $resent_from > 0 ) {
     333            self::mark_resent( $resent_from, $id );
     334        }
     335
    320336        /**
    321337         * Fires after a message history record is written.
    … …  
    800816
    801817    /**
     818     * Note on a row that it was sent again, and as which row.
     819     *
     820     * The original is left as it was — still `failed` or `cancelled`, which is
     821     * what happened to that dispatch — but it stops offering a resend, so one
     822     * failure cannot be sent twice by accident. The new row offers its own
     823     * when it fails too.
     824     *
     825     * @since 2.7.0
     826     * @param int $id Row that was resent.
     827     * @param int $resent_as Row recorded by the resend.
     828     * @return bool True when the row was updated.
     829     */
     830    public static function mark_resent( $id, $resent_as ) {
     831        $id = absint( $id );
     832        $resent_as = absint( $resent_as );
     833
     834        if ( ! $id || ! $resent_as ) {
     835            return false;
     836        }
     837
     838        global $wpdb;
     839
     840        $table = self::get_table_name();
     841
     842        // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- $table is built from $wpdb->prefix and a class constant; the ID is bound as %d.
     843        $meta = $wpdb->get_var( $wpdb->prepare( "SELECT meta FROM {$table} WHERE id = %d", $id ) );
     844
     845        if ( null === $meta ) {
     846            return false;
     847        }
     848
     849        $stored = self::decode_meta( $meta );
     850        $stored['resent_as'] = $resent_as;
     851        $stored['resent_at'] = current_time( 'mysql', true );
     852
     853        $updated = $wpdb->update( $table, array( 'meta' => self::encode_meta( $stored ) ), array( 'id' => $id ), array( '%s' ), array( '%d' ) );
     854
     855        return (bool) $updated;
     856    }
     857
     858
     859    /**
    802860     * Delete every history row.
    803861     *
Note: See TracChangeset for help on using the changeset viewer.