1<?php
2// (c) Copyright by authors of the Tiki Wiki CMS Groupware Project
3//
4// All Rights Reserved. See copyright.txt for details and a complete list of authors.
5// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
6// $Id$
7
8namespace Tiki\Command;
9
10use Symfony\Component\Console\Command\Command;
11use Symfony\Component\Console\Input\InputArgument;
12use Symfony\Component\Console\Input\InputInterface;
13use Symfony\Component\Console\Input\InputOption;
14use Symfony\Component\Console\Output\OutputInterface;
15
16class InstallCommand extends Command
17{
18	protected function configure()
19	{
20		$this
21			->setName('database:install')
22			->setDescription(tr('Clean Tiki install'))
23			->addOption(
24				'force',
25				null,
26				InputOption::VALUE_NONE,
27				tr('Force installation. Overwrite any current database.')
28			)
29			->addOption(
30				'useInnoDB',
31				'i',
32				InputOption::VALUE_REQUIRED,
33				tr('Use InnoDb as storage engine: 1 - InnoDb, 0 - MyISAM.'),
34				1
35			);
36	}
37
38	protected function execute(InputInterface $input, OutputInterface $output)
39	{
40		$force = $input->getOption('force');
41		$installer = \Installer::getInstance();
42		$installed = $installer->tableExists('users_users');
43
44		$optionUseInnoDB = $input->getOption('useInnoDB');
45		if ($optionUseInnoDB !== null) {
46			$installer->useInnoDB = ($optionUseInnoDB == 1) ? true : false;
47		}
48
49		if (! $installed || $force) {
50			$installer->cleanInstall();
51			$output->writeln(tr('Installation completed.'));
52			$output->writeln('<info>' . tr('Queries executed successfully: %0', count($installer->queries['successful'])) . '</info>');
53
54			if (count($installer->queries['failed'])) {
55				foreach ($installer->queries['failed'] as $key => $error) {
56					list($query, $message, $patch) = $error;
57
58					$output->writeln("<error>" . tr('Error %0 in', $key) . " $patch\n\t$query\n\t$message</error>");
59				}
60			}
61
62			if (! DB_STATUS) { // see console.php
63				return;
64			}
65
66			include_once 'tiki-setup.php';
67			\TikiLib::lib('cache')->empty_cache();
68			initialize_prefs(true);
69			\TikiLib::lib('unifiedsearch')->rebuild();
70			\TikiLib::lib('prefs')->rebuildIndex();
71		} else {
72			$output->writeln('<error>' . tr('Database already exists.') . '</error>');
73		}
74	}
75}
76