forked from astorm/Pulsestorm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmagento-increment-version.php
executable file
·145 lines (124 loc) · 3.67 KB
/
magento-increment-version.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
#!/usr/bin/env php
<?php
function input($string)
{
echo $string . "\n] ";
$handle = fopen ("php://stdin","r");
$line = fgets($handle);
fclose($handle);
return $line;
}
function error($string)
{
echo "ERROR: " . $string . "\n";
exit;
}
function get_config_path($code_pool, $package, $module)
{
$path = sprintf(
'app/code/%s/%s/%s',$code_pool, $package, $module);
$path = $path . '/etc/config.xml';
if(is_file($path))
{
return $path;
}
error(sprintf("Could not find %s",$path));
}
function get_version_index()
{
$answer = input("Increment\n" .
"1. Major (X.0.0)\n" .
"2. Minor (0.X.0)\n" .
"3. Bug Fix (0.0.X)");
$answer = trim($answer);
if(!is_numeric($answer) || $answer > 3 || $answer < 1)
{
return get_version_index();
}
return $answer - 1;
}
function dirUpUntilFindSystemPwd($path, $times=0)
{
$base = `pwd`;
for($i=0;$i<$times;$i++)
{
$base = dirname($base);
}
if(file_exists($base . '/' . $path))
{
return $base . '/' . $path;
}
if($base == '/')
{
return false;
}
$times++;
return dirUpUntilFindSystemPwd($path, $times);
}
function dirUpUntilFindCwd($path)
{
static $original_path;
$original_path = $original_path ? $original_path : getcwd();
static $searched;
$searched = $searched ? $searched : array();
$searched[] = getcwd();
if(file_exists($path) || is_dir($path))
{
$path = realpath($path);
chdir($original_path);
return $path;
}
if(getcwd() == '/')
{
chdir($original_path);
return false;
}
chdir('..');
return dirUpUntilFind($path);
}
function getModuleNameFromConfigFile($path)
{
$xml = simplexml_load_file($path);
if(!$xml)
{
}
}
function main($argv)
{
$path = dirUpUntilFindSystemPwd('etc/config.xml');
if(!$path)
{
error("Could not find etc/config.xml");
}
$module = getModuleNameFromConfigFile();
$results = input("Found $path");
}
function fully_interactive($argv)
{
if(!is_dir('app'))
{
error("Couldn't find \"app\" folder in path, please run from a Magento sub-directory.");
}
$code_pool = trim(input("What code pool?"));
$package = trim(input("What package?"));
$module = trim(input("What module?"));
$path = get_config_path($code_pool, $package, $module);
echo "Loading: " . $path . "\n";
$xml = simplexml_load_file($path);
$xVersion = $xml->modules->{$package.'_'.$module}->version;
$version = (string) $xVersion;
echo "Current Version: " . $version . "\n";
//list($major, $minor, $bugfix) = explode(".", $version);
$parts = explode(".", $version);
$index = get_version_index();
$parts[$index] ++;
$version_new = implode(".",$parts);
$xVersion[0] = $version_new;
$xml = $xml->asXml();
if(simplexml_load_string($xml))
{
file_put_contents($path, $xml);
}
echo "Updated $path to $version_new\n";
}
main($argv);