Skip to content

[3.0] Pass a list of rows to Db::insert(), not a single row - #9576

Merged
Sesquipedalian merged 1 commit into
SimpleMachines:release-3.0from
albertlast:3.0/insert-flat-row
Aug 29, 2026
Merged

Sesquipedalian merged 1 commit into
SimpleMachines:release-3.0from
albertlast:3.0/insert-flat-row

Conversation

@albertlast

Copy link
Copy Markdown
Collaborator

Description

The fourth argument of Db::$db->insert() has to be an array of rows. Four call sites pass
one row's values directly. With $backward_compatibility on, the database layer quietly
wraps them; that is off by default in 3.0, and then insert() calls error_backtrace()
with E_USER_ERROR and the request dies with "Invalid data structure sent to the
database."

Logging::trackStats() is the bad one. The UPDATE it tries first matches nothing on
the first tracked event of a new day, so the insert runs, so the page is a 500 — and
because the row is never created, so is every page after it, for the rest of the day. It
takes hitStats being on, or a post, a new topic or a registration being the first thing
tracked that day.

Reproduced on a clean install with hitStats on:

DELETE FROM smf_log_activity WHERE date = CURDATE();
curl -o /dev/null -w '%{http_code}\n' http://localhost:8080/index.php   # 500
curl -o /dev/null -w '%{http_code}\n' http://localhost:8080/index.php   # 500
curl -o /dev/null -w '%{http_code}\n' http://localhost:8080/index.php   # 500, and so on

smf_log_errors fills with Invalid data structure sent to the database.<br>Function: trackStats at Sources/Logging.php:494. With this change the first request answers 200,
creates the row and increments hits from then on.

The other three are narrower:

  • Display::checkMovedMergedRedirect() — marking a moved or merged topic read on the way
    through the redirect.
  • User::logSpider() — the first page a spider fetches each day, when spider_mode is 1.
  • Theme::loadVariant() — saving a member's chosen theme variant.

How this was checked

trackStats() end to end, as above. The other three by inspection: they are the same
misuse of the same argument, and each is unreachable on a stock install without a
configuration this environment does not have — the default theme ships
theme_variants = [], and a spider request dies earlier anyway, on
Typed property SMF\User::$timezone must not be accessed before initialization from
Sources/Time.php:191, which is a separate bug and unchanged either way.

No test: every one of these needs Db::$db, which the unit suite has no connection for.

NotifyTopic::changePref() has the same fault and is deliberately left alone here, because
#9477 already fixes it along with two other faults on that path.

Issues References (Fixes|Related|Closes)

  1. Related: [3.0] Save the notification preference the member asked for #9477

The fourth argument of Db::$db->insert() has to be an array of rows. Four
call sites passed one row's values directly. With $backward_compatibility
on the database layer quietly wraps them, but that is off by default in
3.0, and then insert() calls error_backtrace() with E_USER_ERROR and the
request dies with "Invalid data structure sent to the database".

Logging::trackStats() is the bad one. The UPDATE it tries first matches
nothing on the first tracked event of a new day, so the insert runs, so
the page is a 500 -- and because the row is never created, so is every
page after it, for the rest of the day. That needs 'hitStats' on, or a
post, a new topic or a registration to be the first thing tracked.

The other three are the moved/merged redirect in
Display::checkMovedMergedRedirect(), the spider stats in
User::logSpider(), and saving a theme variant in Theme::loadVariant().

NotifyTopic::changePref() has the same fault and is left alone here,
because SimpleMachines#9477 already fixes it along with two others on that path.

Signed-off-by: albertlast <mathiaspapealbert@hotmail.com>
@Sesquipedalian
Sesquipedalian merged commit 0d07a40 into SimpleMachines:release-3.0 Aug 29, 2026
7 checks passed
@jdarwood007 jdarwood007 modified the milestones: 3.0 Alpha 6, 3.0 Alpha 5 Aug 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants