From da6cefac06bd78a69b63df95a5e0d9603be62eba Mon Sep 17 00:00:00 2001 From: Damian Mooyman Date: Tue, 30 Aug 2016 13:08:11 +1200 Subject: [PATCH] Upgrade code for core namespaces --- _register_database.php | 5 +++-- code/MSSQLAzureDatabase.php | 1 - code/MSSQLDatabase.php | 24 ++++++++-------------- code/MSSQLDatabaseConfigurationHelper.php | 9 ++++---- code/MSSQLQueryBuilder.php | 25 +++++++++-------------- code/MSSQLSchemaManager.php | 9 ++++---- code/SQLServerConnector.php | 5 ----- code/SQLServerQuery.php | 10 +++------ tests/MSSQLDatabaseQueryTest.php | 3 +++ 9 files changed, 36 insertions(+), 55 deletions(-) diff --git a/_register_database.php b/_register_database.php index ac64146..601fa55 100644 --- a/_register_database.php +++ b/_register_database.php @@ -1,9 +1,10 @@ 'MSSQLPDODatabase', 'title' => 'SQL Server 2008 (using PDO)', diff --git a/code/MSSQLAzureDatabase.php b/code/MSSQLAzureDatabase.php index 24d58e8..69df5cf 100644 --- a/code/MSSQLAzureDatabase.php +++ b/code/MSSQLAzureDatabase.php @@ -18,7 +18,6 @@ namespace SilverStripe\MSSQL; * Fulltext indexes are not supported. * * @author Sean Harvey - * @package mssql */ class MSSQLAzureDatabase extends MSSQLDatabase { diff --git a/code/MSSQLDatabase.php b/code/MSSQLDatabase.php index bce8568..02e2263 100644 --- a/code/MSSQLDatabase.php +++ b/code/MSSQLDatabase.php @@ -2,14 +2,14 @@ namespace SilverStripe\MSSQL; +use SilverStripe\Core\Config\Config; +use SilverStripe\Core\ClassInfo; use SilverStripe\ORM\ArrayList; +use SilverStripe\ORM\Connect\SS_Database; use SilverStripe\ORM\DataList; use SilverStripe\ORM\DB; use SilverStripe\ORM\DataObject; -use SilverStripe\ORM\Connect\SS_Database; -use Config; -use ClassInfo; -use PaginatedList; +use SilverStripe\ORM\PaginatedList; use SilverStripe\ORM\Queries\SQLSelect; /** @@ -48,8 +48,6 @@ use SilverStripe\ORM\Queries\SQLSelect; * * References: * @see http://freetds.org - * - * @package mssql */ class MSSQLDatabase extends SS_Database { @@ -217,14 +215,10 @@ class MSSQLDatabase extends SS_Database */ public function searchEngine($classesToSearch, $keywords, $start, $pageLength, $sortBy = "Relevance DESC", $extraFilter = "", $booleanSearch = false, $alternativeFileFilter = "", $invertedMatch = false) { - if (isset($objects)) { - $results = new ArrayList($objects); - } else { - $results = new ArrayList(); - } + $results = new ArrayList(); if (!$this->fullTextEnabled()) { - return $results; + return new PaginatedList($results); } if (!in_array(substr($sortBy, 0, 9), array('"Relevanc', 'Relevance'))) { user_error("Non-relevance sort not supported.", E_USER_ERROR); @@ -262,14 +256,14 @@ class MSSQLDatabase extends SS_Database $class = DataObject::getSchema()->tableClass($tableName); $join = $this->fullTextSearchMSSQL($tableName, $keywords); if (!$join) { - return $results; + return new PaginatedList($results); } // avoid "Null or empty full-text predicate" // Check if we need to add ShowInSearch $where = null; - if ($class === 'SiteTree') { + if ($class === 'SilverStripe\\CMS\\Model\\SiteTree') { $where = array("\"$tableName\".\"ShowInSearch\"!=0"); - } elseif ($class === 'File') { + } elseif ($class === 'SilverStripe\\Assets\\File') { // File.ShowInSearch was added later, keep the database driver backwards compatible // by checking for its existence first $fields = $this->getSchemaManager()->fieldList($tableName); diff --git a/code/MSSQLDatabaseConfigurationHelper.php b/code/MSSQLDatabaseConfigurationHelper.php index 8d25bef..8749f3e 100644 --- a/code/MSSQLDatabaseConfigurationHelper.php +++ b/code/MSSQLDatabaseConfigurationHelper.php @@ -2,18 +2,16 @@ namespace SilverStripe\MSSQL; -use DatabaseConfigurationHelper; +use SilverStripe\Dev\Install\DatabaseAdapterRegistry; +use SilverStripe\Dev\Install\DatabaseConfigurationHelper; use PDO; use Exception; -use DatabaseAdapterRegistry; /** * This is a helper class for the SS installer. * * It does all the specific checking for MSSQLDatabase * to ensure that the configuration is setup correctly. - * - * @package mssql */ class MSSQLDatabaseConfigurationHelper implements DatabaseConfigurationHelper { @@ -111,7 +109,7 @@ class MSSQLDatabaseConfigurationHelper implements DatabaseConfigurationHelper * * @param mixed $conn Connection object/resource * @param string $value Value to quote - * @return string Quoted strieng + * @return string Quoted string */ protected function quote($conn, $value) { @@ -124,6 +122,7 @@ class MSSQLDatabaseConfigurationHelper implements DatabaseConfigurationHelper } else { user_error('Invalid database connection', E_USER_ERROR); } + return null; } /** diff --git a/code/MSSQLQueryBuilder.php b/code/MSSQLQueryBuilder.php index ac5918a..8a251d8 100644 --- a/code/MSSQLQueryBuilder.php +++ b/code/MSSQLQueryBuilder.php @@ -2,25 +2,20 @@ namespace SilverStripe\MSSQL; - use InvalidArgumentException; use SilverStripe\ORM\Queries\SQLSelect; use SilverStripe\ORM\Connect\DBQueryBuilder; - - /** * Builds a SQL query string from a SQLExpression object - * - * @package mssql */ class MSSQLQueryBuilder extends DBQueryBuilder { - + protected function buildSelectQuery(SQLSelect $query, array &$parameters) { list($limit, $offset) = $this->parseLimit($query); - + // If not using ofset then query generation is quite straightforward if (empty($offset)) { $sql = parent::buildSelectQuery($query, $parameters); @@ -30,7 +25,7 @@ class MSSQLQueryBuilder extends DBQueryBuilder } return $sql; } - + // When using offset we must use a subselect // @see http://stackoverflow.com/questions/2135418/equivalent-of-limit-and-offset-for-sql-server $orderby = $query->getOrderBy(); @@ -58,13 +53,13 @@ class MSSQLQueryBuilder extends DBQueryBuilder $firstCol = reset($selects); $orderByClause = "ORDER BY $firstCol"; } - + // Build main query SQL $sql = parent::buildSelectQuery($query, $parameters); - + // Inject row number into selection $sql = preg_replace('/^(SELECT (DISTINCT)?)/i', '${1} ROW_NUMBER() OVER ('.$orderByClause.') AS Number, ', $sql); - + // Sub-query this SQL if (empty($limit)) { $limitCondition = "Number > ?"; @@ -76,13 +71,13 @@ class MSSQLQueryBuilder extends DBQueryBuilder } return "SELECT * FROM ($sql) AS Numbered WHERE $limitCondition ORDER BY Number"; } - + public function buildLimitFragment(SQLSelect $query, array &$parameters) { // Limit is handled at the buildSelectQuery level return ''; } - + public function buildOrderByFragment(SQLSelect $query, array &$parameters) { // If doing a limit/offset at the same time then don't build the orde by fragment here @@ -92,10 +87,10 @@ class MSSQLQueryBuilder extends DBQueryBuilder } return ''; } - + /** * Extracts the limit and offset from the limit clause - * + * * @param SQLSelect $query * @return array Two item array with $limit and $offset as values * @throws InvalidArgumentException diff --git a/code/MSSQLSchemaManager.php b/code/MSSQLSchemaManager.php index cbe0269..a7b1122 100644 --- a/code/MSSQLSchemaManager.php +++ b/code/MSSQLSchemaManager.php @@ -2,15 +2,10 @@ namespace SilverStripe\MSSQL; - use SilverStripe\ORM\Connect\DBSchemaManager; - - /** * Represents and handles all schema management for a MS SQL database - * - * @package mssql */ class MSSQLSchemaManager extends DBSchemaManager { @@ -697,6 +692,7 @@ class MSSQLSchemaManager extends DBSchemaManager * For a given table name, get all the internal index names, * except for those that are primary keys and fulltext indexes. * + * @param string $tableName * @return array */ public function indexNames($tableName) @@ -786,6 +782,9 @@ class MSSQLSchemaManager extends DBSchemaManager /** * @todo Make this work like {@link MySQLDatabase::set()} + * + * @param array $values + * @return string */ public function set($values) { diff --git a/code/SQLServerConnector.php b/code/SQLServerConnector.php index 1547553..7ae76ed 100644 --- a/code/SQLServerConnector.php +++ b/code/SQLServerConnector.php @@ -2,15 +2,10 @@ namespace SilverStripe\MSSQL; - use SilverStripe\ORM\Connect\DBConnector; - - /** * Database connector driver for sqlsrv_ library - * - * @package mssql */ class SQLServerConnector extends DBConnector { diff --git a/code/SQLServerQuery.php b/code/SQLServerQuery.php index 932247d..a2a33a9 100644 --- a/code/SQLServerQuery.php +++ b/code/SQLServerQuery.php @@ -2,29 +2,25 @@ namespace SilverStripe\MSSQL; - -use SilverStripe\ORM\Connect\SS_Query; use DateTime; - +use SilverStripe\ORM\Connect\SS_Query; /** * A result-set from a MSSQL database. - * - * @package mssql */ class SQLServerQuery extends SS_Query { /** * The SQLServerConnector object that created this result set. - * + * * @var SQLServerConnector */ private $connector; /** * The internal MSSQL handle that points to the result set. - * + * * @var resource */ private $handle; diff --git a/tests/MSSQLDatabaseQueryTest.php b/tests/MSSQLDatabaseQueryTest.php index 0e80909..9d8207b 100644 --- a/tests/MSSQLDatabaseQueryTest.php +++ b/tests/MSSQLDatabaseQueryTest.php @@ -1,6 +1,9 @@