Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
thePanz committed Jun 27, 2024
1 parent 76bbc85 commit 36f0816
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 36 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
#- "8.3"
services:
mysql:
image: mysql:5.7-debian
image: mysql:5.7.42-debian
env:
MYSQL_DATABASE: 'doctrine1_test'
MYSQL_USER: 'doctrine1'
Expand Down
36 changes: 15 additions & 21 deletions lib/Doctrine/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@
* @version $Revision$
* @author Konsta Vesterinen <[email protected]>
* @author Lukas Smith <[email protected]> (MDB2 library)
*
* @property Doctrine_Export $export
*/
abstract class Doctrine_Connection extends Doctrine_Configurable implements Countable, IteratorAggregate, Serializable
{
Expand Down Expand Up @@ -241,41 +243,31 @@ public function isConnected()
}

/**
* getOptions
*
* Get array of all options
*
* @return void
* @return array<string, mixed>
*/
public function getOptions()
{
return $this->options;
}

/**
* getOption
*
* Retrieves option
*
* @param string $option
* @return void
* @return null|mixed
*/
public function getOption($option)
public function getOption(string $option)
{
if (isset($this->options[$option])) {
return $this->options[$option];
}
}

/**
* setOption
*
* Set option value
*
* @param string $option
* @return void
* @return mixed
*/
public function setOption($option, $value)
public function setOption(string $option, $value)
{
return $this->options[$option] = $value;
}
Expand Down Expand Up @@ -1545,8 +1537,8 @@ public function dropDatabase()
* which is always guaranteed to exist. Mysql: 'mysql', PostgreSQL: 'postgres', etc.
* This value is set in the Doctrine_Export_{DRIVER} classes if required
*
* @param string $info
* @return void
* @param array $info
* @return Doctrine_Connection
*/
public function getTmpConnection($info)
{
Expand All @@ -1556,7 +1548,9 @@ public function getTmpConnection($info)
$pdoDsn .= 'unix_socket=' . $info['unix_socket'] . ';';
}

$pdoDsn .= 'host=' . $info['host'];
if ($info['host']) {
$pdoDsn .= 'host=' . $info['host'];
}

if ($info['port']) {
$pdoDsn .= ';port=' . $info['port'];
Expand All @@ -1566,10 +1560,10 @@ public function getTmpConnection($info)
$pdoDsn .= ';dbname=' . $this->export->tmpConnectionDatabase;
}

$username = $this->getOption('username');
$password = $this->getOption('password');
$username = $info['user'] ?: $this->getOption('username');
$password = $info['password'] ?: $this->getOption('password');

$conn = $this->getManager()->openConnection(array($pdoDsn, $username, $password), 'doctrine_tmp_connection', false);
$conn = $this->getManager()->openConnection([$pdoDsn, $username, $password], 'doctrine_tmp_connection', false);
$conn->setOption('username', $username);
$conn->setOption('password', $password);

Expand Down
40 changes: 26 additions & 14 deletions lib/Doctrine/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ public static function connection($adapter = null, $name = null)
/**
* Opens a new connection and saves it to Doctrine_Manager->connections
*
* @param PDO|Doctrine_Adapter_Interface $adapter database driver
* @param array|string|PDO|Doctrine_Adapter_Interface $adapter database driver
* @param string $name name of the connection, if empty numeric key is used
* @throws Doctrine_Manager_Exception if trying to bind a connection with an existing name
* @throws Doctrine_Manager_Exception if trying to open connection for unknown driver
Expand All @@ -292,17 +292,17 @@ public function openConnection($adapter, $name = null, $setCurrent = true)
if ( ! isset($adapter[0])) {
throw new Doctrine_Manager_Exception('Empty data source name given.');
}
$e = explode(':', $adapter[0]);
$schema = explode(':', $adapter[0]);

if ($e[0] == 'uri') {
$e[0] = 'odbc';
if ($schema[0] === 'uri') {
$schema[0] = 'odbc';
}

$parts['dsn'] = $adapter[0];
$parts['scheme'] = $e[0];
$parts['user'] = (isset($adapter[1])) ? $adapter[1] : null;
$parts['pass'] = (isset($adapter[2])) ? $adapter[2] : null;
$driverName = $e[0];
$parts['scheme'] = $schema[0];
$parts['user'] = $adapter[1] ?? null;
$parts['pass'] = $adapter[2] ?? null;
$driverName = $schema[0];
$adapter = $parts;
} else {
$parts = $this->parseDsn($adapter);
Expand All @@ -329,7 +329,7 @@ public function openConnection($adapter, $name = null, $setCurrent = true)
return $this->_connections[$name];
}
} else {
$name = $this->_index;
$name = (string) $this->_index;
$this->_index++;
}

Expand All @@ -352,11 +352,23 @@ public function openConnection($adapter, $name = null, $setCurrent = true)
/**
* Parse a pdo style dsn in to an array of parts
*
* @param array $dsn An array of dsn information
* @return array The array parsed
* @param string $dsn An array of dsn information
* @return array{
* dsn: string,
* scheme: string,
* host: ?string,
* user: ?string,
* pass: ?string,
* password: ?string,
* port: ?string,
* path: ?string,
* query: ?string,
* fragment: ?string,
* unix_socket: ?string,
* }
* @todo package:dbal
*/
public function parsePdoDsn($dsn)
public function parsePdoDsn($dsn): array
{
$parts = array();

Expand Down Expand Up @@ -401,7 +413,7 @@ public function parsePdoDsn($dsn)
* @param string $dsn
* @return array $parts
*/
protected function _buildDsnPartsArray($dsn)
protected function _buildDsnPartsArray(string $dsn)
{
// fix sqlite dsn so that it will parse correctly
$dsn = str_replace("////", "/", $dsn);
Expand Down Expand Up @@ -437,7 +449,7 @@ protected function _buildDsnPartsArray($dsn)
* @return array Parsed contents of DSN
* @todo package:dbal
*/
public function parseDsn($dsn)
public function parseDsn(string $dsn)
{
$parts = $this->_buildDsnPartsArray($dsn);

Expand Down
10 changes: 10 additions & 0 deletions tests/MigrationMysqlTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@
*/
class Doctrine_MigrationMysql_TestCase extends Doctrine_UnitTestCase
{
public function prepareTables()
{
$this->tables[] = 'MigrationPhonenumber';
$this->tables[] = 'MigrationUser';
$this->tables[] = 'MigrationProfile';
parent::prepareTables();
}

public function setUp()
{
parent::setUp();
Expand All @@ -41,6 +49,8 @@ public function setUp()
$this->connection->setOption('dsn', $dsn);
$this->connection->dropDatabase();
$this->connection->createDatabase();

$this->connection->export->exportClasses($this->tables);
}

public function testAfterSuccessfullMigrationItWillSetMigratedVersionAsCurrentVersionInMysqlDB()
Expand Down

0 comments on commit 36f0816

Please sign in to comment.