-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInstallController.php
More file actions
109 lines (91 loc) · 3.11 KB
/
InstallController.php
File metadata and controls
109 lines (91 loc) · 3.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<?php
namespace SyncEngine\Controller\Setup;
use Doctrine\ORM\EntityManagerInterface;
use Psr\Log\LoggerInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
use SyncEngine\Controller\Admin\SystemController;
use SyncEngine\Controller\DefaultController;
use SyncEngine\Service\System;
class InstallController extends DefaultController
{
#[Route( '/install', name: 'install' )]
public function renderInstall(
Request $request,
EntityManagerInterface $entityManager,
System $system,
SystemController $systemController,
LoggerInterface $syncengineLogger,
): Response {
if ( true === $system->isInstalled( $entityManager ) ) {
if ( true !== $system->isRegistered( $entityManager ) ) {
return $this->redirectToRoute( 'syncengine_register' );
}
return $this->redirectToRoute( 'syncengine_admin_login' );
}
$env = $system->getEnv();
$form = $systemController->formEnv( $request, $env, $this->trans( 'Install' ) );
// Check if a database is configured and the system is not installed yet.
if ( $env->get( 'DATABASE_URL' ) && ! $system->isInstalled() ) {
// Validate database connection.
$dbConnected = $system->isDatabaseConnected( $entityManager, $env );
if ( $dbConnected instanceof \Throwable ) {
$this->addFlash( 'warning', $dbConnected->getMessage() );
$syncengineLogger->error( $dbConnected );
} elseif ( $dbConnected ) {
try {
// Install database schema.
$success = $system->install( $entityManager, $env );
if ( $success instanceof \Throwable ) {
$this->addFlash( 'warning', $success->getMessage() );
$syncengineLogger->error( $success );
} else {
// Check if installed successfully.
$success = $system->isInstalled( $entityManager, $env );
if ( true === $success ) {
return $this->redirectToRoute( 'syncengine_register' );
}
if ( $success instanceof \Throwable ) {
$this->addFlash( 'warning', $success->getMessage() );
$syncengineLogger->error( $success );
} else {
$this->addFlash( 'warning', $this->trans( 'Unknown database error' ) );
}
}
} catch ( \Throwable $e ) {
$this->addFlash( 'warning', $e->getMessage() );
$syncengineLogger->error( $e );
}
}
}
return $this->render( 'index.html.twig', [
'header' => $this->trans( 'Environment' ),
'form' => $form,
'breadcrumbs' => [
[
'link' => $this->generateUrl( 'syncengine_system_index' ),
'title' => $this->trans( 'System' ),
],
[
'title' => $this->trans( 'Environment' ),
'current' => true,
],
],
] );
}
#[Route( '/install/repair', name: 'install_repair' )]
public function handleRepair(
Request $request,
EntityManagerInterface $entityManager,
System $system,
): Response {
// Reinstall.
$response = $system->installDatabase();
if ( $system->isInstalled( $entityManager ) ) {
return $this->redirectToRoute( 'syncengine_admin_index' );
}
return new JsonResponse( $response );
}
}