[5.4] Fix the inverted existence check when creating session metadata by ManoharPaturi · Pull Request #48562 · joomla/joomla-cms · GitHub
Skip to content

[5.4] Fix the inverted existence check when creating session metadata - #48562

Open
ManoharPaturi wants to merge 1 commit into
joomla:5.4-devfrom
ManoharPaturi:pr3-metadata-manager
Open

ManoharPaturi wants to merge 1 commit into
joomla:5.4-devfrom
ManoharPaturi:pr3-metadata-manager

Conversation

@ManoharPaturi

Copy link
Copy Markdown

Pull Request resolves #

  • I read the Generative AI policy and my contribution is either not created with the help of AI or is compatible with the policy and GNU/GPL 2 or later.

Summary of Changes

MetadataManager::createRecordIfNonExisting() checks whether a session metadata record exists before inserting it. The guard compares against the wrong constant:

$exists = $this->checkSessionRecordExists($session->getId());

// Only touch the database if the record does not already exist
if ($exists !== self::$sessionRecordExists) {
    return;
}

With this comparison the method returns when no record was found and only attempts the insert when a record is already present, which is the opposite of both the method name and the comment above the guard. The insert for an existing record then fails on the primary key and the failure is swallowed, so in practice the method has never created anything.

This PR compares against self::$sessionRecordDoesNotExist instead, so the record is inserted when it is missing. When the state cannot be determined because the existence query failed, nothing is written, matching the conservative handling in createOrUpdateRecord().

The method currently has no callers in the core code base, so no behavioural change is expected anywhere in the CMS; it is public API of a class marked @internal and should behave as documented for any consumer. A unit test class is added covering the missing, existing and undetermined record states; two of the three cases fail against the previous guard.

Testing Instructions

Run the new unit tests:

libraries/vendor/bin/phpunit tests/Unit/Libraries/Cms/Session/MetadataManagerTest.php

Actual result BEFORE applying this Pull Request

createRecordIfNonExisting() inserts nothing when the metadata record is missing and attempts a duplicate insert when it already exists, which fails on the primary key.

Expected result AFTER applying this Pull Request

createRecordIfNonExisting() inserts the metadata record when it is missing, does nothing when it exists, and does nothing when the record state cannot be determined.

Link to documentations

  • No documentation changes for guide.joomla.org needed
  • No documentation changes for manual.joomla.org needed

Copilot AI balanced review requested due to automatic review settings October 4, 2026 02:18

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

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.

4 participants