Fix Rules screen crash: Store::rules() discarded decoded config (by-ref foreach over a cast copy)
Also make an unreadable rule non-fatal on the Rules screen, and add a regression test. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
3bbd77b661
commit
27646c1001
3 files changed
+67
-3
No files matched your search
@@ -26,11 +26,14 @@ final class Store {
|
||||
public static function rules( int $goalId ): array {
|
||||
global $wpdb;
|
||||
$rows = $wpdb->get_results( $wpdb->prepare( 'SELECT * FROM ' . self::t( 'rules' ) . ' WHERE goal_id = %d ORDER BY sort ASC, id ASC', $goalId ), ARRAY_A );
|
||||
foreach ( (array) $rows as &$r ) {
|
||||
$rows = (array) $rows;
|
||||
// Iterate $rows itself by reference: `foreach ( (array) $rows as &$r )` would modify a temporary copy and discard the decoding.
|
||||
foreach ( $rows as &$r ) {
|
||||
$cfg = json_decode( (string) $r['config'], true );
|
||||
$r['config'] = is_array( $cfg ) ? $cfg : array();
|
||||
}
|
||||
return (array) $rows;
|
||||
unset( $r );
|
||||
return $rows;
|
||||
}
|
||||
|
||||
public static function rule( int $ruleId, int $goalId ): ?array {
|
||||
|
||||
Reference in new issue
Block a user