Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
project
drupal
Commits
466fac1e
Commit
466fac1e
authored
Feb 15, 2013
by
Dries Buytaert
Browse files
Issue
#783812
by chx: Allow db drivers outside of 'core'.
parent
9dfc2d82
Changes
5
Hide whitespace changes
Inline
Side-by-side
core/includes/bootstrap.inc
View file @
466fac1e
...
...
@@ -3166,6 +3166,7 @@ function drupal_classloader($class_loader = NULL) {
$loader
->
registerNamespaces
(
array
(
'Drupal\Core'
=>
DRUPAL_ROOT
.
'/core/lib'
,
'Drupal\Component'
=>
DRUPAL_ROOT
.
'/core/lib'
,
'Drupal\Driver'
=>
DRUPAL_ROOT
.
'/drivers/lib'
,
));
// Register namespaces and PEAR-like prefixes for vendor libraries managed
...
...
core/includes/install.core.inc
View file @
466fac1e
...
...
@@ -1026,6 +1026,11 @@ function install_settings_form($form, &$form_state, &$install_state) {
function
install_settings_form_validate
(
$form
,
&
$form_state
)
{
$driver
=
$form_state
[
'values'
][
'driver'
];
$database
=
$form_state
[
'values'
][
$driver
];
$drivers
=
drupal_get_database_types
();
$reflection
=
new
\
ReflectionClass
(
$drivers
[
$driver
]);
$install_namespace
=
$reflection
->
getNamespaceName
();
// Cut the trailing \Install from namespace.
$database
[
'namespace'
]
=
substr
(
$install_namespace
,
0
,
strrpos
(
$install_namespace
,
'\\'
));
$database
[
'driver'
]
=
$driver
;
// TODO: remove when PIFR will be updated to use 'db_prefix' instead of
...
...
core/includes/install.inc
View file @
466fac1e
...
...
@@ -134,12 +134,18 @@ function drupal_get_database_types() {
// contains a database.inc file. That allows us to drop in additional drivers
// without modifying the installer.
require_once
DRUPAL_ROOT
.
'/core/includes/database.inc'
;
foreach
(
file_scan_directory
(
DRUPAL_ROOT
.
'/core/lib/Drupal/Core/Database/Driver'
,
'/^[a-z]*$/i'
,
array
(
'recurse'
=>
FALSE
))
as
$file
)
{
// Allow any valid PHP identifier.
// @see http://www.php.net/manual/en/language.variables.basics.php.
$mask
=
'/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$/'
;
$files
=
file_scan_directory
(
DRUPAL_ROOT
.
'/core/lib/Drupal/Core/Database/Driver'
,
$mask
,
array
(
'recurse'
=>
FALSE
));
if
(
is_dir
(
DRUPAL_ROOT
.
'/drivers/lib/Drupal/Driver/Database'
))
{
$files
+=
file_scan_directory
(
DRUPAL_ROOT
.
'/drivers/lib/Drupal/Driver/Database/'
,
$mask
,
array
(
'recurse'
=>
FALSE
));
}
foreach
(
$files
as
$file
)
{
if
(
file_exists
(
$file
->
uri
.
'/Install/Tasks.php'
))
{
$drivers
[
$file
->
filename
]
=
$file
->
uri
;
}
}
foreach
(
$drivers
as
$driver
=>
$file
)
{
$installer
=
db_installer_object
(
$driver
);
if
(
$installer
->
installable
())
{
...
...
@@ -954,5 +960,11 @@ function db_installer_object($driver) {
// We cannot use Database::getConnection->getDriverClass() here, because
// the connection object is not yet functional.
$task_class
=
"Drupal
\\
Core
\\
Database
\\
Driver
\\
{
$driver
}
\\
Install
\\
Tasks"
;
return
new
$task_class
();
if
(
class_exists
(
$task_class
))
{
return
new
$task_class
();
}
else
{
$task_class
=
"Drupal
\\
Driver
\\
Database
\\
{
$driver
}
\\
Install
\\
Tasks"
;
return
new
$task_class
();
}
}
core/lib/Drupal/Core/Database/Connection.php
View file @
466fac1e
...
...
@@ -620,7 +620,13 @@ protected function expandArguments(&$query, &$args) {
public
function
getDriverClass
(
$class
)
{
if
(
empty
(
$this
->
driverClasses
[
$class
]))
{
$driver
=
$this
->
driver
();
$driver_class
=
"Drupal
\\
Core
\\
Database
\\
Driver
\\
{
$driver
}
\\
{
$class
}
"
;
if
(
!
empty
(
$this
->
connectionOptions
[
'namespace'
]))
{
$driver_class
=
$this
->
connectionOptions
[
'namespace'
]
.
'\\'
.
$class
;
}
else
{
// Fallback for Drupal 7 settings.php.
$driver_class
=
"Drupal
\\
Core
\\
Database
\\
Driver
\\
{
$driver
}
\\
{
$class
}
"
;
}
$this
->
driverClasses
[
$class
]
=
class_exists
(
$driver_class
)
?
$driver_class
:
$class
;
}
return
$this
->
driverClasses
[
$class
];
...
...
core/lib/Drupal/Core/Database/Database.php
View file @
466fac1e
...
...
@@ -374,7 +374,13 @@ final protected static function openConnection($key, $target) {
throw
new
DriverNotSpecifiedException
(
'Driver not specified for this database connection: '
.
$key
);
}
$driver_class
=
"Drupal
\\
Core
\\
Database
\\
Driver
\\
{
$driver
}
\\
Connection"
;
if
(
!
empty
(
self
::
$databaseInfo
[
$key
][
$target
][
'namespace'
]))
{
$driver_class
=
self
::
$databaseInfo
[
$key
][
$target
][
'namespace'
]
.
'\\Connection'
;
}
else
{
// Fallback for Drupal 7 settings.php.
$driver_class
=
"Drupal
\\
Core
\\
Database
\\
Driver
\\
{
$driver
}
\\
Connection"
;
}
$new_connection
=
new
$driver_class
(
self
::
$databaseInfo
[
$key
][
$target
]);
$new_connection
->
setTarget
(
$target
);
$new_connection
->
setKey
(
$key
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment