The Gitlab instance will be restarted on Monday April 28th at 2AM. There will be a short interruption of service.

Skip to content
Snippets Groups Projects
Commit 5d4ec94b authored by Demian Katz's avatar Demian Katz Committed by Robert Lange
Browse files

Fix bug: getSearchObject() followed by save() would corrupt database.

- Only affected PostgreSQL databases.
- We needed to better standardize the way the search object data was normalized.
parent 39f18667
No related merge requests found
...@@ -48,6 +48,22 @@ class Search extends RowGateway ...@@ -48,6 +48,22 @@ class Search extends RowGateway
parent::__construct('id', 'search', $adapter); parent::__construct('id', 'search', $adapter);
} }
/**
* Support method to make sure that the search_object field is formatted as a
* string, since PostgreSQL sometimes represents it as a resource.
*
* @return void
*/
protected function normalizeSearchObject()
{
// 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
if (is_resource($this->search_object)) {
$this->search_object = stream_get_contents($this->search_object);
}
}
/** /**
* Get the search object from the row * Get the search object from the row
* *
...@@ -55,10 +71,9 @@ class Search extends RowGateway ...@@ -55,10 +71,9 @@ class Search extends RowGateway
*/ */
public function getSearchObject() public function getSearchObject()
{ {
// Resource check for PostgreSQL compatibility: // We need to make sure the search object is a string before unserializing:
$raw = is_resource($this->search_object) $this->normalizeSearchObject();
? stream_get_contents($this->search_object) : $this->search_object; $result = unserialize($this->search_object);
$result = unserialize($raw);
if (!($result instanceof \VuFind\Search\Minified)) { if (!($result instanceof \VuFind\Search\Minified)) {
throw new \Exception('Problem decoding saved search'); throw new \Exception('Problem decoding saved search');
} }
...@@ -72,12 +87,9 @@ class Search extends RowGateway ...@@ -72,12 +87,9 @@ class Search extends RowGateway
*/ */
public function save() public function save()
{ {
// Note that if we have a resource, we need to grab the contents before // We can't save if the search object is a resource; make sure it's a
// saving -- this is necessary for PostgreSQL compatibility although MySQL // string first:
// returns a plain string $this->normalizeSearchObject();
$this->search_object = is_resource($this->search_object)
? stream_get_contents($this->search_object)
: $this->search_object;
return parent::save(); return parent::save();
} }
} }
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment