Files
Phraseanet/lib/Alchemy/Phrasea/Helper/DatabaseHelper.php
Nicolas Le Goff 28eecf6a09 Merge branch '3.8'
Conflicts:
	.gitignore
	bin/console
	composer.json
	composer.lock
	hudson/fixtures.sql
	lib/Alchemy/Phrasea/Command/Developer/IniReset.php
	lib/Alchemy/Phrasea/Command/Setup/Install.php
	lib/Alchemy/Phrasea/Controller/Api/Oauth2.php
	lib/Alchemy/Phrasea/Controller/Api/V1.php
	lib/Alchemy/Phrasea/Controller/Prod/Export.php
	lib/Alchemy/Phrasea/Controller/Root/Login.php
	lib/Alchemy/Phrasea/Core/Provider/PhraseanetServiceProvider.php
	lib/Alchemy/Phrasea/Core/Version.php
	lib/Alchemy/Phrasea/Helper/DatabaseHelper.php
	lib/Alchemy/Phrasea/Helper/Prod.php
	lib/classes/API/OAuth2/Application.php
	lib/classes/API/V1/Interface.php
	lib/classes/API/V1/adapter.php
	lib/classes/Setup/Upgrade.php
	lib/classes/media/subdef.php
	lib/classes/task/period/RecordMover.php
	templates/web/prod/index.html.twig
	templates/web/setup/step2.html.twig
	tests/Alchemy/Tests/Phrasea/Controller/Admin/RootTest.php
	tests/Alchemy/Tests/Phrasea/Controller/Root/LoginTest.php
	tests/classes/api/v1/api_v1_adapterTest.php
	tests/db-ref.sqlite
	vagrant/vms/phraseanet-php54-nginx/puphpet/config.yaml
	vagrant/vms/phraseanet-php54-nginx/puphpet/files/exec-once/setup
2014-10-09 19:40:33 +02:00

84 lines
2.3 KiB
PHP

<?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\Helper;
class DatabaseHelper extends Helper
{
public function checkConnection()
{
$hostname = $this->request->query->get('hostname', '127.0.0.1');
$port = (int) $this->request->query->get('port', 3306);
$user = $this->request->query->get('user');
$password = $this->request->query->get('password');
$db_name = $this->request->query->get('db_name');
$connection_ok = $db_ok = $is_databox = $is_appbox = $empty = false;
try {
$conn = $this->app['dbal.provider']->get([
'host' => $hostname,
'port' => $port,
'user' => $user,
'password' => $password
]);
$conn->connect();
$connection_ok = true;
} catch (\Exception $e) {
}
if (null !== $db_name && $connection_ok) {
try {
$conn = $this->app['dbal.provider']->get([
'host' => $hostname,
'port' => $port,
'user' => $user,
'password' => $password,
'dbname' => $db_name,
]);
$conn->connect();
$db_ok = true;
$sql = "SHOW TABLE STATUS";
$stmt = $conn->prepare($sql);
$stmt->execute();
$empty = $stmt->rowCount() === 0;
$rs = $stmt->fetchAll(\PDO::FETCH_ASSOC);
$stmt->closeCursor();
foreach ($rs as $row) {
if ($row["Name"] === 'sitepreff') {
$is_appbox = true;
}
if ($row["Name"] === 'pref') {
$is_databox = true;
}
}
} catch (\Exception $e) {
}
}
return [
'connection' => $connection_ok,
'database' => $db_ok,
'is_empty' => $empty,
'is_appbox' => $is_appbox,
'is_databox' => $is_databox
];
}
}