Merge pull request #968 from romainneutron/doctrine-connection

[3.9] Use Doctrine DBAL as connection
This commit is contained in:
Nicolas Le Goff
2014-02-24 12:15:03 +01:00
62 changed files with 438 additions and 620 deletions

View File

@@ -12,6 +12,7 @@
namespace Alchemy\Phrasea\Command\Setup; namespace Alchemy\Phrasea\Command\Setup;
use Alchemy\Phrasea\Command\Command; use Alchemy\Phrasea\Command\Command;
use Doctrine\DBAL\Connection;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
@@ -129,24 +130,36 @@ class Install extends Command
$abName = $dialog->ask($output, "DB name (phraseanet) : ", 'phraseanet'); $abName = $dialog->ask($output, "DB name (phraseanet) : ", 'phraseanet');
try { try {
$abConn = new \connection_pdo('appbox', $hostname, $port, $dbUser, $dbPassword, $abName, [], $this->container['debug']); $abConn = $this->container['dbal.provider']->get([
'host' => $hostname,
'port' => $port,
'user' => $dbUser,
'password' => $dbPassword,
'dbname' => $abName,
]);
$abConn->connect();
$output->writeln("\n\t<info>Application-Box : Connection successful !</info>\n"); $output->writeln("\n\t<info>Application-Box : Connection successful !</info>\n");
} catch (\Exception $e) { } catch (\Exception $e) {
$output->writeln("\n\t<error>Invalid connection parameters</error>\n"); $output->writeln("\n\t<error>Invalid connection parameters</error>\n");
} }
} while (!$abConn); } while (!$abConn);
} else { } else {
$abConn = new \connection_pdo('appbox', $input->getOption('db-host'), $input->getOption('db-port'), $input->getOption('db-user'), $input->getOption('db-password'), $input->getOption('appbox'), [], $this->container['debug']); $abConn = $this->container['dbal.provider']->get([
'host' => $input->getOption('db-host'),
'port' => $input->getOption('db-port'),
'user' => $input->getOption('db-user'),
'password' => $input->getOption('db-password'),
'dbname' => $input->getOption('appbox'),
]);
$abConn->connect();
$output->writeln("\n\t<info>Application-Box : Connection successful !</info>\n"); $output->writeln("\n\t<info>Application-Box : Connection successful !</info>\n");
} }
return $abConn; return $abConn;
} }
private function getDBConn(InputInterface $input, OutputInterface $output, \connection_pdo $abConn, DialogHelper $dialog) private function getDBConn(InputInterface $input, OutputInterface $output, Connection $abConn, DialogHelper $dialog)
{ {
$credentials = $abConn->get_credentials();
$dbConn = $template = null; $dbConn = $template = null;
if (!$input->getOption('databox')) { if (!$input->getOption('databox')) {
do { do {
@@ -155,7 +168,14 @@ class Install extends Command
if ($dbName) { if ($dbName) {
try { try {
$dbConn = new \connection_pdo('databox', $credentials['hostname'], $credentials['port'], $credentials['user'], $credentials['password'], $dbName, [], $this->container['debug']); $dbConn = $this->container['dbal.provider']->get([
'host' => $abConn->getHost(),
'port' => $abConn->getPort(),
'user' => $abConn->getUsername(),
'password' => $abConn->getPassword(),
'dbname' => $dbName,
]);
$dbConn->connect();
$output->writeln("\n\t<info>Data-Box : Connection successful !</info>\n"); $output->writeln("\n\t<info>Data-Box : Connection successful !</info>\n");
do { do {
@@ -171,7 +191,14 @@ class Install extends Command
} }
} while ($retry); } while ($retry);
} else { } else {
$dbConn = new \connection_pdo('databox', $input->getOption('db-host'), $input->getOption('db-port'), $input->getOption('db-user'), $input->getOption('db-password'), $input->getOption('databox'), [], $this->container['debug']); $dbConn = $this->container['dbal.provider']->get([
'host' => $input->getOption('db-host'),
'port' => $input->getOption('db-port'),
'user' => $input->getOption('db-user'),
'password' => $input->getOption('db-password'),
'dbname' => $input->getOption('databox'),
]);
$dbConn->connect();
$output->writeln("\n\t<info>Data-Box : Connection successful !</info>\n"); $output->writeln("\n\t<info>Data-Box : Connection successful !</info>\n");
$template = $input->getOption('db-template') ? : 'en'; $template = $input->getOption('db-template') ? : 'en';
} }

View File

@@ -11,6 +11,7 @@
namespace Alchemy\Phrasea\Controller\Admin; namespace Alchemy\Phrasea\Controller\Admin;
use Doctrine\DBAL\DBALException;
use Silex\Application; use Silex\Application;
use Silex\ControllerProviderInterface; use Silex\ControllerProviderInterface;
use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\RedirectResponse;
@@ -78,7 +79,7 @@ class Databoxes implements ControllerProviderInterface
$sbas[$sbasId] = [ $sbas[$sbasId] = [
'version' => $databox->get_version(), 'version' => $databox->get_version(),
'image' => '/skins/icons/foldph20close_0.gif', 'image' => '/skins/icons/foldph20close_0.gif',
'server_info' => $databox->get_connection()->server_info(), 'server_info' => $databox->get_connection()->getWrappedConnection()->getAttribute(\PDO::ATTR_SERVER_VERSION),
'name' => \phrasea::sbas_labels($sbasId, $app) 'name' => \phrasea::sbas_labels($sbasId, $app)
]; ];
} catch (\Exception $e) { } catch (\Exception $e) {
@@ -157,8 +158,15 @@ class Databoxes implements ControllerProviderInterface
$dataTemplate = new \SplFileInfo($app['root.path'] . '/lib/conf.d/data_templates/' . $dataTemplate . '.xml'); $dataTemplate = new \SplFileInfo($app['root.path'] . '/lib/conf.d/data_templates/' . $dataTemplate . '.xml');
try { try {
$connbas = new \connection_pdo('databox_creation', $hostname, $port, $user, $password, $dbName, [], $app['debug']); $connbas = $app['dbal.provider']->get([
} catch (\PDOException $e) { 'host' => $hostname,
'port' => $port,
'user' => $user,
'password' => $password,
'dbname' => $dbName,
]);
$connbas->connect();
} catch (DBALException $e) {
return $app->redirectPath('admin_databases', ['success' => 0, 'error' => 'database-failed']); return $app->redirectPath('admin_databases', ['success' => 0, 'error' => 'database-failed']);
} }
@@ -183,7 +191,14 @@ class Databoxes implements ControllerProviderInterface
try { try {
$data_template = new \SplFileInfo($app['root.path'] . '/lib/conf.d/data_templates/' . $dataTemplate . '.xml'); $data_template = new \SplFileInfo($app['root.path'] . '/lib/conf.d/data_templates/' . $dataTemplate . '.xml');
$connbas = new \connection_pdo('databox_creation', $hostname, $port, $userDb, $passwordDb, $dbName, [], $app['debug']); $connbas = $app['dbal.provider']->get([
'host' => $hostname,
'port' => $port,
'user' => $userDb,
'password' => $passwordDb,
'dbname' => $dbName,
]);
$connbas->connect();
try { try {
$base = \databox::create($app, $connbas, $data_template); $base = \databox::create($app, $connbas, $data_template);
$base->registerAdmin($app['authentication']->getUser()); $base->registerAdmin($app['authentication']->getUser());

View File

@@ -18,6 +18,7 @@ use Alchemy\Phrasea\Setup\Requirements\LocalesRequirements;
use Alchemy\Phrasea\Setup\Requirements\PhpRequirements; use Alchemy\Phrasea\Setup\Requirements\PhpRequirements;
use Alchemy\Phrasea\Setup\Requirements\PhraseaRequirements; use Alchemy\Phrasea\Setup\Requirements\PhraseaRequirements;
use Alchemy\Phrasea\Setup\Requirements\SystemRequirements; use Alchemy\Phrasea\Setup\Requirements\SystemRequirements;
use Doctrine\DBAL\Connection;
use Silex\ControllerProviderInterface; use Silex\ControllerProviderInterface;
use Silex\Application as SilexApplication; use Silex\Application as SilexApplication;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
@@ -128,7 +129,14 @@ class Setup implements ControllerProviderInterface
$databox_name = $request->request->get('db_name'); $databox_name = $request->request->get('db_name');
try { try {
$abConn = new \connection_pdo('appbox', $hostname, $port, $user_ab, $ab_password, $appbox_name, [], $app['debug']); $abConn = $app['dbal.provider']->get([
'host' => $hostname,
'port' => $port,
'user' => $user_ab,
'password' => $ab_password,
'dbname' => $appbox_name,
]);
$abConn->connect();
} catch (\Exception $e) { } catch (\Exception $e) {
return $app->redirectPath('install_step2', [ return $app->redirectPath('install_step2', [
'error' => $app->trans('Appbox is unreachable'), 'error' => $app->trans('Appbox is unreachable'),
@@ -137,7 +145,14 @@ class Setup implements ControllerProviderInterface
try { try {
if ($databox_name) { if ($databox_name) {
$dbConn = new \connection_pdo('databox', $hostname, $port, $user_ab, $ab_password, $databox_name, [], $app['debug']); $dbConn = $app['dbal.provider']->get([
'host' => $hostname,
'port' => $port,
'user' => $user_ab,
'password' => $ab_password,
'dbname' => $databox_name,
]);
$dbConn->connect();
} }
} catch (\Exception $e) { } catch (\Exception $e) {
return $app->redirectPath('install_step2', [ return $app->redirectPath('install_step2', [

View File

@@ -11,6 +11,7 @@
namespace Alchemy\Phrasea\Controller\Thesaurus; namespace Alchemy\Phrasea\Controller\Thesaurus;
use Doctrine\DBAL\Connection;
use Silex\Application; use Silex\Application;
use Silex\ControllerProviderInterface; use Silex\ControllerProviderInterface;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
@@ -133,7 +134,7 @@ class Thesaurus implements ControllerProviderInterface
if ($request->get("typ") == "TH" || $request->get("typ") == "CT") { if ($request->get("typ") == "TH" || $request->get("typ") == "CT") {
try { try {
$databox = $app['phraseanet.appbox']->get_databox((int) $bid); $databox = $app['phraseanet.appbox']->get_databox((int) $bid);
$connbas = \connection::getPDOConnection($app, $bid); $databox->get_connection();
if ($request->get("typ") == "TH") { if ($request->get("typ") == "TH") {
$domth = $databox->get_dom_thesaurus(); $domth = $databox->get_dom_thesaurus();
@@ -576,7 +577,7 @@ class Thesaurus implements ControllerProviderInterface
try { try {
$databox = $app['phraseanet.appbox']->get_databox((int) $bid); $databox = $app['phraseanet.appbox']->get_databox((int) $bid);
$connbas = \connection::getPDOConnection($app, $bid); $connbas = $databox->get_connection();
$dom = $databox->get_dom_thesaurus(); $dom = $databox->get_dom_thesaurus();
@@ -783,7 +784,7 @@ class Thesaurus implements ControllerProviderInterface
foreach ($rs as $row) { foreach ($rs as $row) {
try { try {
\connection::getPDOConnection($app, $row['sbas_id']); $app['phraseanet.appbox']->get_databox($row['sbas_id'])->get_connection()->connect();
} catch (\Exception $e) { } catch (\Exception $e) {
continue; continue;
} }
@@ -956,7 +957,7 @@ class Thesaurus implements ControllerProviderInterface
try { try {
$databox = $app['phraseanet.appbox']->get_databox((int) $bid); $databox = $app['phraseanet.appbox']->get_databox((int) $bid);
$connbas = \connection::getPDOConnection($app, $bid); $connbas = $databox->get_connection();
$meta_struct = $databox->get_meta_structure(); $meta_struct = $databox->get_meta_structure();
$domct = $databox->get_dom_cterms(); $domct = $databox->get_dom_cterms();
$domst = $databox->get_dom_structure(); $domst = $databox->get_dom_structure();
@@ -1029,7 +1030,7 @@ class Thesaurus implements ControllerProviderInterface
]); ]);
} }
private function fixThesaurus($app, \DOMDocument $domct, \DOMDocument $domth, \connection_interface $connbas) private function fixThesaurus($app, \DOMDocument $domct, \DOMDocument $domth, Connection $connbas)
{ {
$version = $domth->documentElement->getAttribute("version"); $version = $domth->documentElement->getAttribute("version");
@@ -1064,7 +1065,7 @@ class Thesaurus implements ControllerProviderInterface
try { try {
$databox = $app['phraseanet.appbox']->get_databox((int) $request->get('bid')); $databox = $app['phraseanet.appbox']->get_databox((int) $request->get('bid'));
$connbas = \connection::getPDOConnection($app, $request->get('bid')); $connbas = $databox->get_connection();
$domct = $databox->get_dom_cterms(); $domct = $databox->get_dom_cterms();
$domth = $databox->get_dom_thesaurus(); $domth = $databox->get_dom_thesaurus();
@@ -1261,7 +1262,7 @@ class Thesaurus implements ControllerProviderInterface
try { try {
$databox = $app['phraseanet.appbox']->get_databox((int) $bid); $databox = $app['phraseanet.appbox']->get_databox((int) $bid);
\connection::getPDOConnection($app, $bid); $databox->get_connection()->connect();
$dom = $databox->get_dom_cterms(); $dom = $databox->get_dom_cterms();
$xpath = new \DOMXPath($dom); $xpath = new \DOMXPath($dom);
@@ -1295,7 +1296,8 @@ class Thesaurus implements ControllerProviderInterface
$sql = "UPDATE thit SET value = thit_new WHERE value = :thit_old"; $sql = "UPDATE thit SET value = thit_new WHERE value = :thit_old";
try { try {
$connbas = \connection::getPDOConnection($app, $sbas_id); $databox = $app['phraseanet.appbox']->get_databox($sbas_id);
$connbas = $databox->get_connection();
$stmt = $connbas->prepare($sql); $stmt = $connbas->prepare($sql);
$stmt->execute([ $stmt->execute([
':thit_new' => $thit_newid, ':thit_new' => $thit_newid,
@@ -1336,7 +1338,7 @@ class Thesaurus implements ControllerProviderInterface
try { try {
$databox = $app['phraseanet.appbox']->get_databox((int) $bid); $databox = $app['phraseanet.appbox']->get_databox((int) $bid);
$connbas = \connection::getPDOConnection($app, $bid); $connbas = $databox->get_connection();
$domct = $databox->get_dom_cterms(); $domct = $databox->get_dom_cterms();
$domth = $databox->get_dom_thesaurus(); $domth = $databox->get_dom_thesaurus();
@@ -1635,7 +1637,7 @@ class Thesaurus implements ControllerProviderInterface
try { try {
$databox = $app['phraseanet.appbox']->get_databox((int) $bid); $databox = $app['phraseanet.appbox']->get_databox((int) $bid);
$connbas = \connection::getPDOConnection($app, $bid); $connbas = $databox->get_connection();
$s_thits = ''; $s_thits = '';
$sql = "SELECT DISTINCT value FROM thit"; $sql = "SELECT DISTINCT value FROM thit";
@@ -1729,8 +1731,8 @@ class Thesaurus implements ControllerProviderInterface
} }
try { try {
$connbas = \connection::getPDOConnection($app, $bid);
$databox = $app['phraseanet.appbox']->get_databox((int) $bid); $databox = $app['phraseanet.appbox']->get_databox((int) $bid);
$connbas = $databox->get_connection();
$domct = $databox->get_dom_cterms(); $domct = $databox->get_dom_cterms();
$dom = $databox->get_dom_thesaurus(); $dom = $databox->get_dom_thesaurus();
@@ -1912,7 +1914,7 @@ class Thesaurus implements ControllerProviderInterface
$snewid = str_replace(".", "d", $newid) . "d"; $snewid = str_replace(".", "d", $newid) . "d";
$l = strlen($soldid) + 1; $l = strlen($soldid) + 1;
$connbas = \connection::getPDOConnection($app, $bid); $connbas = $databox->get_connection();
$sql = "UPDATE thit SET value=CONCAT('$snewid', SUBSTRING(value FROM $l)) $sql = "UPDATE thit SET value=CONCAT('$snewid', SUBSTRING(value FROM $l))
WHERE value LIKE :like"; WHERE value LIKE :like";
@@ -2050,7 +2052,7 @@ class Thesaurus implements ControllerProviderInterface
try { try {
$databox = $app['phraseanet.appbox']->get_databox((int) $bid); $databox = $app['phraseanet.appbox']->get_databox((int) $bid);
$connbas = \connection::getPDOConnection($app, $bid); $connbas = $databox->get_connection();
if ($request->get('typ') == "CT") { if ($request->get('typ') == "CT") {
$xqroot = "cterms"; $xqroot = "cterms";
@@ -2448,7 +2450,7 @@ class Thesaurus implements ControllerProviderInterface
try { try {
$databox = $app['phraseanet.appbox']->get_databox((int) $bid); $databox = $app['phraseanet.appbox']->get_databox((int) $bid);
$connbas = \connection::getPDOConnection($app, $bid); $connbas = $databox->get_connection();
if ($request->get('typ') == "CT") { if ($request->get('typ') == "CT") {
$xqroot = "cterms"; $xqroot = "cterms";
@@ -2633,8 +2635,8 @@ class Thesaurus implements ControllerProviderInterface
} }
try { try {
$connbas = \connection::getPDOConnection($app, $bid);
$databox = $app['phraseanet.appbox']->get_databox((int) $bid); $databox = $app['phraseanet.appbox']->get_databox((int) $bid);
$connbas = $databox->get_connection();
$domth = $databox->get_dom_thesaurus(); $domth = $databox->get_dom_thesaurus();
if ($domth) { if ($domth) {
@@ -2862,7 +2864,7 @@ class Thesaurus implements ControllerProviderInterface
try { try {
$databox = $app['phraseanet.appbox']->get_databox((int) $bid); $databox = $app['phraseanet.appbox']->get_databox((int) $bid);
$connbas = \connection::getPDOConnection($app, $bid); $connbas = $databox->get_connection();
$dom = $databox->get_dom_cterms(); $dom = $databox->get_dom_cterms();
@@ -2888,7 +2890,7 @@ class Thesaurus implements ControllerProviderInterface
return new Response($ret->saveXML(), 200, ['Content-Type' => 'text/xml']); return new Response($ret->saveXML(), 200, ['Content-Type' => 'text/xml']);
} }
private function doRejectBranch(\connection_pdo $connbas, \DOMElement $node) private function doRejectBranch(Connection $connbas, \DOMElement $node)
{ {
if (strlen($oldid = $node->getAttribute("id")) > 1) { if (strlen($oldid = $node->getAttribute("id")) > 1) {
$node->setAttribute("id", $newid = ("R" . substr($oldid, 1))); $node->setAttribute("id", $newid = ("R" . substr($oldid, 1)));
@@ -3053,7 +3055,7 @@ class Thesaurus implements ControllerProviderInterface
try { try {
$databox = $app['phraseanet.appbox']->get_databox((int) $bid); $databox = $app['phraseanet.appbox']->get_databox((int) $bid);
$connbas = \connection::getPDOConnection($app, $bid); $connbas = $databox->get_connection();
$s_thits = ';'; $s_thits = ';';
$sql = "SELECT DISTINCT value FROM thit"; $sql = "SELECT DISTINCT value FROM thit";

View File

@@ -445,7 +445,7 @@ class Xmlhttp implements ControllerProviderInterface
private function getPresetHTMLList(Application $app, $sbas_id, $usr_id) private function getPresetHTMLList(Application $app, $sbas_id, $usr_id)
{ {
$conn = \connection::getPDOConnection($app); $conn = $app['phraseanet.appbox']->get_connection();
$html = ''; $html = '';
$sql = 'SELECT edit_preset_id, creation_date, title, xml $sql = 'SELECT edit_preset_id, creation_date, title, xml
@@ -827,7 +827,8 @@ class Xmlhttp implements ControllerProviderInterface
$thid = implode('.', $tids); $thid = implode('.', $tids);
try { try {
$connbas = \connection::getPDOConnection($app, $sbid); $databox = $app['phraseanet.appbox']->get_databox($sbid);
$connbas = $databox->get_connection();
$dbname = \phrasea::sbas_labels($sbid, $app); $dbname = \phrasea::sbas_labels($sbid, $app);
$t_nrec = []; $t_nrec = [];

View File

@@ -37,7 +37,13 @@ class ConnectionTest implements ControllerProviderInterface
$connection_ok = $db_ok = $is_databox = $is_appbox = $empty = false; $connection_ok = $db_ok = $is_databox = $is_appbox = $empty = false;
try { try {
$conn = new \connection_pdo('test', $hostname, $port, $user, $password, null, [], false); $conn = $app['dbal.provider']->get([
'host' => $hostname,
'port' => $port,
'user' => $user,
'password' => $password,
]);
$conn->connect();
$connection_ok = true; $connection_ok = true;
} catch (\Exception $e) { } catch (\Exception $e) {
@@ -45,7 +51,14 @@ class ConnectionTest implements ControllerProviderInterface
if ($dbname && $connection_ok === true) { if ($dbname && $connection_ok === true) {
try { try {
$conn = new \connection_pdo('test', $hostname, $port, $user, $password, $dbname, [], false); $conn = $app['dbal.provider']->get([
'host' => $hostname,
'port' => $port,
'user' => $user,
'password' => $password,
'dbname' => $dbname,
]);
$conn->connect();
$db_ok = true; $db_ok = true;
$sql = "SHOW TABLE STATUS"; $sql = "SHOW TABLE STATUS";

View File

@@ -0,0 +1,64 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2014 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\Core\Connection;
use Doctrine\Common\EventManager;
use Doctrine\DBAL\Configuration;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\DriverManager;
class ConnectionProvider
{
private $config;
/**
* @var Connection[]
*/
private $connections = [];
private $eventManager;
public function __construct(Configuration $config, EventManager $eventManager)
{
$this->config = $config;
$this->eventManager = $eventManager;
}
public function __destruct()
{
foreach ($this->connections as $conn) {
$conn->close();
}
$this->connections = [];
}
/**
* @param $params
*
* @return Connection
*/
public function get(array $params)
{
$params = array_replace([
'driver' => 'pdo_mysql',
'charset' => 'UTF8',
], $params);
$key = md5(serialize($params));
if (isset($this->connections[$key])) {
return $this->connections[$key];
}
return $this->connections[$key] = DriverManager::getConnection($params, $this->config, $this->eventManager);;
}
}

View File

@@ -11,6 +11,9 @@
namespace Alchemy\Phrasea\Core\Provider; namespace Alchemy\Phrasea\Core\Provider;
use Alchemy\Phrasea\Application as PhraseaApplication;
use Alchemy\Phrasea\Cache\ArrayCache;
use Alchemy\Phrasea\Core\Connection\ConnectionProvider;
use Alchemy\Phrasea\Exception\RuntimeException; use Alchemy\Phrasea\Exception\RuntimeException;
use Alchemy\Phrasea\Model\MonologSQLLogger; use Alchemy\Phrasea\Model\MonologSQLLogger;
use Alchemy\Phrasea\Model\NativeQueryProvider; use Alchemy\Phrasea\Model\NativeQueryProvider;
@@ -75,7 +78,7 @@ class ORMServiceProvider implements ServiceProviderInterface
$app['EM.config'] = $app->share(function (Application $app) { $app['EM.config'] = $app->share(function (Application $app) {
$config = new ORMConfiguration(); $config = new ORMConfiguration();
if ($app['debug']) { if ($app->getEnvironment() === PhraseaApplication::ENV_DEV) {
$config->setSQLLogger($app['EM.sql-logger']); $config->setSQLLogger($app['EM.sql-logger']);
} }
@@ -103,17 +106,33 @@ class ORMServiceProvider implements ServiceProviderInterface
}); });
$app['EM.opcode-cache-type'] = $app->share(function (Application $app) { $app['EM.opcode-cache-type'] = $app->share(function (Application $app) {
if ($app['configuration.store']->isSetup()) {
return $app['conf']->get(['main', 'opcodecache', 'type']); return $app['conf']->get(['main', 'opcodecache', 'type']);
}
return 'ArrayCache';
}); });
$app['EM.opcode-cache-options'] = $app->share(function (Application $app) { $app['EM.opcode-cache-options'] = $app->share(function (Application $app) {
if ($app['configuration.store']->isSetup()) {
return $app['conf']->get(['main', 'opcodecache', 'options']); return $app['conf']->get(['main', 'opcodecache', 'options']);
}
return [];
}); });
$app['EM.cache-type'] = $app->share(function (Application $app) { $app['EM.cache-type'] = $app->share(function (Application $app) {
if ($app['configuration.store']->isSetup()) {
return $app['conf']->get(['main', 'cache', 'type']); return $app['conf']->get(['main', 'cache', 'type']);
}
return 'ArrayCache';
}); });
$app['EM.cache-options'] = $app->share(function (Application $app) { $app['EM.cache-options'] = $app->share(function (Application $app) {
if ($app['configuration.store']->isSetup()) {
return $app['conf']->get(['main', 'cache', 'options']); return $app['conf']->get(['main', 'cache', 'options']);
}
return [];
}); });
$app['EM.events-manager'] = $app->share(function (Application $app) { $app['EM.events-manager'] = $app->share(function (Application $app) {
$evm = new EventManager(); $evm = new EventManager();
@@ -130,6 +149,10 @@ class ORMServiceProvider implements ServiceProviderInterface
return $app['conf']->get(['main', 'database']); return $app['conf']->get(['main', 'database']);
}); });
$app['dbal.provider'] = $app->share(function (Application $app) {
return new ConnectionProvider($app['EM.config'], $app['EM.events-manager']);
});
$app['EM'] = $app->share(function (Application $app) { $app['EM'] = $app->share(function (Application $app) {
try { try {
$em = EntityManager::create($app['EM.dbal-conf'], $app['EM.config'], $app['EM.events-manager']); $em = EntityManager::create($app['EM.dbal-conf'], $app['EM.config'], $app['EM.events-manager']);

View File

@@ -196,7 +196,7 @@ class Edit extends \Alchemy\Phrasea\Helper\Helper
WHERE (u.id = " . implode(' OR u.id = ', $this->users) . ") WHERE (u.id = " . implode(' OR u.id = ', $this->users) . ")
AND bu.base_id = :base_id"; AND bu.base_id = :base_id";
$conn = \connection::getPDOConnection($this->app); $conn = $this->app['phraseanet.appbox']->get_connection();
$stmt = $conn->prepare($sql); $stmt = $conn->prepare($sql);
$stmt->execute([':base_id' => $this->base_id]); $stmt->execute([':base_id' => $this->base_id]);
$rs = $stmt->fetchAll(\PDO::FETCH_ASSOC); $rs = $stmt->fetchAll(\PDO::FETCH_ASSOC);
@@ -319,7 +319,7 @@ class Edit extends \Alchemy\Phrasea\Helper\Helper
WHERE (u.id = " . implode(' OR u.id = ', $this->users) . ") WHERE (u.id = " . implode(' OR u.id = ', $this->users) . ")
AND bu.base_id = :base_id"; AND bu.base_id = :base_id";
$conn = \connection::getPDOConnection($this->app); $conn = $this->app['phraseanet.appbox']->get_connection();
$stmt = $conn->prepare($sql); $stmt = $conn->prepare($sql);
$stmt->execute([':base_id' => $this->base_id]); $stmt->execute([':base_id' => $this->base_id]);
$rs = $stmt->fetchAll(\PDO::FETCH_ASSOC); $rs = $stmt->fetchAll(\PDO::FETCH_ASSOC);
@@ -375,7 +375,7 @@ class Edit extends \Alchemy\Phrasea\Helper\Helper
WHERE (u.id = " . implode(' OR u.id = ', $this->users) . ") WHERE (u.id = " . implode(' OR u.id = ', $this->users) . ")
AND b.sbas_id = :sbas_id"; AND b.sbas_id = :sbas_id";
$conn = \connection::getPDOConnection($this->app); $conn = $this->app['phraseanet.appbox']->get_connection();
$stmt = $conn->prepare($sql); $stmt = $conn->prepare($sql);
$stmt->execute([':sbas_id' => $sbas_id]); $stmt->execute([':sbas_id' => $sbas_id]);
$rs = $stmt->fetchAll(\PDO::FETCH_ASSOC); $rs = $stmt->fetchAll(\PDO::FETCH_ASSOC);

View File

@@ -14,6 +14,7 @@ namespace Alchemy\Phrasea\Model\Manager;
use Doctrine\Common\Persistence\ObjectManager; use Doctrine\Common\Persistence\ObjectManager;
use Alchemy\Phrasea\Model\Entities\User; use Alchemy\Phrasea\Model\Entities\User;
use Alchemy\Phrasea\Model\Entities\UserSetting; use Alchemy\Phrasea\Model\Entities\UserSetting;
use Doctrine\DBAL\Connection;
use Doctrine\ORM\UnitOfWork AS UOW; use Doctrine\ORM\UnitOfWork AS UOW;
class UserManager class UserManager
@@ -23,7 +24,7 @@ class UserManager
/** @var \PDO */ /** @var \PDO */
protected $appboxConnection; protected $appboxConnection;
public function __construct(ObjectManager $om, \PDO $appboxConnection) public function __construct(ObjectManager $om, Connection $appboxConnection)
{ {
$this->objectManager = $om; $this->objectManager = $om;
$this->appboxConnection = $appboxConnection; $this->appboxConnection = $appboxConnection;

View File

@@ -12,6 +12,8 @@
namespace Alchemy\Phrasea\Setup; namespace Alchemy\Phrasea\Setup;
use Alchemy\Phrasea\Application; use Alchemy\Phrasea\Application;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\DBALException;
use Doctrine\ORM\Tools\SchemaTool; use Doctrine\ORM\Tools\SchemaTool;
use Alchemy\Phrasea\Model\Entities\User; use Alchemy\Phrasea\Model\Entities\User;
@@ -25,7 +27,7 @@ class Installer
$this->app = $app; $this->app = $app;
} }
public function install($email, $password, \connection_interface $abConn, $serverName, $dataPath, \connection_interface $dbConn = null, $template = null, array $binaryData = []) public function install($email, $password, Connection $abConn, $serverName, $dataPath, Connection $dbConn = null, $template = null, array $binaryData = [])
{ {
$this->rollbackInstall($abConn, $dbConn); $this->rollbackInstall($abConn, $dbConn);
@@ -65,7 +67,7 @@ class Installer
$this->app['conf']->set('registry', $this->app['registry.manipulator']->getRegistryData()); $this->app['conf']->set('registry', $this->app['registry.manipulator']->getRegistryData());
} }
private function createDB(\connection_interface $dbConn = null, $template) private function createDB(Connection $dbConn = null, $template)
{ {
$template = new \SplFileInfo(__DIR__ . '/../../../conf.d/data_templates/' . $template . '-simple.xml'); $template = new \SplFileInfo(__DIR__ . '/../../../conf.d/data_templates/' . $template . '-simple.xml');
$databox = \databox::create($this->app, $dbConn, $template); $databox = \databox::create($this->app, $dbConn, $template);
@@ -115,7 +117,7 @@ class Installer
$this->app['manipulator.user']->createUser(User::USER_GUEST, User::USER_GUEST); $this->app['manipulator.user']->createUser(User::USER_GUEST, User::USER_GUEST);
} }
private function rollbackInstall(\connection_interface $abConn, \connection_interface $dbConn = null) private function rollbackInstall(Connection $abConn, Connection $dbConn = null)
{ {
$structure = simplexml_load_file(__DIR__ . "/../../../conf.d/bases_structure.xml"); $structure = simplexml_load_file(__DIR__ . "/../../../conf.d/bases_structure.xml");
@@ -132,7 +134,7 @@ class Installer
$stmt = $abConn->prepare($sql); $stmt = $abConn->prepare($sql);
$stmt->execute(); $stmt->execute();
$stmt->closeCursor(); $stmt->closeCursor();
} catch (\PDOException $e) { } catch (DBALException $e) {
} }
} }
@@ -143,7 +145,7 @@ class Installer
$stmt = $dbConn->prepare($sql); $stmt = $dbConn->prepare($sql);
$stmt->execute(); $stmt->execute();
$stmt->closeCursor(); $stmt->closeCursor();
} catch (\PDOException $e) { } catch (DBALException $e) {
} }
} }
@@ -169,14 +171,15 @@ class Installer
$this->app['phraseanet.appbox']->insert_datas($this->app); $this->app['phraseanet.appbox']->insert_datas($this->app);
} }
private function createConfigFile($abConn, $serverName, $binaryData) private function createConfigFile(Connection $abConn, $serverName, $binaryData)
{ {
$config = $this->app['configuration.store']->initialize(); $config = $this->app['configuration.store']->initialize();
foreach ($abConn->get_credentials() as $key => $value) { $config['main']['database']['host'] = $abConn->getHost();
$key = $key == 'hostname' ? 'host' : $key; $config['main']['database']['port'] = $abConn->getPort();
$config['main']['database'][$key] = (string) $value; $config['main']['database']['user'] = $abConn->getUsername();
} $config['main']['database']['password'] = $abConn->getPassword();
$config['main']['database']['dbname'] = $abConn->getDatabase();
$config['main']['database']['driver'] = 'pdo_mysql'; $config['main']['database']['driver'] = 'pdo_mysql';
$config['main']['database']['charset'] = 'UTF8'; $config['main']['database']['charset'] = 'UTF8';

View File

@@ -324,7 +324,8 @@ class RecordMoverJob extends AbstractJob
private function playTest(Application $app, $sbas_id, $sql) private function playTest(Application $app, $sbas_id, $sql)
{ {
$connbas = \connection::getPDOConnection($app, $sbas_id); $databox = $app['phraseanet.appbox']->get_databox($sbas_id);
$connbas = $databox->get_connection();
$result = ['rids' => [], 'err' => '', 'n' => null]; $result = ['rids' => [], 'err' => '', 'n' => null];
$result['n'] = $connbas->query('SELECT COUNT(*) AS n FROM (' . $sql . ') AS x')->fetchColumn(); $result['n'] = $connbas->query('SELECT COUNT(*) AS n FROM (' . $sql . ') AS x')->fetchColumn();
@@ -344,7 +345,8 @@ class RecordMoverJob extends AbstractJob
private function calcWhere(Application $app, $sbas_id, &$sxtask) private function calcWhere(Application $app, $sbas_id, &$sxtask)
{ {
$connbas = \connection::getPDOConnection($app, $sbas_id); $databox = $app['phraseanet.appbox']->get_databox($sbas_id);
$connbas = $databox->get_connection();
$tw = []; $tw = [];
$join = ''; $join = '';

View File

@@ -224,7 +224,8 @@ class Session_Logger
try { try {
$logger = $app['phraseanet.logger']($app['phraseanet.appbox']->get_databox($sbas_id)); $logger = $app['phraseanet.logger']($app['phraseanet.appbox']->get_databox($sbas_id));
$connbas = connection::getPDOConnection($app, $sbas_id); $databox = $app['phraseanet.appbox']->get_databox($sbas_id);
$connbas = $databox->get_connection();
$sql = 'SELECT appli FROM log WHERE id = :log_id'; $sql = 'SELECT appli FROM log WHERE id = :log_id';
$stmt = $connbas->prepare($sql); $stmt = $connbas->prepare($sql);
$stmt->execute([':log_id' => $logger->get_id()]); $stmt->execute([':log_id' => $logger->get_id()]);

View File

@@ -54,8 +54,8 @@ class appbox extends base
public function __construct(Application $app) public function __construct(Application $app)
{ {
$this->app = $app; $this->app = $app;
$this->connection = connection::getPDOConnection($app);
$connexion = $app['conf']->get(['main', 'database']); $connexion = $app['conf']->get(['main', 'database']);
$this->connection = $app['dbal.provider']->get($connexion);
$this->host = $connexion['host']; $this->host = $connexion['host'];
$this->port = $connexion['port']; $this->port = $connexion['port'];

View File

@@ -13,6 +13,7 @@ use Alchemy\Phrasea\Application;
use Alchemy\Phrasea\Core\Version as PhraseaVersion; use Alchemy\Phrasea\Core\Version as PhraseaVersion;
use vierbergenlars\SemVer\version; use vierbergenlars\SemVer\version;
use Alchemy\Phrasea\Model\Entities\User; use Alchemy\Phrasea\Model\Entities\User;
use Doctrine\DBAL\Connection;
abstract class base implements cache_cacheableInterface abstract class base implements cache_cacheableInterface
{ {
@@ -137,7 +138,7 @@ abstract class base implements cache_cacheableInterface
/** /**
* *
* @return connection_pdo * @return Connection
*/ */
public function get_connection() public function get_connection()
{ {

View File

@@ -52,7 +52,7 @@ class cache_databox
return; return;
} }
$connsbas = \connection::getPDOConnection($app, $sbas_id); $connsbas = $databox->get_connection();
$sql = 'SELECT type, value FROM memcached WHERE site_id = :site_id'; $sql = 'SELECT type, value FROM memcached WHERE site_id = :site_id';
$stmt = $connsbas->prepare($sql); $stmt = $connsbas->prepare($sql);
@@ -124,7 +124,7 @@ class cache_databox
$app['phraseanet.appbox']->set_data_to_cache($now, 'memcached_update_' . $sbas_id); $app['phraseanet.appbox']->set_data_to_cache($now, 'memcached_update_' . $sbas_id);
$conn = \connection::getPDOConnection($app); $conn = $app['phraseanet.appbox']->get_connection();
$sql = 'UPDATE sitepreff SET memcached_update = :date'; $sql = 'UPDATE sitepreff SET memcached_update = :date';
$stmt = $conn->prepare($sql); $stmt = $conn->prepare($sql);
@@ -144,8 +144,8 @@ class cache_databox
*/ */
public static function update(Application $app, $sbas_id, $type, $value = '') public static function update(Application $app, $sbas_id, $type, $value = '')
{ {
$databox = $app['phraseanet.appbox']->get_databox($sbas_id);
$connbas = \connection::getPDOConnection($app, $sbas_id); $connbas = $databox->get_connection();
$sql = 'SELECT distinct site_id as site_id $sql = 'SELECT distinct site_id as site_id
FROM clients FROM clients

View File

@@ -10,9 +10,9 @@
*/ */
use Alchemy\Phrasea\Application; use Alchemy\Phrasea\Application;
use Alchemy\Phrasea\Exception\InvalidArgumentException; use Alchemy\Phrasea\Exception\InvalidArgumentException;
use Alchemy\Phrasea\Model\Entities\User; use Alchemy\Phrasea\Model\Entities\User;
use Doctrine\DBAL\Connection;
class collection implements cache_cacheableInterface class collection implements cache_cacheableInterface
{ {
@@ -92,7 +92,7 @@ class collection implements cache_cacheableInterface
'nl' => $row['label_nl'], 'nl' => $row['label_nl'],
]; ];
$conn = connection::getPDOConnection($this->app); $conn = $this->app['phraseanet.appbox']->get_connection();
$sql = 'SELECT server_coll_id, sbas_id, base_id, active, ord FROM bas $sql = 'SELECT server_coll_id, sbas_id, base_id, active, ord FROM bas
WHERE server_coll_id = :coll_id AND sbas_id = :sbas_id'; WHERE server_coll_id = :coll_id AND sbas_id = :sbas_id';
@@ -547,7 +547,7 @@ class collection implements cache_cacheableInterface
return $this; return $this;
} }
private static function getNewOrder(\connection_pdo $conn, $sbas_id) private static function getNewOrder(Connection $conn, $sbas_id)
{ {
$sql = "SELECT GREATEST(0, MAX(ord)) + 1 AS ord FROM bas WHERE sbas_id = :sbas_id"; $sql = "SELECT GREATEST(0, MAX(ord)) + 1 AS ord FROM bas WHERE sbas_id = :sbas_id";
$stmt = $conn->prepare($sql); $stmt = $conn->prepare($sql);

View File

@@ -1,180 +0,0 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2014 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
use Alchemy\Phrasea\Application;
class connection
{
/**
*
* @var Array
*/
private static $_PDO_instance = [];
/**
*
* @var boolean
*/
private static $_selfinstance;
/**
*
* @var Array
*/
public static $log = [];
protected $app;
public function __construct(Application $app)
{
$this->app = $app;
}
/**
*
*/
public function __destruct()
{
self::printLog($this->app);
return;
}
/**
*
* @return Void
*/
public static function printLog(Application $app)
{
if ($app->getEnvironment() !== Application::ENV_DEV) {
return;
}
$totalTime = 0;
foreach (self::$log as $entry) {
$query = $entry['query'];
do {
$query = str_replace(["\n", " "], " ", $query);
} while ($query != str_replace(["\n", " "], " ", $query));
$totalTime += $entry['time'];
$string = $entry['time'] . "\t" . ' - ' . $query . ' - ' . "\n";
file_put_contents(__DIR__ . '/../../logs/mysql_log.log', $string, FILE_APPEND);
}
$string = count(self::$log) . ' queries - ' . $totalTime
. "\nEND OF QUERY " . $_SERVER['PHP_SELF']
. "?";
foreach ($_GET as $key => $value) {
$string .= $key . ' = ' . $value . ' & ';
}
$string .= "\nPOST datas :\n ";
foreach ($_POST as $key => $value) {
$string .= "\t\t" . $key . ' = ' . (is_scalar($value) ? $value : 'non-scalar value') . "\n";
}
$string .= "\n\n\n\n";
file_put_contents(__DIR__ . '/../../logs/mysql_log.log', $string, FILE_APPEND);
return;
}
/**
*
* @return type
*/
protected static function instantiate(Application $app)
{
if (!self::$_selfinstance)
self::$_selfinstance = new self($app);
return;
}
/**
*
* @param Application $app
* @param string $name
*
* @return connection_pdo
*/
public static function getPDOConnection(Application $app, $name = null)
{
self::instantiate($app);
if (trim($name) == '') {
$name = 'appbox';
} elseif (is_int((int) $name)) {
$name = (int) $name;
} else {
return false;
}
if (!isset(self::$_PDO_instance[$name])) {
$hostname = $port = $user = $password = $dbname = false;
$connection_params = [];
if (trim($name) !== 'appbox') {
$connection_params = phrasea::sbas_params($app);
} else {
$connexion = $app['conf']->get(['main', 'database']);
$hostname = $connexion['host'];
$port = $connexion['port'];
$user = $connexion['user'];
$password = $connexion['password'];
$dbname = $connexion['dbname'];
}
if (isset($connection_params[$name])) {
$hostname = $connection_params[$name]['host'];
$port = $connection_params[$name]['port'];
$user = $connection_params[$name]['user'];
$password = $connection_params[$name]['pwd'];
$dbname = $connection_params[$name]['dbname'];
}
try {
self::$_PDO_instance[$name] = new connection_pdo($name, $hostname, $port, $user, $password, $dbname, [], $app['debug']);
} catch (\Exception $e) {
throw new Exception('Connection not available');
}
}
if (array_key_exists($name, self::$_PDO_instance)) {
return self::$_PDO_instance[$name];
}
throw new Exception('Connection not available');
}
/**
*
* @param type $name
* @return type
*/
public static function close_PDO_connection($name)
{
if (isset(self::$_PDO_instance[$name])) {
self::$_PDO_instance[$name] = null;
unset(self::$_PDO_instance[$name]);
}
return;
}
public static function close_connections()
{
foreach (self::$_PDO_instance as $name => $conn) {
self::close_PDO_connection($name);
}
return;
}
}

View File

@@ -1,85 +0,0 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2014 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
abstract class connection_abstract extends PDO
{
protected $name;
protected $credentials = [];
protected $multi_db = true;
public function get_credentials()
{
return $this->credentials;
}
public function is_multi_db()
{
return $this->multi_db;
}
/**
*
* @return string
*/
public function get_name()
{
return $this->name;
}
public function ping()
{
try {
$this->query('SELECT 1');
} catch (PDOException $e) {
return false;
}
return true;
}
/**
*
* @param string $statement
* @param array $driver_options
* @return PDOStatement
*/
public function prepare($statement, $driver_options = [])
{
return parent::prepare($statement, $driver_options);
}
/**
*
* @return boolean
*/
public function beginTransaction()
{
return parent::beginTransaction();
}
/**
*
* @return boolean
*/
public function commit()
{
return parent::commit();
}
/**
*
* @return string
*/
public function server_info()
{
return parent::getAttribute(constant("PDO::ATTR_SERVER_VERSION"));
}
}

View File

@@ -1,32 +0,0 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2014 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
interface connection_interface
{
public function ping();
public function get_name();
public function is_multi_db();
public function get_credentials();
public function close();
public function prepare($statement, $driver_options = []);
public function beginTransaction();
public function commit();
public function server_info();
}

View File

@@ -1,91 +0,0 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2014 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
class connection_pdo extends connection_abstract implements connection_interface
{
protected $debug;
/**
*
* @param string $name
* @param string $hostname
* @param int $port
* @param string $user
* @param string $passwd
* @param string $dbname
* @param array $options
* @param Boolean $debug
*
* @return connection_pdo
*/
public function __construct($name, $hostname, $port, $user, $passwd, $dbname = false, $options = [], $debug = false)
{
$this->debug = $debug;
$this->name = $name;
if ($dbname)
$dsn = 'mysql:dbname=' . $dbname . ';host=' . $hostname . ';port=' . $port . ';';
else
$dsn = 'mysql:host=' . $hostname . ';port=' . $port . ';';
$this->credentials['hostname'] = $hostname;
$this->credentials['port'] = $port;
$this->credentials['user'] = $user;
$this->credentials['password'] = $passwd;
if ($dbname)
$this->credentials['dbname'] = $dbname;
parent::__construct($dsn, $user, $passwd, $options);
$this->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$this->query("
SET character_set_results = 'utf8', character_set_client = 'utf8',
character_set_connection = 'utf8', character_set_database = 'utf8',
character_set_server = 'utf8'");
return $this;
}
/**
*
* @param type $statement
* @param type $driver_options
* @return PDOStatement
*/
public function prepare($statement, $driver_options = [])
{
if ($this->debug) {
return new connection_pdoStatementDebugger(parent::prepare($statement, $driver_options));
} else {
return parent::prepare($statement, $driver_options);
}
}
/**
*
* @return void
*/
public function close()
{
connection::close_PDO_connection($this->name);
}
/**
*
* @param string $message
* @return connection_pdo
*/
protected function log($message)
{
file_put_contents(__DIR__ . '/../../../logs/sql_log.log', $message . "\n", FILE_APPEND);
return $this;
}
}

View File

@@ -1,51 +0,0 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2014 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
class connection_pdoStatementDebugger
{
/**
*
* @var PDOStatement
*/
protected $statement;
public function __construct(PDOStatement $statement)
{
$this->statement = $statement;
return $this;
}
public function execute($params = [])
{
$start = microtime(true);
$exception = null;
try {
$result = $this->statement->execute($params);
} catch (\Exception $e) {
$exception = $e;
}
$time = microtime(true) - $start;
connection::$log[] = [
'query' => '' . str_replace(array_keys($params), array_values($params), $this->statement->queryString),
'time' => $time
];
if ($exception instanceof Exception)
throw $exception;
return $result;
}
public function __call($function_name, $parameters)
{
return call_user_func_array([$this->statement, $function_name], $parameters);
}
}

View File

@@ -10,9 +10,10 @@
*/ */
use Alchemy\Phrasea\Application; use Alchemy\Phrasea\Application;
use Symfony\Component\Filesystem\Filesystem;
use Alchemy\Phrasea\Model\Entities\User; use Alchemy\Phrasea\Model\Entities\User;
use Alchemy\Phrasea\Exception\InvalidArgumentException; use Alchemy\Phrasea\Exception\InvalidArgumentException;
use Doctrine\DBAL\Connection;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Translation\TranslatorInterface; use Symfony\Component\Translation\TranslatorInterface;
@@ -120,7 +121,13 @@ class databox extends base
throw new NotFoundHttpException(sprintf('databox %d not found', $sbas_id)); throw new NotFoundHttpException(sprintf('databox %d not found', $sbas_id));
} }
$this->connection = connection::getPDOConnection($app, $sbas_id); $this->connection = $app['dbal.provider']->get([
'host' => $connection_params[$sbas_id]['host'],
'port' => $connection_params[$sbas_id]['port'],
'user' => $connection_params[$sbas_id]['user'],
'password' => $connection_params[$sbas_id]['pwd'],
'dbname' => $connection_params[$sbas_id]['dbname'],
]);
$this->host = $connection_params[$sbas_id]['host']; $this->host = $connection_params[$sbas_id]['host'];
$this->port = $connection_params[$sbas_id]['port']; $this->port = $connection_params[$sbas_id]['port'];
@@ -225,7 +232,7 @@ class databox extends base
} }
$conn = connection::getPDOConnection($this->app); $conn = $this->app['phraseanet.appbox']->get_connection();
$sql = "SELECT b.server_coll_id FROM sbas s, bas b $sql = "SELECT b.server_coll_id FROM sbas s, bas b
WHERE s.sbas_id = b.sbas_id AND b.sbas_id = :sbas_id WHERE s.sbas_id = b.sbas_id AND b.sbas_id = :sbas_id
@@ -492,24 +499,22 @@ class databox extends base
return; return;
} }
public static function create(Application $app, connection_pdo $connection, \SplFileInfo $data_template) public static function create(Application $app, Connection $connection, \SplFileInfo $data_template)
{ {
if ( ! file_exists($data_template->getRealPath())) { if ( ! file_exists($data_template->getRealPath())) {
throw new \InvalidArgumentException($data_template->getRealPath() . " does not exist"); throw new \InvalidArgumentException($data_template->getRealPath() . " does not exist");
} }
$credentials = $connection->get_credentials();
$sql = 'SELECT sbas_id $sql = 'SELECT sbas_id
FROM sbas FROM sbas
WHERE host = :host AND port = :port AND dbname = :dbname WHERE host = :host AND port = :port AND dbname = :dbname
AND user = :user AND pwd = :password'; AND user = :user AND pwd = :password';
$host = $credentials['hostname']; $host = $connection->getHost();
$port = $credentials['port']; $port = $connection->getPort();
$dbname = $credentials['dbname']; $dbname = $connection->getDatabase();
$user = $credentials['user']; $user = $connection->getUsername();
$password = $credentials['password']; $password = $connection->getPassword();
$params = [ $params = [
':host' => $host ':host' => $host
@@ -589,7 +594,14 @@ class databox extends base
*/ */
public static function mount(Application $app, $host, $port, $user, $password, $dbname) public static function mount(Application $app, $host, $port, $user, $password, $dbname)
{ {
new connection_pdo('test', $host, $port, $user, $password, $dbname, [], $app['debug']); $conn = $app['dbal.provider']->get([
'host' => $host,
'port' => $port,
'user' => $user,
'password' => $password,
'dbname' => $dbname,
]);
$conn->connect();
$conn = $app['phraseanet.appbox']->get_connection(); $conn = $app['phraseanet.appbox']->get_connection();
$sql = 'SELECT MAX(ord) as ord FROM sbas'; $sql = 'SELECT MAX(ord) as ord FROM sbas';
@@ -733,7 +745,7 @@ class databox extends base
public function get_serialized_server_info() public function get_serialized_server_info()
{ {
return sprintf("%s@%s:%s (MySQL %s)", $this->dbname, $this->host, $this->port, $this->get_connection()->server_info()); return sprintf("%s@%s:%s (MySQL %s)", $this->dbname, $this->host, $this->port, $this->get_connection()->getWrappedConnection()->getAttribute(\PDO::ATTR_SERVER_VERSION));
} }
public static function get_available_dcfields() public static function get_available_dcfields()
@@ -763,7 +775,7 @@ class databox extends base
*/ */
public function get_mountable_colls() public function get_mountable_colls()
{ {
$conn = connection::getPDOConnection($this->app); $conn = $this->app['phraseanet.appbox']->get_connection();
$colls = []; $colls = [];
$sql = 'SELECT server_coll_id FROM bas WHERE sbas_id = :sbas_id'; $sql = 'SELECT server_coll_id FROM bas WHERE sbas_id = :sbas_id';
@@ -798,7 +810,7 @@ class databox extends base
public function get_activable_colls() public function get_activable_colls()
{ {
$conn = connection::getPDOConnection($this->app); $conn = $this->app['phraseanet.appbox']->get_connection();
$base_ids = []; $base_ids = [];
$sql = 'SELECT base_id FROM bas WHERE sbas_id = :sbas_id AND active = "0"'; $sql = 'SELECT base_id FROM bas WHERE sbas_id = :sbas_id AND active = "0"';
@@ -973,7 +985,7 @@ class databox extends base
*/ */
public function registerAdmin(User $user) public function registerAdmin(User $user)
{ {
$conn = connection::getPDOConnection($this->app); $conn = $this->app['phraseanet.appbox']->get_connection();
$this->app['acl']->get($user) $this->app['acl']->get($user)
->give_access_to_sbas([$this->id]) ->give_access_to_sbas([$this->id])

View File

@@ -9,10 +9,12 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
use Alchemy\Phrasea\Application; use Alchemy\Phrasea\Application;
use Alchemy\Phrasea\Vocabulary; use Alchemy\Phrasea\Vocabulary;
use Alchemy\Phrasea\Vocabulary\ControlProvider\ControlProviderInterface; use Alchemy\Phrasea\Vocabulary\ControlProvider\ControlProviderInterface;
use Alchemy\Phrasea\Metadata\Tag\Nosource; use Alchemy\Phrasea\Metadata\Tag\Nosource;
use Doctrine\DBAL\Connection;
use PHPExiftool\Driver\TagInterface; use PHPExiftool\Driver\TagInterface;
use PHPExiftool\Driver\TagFactory; use PHPExiftool\Driver\TagFactory;
use PHPExiftool\Exception\TagUnknown; use PHPExiftool\Exception\TagUnknown;
@@ -303,7 +305,7 @@ class databox_field implements cache_cacheableInterface
/** /**
* *
* @return connection_pdo * @return Connection
*/ */
public function get_connection() public function get_connection()
{ {

View File

@@ -454,7 +454,7 @@ class databox_status
public static function operation_and(Application $app, $stat1, $stat2) public static function operation_and(Application $app, $stat1, $stat2)
{ {
$conn = connection::getPDOConnection($app); $conn = $app['phraseanet.appbox']->get_connection();
$status = '0'; $status = '0';
@@ -481,7 +481,7 @@ class databox_status
public static function operation_and_not(Application $app, $stat1, $stat2) public static function operation_and_not(Application $app, $stat1, $stat2)
{ {
$conn = connection::getPDOConnection($app); $conn = $app['phraseanet.appbox']->get_connection();
$status = '0'; $status = '0';
@@ -508,7 +508,7 @@ class databox_status
public static function operation_or(Application $app, $stat1, $stat2) public static function operation_or(Application $app, $stat1, $stat2)
{ {
$conn = connection::getPDOConnection($app); $conn = $app['phraseanet.appbox']->get_connection();
$status = '0'; $status = '0';
@@ -541,7 +541,7 @@ class databox_status
throw new \Exception(sprintf('`%s`is non-decimal value', $status)); throw new \Exception(sprintf('`%s`is non-decimal value', $status));
} }
$conn = connection::getPDOConnection($app); $conn = $app['phraseanet.appbox']->get_connection();
$sql = 'select bin(' . $status . ') as result'; $sql = 'select bin(' . $status . ') as result';
@@ -570,7 +570,7 @@ class databox_status
throw new \Exception('Non-hexadecimal value'); throw new \Exception('Non-hexadecimal value');
} }
$conn = connection::getPDOConnection($app); $conn = $app['phraseanet.appbox']->get_connection();
$sql = 'select BIN( CAST( 0x' . trim($status) . ' AS UNSIGNED ) ) as result'; $sql = 'select BIN( CAST( 0x' . trim($status) . ' AS UNSIGNED ) ) as result';

View File

@@ -11,6 +11,7 @@
use Alchemy\Phrasea\Application; use Alchemy\Phrasea\Application;
use Alchemy\Phrasea\Exception\RuntimeException; use Alchemy\Phrasea\Exception\RuntimeException;
use Doctrine\DBAL\DBALException;
class media_Permalink_Adapter implements media_Permalink_Interface, cache_cacheableInterface class media_Permalink_Adapter implements media_Permalink_Interface, cache_cacheableInterface
{ {
@@ -333,7 +334,7 @@ class media_Permalink_Adapter implements media_Permalink_Interface, cache_cachea
$stmt = $databox->get_connection()->prepare($sql); $stmt = $databox->get_connection()->prepare($sql);
try { try {
$stmt->execute($params); $stmt->execute($params);
} catch (\PDOException $e) { } catch (DBALException $e) {
$error = $e; $error = $e;
} }
$stmt->closeCursor(); $stmt->closeCursor();

View File

@@ -70,7 +70,7 @@ class module_console_sphinxGenerateSuggestion extends Command
} }
try { try {
$connbas = connection::getPDOConnection($this->container, $sbas_id); $connbas = $databox->get_connection()->connect();
} catch (\Exception $e) { } catch (\Exception $e) {
continue; continue;
} }

View File

@@ -10,6 +10,7 @@
*/ */
use Alchemy\Phrasea\Application; use Alchemy\Phrasea\Application;
use Doctrine\DBAL\DBALException;
class module_report class module_report
{ {
@@ -820,7 +821,8 @@ class module_report
return $this->report; return $this->report;
} }
$conn = connection::getPDOConnection($this->app, $this->sbas_id); $databox = $this->app['phraseanet.appbox']->get_databox($this->sbas_id);
$conn = $databox->get_connection();
$this->buildReq($groupby, $on); $this->buildReq($groupby, $on);
@@ -830,7 +832,7 @@ class module_report
$stmt->execute($this->params); $stmt->execute($this->params);
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC); $rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
$stmt->closeCursor(); $stmt->closeCursor();
} catch (PDOException $e) { } catch (DBALException $e) {
echo $e->getMessage(); echo $e->getMessage();
return; return;

View File

@@ -617,7 +617,8 @@ class module_report_activity extends module_report
public static function topTenUser(Application $app, $dmin, $dmax, $sbas_id, $list_coll_id) public static function topTenUser(Application $app, $dmin, $dmax, $sbas_id, $list_coll_id)
{ {
$conn = connection::getPDOConnection($app, $sbas_id); $databox = $app['phraseanet.appbox']->get_databox($sbas_id);
$conn = $databox->get_connection();
$result = []; $result = [];
$result['top_ten_doc'] = []; $result['top_ten_doc'] = [];
$result['top_ten_prev'] = []; $result['top_ten_prev'] = [];
@@ -697,7 +698,8 @@ class module_report_activity extends module_report
public static function activity(Application $app, $dmin, $dmax, $sbas_id, $list_coll_id) public static function activity(Application $app, $dmin, $dmax, $sbas_id, $list_coll_id)
{ {
$conn = connection::getPDOConnection($app, $sbas_id); $databox = $app['phraseanet.appbox']->get_databox($sbas_id);
$conn = $databox->get_connection();
$res = []; $res = [];
$datefilter = $datefilter =
module_report_sqlfilter::constructDateFilter($dmin, $dmax); module_report_sqlfilter::constructDateFilter($dmin, $dmax);
@@ -743,7 +745,8 @@ class module_report_activity extends module_report
public static function activityDay(Application $app, $dmin, $dmax, $sbas_id, $list_coll_id) public static function activityDay(Application $app, $dmin, $dmax, $sbas_id, $list_coll_id)
{ {
$conn = connection::getPDOConnection($app, $sbas_id); $databox = $app['phraseanet.appbox']->get_databox($sbas_id);
$conn = $databox->get_connection();
$result = []; $result = [];
$res = []; $res = [];
$datefilter = $datefilter =
@@ -785,7 +788,8 @@ class module_report_activity extends module_report
public static function activityQuestion(Application $app, $dmin, $dmax, $sbas_id, $list_coll_id) public static function activityQuestion(Application $app, $dmin, $dmax, $sbas_id, $list_coll_id)
{ {
$conn = connection::getPDOConnection($app, $sbas_id); $databox = $app['phraseanet.appbox']->get_databox($sbas_id);
$conn = $databox->get_connection();
$result = []; $result = [];
$datefilter = $datefilter =
module_report_sqlfilter::constructDateFilter($dmin, $dmax); module_report_sqlfilter::constructDateFilter($dmin, $dmax);
@@ -825,7 +829,8 @@ class module_report_activity extends module_report
public static function activiteTopQuestion(Application $app, $dmin, $dmax, $sbas_id, $list_coll_id) public static function activiteTopQuestion(Application $app, $dmin, $dmax, $sbas_id, $list_coll_id)
{ {
$conn = connection::getPDOConnection($app, $sbas_id); $databox = $app['phraseanet.appbox']->get_databox($sbas_id);
$conn = $databox->get_connection();
$result = []; $result = [];
$datefilter = $datefilter =
module_report_sqlfilter::constructDateFilter($dmin, $dmax); module_report_sqlfilter::constructDateFilter($dmin, $dmax);
@@ -868,7 +873,8 @@ class module_report_activity extends module_report
public static function activiteTopTenSiteView(Application $app, $dmin, $dmax, $sbas_id, $list_coll_id) public static function activiteTopTenSiteView(Application $app, $dmin, $dmax, $sbas_id, $list_coll_id)
{ {
$conn = connection::getPDOConnection($app, $sbas_id); $databox = $app['phraseanet.appbox']->get_databox($sbas_id);
$conn = $databox->get_connection();
$result = []; $result = [];
$datefilter = module_report_sqlfilter::constructDateFilter($dmin, $dmax); $datefilter = module_report_sqlfilter::constructDateFilter($dmin, $dmax);
$collfilter = module_report_sqlfilter::constructCollectionFilter($app, $list_coll_id); $collfilter = module_report_sqlfilter::constructCollectionFilter($app, $list_coll_id);
@@ -911,7 +917,8 @@ class module_report_activity extends module_report
public static function activiteAddedDocument(Application $app, $dmin, $dmax, $sbas_id, $list_coll_id) public static function activiteAddedDocument(Application $app, $dmin, $dmax, $sbas_id, $list_coll_id)
{ {
$conn = connection::getPDOConnection($app, $sbas_id); $databox = $app['phraseanet.appbox']->get_databox($sbas_id);
$conn = $databox->get_connection();
$result = []; $result = [];
$datefilter = module_report_sqlfilter::constructDateFilter($dmin, $dmax); $datefilter = module_report_sqlfilter::constructDateFilter($dmin, $dmax);
$collfilter = module_report_sqlfilter::constructCollectionFilter($app, $list_coll_id); $collfilter = module_report_sqlfilter::constructCollectionFilter($app, $list_coll_id);
@@ -946,7 +953,8 @@ class module_report_activity extends module_report
public static function activiteEditedDocument(Application $app, $dmin, $dmax, $sbas_id, $list_coll_id) public static function activiteEditedDocument(Application $app, $dmin, $dmax, $sbas_id, $list_coll_id)
{ {
$conn = connection::getPDOConnection($app, $sbas_id); $databox = $app['phraseanet.appbox']->get_databox($sbas_id);
$conn = $databox->get_connection();
$result = []; $result = [];
$datefilter = module_report_sqlfilter::constructDateFilter($dmin, $dmax); $datefilter = module_report_sqlfilter::constructDateFilter($dmin, $dmax);
$collfilter = module_report_sqlfilter::constructCollectionFilter($app, $list_coll_id); $collfilter = module_report_sqlfilter::constructCollectionFilter($app, $list_coll_id);
@@ -982,7 +990,8 @@ class module_report_activity extends module_report
public static function activiteAddedTopTenUser(Application $app, $dmin, $dmax, $sbas_id, $list_coll_id) public static function activiteAddedTopTenUser(Application $app, $dmin, $dmax, $sbas_id, $list_coll_id)
{ {
$conn = connection::getPDOConnection($app, $sbas_id); $databox = $app['phraseanet.appbox']->get_databox($sbas_id);
$conn = $databox->get_connection();
$result = []; $result = [];
$datefilter = module_report_sqlfilter::constructDateFilter($dmin, $dmax); $datefilter = module_report_sqlfilter::constructDateFilter($dmin, $dmax);
$collfilter = module_report_sqlfilter::constructCollectionFilter($app, $list_coll_id); $collfilter = module_report_sqlfilter::constructCollectionFilter($app, $list_coll_id);

View File

@@ -134,7 +134,8 @@ class module_report_connexion extends module_report
public static function getNbConn(Application $app, $dmin, $dmax, $sbas_id, $list_coll_id) public static function getNbConn(Application $app, $dmin, $dmax, $sbas_id, $list_coll_id)
{ {
$conn = connection::getPDOConnection($app, $sbas_id); $databox = $app['phraseanet.appbox']->get_databox($sbas_id);
$conn = $databox->get_connection();
$datefilter = module_report_sqlfilter::constructDateFilter($dmin, $dmax); $datefilter = module_report_sqlfilter::constructDateFilter($dmin, $dmax);
$collfilter = module_report_sqlfilter::constructCollectionFilter($app, $list_coll_id); $collfilter = module_report_sqlfilter::constructCollectionFilter($app, $list_coll_id);

View File

@@ -10,6 +10,7 @@
*/ */
use Alchemy\Phrasea\Application; use Alchemy\Phrasea\Application;
use Doctrine\DBAL\DBALException;
class module_report_dashboard_feed implements module_report_dashboard_componentInterface class module_report_dashboard_feed implements module_report_dashboard_componentInterface
{ {
@@ -206,7 +207,7 @@ class module_report_dashboard_feed implements module_report_dashboard_componentI
$this->app, $this->dminsql, $this->dmaxsql, $this->sbasid, $this->collection $this->app, $this->dminsql, $this->dmaxsql, $this->sbasid, $this->collection
); );
} }
} catch (PDOException $e) { } catch (DBALException $e) {
} }

View File

@@ -171,7 +171,8 @@ class module_report_download extends module_report
public static function getNbDl(Application $app, $dmin, $dmax, $sbas_id, $list_coll_id) public static function getNbDl(Application $app, $dmin, $dmax, $sbas_id, $list_coll_id)
{ {
$conn = connection::getPDOConnection($app, $sbas_id); $databox = $app['phraseanet.appbox']->get_databox($sbas_id);
$conn = $databox->get_connection();
$params = [':site_id' => $app['conf']->get(['main', 'key'])]; $params = [':site_id' => $app['conf']->get(['main', 'key'])];
$datefilter = module_report_sqlfilter::constructDateFilter($dmin, $dmax); $datefilter = module_report_sqlfilter::constructDateFilter($dmin, $dmax);

View File

@@ -534,7 +534,8 @@ class module_report_nav extends module_report
public function buildTabInfoNav($tab = false, $navigator) public function buildTabInfoNav($tab = false, $navigator)
{ {
$conn = connection::getPDOConnection($this->app, $this->sbas_id); $databox = $this->app['phraseanet.appbox']->get_databox($this->sbas_id);
$conn = $databox->get_connection();
$this->title = $this->app->trans('report:: Information sur le navigateur %name%', ['%name%' => $navigator]); $this->title = $this->app->trans('report:: Information sur le navigateur %name%', ['%name%' => $navigator]);
$sqlBuilder = new module_report_sql($this->app, $this); $sqlBuilder = new module_report_sql($this->app, $this);
$filter = $sqlBuilder->getFilters(); $filter = $sqlBuilder->getFilters();

View File

@@ -15,13 +15,13 @@ class module_report_sql
{ {
/** /**
* *
* @var connection_PDO * @var Connection
*/ */
public $conn; public $conn;
/** /**
* *
* @var connection_PDO * @var Connection
*/ */
public $connbas; public $connbas;
@@ -39,8 +39,8 @@ class module_report_sql
public function __construct(Application $app, module_report $report) public function __construct(Application $app, module_report $report)
{ {
$this->conn = connection::getPDOConnection($app); $this->conn = $app['phraseanet.appbox']->get_connection();
$this->connbas = connection::getPDOConnection($app, $report->getSbasId()); $this->connbas = $app['phraseanet.appbox']->get_databox($report->getSbasId())->get_connection();
$this->filter = new module_report_sqlfilter($app, $report); $this->filter = new module_report_sqlfilter($app, $report);
$this->sql = ''; $this->sql = '';
$this->params = []; $this->params = [];
@@ -118,7 +118,7 @@ class module_report_sql
/** /**
* *
* @return connection_PDO * @return Connection
*/ */
public function getConnBas() public function getConnBas()
{ {

View File

@@ -22,7 +22,7 @@ class module_report_sqlfilter
public function __construct(Application $app, module_report $report) public function __construct(Application $app, module_report $report)
{ {
$this->app = $app; $this->app = $app;
$this->conn = connection::getPDOConnection($app, $report->getSbasid()); $this->conn = $app['phraseanet.appbox']->get_databox($report->getSbasId())->get_connection();
if (is_array($report->getTransQueryString())) if (is_array($report->getTransQueryString()))
$this->cor_query = $report->getTransQueryString(); $this->cor_query = $report->getTransQueryString();

View File

@@ -116,7 +116,7 @@ class patch_320alpha4a implements patchInterface
$databox->delete_data_from_cache(databox::CACHE_STRUCTURE); $databox->delete_data_from_cache(databox::CACHE_STRUCTURE);
$databox->delete_data_from_cache(databox::CACHE_META_STRUCT); $databox->delete_data_from_cache(databox::CACHE_META_STRUCT);
$conn = connection::getPDOConnection($app); $conn = $app['phraseanet.appbox']->get_connection();
$sql = 'DELETE FROM `task2` WHERE class="readmeta"'; $sql = 'DELETE FROM `task2` WHERE class="readmeta"';
$stmt = $conn->prepare($sql); $stmt = $conn->prepare($sql);

View File

@@ -10,6 +10,7 @@
*/ */
use Alchemy\Phrasea\Application; use Alchemy\Phrasea\Application;
use Doctrine\DBAL\DBALException;
class patch_360alpha1b implements patchInterface class patch_360alpha1b implements patchInterface
{ {
@@ -62,7 +63,7 @@ class patch_360alpha1b implements patchInterface
$stmt = $databox->get_connection()->prepare($sql); $stmt = $databox->get_connection()->prepare($sql);
$stmt->execute(); $stmt->execute();
$stmt->closeCursor(); $stmt->closeCursor();
} catch (\PDOException $e) { } catch (DBALException $e) {
} }

View File

@@ -10,6 +10,7 @@
*/ */
use Alchemy\Phrasea\Application; use Alchemy\Phrasea\Application;
use Doctrine\DBAL\DBALException;
class patch_360alpha2b implements patchInterface class patch_360alpha2b implements patchInterface
{ {
@@ -78,7 +79,7 @@ class patch_360alpha2b implements patchInterface
$stmt = $databox->get_connection()->prepare($sql); $stmt = $databox->get_connection()->prepare($sql);
$stmt->execute(); $stmt->execute();
$stmt->closeCursor(); $stmt->closeCursor();
} catch (\Exception $e) { } catch (DBALException $e) {
} }
@@ -88,7 +89,7 @@ class patch_360alpha2b implements patchInterface
$stmt = $databox->get_connection()->prepare($sql); $stmt = $databox->get_connection()->prepare($sql);
$stmt->execute(); $stmt->execute();
$stmt->closeCursor(); $stmt->closeCursor();
} catch (\PDOException $e) { } catch (DBALException $e) {
} }

View File

@@ -69,7 +69,7 @@ class patch_361alpha1a implements patchInterface
$sbas_id = (int) $row['sbas_id']; $sbas_id = (int) $row['sbas_id'];
try { try {
$connbas = connection::getPDOConnection($app, $sbas_id); $connbas = $app['phraseanet.appbox']->get_databox($sbas_id)->get_connection()->connect();
} catch (\Exception $e) { } catch (\Exception $e) {
$conn->exec('DELETE FROM ValidationDatas WHERE basket_element_id = ' . $row['id']); $conn->exec('DELETE FROM ValidationDatas WHERE basket_element_id = ' . $row['id']);
$conn->exec('DELETE FROM BasketElements WHERE id = ' . $row['id']); $conn->exec('DELETE FROM BasketElements WHERE id = ' . $row['id']);

View File

@@ -12,6 +12,7 @@
use Alchemy\Phrasea\Application; use Alchemy\Phrasea\Application;
use Alchemy\Phrasea\Model\Entities\LazaretFile; use Alchemy\Phrasea\Model\Entities\LazaretFile;
use Alchemy\Phrasea\Model\Entities\LazaretSession; use Alchemy\Phrasea\Model\Entities\LazaretSession;
use Doctrine\DBAL\DBALException;
use MediaAlchemyst\Exception\ExceptionInterface as MediaAlchemystException; use MediaAlchemyst\Exception\ExceptionInterface as MediaAlchemystException;
use MediaAlchemyst\Specification\Image as ImageSpec; use MediaAlchemyst\Specification\Image as ImageSpec;
@@ -68,7 +69,7 @@ class patch_370alpha7a extends patchAbstract
$stmt = $conn->prepare($sql); $stmt = $conn->prepare($sql);
$stmt->execute(); $stmt->execute();
$rs = $stmt->fetchAll(); $rs = $stmt->fetchAll();
} catch (\PDOException $e) { } catch (DBALException $e) {
// table not found // table not found
if ($e->getCode() == '42S02') { if ($e->getCode() == '42S02') {

View File

@@ -12,6 +12,7 @@
use Alchemy\Phrasea\Application; use Alchemy\Phrasea\Application;
use Alchemy\Phrasea\Model\Entities\Session; use Alchemy\Phrasea\Model\Entities\Session;
use Alchemy\Phrasea\Model\Entities\SessionModule; use Alchemy\Phrasea\Model\Entities\SessionModule;
use Doctrine\DBAL\DBALException;
class patch_380alpha11a extends patchAbstract class patch_380alpha11a extends patchAbstract
{ {
@@ -66,7 +67,7 @@ class patch_380alpha11a extends patchAbstract
$stmt->execute(); $stmt->execute();
$rs = $stmt->fetchAll(\PDO::FETCH_ASSOC); $rs = $stmt->fetchAll(\PDO::FETCH_ASSOC);
$stmt->closeCursor(); $stmt->closeCursor();
} catch (\PDOException $e) { } catch (DBALException $e) {
// this may fail on oldest versions // this may fail on oldest versions
return false; return false;
} }

View File

@@ -9,9 +9,11 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
use Doctrine\DBAL\Connection;
class patchthesaurus_100 implements patchthesaurus_interface class patchthesaurus_100 implements patchthesaurus_interface
{ {
public function patch($version, \DOMDocument $domct, \DOMDocument $domth, \connection_interface $connbas, \unicode $unicode) public function patch($version, \DOMDocument $domct, \DOMDocument $domth, Connection $connbas, \unicode $unicode)
{ {
if ($version == "") { if ($version == "") {
$th = $domth->documentElement; $th = $domth->documentElement;

View File

@@ -9,9 +9,11 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
use Doctrine\DBAL\Connection;
class patchthesaurus_200 implements patchthesaurus_interface class patchthesaurus_200 implements patchthesaurus_interface
{ {
public function patch($version, \DOMDocument $domct, \DOMDocument $domth, \connection_interface $connbas, \unicode $unicode) public function patch($version, \DOMDocument $domct, \DOMDocument $domth, Connection $connbas, \unicode $unicode)
{ {
if ($version == "2.0.0") { if ($version == "2.0.0") {
$th = $domth->documentElement; $th = $domth->documentElement;

View File

@@ -9,9 +9,11 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
use Doctrine\DBAL\Connection;
class patchthesaurus_201 implements patchthesaurus_interface class patchthesaurus_201 implements patchthesaurus_interface
{ {
public function patch($version, \DOMDocument $domct, \DOMDocument $domth, \connection_interface $connbas, \unicode $unicode) public function patch($version, \DOMDocument $domct, \DOMDocument $domth, Connection $connbas, \unicode $unicode)
{ {
if ($version == "2.0.1") { if ($version == "2.0.1") {
$th = $domth->documentElement; $th = $domth->documentElement;

View File

@@ -9,9 +9,11 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
use Doctrine\DBAL\Connection;
class patchthesaurus_202 implements patchthesaurus_interface class patchthesaurus_202 implements patchthesaurus_interface
{ {
public function patch($version, \DOMDocument $domct, \DOMDocument $domth, \connection_interface $connbas, \unicode $unicode) public function patch($version, \DOMDocument $domct, \DOMDocument $domth, Connection $connbas, \unicode $unicode)
{ {
if ($version == "2.0.2") { if ($version == "2.0.2") {
$th = $domth->documentElement; $th = $domth->documentElement;

View File

@@ -9,9 +9,11 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
use Doctrine\DBAL\Connection;
class patchthesaurus_203 implements patchthesaurus_interface class patchthesaurus_203 implements patchthesaurus_interface
{ {
public function patch($version, \DOMDocument $domct, \DOMDocument $domth, \connection_interface $connbas, \unicode $unicode) public function patch($version, \DOMDocument $domct, \DOMDocument $domth, Connection $connbas, \unicode $unicode)
{ {
$needreindex = false; $needreindex = false;
@@ -93,7 +95,7 @@ class patchthesaurus_203 implements patchthesaurus_interface
return($version); return($version);
} }
public function fixRejected(connection_pdo &$connbas, &$node, $rejected) public function fixRejected(Connection $connbas, &$node, $rejected)
{ {
if ($node->nodeType != XML_ELEMENT_NODE) { if ($node->nodeType != XML_ELEMENT_NODE) {
return; return;
@@ -123,7 +125,7 @@ class patchthesaurus_203 implements patchthesaurus_interface
$this->fixRejected($connbas, $n, $rejected); $this->fixRejected($connbas, $n, $rejected);
} }
public function fixIds(connection_pdo &$connbas, &$node) public function fixIds(Connection $connbas, &$node)
{ {
if ($node->nodeType != XML_ELEMENT_NODE) { if ($node->nodeType != XML_ELEMENT_NODE) {
return; return;

View File

@@ -9,9 +9,11 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
use Doctrine\DBAL\Connection;
class patchthesaurus_204 implements patchthesaurus_interface class patchthesaurus_204 implements patchthesaurus_interface
{ {
public function patch($version, \DOMDocument $domct, \DOMDocument $domth, \connection_interface $connbas, \unicode $unicode) public function patch($version, \DOMDocument $domct, \DOMDocument $domth, Connection $connbas, \unicode $unicode)
{ {
$needreindex = false; $needreindex = false;
@@ -95,7 +97,7 @@ class patchthesaurus_204 implements patchthesaurus_interface
return($version); return($version);
} }
public function fixRejected(connection_pdo &$connbas, &$node, $rejected) public function fixRejected(Connection &$connbas, &$node, $rejected)
{ {
if ($node->nodeType != XML_ELEMENT_NODE) { if ($node->nodeType != XML_ELEMENT_NODE) {
return; return;
@@ -125,7 +127,7 @@ class patchthesaurus_204 implements patchthesaurus_interface
$this->fixRejected($connbas, $n, $rejected); $this->fixRejected($connbas, $n, $rejected);
} }
public function fixIds(connection_pdo &$connbas, &$node) public function fixIds(Connection $connbas, &$node)
{ {
if ($node->nodeType != XML_ELEMENT_NODE) { if ($node->nodeType != XML_ELEMENT_NODE) {
return; return;

View File

@@ -9,7 +9,9 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
use Doctrine\DBAL\Connection;
interface patchthesaurus_interface interface patchthesaurus_interface
{ {
public function patch($version, \DOMDocument $domct, \DOMDocument $domth, \connection_interface $connbas, \unicode $unicode); public function patch($version, \DOMDocument $domct, \DOMDocument $domth, Connection $connbas, \unicode $unicode);
} }

View File

@@ -119,7 +119,7 @@ class phrasea
public static function baseFromColl($sbas_id, $coll_id, Application $app) public static function baseFromColl($sbas_id, $coll_id, Application $app)
{ {
if (!self::$_coll2bas) { if (!self::$_coll2bas) {
$conn = connection::getPDOConnection($app); $conn = $app['phraseanet.appbox']->get_connection();
$sql = 'SELECT base_id, server_coll_id, sbas_id FROM bas'; $sql = 'SELECT base_id, server_coll_id, sbas_id FROM bas';
$stmt = $conn->prepare($sql); $stmt = $conn->prepare($sql);
$stmt->execute(); $stmt->execute();
@@ -169,7 +169,7 @@ class phrasea
public static function collFromBas(Application $app, $base_id) public static function collFromBas(Application $app, $base_id)
{ {
if (!self::$_bas2coll) { if (!self::$_bas2coll) {
$conn = connection::getPDOConnection($app); $conn = $app['phraseanet.appbox']->get_connection();
$sql = 'SELECT base_id, server_coll_id FROM bas'; $sql = 'SELECT base_id, server_coll_id FROM bas';
$stmt = $conn->prepare($sql); $stmt = $conn->prepare($sql);
$stmt->execute(); $stmt->execute();

View File

@@ -48,7 +48,7 @@ class random
public function cleanTokens() public function cleanTokens()
{ {
try { try {
$conn = connection::getPDOConnection($this->app); $conn = $this->app['phraseanet.appbox']->get_connection();
$date = new DateTime(); $date = new DateTime();
$date = $this->app['date-formatter']->format_mysql($date); $date = $this->app['date-formatter']->format_mysql($date);
@@ -120,7 +120,7 @@ class random
public function getUrlToken($type, $usr, DateTime $end_date = null, $datas = '') public function getUrlToken($type, $usr, DateTime $end_date = null, $datas = '')
{ {
$this->cleanTokens(); $this->cleanTokens();
$conn = connection::getPDOConnection($this->app); $conn = $this->app['phraseanet.appbox']->get_connection();
$token = $test = false; $token = $test = false;
switch ($type) { switch ($type) {
@@ -178,7 +178,7 @@ class random
$this->cleanTokens(); $this->cleanTokens();
try { try {
$conn = connection::getPDOConnection($this->app); $conn = $this->app['phraseanet.appbox']->get_connection();
$sql = 'DELETE FROM tokens WHERE value = :token'; $sql = 'DELETE FROM tokens WHERE value = :token';
$stmt = $conn->prepare($sql); $stmt = $conn->prepare($sql);
$stmt->execute([':token' => $token]); $stmt->execute([':token' => $token]);
@@ -195,7 +195,7 @@ class random
public function updateToken($token, $datas) public function updateToken($token, $datas)
{ {
try { try {
$conn = connection::getPDOConnection($this->app); $conn = $this->app['phraseanet.appbox']->get_connection();
$sql = 'UPDATE tokens SET datas = :datas $sql = 'UPDATE tokens SET datas = :datas
WHERE value = :token'; WHERE value = :token';
@@ -216,7 +216,7 @@ class random
{ {
$this->cleanTokens(); $this->cleanTokens();
$conn = connection::getPDOConnection($this->app); $conn = $this->app['phraseanet.appbox']->get_connection();
$sql = 'SELECT * FROM tokens $sql = 'SELECT * FROM tokens
WHERE value = :token WHERE value = :token
AND (expire_on > NOW() OR expire_on IS NULL)'; AND (expire_on > NOW() OR expire_on IS NULL)';
@@ -243,7 +243,7 @@ class random
*/ */
public function getValidationToken($userId, $basketId) public function getValidationToken($userId, $basketId)
{ {
$conn = \connection::getPDOConnection($this->app); $conn = $this->app['phraseanet.appbox']->get_connection();
$sql = ' $sql = '
SELECT value FROM tokens SELECT value FROM tokens
WHERE type = :type WHERE type = :type

View File

@@ -295,7 +295,8 @@ class record_adapter implements record_Interface, cache_cacheableInterface
throw new Exception('unrecognized document type'); throw new Exception('unrecognized document type');
} }
$connbas = connection::getPDOConnection($this->app, $this->get_sbas_id()); $databox = $this->app['phraseanet.appbox']->get_databox($this->get_sbas_id());
$connbas = $databox->get_connection();
$sql = 'UPDATE record SET type = :type WHERE record_id = :record_id'; $sql = 'UPDATE record SET type = :type WHERE record_id = :record_id';
$stmt = $connbas->prepare($sql); $stmt = $connbas->prepare($sql);
@@ -1099,7 +1100,8 @@ class record_adapter implements record_Interface, cache_cacheableInterface
*/ */
public function rebuild_subdefs() public function rebuild_subdefs()
{ {
$connbas = connection::getPDOConnection($this->app, $this->get_sbas_id()); $databox = $this->app['phraseanet.appbox']->get_databox($this->get_sbas_id());
$connbas = $databox->get_connection();
$sql = 'UPDATE record SET jeton=(jeton | ' . JETON_MAKE_SUBDEF . ') WHERE record_id = :record_id'; $sql = 'UPDATE record SET jeton=(jeton | ' . JETON_MAKE_SUBDEF . ') WHERE record_id = :record_id';
$stmt = $connbas->prepare($sql); $stmt = $connbas->prepare($sql);
$stmt->execute([':record_id' => $this->get_record_id()]); $stmt->execute([':record_id' => $this->get_record_id()]);
@@ -1113,7 +1115,8 @@ class record_adapter implements record_Interface, cache_cacheableInterface
*/ */
public function write_metas() public function write_metas()
{ {
$connbas = connection::getPDOConnection($this->app, $this->get_sbas_id()); $databox = $this->app['phraseanet.appbox']->get_databox($this->get_sbas_id());
$connbas = $databox->get_connection();
$sql = 'UPDATE record $sql = 'UPDATE record
SET jeton = ' . (JETON_WRITE_META_DOC | JETON_WRITE_META_SUBDEF) . ' SET jeton = ' . (JETON_WRITE_META_DOC | JETON_WRITE_META_SUBDEF) . '
WHERE record_id= :record_id'; WHERE record_id= :record_id';
@@ -1130,7 +1133,8 @@ class record_adapter implements record_Interface, cache_cacheableInterface
*/ */
public function set_binary_status($status) public function set_binary_status($status)
{ {
$connbas = connection::getPDOConnection($this->app, $this->get_sbas_id()); $databox = $this->app['phraseanet.appbox']->get_databox($this->get_sbas_id());
$connbas = $databox->get_connection();
$sql = 'UPDATE record SET status = 0b' . $status . ' $sql = 'UPDATE record SET status = 0b' . $status . '
WHERE record_id= :record_id'; WHERE record_id= :record_id';
@@ -1333,7 +1337,8 @@ class record_adapter implements record_Interface, cache_cacheableInterface
*/ */
public static function get_record_by_sha(Application $app, $sbas_id, $sha256, $record_id = null) public static function get_record_by_sha(Application $app, $sbas_id, $sha256, $record_id = null)
{ {
$conn = connection::getPDOConnection($app, $sbas_id); $databox = $app['phraseanet.appbox']->get_databox($sbas_id);
$conn = $databox->get_connection();
$sql = "SELECT record_id $sql = "SELECT record_id
FROM record r FROM record r
@@ -1583,7 +1588,8 @@ class record_adapter implements record_Interface, cache_cacheableInterface
public function log_view($log_id, $referrer, $gv_sit) public function log_view($log_id, $referrer, $gv_sit)
{ {
$connbas = connection::getPDOConnection($this->app, $this->get_sbas_id()); $databox = $this->app['phraseanet.appbox']->get_databox($this->get_sbas_id());
$connbas = $databox->get_connection();
$sql = 'INSERT INTO log_view (id, log_id, date, record_id, referrer, site_id) $sql = 'INSERT INTO log_view (id, log_id, date, record_id, referrer, site_id)
VALUES VALUES

View File

@@ -328,7 +328,8 @@ class record_preview extends record_adapter
$report = $this->app['acl']->get($this->app['authentication']->getUser())->has_right_on_base($this->get_base_id(), 'canreport'); $report = $this->app['acl']->get($this->app['authentication']->getUser())->has_right_on_base($this->get_base_id(), 'canreport');
$connsbas = connection::getPDOConnection($this->app, $this->get_sbas_id()); $databox = $this->app['phraseanet.appbox']->get_databox($this->get_sbas_id());
$connsbas = $databox->get_connection();
$sql = 'SELECT d . * , l.user, l.usrid as usr_id, l.site $sql = 'SELECT d . * , l.user, l.usrid as usr_id, l.site
FROM log_docs d, log l FROM log_docs d, log l
@@ -431,7 +432,8 @@ class record_preview extends record_adapter
AND site_id = :site AND site_id = :site
GROUP BY datee ORDER BY datee ASC'; GROUP BY datee ORDER BY datee ASC';
$connsbas = connection::getPDOConnection($this->app, $this->get_sbas_id()); $databox = $this->app['phraseanet.appbox']->get_databox($this->get_sbas_id());
$connsbas = $databox->get_connection();
$stmt = $connsbas->prepare($sql); $stmt = $connsbas->prepare($sql);
$stmt->execute( $stmt->execute(
[ [
@@ -499,7 +501,8 @@ class record_preview extends record_adapter
return $this->refferer_popularity; return $this->refferer_popularity;
} }
$connsbas = connection::getPDOConnection($this->app, $this->get_sbas_id()); $databox = $this->app['phraseanet.appbox']->get_databox($this->get_sbas_id());
$connsbas = $databox->get_connection();
$sql = 'SELECT count( id ) AS views, referrer $sql = 'SELECT count( id ) AS views, referrer
FROM `log_view` FROM `log_view`
@@ -592,7 +595,8 @@ class record_preview extends record_adapter
AND site= :site AND site= :site
GROUP BY datee ORDER BY datee ASC'; GROUP BY datee ORDER BY datee ASC';
$connsbas = connection::getPDOConnection($this->app, $this->get_sbas_id()); $databox = $this->app['phraseanet.appbox']->get_databox($this->get_sbas_id());
$connsbas = $databox->get_connection();
$stmt = $connsbas->prepare($sql); $stmt = $connsbas->prepare($sql);
$stmt->execute( $stmt->execute(
[ [

View File

@@ -84,7 +84,7 @@ class InstallTest extends \PhraseanetTestCase
self::$DI['cli']['phraseanet.installer']->expects($this->once()) self::$DI['cli']['phraseanet.installer']->expects($this->once())
->method('install') ->method('install')
->with($email, $password, $this->isInstanceOf('\connection_interface'), $serverName, $dataPath, $this->isInstanceOf('\connection_interface'), $template, $this->anything()); ->with($email, $password, $this->isInstanceOf('Doctrine\DBAL\Connection'), $serverName, $dataPath, $this->isInstanceOf('Doctrine\DBAL\Connection'), $template, $this->anything());
$command = new Install('system:check'); $command = new Install('system:check');
$command->setHelperSet($helperSet); $command->setHelperSet($helperSet);

View File

@@ -29,11 +29,23 @@ class XSendFileMappingGeneratorTest extends \PhraseanetTestCase
self::$DI['cli']['monolog'] = self::$DI['cli']->share(function () { self::$DI['cli']['monolog'] = self::$DI['cli']->share(function () {
return $this->getMockBuilder('Monolog\Logger')->disableOriginalConstructor()->getMock(); return $this->getMockBuilder('Monolog\Logger')->disableOriginalConstructor()->getMock();
}); });
self::$DI['cli']['conf'] = $this->getMockBuilder('Alchemy\Phrasea\Core\Configuration\PropertyAccess')
$originalConf = self::$DI['cli']['conf'];
$conf = $this->getMockBuilder('Alchemy\Phrasea\Core\Configuration\PropertyAccess')
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
if ($option) { $conf->expects($this->any())
->method('get')
->will($this->returnCallback(function ($property) use ($originalConf) {
switch ($property) {
case ['main', 'database']:
return $originalConf->get($property);
break;
}
}));
self::$DI['cli']['conf'] = $conf;
if ($option) {
self::$DI['cli']['conf']->expects($this->once()) self::$DI['cli']['conf']->expects($this->once())
->method('set') ->method('set')
->with('xsendfile'); ->with('xsendfile');

View File

@@ -29,7 +29,7 @@ abstract class AbstractSetupTester extends \PhraseanetTestCase
protected function goBackTo31() protected function goBackTo31()
{ {
$app = new Application('test'); $app = new Application('test');
$credentials = $app['phraseanet.appbox']->get_connection()->get_credentials(); $conn = $app['phraseanet.appbox']->get_connection();
$this->uninstall(); $this->uninstall();
@@ -38,10 +38,10 @@ abstract class AbstractSetupTester extends \PhraseanetTestCase
file_put_contents( __DIR__ . '/../../../../../config/_GV.php', str_replace('http://local.phrasea/', 'http://local.phrasea.tester/', file_get_contents( __DIR__ . '/../../../../../config/_GV.php'))); file_put_contents( __DIR__ . '/../../../../../config/_GV.php', str_replace('http://local.phrasea/', 'http://local.phrasea.tester/', file_get_contents( __DIR__ . '/../../../../../config/_GV.php')));
file_put_contents(__DIR__ . '/../../../../../config/connexion.inc', "<?php\n file_put_contents(__DIR__ . '/../../../../../config/connexion.inc', "<?php\n
\$hostname = '".$credentials['hostname']."'; \$hostname = '".$conn->getHost()."';
\$port = '".$credentials['port']."'; \$port = '".$conn->getPort()."';
\$user = '".$credentials['user']."'; \$user = '".$conn->getUsername()."';
\$password = '".$credentials['password']."'; \$password = '".$conn->getPassword()."';
\$dbname = 'ab_unitTests'; \$dbname = 'ab_unitTests';
"); ");
@@ -54,17 +54,17 @@ abstract class AbstractSetupTester extends \PhraseanetTestCase
protected function goBackTo35() protected function goBackTo35()
{ {
$app = new Application('test'); $app = new Application('test');
$credentials = $app['phraseanet.appbox']->get_connection()->get_credentials(); $conn = $app['phraseanet.appbox']->get_connection();
$this->uninstall(); $this->uninstall();
file_put_contents(__DIR__ . '/../../../../../config/config.inc', "<?php\n\$servername = 'http://local.phrasea';\n"); file_put_contents(__DIR__ . '/../../../../../config/config.inc', "<?php\n\$servername = 'http://local.phrasea';\n");
file_put_contents(__DIR__ . '/../../../../../config/connexion.inc', "<?php\n file_put_contents(__DIR__ . '/../../../../../config/connexion.inc', "<?php\n
\$hostname = '".$credentials['hostname']."'; \$hostname = '".$conn->getHost()."';
\$port = '".$credentials['port']."'; \$port = '".$conn->getPort()."';
\$user = '".$credentials['user']."'; \$user = '".$conn->getUsername()."';
\$password = '".$credentials['password']."'; \$password = '".$conn->getPassword()."';
\$dbname = '".$credentials['dbname']."'; \$dbname = '".$conn->getDatabase()."';
"); ");
$this->tearDownHandlers[] = function () { $this->tearDownHandlers[] = function () {

View File

@@ -15,19 +15,16 @@ class InstallerTest extends \PhraseanetTestCase
public function setUp() public function setUp()
{ {
parent::setUp(); parent::setUp();
\connection::close_connections();
} }
public function tearDown() public function tearDown()
{ {
\connection::close_connections();
parent::tearDown(); parent::tearDown();
} }
public static function tearDownAfterClass() public static function tearDownAfterClass()
{ {
$app = new Application('test'); $app = new Application('test');
\connection::close_connections();
\phrasea::reset_sbasDatas($app['phraseanet.appbox']); \phrasea::reset_sbasDatas($app['phraseanet.appbox']);
\phrasea::reset_baseDatas($app['phraseanet.appbox']); \phrasea::reset_baseDatas($app['phraseanet.appbox']);
parent::tearDownAfterClass(); parent::tearDownAfterClass();
@@ -53,8 +50,22 @@ class InstallerTest extends \PhraseanetTestCase
$app['configuration.store'] = new Configuration(new Yaml(), new Compiler(), $config, $compiled, true); $app['configuration.store'] = new Configuration(new Yaml(), new Compiler(), $config, $compiled, true);
$abConn = new \connection_pdo('abConn', 'localhost', 3306, $credentials['user'], $credentials['password'], 'ab_unitTests'); $abConn = self::$DI['app']['dbal.provider']->get([
$dbConn = new \connection_pdo('dbConn', 'localhost', 3306, $credentials['user'], $credentials['password'], 'db_unitTests'); 'host' => 'localhost',
'port' => 3306,
'user' => $credentials['user'],
'password' => $credentials['password'],
'dbname' => 'ab_unitTests',
]);
$abConn->connect();
$dbConn = self::$DI['app']['dbal.provider']->get([
'host' => 'localhost',
'port' => 3306,
'user' => $credentials['user'],
'password' => $credentials['password'],
'dbname' => 'db_unitTests',
]);
$dbConn->connect();
$template = 'en'; $template = 'en';
$dataPath = __DIR__ . '/../../../../../datas/'; $dataPath = __DIR__ . '/../../../../../datas/';

View File

@@ -1,5 +1,6 @@
<?php <?php
use Doctrine\DBAL\DBALException;
use Silex\Application; use Silex\Application;
use Symfony\Component\DomCrawler\Crawler; use Symfony\Component\DomCrawler\Crawler;
@@ -90,18 +91,15 @@ abstract class PhraseanetAuthenticatedWebTestCase extends \PhraseanetAuthenticat
$connexion = self::$DI['app']['phraseanet.configuration']['main']['database']; $connexion = self::$DI['app']['phraseanet.configuration']['main']['database'];
try { try {
$conn = new \connection_pdo( $conn = self::$DI['app']['dbal.provider']->get([
'databox_creation', 'host' => $connexion['host'],
$connexion['host'], 'port' => $connexion['port'],
$connexion['port'], 'user' => $connexion['user'],
$connexion['user'], 'password' => $connexion['password'],
$connexion['password'], 'dbname' => 'unit_test_db',
'unit_test_db', ]);
[], $conn->connect();
false } catch (DBALException $e) {
);
} catch (\PDOException $e) {
$this->markTestSkipped('Could not reach DB'); $this->markTestSkipped('Could not reach DB');
} }

View File

@@ -70,6 +70,10 @@ abstract class PhraseanetTestCase extends WebTestCase
{ {
parent::setUp(); parent::setUp();
if (null !== self::$DI) {
unset(self::$DI['app']['dbal.provider']);
}
self::$DI = new \Pimple(); self::$DI = new \Pimple();
ini_set('memory_limit', '4096M'); ini_set('memory_limit', '4096M');

View File

@@ -112,7 +112,7 @@ class collectionTest extends \PhraseanetAuthenticatedTestCase
public function testGet_connection() public function testGet_connection()
{ {
$this->assertInstanceOf('connection_pdo', self::$object->get_connection()); $this->assertInstanceOf('Doctrine\DBAL\Connection', self::$object->get_connection());
} }
/** /**

View File

@@ -70,8 +70,8 @@ class databox_fieldTest extends \PhraseanetTestCase
public function testGet_connection() public function testGet_connection()
{ {
$this->assertInstanceOf('\connection_pdo', $this->object_mono->get_connection()); $this->assertInstanceOf('Doctrine\DBAL\Connection', $this->object_mono->get_connection());
$this->assertInstanceOf('\connection_pdo', $this->object_multi->get_connection()); $this->assertInstanceOf('Doctrine\DBAL\Connection', $this->object_multi->get_connection());
} }
public function testGet_databox() public function testGet_databox()

View File

@@ -10,6 +10,9 @@ class report_sqlActionTest extends \PhraseanetAuthenticatedTestCase
parent::setUp(); parent::setUp();
$this->mock = $this->getMock('module_report', [], [], '', false); $this->mock = $this->getMock('module_report', [], [], '', false);
$this->mock->expects($this->any())
->method('getSbasId')
->will($this->returnValue(self::$DI['collection']->get_databox()->get_sbas_id()));
$this->action = new module_report_sqlaction(self::$DI['app'], $this->mock); $this->action = new module_report_sqlaction(self::$DI['app'], $this->mock);
} }

View File

@@ -7,6 +7,9 @@ class report_sqlTest extends \PhraseanetAuthenticatedTestCase
{ {
parent::setUp(); parent::setUp();
$report = $this->getMock('module_report', [], [], '', false); $report = $this->getMock('module_report', [], [], '', false);
$report->expects($this->any())
->method('getSbasId')
->will($this->returnValue(self::$DI['collection']->get_databox()->get_sbas_id()));
$this->sql = new module_report_sql(self::$DI['app'], $report); $this->sql = new module_report_sql(self::$DI['app'], $report);
} }