Check for PDO instead of removed function for PHP 7 compatibility
This commit is contained in:
parent
4d672ded24
commit
e95bc68ac7
|
@ -89,7 +89,7 @@ class Setup {
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function class_exists($name) {
|
protected function class_exists($name) {
|
||||||
return class_exists($name);
|
return class_exists($name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,10 +98,19 @@ class Setup {
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function is_callable($name) {
|
protected function is_callable($name) {
|
||||||
return is_callable($name);
|
return is_callable($name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wrapper around \PDO::getAvailableDrivers
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
protected function getAvailableDbDriversForPdo() {
|
||||||
|
return \PDO::getAvailableDrivers();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the available and supported databases of this instance
|
* Get the available and supported databases of this instance
|
||||||
*
|
*
|
||||||
|
@ -117,8 +126,8 @@ class Setup {
|
||||||
'name' => 'SQLite'
|
'name' => 'SQLite'
|
||||||
),
|
),
|
||||||
'mysql' => array(
|
'mysql' => array(
|
||||||
'type' => 'function',
|
'type' => 'pdo',
|
||||||
'call' => 'mysql_connect',
|
'call' => 'mysql',
|
||||||
'name' => 'MySQL/MariaDB'
|
'name' => 'MySQL/MariaDB'
|
||||||
),
|
),
|
||||||
'pgsql' => array(
|
'pgsql' => array(
|
||||||
|
@ -147,10 +156,15 @@ class Setup {
|
||||||
foreach($configuredDatabases as $database) {
|
foreach($configuredDatabases as $database) {
|
||||||
if(array_key_exists($database, $availableDatabases)) {
|
if(array_key_exists($database, $availableDatabases)) {
|
||||||
$working = false;
|
$working = false;
|
||||||
if($availableDatabases[$database]['type'] === 'class') {
|
$type = $availableDatabases[$database]['type'];
|
||||||
$working = $this->class_exists($availableDatabases[$database]['call']);
|
$call = $availableDatabases[$database]['call'];
|
||||||
} elseif ($availableDatabases[$database]['type'] === 'function') {
|
|
||||||
$working = $this->is_callable($availableDatabases[$database]['call']);
|
if($type === 'class') {
|
||||||
|
$working = $this->class_exists($call);
|
||||||
|
} elseif ($type === 'function') {
|
||||||
|
$working = $this->is_callable($call);
|
||||||
|
} elseif($type === 'pdo') {
|
||||||
|
$working = in_array($call, $this->getAvailableDbDriversForPdo(), TRUE);
|
||||||
}
|
}
|
||||||
if($working) {
|
if($working) {
|
||||||
$supportedDatabases[$database] = $availableDatabases[$database]['name'];
|
$supportedDatabases[$database] = $availableDatabases[$database]['name'];
|
||||||
|
|
|
@ -35,7 +35,7 @@ class Test_OC_Setup extends \Test\TestCase {
|
||||||
$this->logger = $this->getMock('\OCP\ILogger');
|
$this->logger = $this->getMock('\OCP\ILogger');
|
||||||
$this->random = $this->getMock('\OCP\Security\ISecureRandom');
|
$this->random = $this->getMock('\OCP\Security\ISecureRandom');
|
||||||
$this->setupClass = $this->getMock('\OC\Setup',
|
$this->setupClass = $this->getMock('\OC\Setup',
|
||||||
['class_exists', 'is_callable'],
|
['class_exists', 'is_callable', 'getAvailableDbDriversForPdo'],
|
||||||
[$this->config, $this->iniWrapper, $this->l10n, $this->defaults, $this->logger, $this->random]);
|
[$this->config, $this->iniWrapper, $this->l10n, $this->defaults, $this->logger, $this->random]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,9 +51,13 @@ class Test_OC_Setup extends \Test\TestCase {
|
||||||
->method('class_exists')
|
->method('class_exists')
|
||||||
->will($this->returnValue(true));
|
->will($this->returnValue(true));
|
||||||
$this->setupClass
|
$this->setupClass
|
||||||
->expects($this->exactly(2))
|
->expects($this->once())
|
||||||
->method('is_callable')
|
->method('is_callable')
|
||||||
->will($this->returnValue(false));
|
->will($this->returnValue(false));
|
||||||
|
$this->setupClass
|
||||||
|
->expects($this->once())
|
||||||
|
->method('getAvailableDbDriversForPdo')
|
||||||
|
->will($this->returnValue([]));
|
||||||
$result = $this->setupClass->getSupportedDatabases();
|
$result = $this->setupClass->getSupportedDatabases();
|
||||||
$expectedResult = array(
|
$expectedResult = array(
|
||||||
'sqlite' => 'SQLite'
|
'sqlite' => 'SQLite'
|
||||||
|
@ -74,9 +78,13 @@ class Test_OC_Setup extends \Test\TestCase {
|
||||||
->method('class_exists')
|
->method('class_exists')
|
||||||
->will($this->returnValue(false));
|
->will($this->returnValue(false));
|
||||||
$this->setupClass
|
$this->setupClass
|
||||||
->expects($this->exactly(3))
|
->expects($this->exactly(2))
|
||||||
->method('is_callable')
|
->method('is_callable')
|
||||||
->will($this->returnValue(false));
|
->will($this->returnValue(false));
|
||||||
|
$this->setupClass
|
||||||
|
->expects($this->once())
|
||||||
|
->method('getAvailableDbDriversForPdo')
|
||||||
|
->will($this->returnValue([]));
|
||||||
$result = $this->setupClass->getSupportedDatabases();
|
$result = $this->setupClass->getSupportedDatabases();
|
||||||
|
|
||||||
$this->assertSame(array(), $result);
|
$this->assertSame(array(), $result);
|
||||||
|
@ -94,9 +102,13 @@ class Test_OC_Setup extends \Test\TestCase {
|
||||||
->method('class_exists')
|
->method('class_exists')
|
||||||
->will($this->returnValue(true));
|
->will($this->returnValue(true));
|
||||||
$this->setupClass
|
$this->setupClass
|
||||||
->expects($this->exactly(3))
|
->expects($this->exactly(2))
|
||||||
->method('is_callable')
|
->method('is_callable')
|
||||||
->will($this->returnValue(true));
|
->will($this->returnValue(true));
|
||||||
|
$this->setupClass
|
||||||
|
->expects($this->once())
|
||||||
|
->method('getAvailableDbDriversForPdo')
|
||||||
|
->will($this->returnValue(['mysql']));
|
||||||
$result = $this->setupClass->getSupportedDatabases();
|
$result = $this->setupClass->getSupportedDatabases();
|
||||||
$expectedResult = array(
|
$expectedResult = array(
|
||||||
'sqlite' => 'SQLite',
|
'sqlite' => 'SQLite',
|
||||||
|
|
Loading…
Reference in New Issue