forked from PrestaShop/PrestaShop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
diff-hooks.php
147 lines (119 loc) · 4.65 KB
/
diff-hooks.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
<?php
$path_to_16 = $argv[1];
$path_to_17 = $argv[2];
$grep = "grep -ri --exclude-dir=.git --exclude-dir=bin --exclude-dir=cache --exclude-dir=modules --exclude-dir=tests --exclude-dir=vendor --exclude=diff-hooks.php --exclude=diff-hooks.html";
exec("$grep 'hook h=' ".$path_to_16."/themes", $hookHIn16);
exec("$grep 'hook h=' ".$path_to_17."/themes", $hookHIn17);
exec("$grep 'Hook::exec' ".$path_to_16, $hookExecIn16);
exec("$grep 'Hook::exec' ".$path_to_17, $hookExecIn17);
$hooks16 = array_merge(getFormattedHookList($hookHIn16, $path_to_16), getFormattedHookList($hookExecIn16, $path_to_16));
$hooks17 = array_merge(getFormattedHookList($hookHIn17, $path_to_17), getFormattedHookList($hookExecIn17, $path_to_17));
ksort($hooks16);
ksort($hooks17);
generateHTML(array_intersect_key($hooks16, $hooks17), array_diff_key($hooks16, $hooks17), array_diff_key($hooks17, $hooks16), $hooks16, $hooks17);
function generateHTML($commonHooks, $hooksOnly16, $hooksOnly17, $hooks16, $hooks17)
{
$html = '
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap-theme.min.css" integrity="sha384-fLW2N01lMqjakBkx3l/M9EahuwpSfeNvV63J5ezn3uZzapT0u7EYsXMjQV+0En5r" crossorigin="anonymous">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
</head>
<body>
<div class="container">';
$html .= '<h1>Common hooks</h1>';
$html .= '<table class="table table-bordered">';
$html .= '<thead>';
$html .= '<tr>';
$html .= '<th>Hook name</th><th>File(s) in 1.6</th><th>File(s) in 1.7</th>';
$html .= '</tr>';
$html .= '</thead>';
foreach ($commonHooks as $hookName => $files) {
$html .= '<tr>';
$html .= '<td>'.$hookName.'</td><td><ul>';
foreach ($files as $file) {
$html .= '<li>'.$file.'</li>';
}
$html .= '</ul></td><td><ul>';
foreach ($hooks17[$hookName] as $file) {
$html .= '<li>'.$file.'</li>';
}
$html .= '</ul></td>';
$html .= '</tr>';
}
$html .= '</table>';
$html .= '<h1>Hooks only in 1.6</h1>';
$html .= '<table class="table table-bordered">';
$html .= '<thead>';
$html .= '<tr>';
$html .= '<th>Hook name</th><th>File(s)</th>';
$html .= '</tr>';
$html .= '</thead>';
foreach ($hooksOnly16 as $hookName => $files) {
$html .= '<tr>';
$html .= '<td>'.$hookName.'</td><td><ul>';
foreach ($files as $file) {
$html .= '<li>'.$file.'</li>';
}
$html .= '</ul></td>';
$html .= '</tr>';
}
$html .= '</table>';
$html .= '<h1>Hooks only in 1.7</h1>';
$html .= '<table class="table table-bordered">';
$html .= '<thead>';
$html .= '<tr>';
$html .= '<th>Hook name</th><th>File(s)</th>';
$html .= '</tr>';
$html .= '</thead>';
foreach ($hooksOnly17 as $hookName => $files) {
$html .= '<tr>';
$html .= '<td>'.$hookName.'</td><td><ul>';
foreach ($files as $file) {
$html .= '<li>'.$file.'</li>';
}
$html .= '</ul></td>';
$html .= '</tr>';
}
$html .= '</table>';
$html .= '
</div>
</body>
</html>';
file_put_contents(dirname(__FILE__).DIRECTORY_SEPARATOR.'diff-hooks.html', $html);
}
function getFormattedHookList($hookList, $folder)
{
$list = [];
foreach ($hookList as $hook) {
$line = explode(':', $hook, 2);
if (count($line) !== 2) {
echo "Warning, could not parse hook in:\n$hook\n\n";
continue;
}
$hookName = getHookName($line[1]);
if (!preg_match('/^\w+$/', $hookName)) {
echo "Warning, strange hook name found in {$line[0]}:\n$hookName\n\n";
continue;
}
$path = formatFilePath($line[0], $folder);
$list[$hookName][$path] = $path;
ksort($list[getHookName($line[1])]);
}
ksort($list);
return $list;
}
function getHookName($str)
{
preg_match('/(?:hook h=|Hook::exec\()[\'"](\w+)[\'"]/', $str, $matches);
return isset($matches[1]) ? $matches[1] : $str;
}
function formatFilePath($path, $folder)
{
return substr($path, strlen($folder));
}