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
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
*
......@@ -55,10 +71,9 @@ class Search extends RowGateway
*/
public function getSearchObject()
{
// Resource check for PostgreSQL compatibility:
$raw = is_resource($this->search_object)
? stream_get_contents($this->search_object) : $this->search_object;
$result = unserialize($raw);
// We need to make sure the search object is a string before unserializing:
$this->normalizeSearchObject();
$result = unserialize($this->search_object);
if (!($result instanceof \VuFind\Search\Minified)) {
throw new \Exception('Problem decoding saved search');
}
......@@ -72,12 +87,9 @@ class Search extends RowGateway
*/
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;
// We can't save if the search object is a resource; make sure it's a
// string first:
$this->normalizeSearchObject();
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