0 ? $post_modified . '|' . $revision : $post_modified; } public static function get_revision( int $product_id ): int { $raw = \get_post_meta( $product_id, self::REVISION_META_KEY, true ); return is_numeric( $raw ) ? (int) $raw : 0; } /** * Increment and persist the editor revision. Called once per successful save * inside the per-product lock so the bump itself cannot race. */ public static function bump_revision( int $product_id ): int { $next = self::get_revision( $product_id ) + 1; \update_post_meta( $product_id, self::REVISION_META_KEY, $next ); return $next; } public static function for_product( \WC_Product $product ): string { $date = $product->get_date_modified(); $post_modified = ( is_object( $date ) && method_exists( $date, 'date' ) ) ? (string) $date->date( 'Y-m-d H:i:s' ) : ''; return self::compose( $post_modified, self::get_revision( (int) $product->get_id() ) ); } public static function for_product_id( int $product_id, string $post_modified ): string { return self::compose( $post_modified, self::get_revision( $product_id ) ); } /** * Token for any post id, reading post_modified from the post itself. * * Three callers - ContentSnapshots\SnapshotReadController, * ContentReview\ContentReviewController and Premium\Rollback\ * SnapshotRestController - each carried a byte-identical private * `attachmentToken()` doing exactly this null-safe read before delegating * here, with docblocks cross-referencing each other to stay in step. The * composition was already shared; only this accessor was copied. One owner * removes the copies and the "keep these in sync by hand" instruction. * * @param int $post_id Post id (a product or an attachment subject). * @return string */ public static function for_post_id( int $post_id ): string { $post = function_exists( 'get_post' ) ? \get_post( $post_id ) : null; $post_modified = ( is_object( $post ) && isset( $post->post_modified ) ) ? (string) $post->post_modified : ''; return self::for_product_id( $post_id, $post_modified ); } }