Repository navigation
Expand file tree
/
Copy pathcli.php
More file actions
103 lines (80 loc) · 2.55 KB
/
Copy pathcli.php
File metadata and controls
103 lines (80 loc) · 2.55 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
<?php
if (!function_exists('cli_output')) {
function cli_output($message, $exit_status = null) {
echo $message . PHP_EOL;
if ($exit_status !== null) {
exit($exit_status);
}
}
}
if (!function_exists('cli_output_array')) {
function cli_output_array($array, $before = null, $after = null, $exit_status = null) {
if(!is_array($array)) {
cli_output('This output method only accept arrays', true);
}
$message = '';
foreach ($array as $item) {
$message .= $item . PHP_EOL;
}
if($before !== null) {
echo PHP_EOL;
echo '====================================' . PHP_EOL;
echo $before . PHP_EOL;
echo '====================================' . PHP_EOL;
}
echo $message . PHP_EOL;
if($after !== null) {
echo $after;
}
if ($exit_status !== null) {
exit($exit_status);
}
}
}
if (!function_exists('cli_find_version')) {
function cli_find_version() {
$current_dir = dirname(__FILE__);
$index_contents = file_get_contents($current_dir . '/index.php');
$matches = array();
preg_match('~define\s*\(\s*\'VERSION\'\s*,\s*\'(.*?)\'\s*\)\s*;~', $index_contents, $matches);
if (!empty($matches[1])) {
return $matches[1];
} else {
cli_output("Cannot find OpenCart version.", 1);
}
}
}
// The action starts... Let's check for the CLI mode
if (php_sapi_name() != 'cli') {
header("Location:/");
cli_output("Get out.", 1);
}
// Version
if (!defined('VERSION')) define('VERSION', cli_find_version());
// Status constant. Should be set to TRUE.
if (!defined('OPENCART_CLI_MODE')) define('OPENCART_CLI_MODE', TRUE);
// Change directory to allow the script to be called from anywhere.
chdir(dirname(__FILE__));
// Determine the admin folder
if (empty($argv[1]) || !is_dir($argv[1])) {
cli_output("Invalid request. Expecting: <admin-folder-name>", 1);
} else {
$config_root = './' . $argv[1] . '/';
}
// Set SERVER_PORT
if (!isset($_SERVER['SERVER_PORT'])) {
$_SERVER['SERVER_PORT'] = 80;
}
// Load Configuration
if (is_file($config_root . 'config.php')) {
require_once($config_root . 'config.php');
}
// Check if OpenCart is installed
if (!defined('DIR_APPLICATION')) {
cli_output("OpenCart not installed.", 1);
}
// Startup
require_once(DIR_SYSTEM . 'startup.php');
$application_config = 'cli';
// Application
require_once(DIR_SYSTEM . 'cli-framework.php');