forked from FluidTYPO3/flux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCommandLineLauncher.php
143 lines (133 loc) · 5.58 KB
/
CommandLineLauncher.php
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<?php
if (!defined('TYPO3_cliMode')) {
die('You cannot run this script directly!');
}
require_once (PATH_t3lib . 'class.t3lib_cli.php');
require_once ('DynFlexMigration.php');
/**
* CLI
*/
class tx_flux_cli extends t3lib_cli {
/**
* Constructor
*/
public function __construct() {
parent::__construct();
$this->cli_help['name'] = 'Flux CLI script';
$this->cli_help['synopsis'] = '###OPTIONS###';
$this->cli_help['description'] = 'available tasks:' . PHP_EOL . PHP_EOL . $this->cli_indent('migrateFluxOutsource - Migration script for extensions using FEDs page/fce template features', 2);
$this->cli_help['examples'] = '/.../cli_dispatch.phpsh flux <taskname>';
$this->cli_help['author'] = 'http://fedext.net';
$this->cli_help['license'] = 'GNU General Public License';
}
/**
* CLI engine
*
* @param array $argv Command line arguments
* @return string
*/
public function cli_main($argv) {
unset($argv); // TODO: remove if $argv is needed in the future
$task = (string)$this->cli_args['_DEFAULT'][1];
if (!$task) {
$this->cli_validateArgs();
$this->cli_help();
exit;
}
switch($task) {
case 'migrate':
$this->cli_options[] = array('[extension]', 'Extension (folder) name to parse');
$this->cli_options[] = array('-m', 'Migrate to flux (templates & DB)');
$this->cli_options[] = array('-t', 'Migrate to flux (only templates)');
$this->cli_options[] = array('-d', 'Migrate to flux (only DB)');
$this->cli_options[] = array('-i', 'Interactive mode (no modifications w/o user confirmation)');
$this->cli_options[] = array('--dry-run', 'Only display migration changes');
$this->cli_options[] = array('--additional-type foo [bar]', 'Additional template file type(s) to parse (default types: html)');
$this->cli_options[] = array('--additional-dir dir1 [dir2]', 'Additional template directories to parse (e.g.: /fileadmin/templates) - absolute paths relate to TYPO3 root; realtive paths relate to extenision root');
$this->cli_options[] = array('-f', 'Force (omit warning message regarding backup)');
$configuration = $this->parseMigrationConfig();
if (!$configuration[DynFlexMigration::CONFIG_TARGET]) {
$this->cli_help();
exit;
}
$migrator = new DynFlexMigration($this);
$migrator->migrate($configuration);
break;
default:
echo 'No valid Task given' . "\n\n";
$this->cli_help();
break;
}
}
/**
* parse CLI arguments and assign defaults
* @TODO set defaults in migration class?
* @return array configuration array
*/
protected function parseMigrationConfig() {
$configuration = array();
// extension name
$configuration[DynFlexMigration::CONFIG_EXT] = '*';
if ($extension = $this->cli_args['_DEFAULT'][2]) {
$configuration[DynFlexMigration::CONFIG_EXT] = $extension;
}
// mode: auto / interactive / dry
$configuration[DynFlexMigration::CONFIG_MODE] = DynFlexMigration::CONFIG_MODE_AUTO;
if ($this->cli_isArg('-i')) {
$configuration[DynFlexMigration::CONFIG_MODE] = DynFlexMigration::CONFIG_MODE_INTERACTIVE;
} elseif ($this->cli_isArg('--dry-run')) {
$configuration[DynFlexMigration::CONFIG_MODE] = DynFlexMigration::CONFIG_MODE_DRY;
}
// target: template / database
if ($this->cli_isArg('-t')) {
$configuration[DynFlexMigration::CONFIG_TARGET][DynFlexMigration::CONFIG_TARGET_TEMPLATES] = TRUE;
}
if ($this->cli_isArg('-d')) {
$configuration[DynFlexMigration::CONFIG_TARGET][DynFlexMigration::CONFIG_TARGET_DATABASE] = TRUE;
}
if ($this->cli_isArg('-m')) {
$configuration[DynFlexMigration::CONFIG_TARGET][DynFlexMigration::CONFIG_TARGET_TEMPLATES] = TRUE;
$configuration[DynFlexMigration::CONFIG_TARGET][DynFlexMigration::CONFIG_TARGET_DATABASE] = TRUE;
}
// enable both mirations if interactive or dry-run mode and no -t -d -m switch given
if ($configuration[DynFlexMigration::CONFIG_MODE] != DynFlexMigration::CONFIG_MODE_AUTO) {
if (!$configuration[DynFlexMigration::CONFIG_TARGET]) {
$configuration[DynFlexMigration::CONFIG_TARGET][DynFlexMigration::CONFIG_TARGET_TEMPLATES] = TRUE;
$configuration[DynFlexMigration::CONFIG_TARGET][DynFlexMigration::CONFIG_TARGET_DATABASE] = TRUE;
}
}
// template file types
$configuration[DynFlexMigration::CONFIG_TEMPLATE_TYPES][] = 'html';
//$configuration[DynFlexMigration::CONFIG_TEMPLATE_TYPES][] = 'xml';
$index = 0;
while ($extension = $this->cli_argValue('--additional-type', $index++)) {
$configuration[DynFlexMigration::CONFIG_TEMPLATE_TYPES][] = $extension;
}
// template directories
$configuration[DynFlexMigration::CONFIG_TEMPLATE_DIRECTORIES][] = 'Resources/Private';
$index = 0;
while ($directory = $this->cli_argValue('--additional-dir', $index++)) {
$configuration[DynFlexMigration::CONFIG_TEMPLATE_DIRECTORIES][] = $directory;
}
// omit backup warning
$configuration[DynFlexMigration::CONFIG_OMIT_BACKUP_WARNING] = FALSE;
if ($this->cli_isArg('-f')) {
$configuration[DynFlexMigration::CONFIG_OMIT_BACKUP_WARNING] = TRUE;
}
return $configuration;
}
/**
* Asks for Yes/No from shell and returns true if "y" or "yes" is found as input (flushes ob before waitung 4 input).
*
* @param string String to ask before...
* @return boolean TRUE if "y" or "yes" is the input (case insensitive)
*/
public function cli_keyboardInput_yes($msg = '') {
echo $msg . ' (Yes/No + return): ';
// ONLY makes sense to echo it out since we are awaiting keyboard input - that cannot be silenced...
ob_flush();
return t3lib_div::inList('y,yes', strtolower($this->cli_keyboardInput()));
}
}
$cleanerObj = t3lib_div::makeInstance('tx_flux_cli');
$cleanerObj->cli_main($_SERVER['argv']);