Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Workaround for PostgreSQL inconsistent bytea encoding requirements. #594

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 15 additions & 3 deletions module/VuFind/src/VuFind/Db/Row/Search.php
Expand Up @@ -58,6 +58,11 @@ public function getSearchObject()
// Resource check for PostgreSQL compatibility:
$raw = is_resource($this->search_object)
? stream_get_contents($this->search_object) : $this->search_object;
// Some search objects may be Base64-encoded; if so, they're flagged
// with a prefix so we know how to decode them:
if (substr($raw, 0, 5) == 'B64__') {
$raw = base64_decode(substr($raw, 5));
}
$result = unserialize($raw);
if (!($result instanceof \VuFind\Search\Minified)) {
throw new \Exception('Problem decoding saved search');
Expand All @@ -75,9 +80,16 @@ public function save()
// Note that if we have a resource, we need to grab the contents before
// saving -- this is necessary for PostgreSQL compatibility although MySQL
// returns a plain string
$this->search_object = is_resource($this->search_object)
? stream_get_contents($this->search_object)
: $this->search_object;
if (is_resource($this->search_object)) {
$this->search_object = stream_get_contents($this->search_object);
}
// Due to inconsistent encoding standards for bytea fields in different
// versions of PostgreSQL, we need to base64-encode serialized objects
// before storing them to avoid errors caused by special characters such
// as backslashes.
if ('PostgreSQL' == $this->sql->getAdapter()->getPlatform()->getName()) {
$this->search_object = 'B64__' . base64_encode($this->search_object);
}
parent::save();
}
}