File: /var/www/dvpis2025/dvpis.kaunokolegija.lt/src/Controller/DbManagementController.php
<?php
namespace App\Controller;
use Doctrine\ORM\EntityManagerInterface;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\Request;
/**
* Dbmanagement controller.
*
* @Security("is_granted('ROLE_STUDY_DEPARTMENT')")
*/
#[Route(path: 'dbmanagement')]
class DbManagementController extends AbstractController
{
public function __construct(
private readonly EntityManagerInterface $em,
) {
}
/**
* Lists all dbManagement entities.
*
* @Method("GET")
*/
#[Route(path: '/', name: 'dbmanagement_index')]
public function indexAction()
{
$query = "SHOW DATABASES LIKE 'dvpis%'";
$statement = $this->em->getConnection()->prepare($query);
$statement->execute();
$dbManagements = $statement->fetchAll();
return $this->render('dbmanagement/index.html.twig', array(
'dbManagements' => $dbManagements,
));
}
/**
* change database.
*
* @Method({"GET"})
*/
#[Route(path: '/changedb/{db}', name: 'dbmanagement_changedb')]
public function changeDbAction(Request $request, $db = 'dvpis')
{
if ($db == 'dvpis') {
unset($_COOKIE['newDb']);
setcookie('newDb', 'dvpis', -1, "/");
} else {
setcookie('newDb', $db, 0, "/");
}
return $this->redirectToRoute('dbmanagement_index');
}
/**
* change database to default.
*
* @Method({"GET"})
*/
#[Route(path: '/changedbdefault', name: 'dbmanagement_defaultdb')]
public function changeDbDefaultAction(Request $request)
{
return $this->changeDbAction($request);
}
}