1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace XoopsConsole\Commands; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\Console\Command\Command; |
6
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
7
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
8
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
9
|
|
|
use Symfony\Component\Console\Input\InputOption; |
10
|
|
|
use Xoops\Core\XoopsTpl; |
11
|
|
|
|
12
|
|
|
class CiInstallCommand extends Command |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* establish the command configuration |
16
|
|
|
* @return void |
17
|
|
|
*/ |
18
|
|
|
protected function configure() |
19
|
|
|
{ |
20
|
|
|
$this->setName("ci-install") |
21
|
|
|
->setDescription("Install a minimal XOOPS for CI processes") |
22
|
|
|
->setDefinition(array()) |
23
|
|
|
->setHelp(<<<EOT |
24
|
|
|
The <info>ci-install</info> command installs a default XOOPS system for use in the |
25
|
|
|
travis-ci continuous integration environment. This command expects on an |
26
|
|
|
appropriate mainfile.php to have been previously created, possibly using the |
27
|
|
|
<info>ci-bootstrap</info> command (only available if mainfile.php does not exist.) |
28
|
|
|
EOT |
29
|
|
|
); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* execute the command |
34
|
|
|
* |
35
|
|
|
* @param InputInterface $input input handler |
36
|
|
|
* @param OutputInterface $output output handler |
37
|
|
|
* @return void |
38
|
|
|
*/ |
39
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
40
|
|
|
{ |
41
|
|
|
// install the 'system' module |
42
|
|
|
$xoops = \Xoops::getInstance(); |
43
|
|
|
$module = 'system'; |
44
|
|
|
$output->writeln(sprintf('Installing %s', $module)); |
45
|
|
|
if (false !== $xoops->getModuleByDirname($module)) { |
|
|
|
|
46
|
|
|
$output->writeln(sprintf('<error>%s module is already installed!</error>', $module)); |
47
|
|
|
return; |
48
|
|
|
} |
49
|
|
|
$xoops->setTpl(new XoopsTpl()); |
50
|
|
|
\XoopsLoad::load('module', 'system'); |
51
|
|
|
$sysmod = new \SystemModule(); |
52
|
|
|
$result = $sysmod->install($module); |
53
|
|
|
foreach ($sysmod->trace as $message) { |
54
|
|
|
if (is_array($message)) { |
55
|
|
|
foreach ($message as $subMessage) { |
56
|
|
|
if (!is_array($subMessage)) { |
57
|
|
|
$output->writeln(strip_tags($subMessage)); |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
} else { |
61
|
|
|
$output->writeln(strip_tags($message)); |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
if ($result===false) { |
65
|
|
|
$output->writeln(sprintf('<error>Install of %s module failed!</error>', $module)); |
66
|
|
|
} else { |
67
|
|
|
$output->writeln(sprintf('<info>Install of %s module completed.</info>', $module)); |
68
|
|
|
} |
69
|
|
|
$xoops->cache()->delete('system'); |
70
|
|
|
|
71
|
|
|
// add an admin user |
72
|
|
|
$adminname = 'admin'; |
73
|
|
|
$adminpass = password_hash($adminname, PASSWORD_DEFAULT); // user: admin pass: admin |
74
|
|
|
$regdate = time(); |
75
|
|
|
$result = $xoops->db()->insertPrefix( |
76
|
|
|
'system_user', |
77
|
|
|
array( |
78
|
|
|
// 'uid' => 1, // mediumint(8) unsigned NOT NULL auto_increment, |
79
|
|
|
'uname' => $adminname, // varchar(25) NOT NULL default '', |
80
|
|
|
'email' => 'nobody@localhost', // varchar(60) NOT NULL default '', |
81
|
|
|
'user_regdate' => $regdate, // int(10) unsigned NOT NULL default '0', |
82
|
|
|
'user_viewemail' => 1, // tinyint(1) unsigned NOT NULL default '0', |
83
|
|
|
'pass' => $adminpass, // varchar(255) NOT NULL default '', |
84
|
|
|
'rank' => 7, // smallint(5) unsigned NOT NULL default '0', |
85
|
|
|
'level' => 5, // tinyint(3) unsigned NOT NULL default '1', |
86
|
|
|
'last_login' => $regdate, // int(10) unsigned NOT NULL default '0', |
87
|
|
|
) |
88
|
|
|
); |
89
|
|
|
$output->writeln(sprintf('<info>Inserted %d user.</info>', $result)); |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|