-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathRoboFile.php
140 lines (118 loc) · 4.14 KB
/
RoboFile.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
<?php
require_once('vendor/autoload.php');
if (file_exists(__DIR__.'/.env')) {
Dotenv::load(__DIR__);
}
class RoboFile extends \Robo\Tasks
{
use \Robo\Task\Development\loadTasks;
use \Robo\Common\TaskIO;
/**
* @var array
*/
private $opencart_config;
/**
* @var int
*/
private $server_port = 80;
/**
* @var string
*/
private $server_url = 'http://localhost';
public function __construct()
{
foreach ($_ENV as $option => $value) {
if (substr($option, 0, 3) === 'OC_') {
$option = strtolower(substr($option, 3));
$this->opencart_config[$option] = $value;
} elseif ($option === 'SERVER_PORT') {
$this->server_port = (int) $value;
} elseif ($option === 'SERVER_URL') {
$this->server_url = $value;
}
}
$this->opencart_config['http_server'] = $this->server_url.':'.$this->server_port.'/';
$required = array('db_username', 'password', 'email');
$missing = array();
foreach ($required as $config) {
if (empty($this->opencart_config[$config])) {
$missing[] = 'OC_'.strtoupper($config);
}
}
if (!empty($missing)) {
$this->printTaskError("<error> Missing ".implode(', ', $missing));
$this->printTaskError("<error> See .env.sample ");
die();
}
}
public function opencartSetup()
{
$this->taskDeleteDir('www')->run();
$this->taskFileSystemStack()
->mirror('vendor/opencart/opencart/upload', 'www')
->chmod('www', 0777, 0000, true)
->run();
// Create new database, drop if exists already
try {
$conn = new PDO("mysql:host=".$this->opencart_config['db_hostname'], $this->opencart_config['db_username'], $this->opencart_config['db_password']);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$conn->exec("DROP DATABASE IF EXISTS `" . $this->opencart_config['db_database'] . "`");
$conn->exec("CREATE DATABASE `" . $this->opencart_config['db_database'] . "`");
}
catch(PDOException $e)
{
$this->printTaskError("<error> Could not connect ot database...");
}
$conn = null;
$install = $this->taskExec('php')->arg('www/install/cli_install.php')->arg('install');
foreach ($this->opencart_config as $option => $value) {
$install->option($option, $value);
}
$install->run();
$this->taskDeleteDir('www/install')->run();
}
public function opencartRun()
{
$this->taskServer($this->server_port)
->dir('www')
->run();
}
public function projectDeploy()
{
$this->taskFileSystemStack()
->mirror('src/upload', 'www')
->copy('src/install.xml','www/system/install.ocmod.xml')
->run();
}
public function projectWatch()
{
$this->projectDeploy();
$this->taskWatch()
->monitor('composer.json', function () {
$this->taskComposerUpdate()->run();
$this->taskWatch();
})->monitor('src/', function () {
$this->taskWatch();
})->run();
}
public function projectPackage()
{
$this->taskDeleteDir('target')->run();
$this->taskFileSystemStack()->mkdir('target')->run();
$zip = new ZipArchive();
$filename = "target/build.ocmod.zip";
if ($zip->open($filename, ZipArchive::CREATE)!==TRUE) {
$this->printTaskError("<error> Could not create ZipArchive");
exit();
}
$iterator = new \RecursiveIteratorIterator(
new \RecursiveDirectoryIterator("src", \RecursiveDirectoryIterator::SKIP_DOTS), \RecursiveIteratorIterator::CHILD_FIRST
);
foreach ($iterator as $file) {
if ($file->isFile() && $file->isReadable()) {
$zip->addFile($file->getPathname(),substr($file->getPathname(),4));
}
}
$zip->close();
}
}