diff --git a/module/VuFind/config/module.config.php b/module/VuFind/config/module.config.php index c85fe33d182c56a5f73c0feed5e95e4f094c81a3..b8f59b9c3fdd3ba0083cf3e7cbec492b952e41c6 100644 --- a/module/VuFind/config/module.config.php +++ b/module/VuFind/config/module.config.php @@ -273,6 +273,9 @@ $config = array( ), 'service_manager' => array( 'factories' => array( + 'dbadapter' => function ($sm) { + return \VuFind\Db\AdapterFactory::getAdapter(); + }, 'ilsconnection' => function ($sm) { $config = \VuFind\Config\Reader::getConfig(); $catalog = new \VuFind\ILS\Connection(); diff --git a/module/VuFind/src/VuFind/Bootstrap.php b/module/VuFind/src/VuFind/Bootstrap.php index 13376f31fd6821fe9fa0f1ce723141b22e819a51..447c2cd0fd4c392e73c01f6aac0e6cf9b07dfc4a 100644 --- a/module/VuFind/src/VuFind/Bootstrap.php +++ b/module/VuFind/src/VuFind/Bootstrap.php @@ -27,9 +27,7 @@ */ namespace VuFind; use VuFind\Config\Reader as ConfigReader, - VuFind\Db\AdapterFactory as DbAdapterFactory, VuFind\Theme\Initializer as ThemeInitializer, Zend\Console\Console, - Zend\Db\TableGateway\Feature\GlobalAdapterFeature as DbGlobalAdapter, Zend\Mvc\MvcEvent, Zend\Mvc\Router\Http\RouteMatch, Zend\ServiceManager\Config as ServiceManagerConfig, Zend\ServiceManager\ServiceLocatorAwareInterface; @@ -117,17 +115,6 @@ class Bootstrap \VuFind\Connection\Manager::setServiceLocator($serviceManager); } - /** - * Set up the default database adapter. Do this early since the session handler - * may depend on database access. - * - * @return void - */ - protected function initDatabase() - { - DbGlobalAdapter::setStaticAdapter(DbAdapterFactory::getAdapter()); - } - /** * Set up the session. This should be done early since other startup routines * may rely on session access. diff --git a/module/VuFind/src/VuFind/Controller/UpgradeController.php b/module/VuFind/src/VuFind/Controller/UpgradeController.php index d04c27286e90480e18beeca60733fb75e5a066ae..2cdb84c913515a7c17fdc83570ffe8ac6f61b364 100644 --- a/module/VuFind/src/VuFind/Controller/UpgradeController.php +++ b/module/VuFind/src/VuFind/Controller/UpgradeController.php @@ -29,7 +29,6 @@ namespace VuFind\Controller; use ArrayObject, VuFind\Config\Reader as ConfigReader, VuFind\Cookie\Container as CookieContainer, VuFind\Db\AdapterFactory, VuFind\Exception\RecordMissing as RecordMissingException, - Zend\Db\TableGateway\Feature\GlobalAdapterFeature as DbGlobalAdapter, Zend\Session\Container as SessionContainer; /** @@ -202,7 +201,7 @@ class UpgradeController extends AbstractBase try { // Set up the helper with information from our SQL file: $this->dbUpgrade() - ->setAdapter(DbGlobalAdapter::getStaticAdapter()) + ->setAdapter($this->getServiceLocator()->get('DBAdapter')) ->loadSql(APPLICATION_PATH . '/module/VuFind/sql/mysql.sql'); // Check for missing tables. Note that we need to finish dealing with diff --git a/module/VuFind/src/VuFind/Db/Row/User.php b/module/VuFind/src/VuFind/Db/Row/User.php index 43a8750eea18da2c5672a591c978ea352badcd4a..81adc1ea71c9ba5a83aee7d6d27f20d61f5269e7 100644 --- a/module/VuFind/src/VuFind/Db/Row/User.php +++ b/module/VuFind/src/VuFind/Db/Row/User.php @@ -26,8 +26,7 @@ * @link http://vufind.org Main Site */ namespace VuFind\Db\Row; -use Zend\Db\Sql\Expression, Zend\Db\Sql\Predicate\Predicate, Zend\Db\Sql\Sql, - Zend\Db\TableGateway\Feature\GlobalAdapterFeature; +use Zend\Db\Sql\Expression, Zend\Db\Sql\Predicate\Predicate, Zend\Db\Sql\Sql; /** * Row Definition for user @@ -80,7 +79,10 @@ class User extends ServiceLocatorAwareGateway // Since this object is frequently stored in the session, we should // reconnect to the database as part of the save action to prevent // exceptions: - $this->sql = new Sql(GlobalAdapterFeature::getStaticAdapter(), $this->table); + $this->sql = new Sql( + $this->getServiceLocator()->getServiceLocator()->get('DBAdapter'), + $this->table + ); return parent::save(); } diff --git a/module/VuFind/src/VuFind/Db/Table/Gateway.php b/module/VuFind/src/VuFind/Db/Table/Gateway.php index 6952498a940a1688656ee37225c39a3cbe604b73..f212d764794274d0c7830fc03085629d0d79f635 100644 --- a/module/VuFind/src/VuFind/Db/Table/Gateway.php +++ b/module/VuFind/src/VuFind/Db/Table/Gateway.php @@ -27,8 +27,6 @@ */ namespace VuFind\Db\Table; use Zend\Db\TableGateway\AbstractTableGateway, - Zend\Db\TableGateway\Feature\FeatureSet, - Zend\Db\TableGateway\Feature\GlobalAdapterFeature, Zend\ServiceManager\ServiceLocatorAwareInterface, Zend\ServiceManager\ServiceLocatorInterface; @@ -63,8 +61,6 @@ class Gateway extends AbstractTableGateway implements ServiceLocatorAwareInterfa { $this->table = $table; $this->rowClass = $rowClass; - $this->featureSet = new FeatureSet(); - $this->featureSet->addFeature(new GlobalAdapterFeature()); } /** @@ -77,6 +73,8 @@ class Gateway extends AbstractTableGateway implements ServiceLocatorAwareInterfa if ($this->isInitialized) { return; } + $this->adapter = $this->getServiceLocator()->getServiceLocator() + ->get('DBAdapter'); parent::initialize(); if (null !== $this->rowClass) { $resultSetPrototype = $this->getResultSetPrototype(); diff --git a/module/VuFind/src/VuFind/Log/Logger.php b/module/VuFind/src/VuFind/Log/Logger.php index fbd7700345fba4d0310057386378648314423f5e..b1bd5f5d32c00d160f1ecf750f61031d8c6928dc 100644 --- a/module/VuFind/src/VuFind/Log/Logger.php +++ b/module/VuFind/src/VuFind/Log/Logger.php @@ -26,8 +26,7 @@ * @link http://vufind.org Main Site */ namespace VuFind\Log; -use Zend\Db\TableGateway\Feature\GlobalAdapterFeature as DbGlobalAdapter, - Zend\Log\Logger as BaseLogger, +use Zend\Log\Logger as BaseLogger, Zend\ServiceManager\ServiceLocatorAwareInterface, Zend\ServiceManager\ServiceLocatorInterface; @@ -95,7 +94,7 @@ class Logger extends BaseLogger implements ServiceLocatorAwareInterface // Make Writers $filters = explode(',', $error_types); $writer = new Writer\Db( - DbGlobalAdapter::getStaticAdapter(), + $this->getServiceLocator()->get('DBAdapter'), $table_name, $columnMapping ); $this->addWriters($writer, $filters); diff --git a/module/VuFind/src/VuFind/Tests/DbTestCase.php b/module/VuFind/src/VuFind/Tests/DbTestCase.php index b495dd17c50ea1e3bcadfc8927c5a6657788f3a8..b55a4599c152d590086510a75d0574ce7687d71a 100644 --- a/module/VuFind/src/VuFind/Tests/DbTestCase.php +++ b/module/VuFind/src/VuFind/Tests/DbTestCase.php @@ -27,8 +27,6 @@ * @link http://vufind.org/wiki/unit_tests Wiki */ namespace VuFind\Tests; -use VuFind\Db\AdapterFactory as DbAdapterFactory, - Zend\Db\TableGateway\Feature\GlobalAdapterFeature as DbGlobalAdapter; /** * Abstract base class for PHPUnit database test cases. @@ -42,20 +40,6 @@ use VuFind\Db\AdapterFactory as DbAdapterFactory, abstract class DbTestCase extends TestCase { - /** - * Setup method -- make sure static adapter is available for testing. - * - * @return void - */ - public static function prepareAdapter() - { - try { - DbGlobalAdapter::getStaticAdapter(); - } catch (\Zend\Db\TableGateway\Exception\RuntimeException $e) { - DbGlobalAdapter::setStaticAdapter(DbAdapterFactory::getAdapter()); - } - } - /** * Get a service manager. * @@ -68,6 +52,7 @@ abstract class DbTestCase extends TestCase // Add database service: if (!$sm->has('DbTablePluginManager')) { + $sm->setService('DBAdapter', \VuFind\Db\AdapterFactory::getAdapter()); $factory = new \VuFind\Db\Table\PluginManager( new \Zend\ServiceManager\Config( array( diff --git a/module/VuFind/tests/unit-tests/src/Auth/DatabaseTest.php b/module/VuFind/tests/unit-tests/src/Auth/DatabaseTest.php index 668c3ffb1b5bb67f838605a01f5ccb23f4094bba..00ad8638e9ceb9765c3fd630bc0e4d5a03788ca7 100644 --- a/module/VuFind/tests/unit-tests/src/Auth/DatabaseTest.php +++ b/module/VuFind/tests/unit-tests/src/Auth/DatabaseTest.php @@ -56,9 +56,6 @@ class DatabaseTest extends \VuFind\Tests\DbTestCase */ public static function setUpBeforeClass() { - // Set up database adapter: - static::prepareAdapter(); - // Fail if there are already users in the database (we don't want to run this // on a real system -- it's only meant for the continuous integration server) $test = new DatabaseTest(); diff --git a/module/VuFind/tests/unit-tests/src/Auth/ILSTest.php b/module/VuFind/tests/unit-tests/src/Auth/ILSTest.php index af6b4dbdcd98d747762ac32753abbbba9e48c550..a9fac52cd74fdcf12ed8cef796d6474a54af407d 100644 --- a/module/VuFind/tests/unit-tests/src/Auth/ILSTest.php +++ b/module/VuFind/tests/unit-tests/src/Auth/ILSTest.php @@ -59,9 +59,6 @@ class ILSTest extends \VuFind\Tests\DbTestCase */ public static function setUpBeforeClass() { - // Set up database adapter: - static::prepareAdapter(); - // Fail if there are already users in the database (we don't want to run this // on a real system -- it's only meant for the continuous integration server) $test = new ILSTest(); diff --git a/module/VuFind/tests/unit-tests/src/Auth/ShibbolethTest.php b/module/VuFind/tests/unit-tests/src/Auth/ShibbolethTest.php index 337333c1839777b588dffdc39999b65be4c340cf..5af8af456bc983019fad731ed4f2541a6dea7770 100644 --- a/module/VuFind/tests/unit-tests/src/Auth/ShibbolethTest.php +++ b/module/VuFind/tests/unit-tests/src/Auth/ShibbolethTest.php @@ -46,9 +46,6 @@ class ShibbolethTest extends \VuFind\Tests\DbTestCase */ public static function setUpBeforeClass() { - // Set up database adapter: - static::prepareAdapter(); - // Fail if there are already users in the database (we don't want to run this // on a real system -- it's only meant for the continuous integration server) $test = new ShibbolethTest(); diff --git a/module/VuFind/tests/unit-tests/src/Db/Table/ChangeTrackerTest.php b/module/VuFind/tests/unit-tests/src/Db/Table/ChangeTrackerTest.php index fd02547e7bae399256bfea10156a26181c68a05d..1cb07e2d76b1bf7702ed6bc74759c04f54976885 100644 --- a/module/VuFind/tests/unit-tests/src/Db/Table/ChangeTrackerTest.php +++ b/module/VuFind/tests/unit-tests/src/Db/Table/ChangeTrackerTest.php @@ -39,11 +39,6 @@ use VuFind\Db\Table\ChangeTracker; */ class ChangeTrackerTest extends \VuFind\Tests\DbTestCase { - public static function setUpBeforeClass() - { - static::prepareAdapter(); - } - /** * Test change tracking * @@ -52,7 +47,7 @@ class ChangeTrackerTest extends \VuFind\Tests\DbTestCase public function testChangeTracker() { $core = 'testCore'; - $tracker = new ChangeTracker(); + $tracker = $this->getTable('ChangeTracker'); // Create a new row: $tracker->index($core, 'test1', 1326833170);