Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Prevent colliding internal cache ids based on adapter #42

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

richard-parnaby-king
Copy link

Resolves #41
json_encode($this->getAdapter()) would always return an empty object for \Zend\Paginator\Adapter\DbSelect adapters (i.e. {}). By performing print_r on the adapter we can get the current state which, in the case of DbSelect, includes an sql object containing table name, join details, where clause, etc.
This change will prevent collisions between adapters that do not have any public properties and/or values.

`json_encode($this->getAdapter())` would always return an empty object for `\Zend\Paginator\Adapter\DbSelect` adapters (i.e. `{}`). By performing `print_r` on the adapter we can get the current state which, in the case of `DbSelect`, includes an sql object containing table name, join details, etc.
This will prevent collisions introduced in 2.8
Copy link
Member

@weierophinney weierophinney left a comment

Choose a reason for hiding this comment

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

Besides the comment below, we also need unit tests for this change, to demonstrate it actually works.

Thanks!

@@ -865,7 +865,7 @@ protected function _getCacheInternalId()
// @codingStandardsIgnoreEnd
return md5(
get_class($this->getAdapter())
. json_encode($this->getAdapter())
. hash('sha512', print_r($this->getAdapter(), true))
Copy link
Member

Choose a reason for hiding this comment

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

Wouldn't spl_object_hash($this->getAdapter()) make more sense here?

Copy link
Member

Choose a reason for hiding this comment

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

@weierophinney
See your own comment: #41 (comment)

Copy link
Member

Choose a reason for hiding this comment

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

spl_object_hash has been used in the past: 54f4f4c#diff-b7dae88f55a82631386bada74d3d1e9fL863

Copy link
Member

Choose a reason for hiding this comment

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

Ah, okay, that makes sense again. (I'm getting old and can't remember this stuff!)

Still need unit tests, though!

@weierophinney
Copy link
Member

This repository has been closed and moved to laminas/laminas-paginator; a new issue has been opened at laminas/laminas-paginator#2.

@weierophinney
Copy link
Member

This repository has been moved to laminas/laminas-paginator. If you feel that this patch is still relevant, please re-open against that repository, and reference this issue. To re-open, we suggest the following workflow:

  • Squash all commits in your branch (git rebase -i origin/{branch})
  • Make a note of all changed files (`git diff --name-only origin/{branch}...HEAD
  • Run the laminas/laminas-migration tool on the code.
  • Clone laminas/laminas-paginator to another directory.
  • Copy the files from the second bullet point to the clone of laminas/laminas-paginator.
  • In your clone of laminas/laminas-paginator, commit the files, push to your fork, and open the new PR.
    We will be providing tooling via laminas/laminas-migration soon to help automate the process.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2.8 _getCacheInternalId() is too generic
3 participants