Add use of core serializer

This commit is contained in:
Romain Neutron
2012-01-23 18:15:15 +01:00
parent 59fb747ca6
commit 7f0982848a
6 changed files with 345 additions and 288 deletions

View File

@@ -25,7 +25,6 @@ use Silex\ControllerCollection;
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class ConnectionTest implements ControllerProviderInterface
{
@@ -34,70 +33,78 @@ class ConnectionTest implements ControllerProviderInterface
$controllers = new ControllerCollection();
$controllers->get('/mysql/', function() use ($app)
{
require_once __DIR__ . '/../../../../classes/connection/pdo.class.php';
$request = $app['request'];
$hostname = $request->get('hostname', '127.0.0.1');
$port = (int) $request->get('port', 3306);
$user = $request->get('user');
$password = $request->get('password');
$dbname = $request->get('dbname');
$connection_ok = $db_ok = $is_databox = $is_appbox = $empty = false;
try
{
$conn = new \connection_pdo('test', $hostname, $port, $user, $password);
$connection_ok = true;
}
catch (\Exception $e)
{
}
if ($dbname && $connection_ok === true)
{
try
{
$conn = new \connection_pdo('test', $hostname, $port, $user, $password, $dbname);
$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)
{
require_once __DIR__ . '/../../../../classes/connection/pdo.class.php';
$request = $app['request'];
$hostname = $request->get('hostname', '127.0.0.1');
$port = (int) $request->get('port', 3306);
$user = $request->get('user');
$password = $request->get('password');
$dbname = $request->get('dbname');
$connection_ok = $db_ok = $is_databox = $is_appbox = $empty = false;
try
if ($row["Name"] === 'sitepreff')
{
$conn = new \connection_pdo('test', $hostname, $port, $user, $password);
$connection_ok = true;
$is_appbox = true;
}
catch (\Exception $e)
if ($row["Name"] === 'pref')
{
$is_databox = true;
}
}
}
catch (\Exception $e)
{
}
}
if ($dbname && $connection_ok === true)
{
try
{
$conn = new \connection_pdo('test', $hostname, $port, $user, $password, $dbname);
$db_ok = true;
$Serializer = $app['Core']['Serializer'];
$sql = "SHOW TABLE STATUS";
$stmt = $conn->prepare($sql);
$stmt->execute();
$datas = array(
'connection' => $connection_ok
, 'database' => $db_ok
, 'is_empty' => $empty
, 'is_appbox' => $is_appbox
, 'is_databox' => $is_databox
);
$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 new Response(\p4string::jsonencode(array(
'connection' => $connection_ok
, 'database' => $db_ok
, 'is_empty' => $empty
, 'is_appbox' => $is_appbox
, 'is_databox' => $is_databox
)), 200, array('content-type' => 'application/json'));
});
return new Response(
$Serializer->serialize($datas, 'json')
, 200
, array('content-type' => 'application/json')
);
});
return $controllers;
}