Skip to content
Snippets Groups Projects
Commit d52fbf76 authored by Demian Katz's avatar Demian Katz
Browse files

Progress on PostgreSQL compatibility (thanks to Michele Meloni).

parent 944c4a84
No related merge requests found
...@@ -262,6 +262,9 @@ require_login = true ...@@ -262,6 +262,9 @@ require_login = true
[Database] [Database]
database = mysql://root@localhost/vufind database = mysql://root@localhost/vufind
; If your database (e.g. PostgreSQL) uses a schema, you can set it here:
;schema = schema_name
; The character set of the database -- may be latin1 or utf8; utf8 is STRONGLY ; The character set of the database -- may be latin1 or utf8; utf8 is STRONGLY
; RECOMMENDED and is the default if no value is set here. You may need latin1 ; RECOMMENDED and is the default if no value is set here. You may need latin1
; for compatibility with existing VuFind 1.x installations. ; for compatibility with existing VuFind 1.x installations.
......
...@@ -346,6 +346,19 @@ $config = array( ...@@ -346,6 +346,19 @@ $config = array(
'config_reader' => array( 'config_reader' => array(
'abstract_factories' => array('VuFind\Config\PluginFactory'), 'abstract_factories' => array('VuFind\Config\PluginFactory'),
), ),
// PostgreSQL sequence mapping
'pgsql_seq_mapping' => array(
'comments' => array('id', 'comments_id_seq'),
'oai_resumption' => array('id', 'oai_resumption_id_seq'),
'resource' => array('id', 'resource_id_seq'),
'resource_tags' => array('id', 'resource_tags_id_seq'),
'search' => array('id', 'search_id_seq'),
'session' => array('id', 'session_id_seq'),
'tags' => array('id', 'tags_id_seq'),
'user' => array('id', 'user_id_seq'),
'user_list' => array('id', 'user_list_id_seq'),
'user_resource' => array('id', 'user_resource_id_seq')
),
// This section contains service manager configurations for all VuFind // This section contains service manager configurations for all VuFind
// pluggable components: // pluggable components:
'plugin_managers' => array( 'plugin_managers' => array(
......
...@@ -102,18 +102,30 @@ class AdapterFactory ...@@ -102,18 +102,30 @@ class AdapterFactory
* @return object * @return object
*/ */
public function getAdapterFromOptions($options) public function getAdapterFromOptions($options)
{ {
// Set up custom options by database type: // Set up custom options by database type:
switch (strtolower($options['driver'])) { $driver = strtolower($options['driver']);
switch ($driver) {
case 'mysqli': case 'mysqli':
$options['charset'] = isset($this->config->Database->charset) $options['charset'] = isset($this->config->Database->charset)
? $this->config->Database->charset : 'utf8'; ? $this->config->Database->charset : 'utf8';
$options['options'] = array('buffer_results' => true); $options['options'] = array('buffer_results' => true);
break; break;
} }
// Set up database connection: // Set up database connection:
return new Adapter($options); $adapter = new Adapter($options);
// Special-case setup:
if ($driver == 'pdo_pgsql' && isset($this->config->Database->schema)) {
// Set schema
$statement = $adapter->createStatement(
'SET search_path TO ' . $this->config->Database->schema
);
$result = $statement->execute();
}
return $adapter;
} }
/** /**
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
*/ */
namespace VuFind\Db\Table; namespace VuFind\Db\Table;
use Zend\Db\TableGateway\AbstractTableGateway, use Zend\Db\TableGateway\AbstractTableGateway,
Zend\Db\TableGateway\Feature,
Zend\ServiceManager\ServiceLocatorAwareInterface, Zend\ServiceManager\ServiceLocatorAwareInterface,
Zend\ServiceManager\ServiceLocatorInterface; Zend\ServiceManager\ServiceLocatorInterface;
...@@ -85,6 +86,21 @@ class Gateway extends AbstractTableGateway implements ServiceLocatorAwareInterfa ...@@ -85,6 +86,21 @@ class Gateway extends AbstractTableGateway implements ServiceLocatorAwareInterfa
if ($this->isInitialized) { if ($this->isInitialized) {
return; return;
} }
// Special case for PostgreSQL sequences:
if ($this->adapter->getDriver()->getDatabasePlatformName() == "Postgresql") {
$cfg = $this->getServiceLocator()->getServiceLocator()->get('config');
$maps = $cfg['vufind']['pgsql_seq_mapping'];
if (isset($maps[$this->table])) {
$this->featureSet = new Feature\FeatureSet();
$this->featureSet->addFeature(
new Feature\SequenceFeature(
$maps[$this->table][0], $maps[$this->table][1]
)
);
}
}
parent::initialize(); parent::initialize();
if (null !== $this->rowClass) { if (null !== $this->rowClass) {
$resultSetPrototype = $this->getResultSetPrototype(); $resultSetPrototype = $this->getResultSetPrototype();
......
...@@ -99,7 +99,7 @@ class Tags extends Gateway ...@@ -99,7 +99,7 @@ class Tags extends Gateway
*/ */
public function getForResource($id, $source = 'VuFind', $limit = 0, public function getForResource($id, $source = 'VuFind', $limit = 0,
$list = null, $user = null, $sort = 'count' $list = null, $user = null, $sort = 'count'
) { ) {
return $this->select( return $this->select(
function ($select) use ($id, $source, $limit, $list, $user, $sort) { function ($select) use ($id, $source, $limit, $list, $user, $sort) {
$select->columns( $select->columns(
...@@ -119,7 +119,7 @@ class Tags extends Gateway ...@@ -119,7 +119,7 @@ class Tags extends Gateway
); );
$select->where->equalTo('r.record_id', $id) $select->where->equalTo('r.record_id', $id)
->equalTo('r.source', $source); ->equalTo('r.source', $source);
$select->group(array('id', 'tag')); $select->group(array('tags.id', 'tag'));
if ($sort == 'count') { if ($sort == 'count') {
$select->order(array('cnt DESC', 'tags.tag')); $select->order(array('cnt DESC', 'tags.tag'));
......
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