aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--app/build.xml1
-rw-r--r--composer.json9
-rw-r--r--src/Wallabag/CoreBundle/Command/InstallCommand.php165
3 files changed, 167 insertions, 8 deletions
diff --git a/app/build.xml b/app/build.xml
index 16ef73ed..b3f4c13a 100644
--- a/app/build.xml
+++ b/app/build.xml
@@ -9,7 +9,6 @@
9 <target name="prepare" depends="clean" description="Prepare for build"> 9 <target name="prepare" depends="clean" description="Prepare for build">
10 <exec executable="composer"> 10 <exec executable="composer">
11 <arg value="install"/> 11 <arg value="install"/>
12 <arg value="--dev"/>
13 <arg value="--no-interaction"/> 12 <arg value="--no-interaction"/>
14 <arg value="--working-dir=.."/> 13 <arg value="--working-dir=.."/>
15 </exec> 14 </exec>
diff --git a/composer.json b/composer.json
index d83a497e..2b22d6bd 100644
--- a/composer.json
+++ b/composer.json
@@ -87,25 +87,20 @@
87 "phpunit/phpunit": "~4.4" 87 "phpunit/phpunit": "~4.4"
88 }, 88 },
89 "scripts": { 89 "scripts": {
90 "post-root-package-install": [
91 "SymfonyStandard\\Composer::hookRootPackageInstall"
92 ],
93 "post-install-cmd": [ 90 "post-install-cmd": [
94 "Incenteev\\ParameterHandler\\ScriptHandler::buildParameters", 91 "Incenteev\\ParameterHandler\\ScriptHandler::buildParameters",
95 "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap", 92 "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
96 "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache", 93 "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
97 "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets", 94 "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
98 "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile", 95 "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile",
99 "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::removeSymfonyStandardFiles", 96 "app/console wallabag:install --no-interaction"
100 "bin/install"
101 ], 97 ],
102 "post-update-cmd": [ 98 "post-update-cmd": [
103 "Incenteev\\ParameterHandler\\ScriptHandler::buildParameters", 99 "Incenteev\\ParameterHandler\\ScriptHandler::buildParameters",
104 "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap", 100 "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
105 "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache", 101 "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
106 "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets", 102 "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
107 "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile", 103 "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile"
108 "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::removeSymfonyStandardFiles"
109 ] 104 ]
110 }, 105 },
111 "extra": { 106 "extra": {
diff --git a/src/Wallabag/CoreBundle/Command/InstallCommand.php b/src/Wallabag/CoreBundle/Command/InstallCommand.php
new file mode 100644
index 00000000..32180020
--- /dev/null
+++ b/src/Wallabag/CoreBundle/Command/InstallCommand.php
@@ -0,0 +1,165 @@
1<?php
2
3namespace Wallabag\CoreBundle\Command;
4
5use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
6use Symfony\Component\Console\Input\InputInterface;
7use Symfony\Component\Console\Output\OutputInterface;
8use Wallabag\CoreBundle\Entity\Users;
9use Wallabag\CoreBundle\Entity\UsersConfig;
10
11class InstallCommand extends ContainerAwareCommand
12{
13 protected function configure()
14 {
15 $this
16 ->setName('wallabag:install')
17 ->setDescription('Wallabag installer.')
18 ;
19 }
20
21 protected function execute(InputInterface $input, OutputInterface $output)
22 {
23 $output->writeln('<info>Installing Wallabag.</info>');
24 $output->writeln('');
25
26 $this
27 ->checkStep($output)
28 ->setupStep($input, $output)
29 ;
30
31 $output->writeln('<info>Wallabag has been successfully installed.</info>');
32 $output->writeln('<comment>Just execute `php app/console server:run` for using wallabag: http://localhost:8000</comment>');
33 }
34
35 protected function checkStep(OutputInterface $output)
36 {
37 $output->writeln('<info>Checking system requirements.</info>');
38
39 $fulfilled = true;
40
41 // @TODO: find a better way to check requirements
42 $output->writeln('<comment>Check PCRE</comment>');
43 if (extension_loaded('pcre')) {
44 $output->writeln(' <info>OK</info>');
45 } else {
46 $fulfilled = false;
47 $output->writeln(' <error>ERROR</error>');
48 $output->writeln('<comment>You should enabled PCRE extension</comment>');
49 }
50
51 $output->writeln('<comment>Check DOM</comment>');
52 if (extension_loaded('DOM')) {
53 $output->writeln(' <info>OK</info>');
54 } else {
55 $fulfilled = false;
56 $output->writeln(' <error>ERROR</error>');
57 $output->writeln('<comment>You should enabled DOM extension</comment>');
58 }
59
60 if (!$fulfilled) {
61 throw new RuntimeException('Some system requirements are not fulfilled. Please check output messages and fix them.');
62 }
63
64 $output->writeln('');
65
66 return $this;
67 }
68
69 protected function setupStep(InputInterface $input, OutputInterface $output)
70 {
71 $output->writeln('<info>Setting up database.</info>');
72
73 $this->setupDatabase($input, $output);
74
75 // if ($this->getHelperSet()->get('dialog')->askConfirmation($output, '<question>Load fixtures (Y/N)?</question>', false)) {
76 // $this->setupFixtures($input, $output);
77 // }
78
79 $output->writeln('');
80 $output->writeln('<info>Administration setup.</info>');
81
82 $this->setupAdmin($output);
83
84 $output->writeln('');
85
86 return $this;
87 }
88
89 protected function setupDatabase(InputInterface $input, OutputInterface $output)
90 {
91 if ($this->getHelperSet()->get('dialog')->askConfirmation($output, '<question>Drop current database (Y/N)?</question>', true)) {
92 $connection = $this->getContainer()->get('doctrine')->getConnection();
93 $params = $connection->getParams();
94
95 $name = isset($params['path']) ? $params['path'] : (isset($params['dbname']) ? $params['dbname'] : false);
96 unset($params['dbname']);
97
98 if (!isset($params['path'])) {
99 $name = $connection->getDatabasePlatform()->quoteSingleIdentifier($name);
100 }
101
102 $connection->getSchemaManager()->dropDatabase($name);
103 } else {
104 throw new \Exception("Install setup stopped, database need to be dropped. Please backup your current one and re-launch the install command.");
105 }
106
107 $this
108 ->runCommand('doctrine:database:create', $input, $output)
109 ->runCommand('doctrine:schema:create', $input, $output)
110 ->runCommand('cache:clear', $input, $output)
111 ->runCommand('assets:install', $input, $output)
112 ->runCommand('assetic:dump', $input, $output)
113 ;
114 }
115
116 protected function setupFixtures(InputInterface $input, OutputInterface $output)
117 {
118 $doctrineConfig = $this->getContainer()->get('doctrine.orm.entity_manager')->getConnection()->getConfiguration();
119 $logger = $doctrineConfig->getSQLLogger();
120 // speed up fixture load
121 $doctrineConfig->setSQLLogger(null);
122 $this->runCommand('doctrine:fixtures:load', $input, $output);
123 $doctrineConfig->setSQLLogger($logger);
124 }
125
126 protected function setupAdmin(OutputInterface $output)
127 {
128 $dialog = $this->getHelperSet()->get('dialog');
129 $em = $this->getContainer()->get('doctrine.orm.entity_manager');
130
131 $user = new Users();
132 $user->setUsername($dialog->ask($output, '<question>Username</question> <comment>(default: wallabag)</comment> :', 'wallabag'));
133 $user->setPassword($dialog->ask($output, '<question>Password</question> <comment>(default: wallabag)</comment> :', 'wallabag'));
134 $user->setEmail($dialog->ask($output, '<question>Email:</question>', ''));
135
136 $em->persist($user);
137
138 $pagerConfig = new UsersConfig();
139 $pagerConfig->setUserId($user->getId());
140 $pagerConfig->setName('pager');
141 $pagerConfig->setValue(10);
142
143 $em->persist($pagerConfig);
144
145 // $languageConfig = new LanguageConfig();
146 // $languageConfig->setUserId($user->getId());
147 // $languageConfig->setName('language');
148 // $languageConfig->setValue('en_EN.UTF8');
149
150 // $em->persist($languageConfig);
151
152 $em->flush();
153 }
154
155 protected function runCommand($command, InputInterface $input, OutputInterface $output)
156 {
157 $this
158 ->getApplication()
159 ->find($command)
160 ->run($input, $output)
161 ;
162
163 return $this;
164 }
165}