getRepository(Log::class)->findAll();
if(empty($data)){
echo json_encode(['success' => false]);
}
else{
$view = '
Table ' . TABLE_PREFIX . 'log de la base de données
| date et heure (Greenwich) |
connexion réussie |
';
foreach($data as $entry){
$view .= '
| ' . $entry->getFormatedDate() . ' |
' . ($entry->getSuccess() ? 'oui' : 'non') . ' |
';
}
$view .= '
';
echo json_encode(['success' => true, 'view' => $view]);
}
die;
}
static public function eraseLogs(EntityManager $entityManager): void
{
try{
$table = $entityManager->getClassMetadata(Log::class)->getTableName();
$entityManager->getConnection()->executeStatement("TRUNCATE TABLE {$table}"); // SQL donné à DBAL
echo json_encode(['success' => true]);
}
catch(Exception $e){
echo json_encode(['success' => false]);
}
die;
}
static public function getLastDump(): void
{
try{
$file_path = Backup::$backup_dir . '/' . Backup::getLastBackupName();
header('Content-Type: application/octet-stream'); // signifie fichier quelconque, du binaire quoi!
header('Content-Disposition: attachment; filename="' . basename($file_path) . '"'); // pour provoquer un téléchargement et non pour afficher
header('Content-Length: ' . filesize($file_path)); // peut servir côté client (barre de progression...)
readfile($file_path);
die;
}
// exeptions lancées dans Backup::mySQLdump
catch(RuntimeException $e){ // pas d'info $e pour le client7
header('Location: ' . new URL(['page' => 'maintenance', 'get_last_dump' => $e->getMessage()]));
}
die;
}
static public function getAllMedia(): void
{
try{
$file_path = '../var/' . UserDataService::createZip('all_media.zip', ['user_data/assets', 'user_data/images', 'user_data/media']);
header('Content-Type: application/zip');
header('Content-Disposition: attachment; filename="' . basename($file_path) . '"'); // pour provoquer un téléchargement et non pour afficher
header('Content-Length: ' . filesize($file_path)); // peut servir côté client (barre de progression...)
readfile($file_path);
die;
}
// exeptions lancées dans Backup::mySQLdump
catch(RuntimeException $e){ // pas d'info $e pour le client7
header('Location: ' . new URL(['page' => 'maintenance', 'get_all_media' => $e->getMessage()]));
}
die;
}
// parce qu'il faut un contrôleur
static public function handleBackupSelection(EntityManager $entityManager, string $selected_file): void
{
if(pathinfo($selected_file)['extension'] !== 'sql'){ // pas censé se produire en fait
throw new Exception("charger un fichier au format SQL");
}
Backup::restoreDatabase($entityManager, $selected_file);
}
static public function downloadSQL(EntityManager $entityManager, UploadedFile $uploaded_file): void
{
if(pathinfo($uploaded_file->getClientOriginalName())['extension'] !== 'sql'){
throw new Exception("Charger un fichier au format SQL");
}
//echo $uploaded_file->getSize(); // à garder de côté au cas où
$date = new DateTime;
$server_place = Config::$database . '_' . $date->format('Y-m-d') . '_uploaded.sql';
try{
// enregistrer le fichier
$uploaded_file->move(Backup::$backup_dir, $server_place);
// s'en servir
Backup::restoreDatabase($entityManager, $server_place);
}
finally{}
}
}