-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathMove.php
168 lines (150 loc) · 4.33 KB
/
Move.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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
<?php
define('CONTROLLER', 'application/controllers/');
define('EXT', '.php');
define('QUERY', 'application/query/');
$method = [
'grid',
'append',
'saveOne',
'remove',
'dropdown',
'pivot'
];
if (php_sapi_name() != "cli") {
echo "Maaf. Proses harus dilakukan lewat CLI<br>";
echo "Proses hanya bisa dijalankan lewat CLI";
return false;
}
if(!isset($argv[1])){
echo "Gagal..\n";
echo "Argumen pertama harus diisi dengan modul yang akan dipindahkan.\n";
echo "Format argumen [role]/[method]/path/to/sql [role2]/path/to/sql.\n";
echo "Contoh: php Build.php operator/grid/user/author operator/writer.\n";
return false;
}
if(!isset($argv[2])){
echo "Gagal..\n";
echo "Argumen harus disi dengan modul tujuan.\n";
echo "Format argumen [role]/path/to/sql\n";
echo "Contoh: php Build.php operator/grid/user/author operator/writer.\n";
return false;
}
$par = explode('/',$argv[1]);
if(count($par)<3){
echo "Gagal..\n";
echo "Argumen minimal terdiri dari 3 segment: role, method dan path.\n";
echo "Format argumen [role]/[method]/path/to/sql\n";
echo "Contoh: php Build.php operator/grid/user/author operator/writer.\n";
return false;
}
if(! in_array($par[1], $method)){
echo "Gagal..\n";
echo "method [" . $par[1] . "] tidak tersedia.\n";
echo "method yang diijinkan adalah: " . implode(',', $method) . ".\n";
return false;
}
$par2 = explode('/',$argv[2]);
if(count($par)<2){
echo "Gagal..\n";
echo "Argumen minimal terdiri dari 2 segment: role, path.\n";
echo "Format argumen [role]/path/to/sql\n";
echo "Contoh: php Build.php operator/grid/user/author operator/writer.\n";
return false;
}
echo "Sedang memproses....\n";
exit;
$controller = CONTROLLER . ucfirst(strtolower($ar[0])) . EXT;
if(!file_exists($controller)){
$fc = fopen($controller, "w");
$txt = "<?php defined('BASEPATH') OR exit('No direct script access allowed');\n";
$txt .= "\n";
$txt .= "class " . ucfirst(strtolower($par[0])) . " extends MY_Controller{\n";
$txt .= "}\n";
fwrite($fc, $txt);
fclose($fc);
echo $controller." telah dibuat.\n";
}
$role = QUERY . strtolower($par[0]);
if(!file_exists($role)){
mkdir($role, 0755);
}
$path = $role;
for($i=2; $i < count($par); $i++){
$path .= '/' . strtolower($par[$i]);
if(!file_exists($path)){
mkdir($path, 0755);
}
}
$sql = $path ."/". $par[1] . EXT;
$fs = fopen($sql, "w");
$txt = "<?php defined('BASEPATH') OR exit('No direct script access allowed');\n";
$txt .= "\n";
$txt .= "/*===============================================================\n";
$txt .= "* CodeIgniter Base Config\n";
$txt .= "* @package CI_BaseConfig\n";
$txt .= "* @author Harjito\n";
$txt .= "* @copyright Copyright (c) 2017 - 2018, eProject Technology. ";
$txt .= "(https://e-project-tech.com/)\n";
$txt .="===============================================================*/\n";
$txt .= "\n";
/*
*---------------------------------------------------------------
* APPLICATION ENVIRONMENT
*---------------------------------------------------------------
*
* You can load different configurations depending on your
* current environment. Setting the environment also influences
* things like logging and error reporting.
*
* This can be set to anything, but default usage is:
*
* development
* testing
* production
*
* NOTE: If you change these, also change the error_reporting() code below
*/
$txt .= "\$obj = new stdClass();\n";
$txt .= "\$obj->table = '';\n";
switch ($par[1]){
case 'grid' :
$txt .= "\$obj->select = '';\n";
$txt .="\$obj->join = [\n";
$txt .= "\t['','',''],\n";
$txt .="];\n";
$txt .= "\$obj->where = [\n";
$txt .= "\t''=> ''\n";
$txt .= "];\n";
$txt .= "\$obj->group = '';\n";
$txt .= "\$obj->order = '';\n";
$txt .= "\$obj->exclude = '';\n";
$txt .= "\$obj->session = [\n";
$txt .= "\t\n";
$txt .= "];\n";
break;
case 'saveOne' :
$txt .="\$obj->field = [\n";
$txt .="\t\n";
$txt .="];\n";
$txt .="\$obj->key = 'id';\n";
break;
case 'remove' :
$txt .="\$obj->key = 'id';\n";
$txt .= "\$obj->session = [\n";
$txt .= "\t\n";
$txt .= "];\n";
break;
case 'append' :
$txt .="\$obj->field = [\n";
$txt .="\t\n";
$txt .="];\n";
$txt .= "\$obj->session = [\n";
$txt .= "\t\n";
$txt .= "];\n";
break;
}
fwrite($fs, $txt);
fclose($fs);
echo $sql . "\n";
//print_r($argv);
?>