1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Sugarcrm\UpgradeSpec\Data\Provider; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\Finder\Finder; |
6
|
|
|
|
7
|
|
|
use Symfony\Component\Filesystem\Filesystem; |
8
|
|
|
use Symfony\Component\Filesystem\Exception\IOExceptionInterface; |
9
|
|
|
use ZipArchive; |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
class LocalUpgradePackage implements PackageDataProviderInterface |
13
|
|
|
{ |
14
|
|
|
private $upgradePackagePath; |
|
|
|
|
15
|
|
|
|
16
|
|
|
private $zipExtractor; |
|
|
|
|
17
|
|
|
|
18
|
|
|
private $data; |
|
|
|
|
19
|
|
|
|
20
|
|
|
private $etractedPackagePath; |
21
|
|
|
|
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* LocalUpgradePackage constructor. |
25
|
|
|
* |
26
|
|
|
* @param Cache $cache |
|
|
|
|
27
|
|
|
* @param $zipExtractor |
28
|
|
|
* @param String $pathToBuild |
|
|
|
|
29
|
|
|
*/ |
30
|
|
|
public function __construct() |
31
|
|
|
{ |
32
|
|
|
|
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/* |
36
|
|
|
* calculates all modified files in new directory |
37
|
|
|
*/ |
38
|
|
|
public function getListOfCustomizations(Context $context) |
39
|
|
|
{ |
40
|
|
|
|
41
|
|
|
if ($context->pathToUpgradePackage) { |
42
|
|
|
$this->setExtractedPackagePath($context->version); |
43
|
|
|
$this->initPackageDirectory($this->getExtractedPackagePath()); |
44
|
|
|
$this->extractUpgradePackage($context->pathToUpgradePackage); |
45
|
|
|
$customizations = array(); |
46
|
|
|
$finder = new Finder(); |
47
|
|
|
$customizations['deleted_files'] = |
48
|
|
|
$this->getDirectoryFileList($finder, $this->etractedPackagePath . '/scripts/files_to_remove/'); |
49
|
|
|
|
50
|
|
|
$customizations['sql_scripts'] = |
51
|
|
|
$this->getDirectoryFileList($finder, $this->etractedPackagePath . '/scripts/'); |
52
|
|
|
|
53
|
|
|
$customizations['sql_scripts'] = |
54
|
|
|
$this->getDirectoryFileList($finder, $this->etractedPackagePath . '/scripts/'); |
55
|
|
|
} |
56
|
|
|
return $customizations; |
|
|
|
|
57
|
|
|
} |
58
|
|
|
/** |
59
|
|
|
* Get list of files needs to be deleted |
60
|
|
|
* |
61
|
|
|
* @param String $pathToUpgradePackage |
62
|
|
|
* |
63
|
|
|
* @return mixed |
64
|
|
|
*/ |
65
|
|
|
public function getListOfDeletedFiles($pathToUpgradePackage) |
|
|
|
|
66
|
|
|
{ |
67
|
|
|
return ''; |
68
|
|
|
} |
69
|
|
|
/** |
70
|
|
|
* Get list of files needs to be Modified |
71
|
|
|
* |
72
|
|
|
* @param String $pathToUpgradePackage |
73
|
|
|
* |
74
|
|
|
* @return mixed |
75
|
|
|
*/ |
76
|
|
|
public function getListOfModifiedFiles($pathToUpgradePackage) |
|
|
|
|
77
|
|
|
{ |
78
|
|
|
return ''; |
79
|
|
|
} |
80
|
|
|
/** |
81
|
|
|
* Get list of scripts needs to be run for upgrade |
82
|
|
|
* |
83
|
|
|
* @param String $pathToUpgradePackage |
84
|
|
|
* |
85
|
|
|
* @return mixed |
86
|
|
|
*/ |
87
|
|
|
public function getListOfScripts($pathToUpgradePackage) |
|
|
|
|
88
|
|
|
{ |
89
|
|
|
return ''; |
90
|
|
|
} |
91
|
|
|
/** |
92
|
|
|
* Get list of sql migration scripts needs to be run for upgrade |
93
|
|
|
* |
94
|
|
|
* @param String $pathToUpgradePackage |
95
|
|
|
* |
96
|
|
|
* @return mixed |
97
|
|
|
*/ |
98
|
|
|
public function getListOfSQLScripts($pathToUpgradePackage) |
|
|
|
|
99
|
|
|
{ |
100
|
|
|
return ''; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
|
104
|
|
|
/* |
105
|
|
|
* @param Finder $finder |
106
|
|
|
* @param String $path |
107
|
|
|
* return mixed |
108
|
|
|
*/ |
109
|
|
|
private function getDirectoryFileList($finder, $path) |
|
|
|
|
110
|
|
|
{ |
111
|
|
|
$filesLIst = []; |
112
|
|
|
$finder->files()->in($this->pathToUpgradePackage . '/scripts/files_to_remove/'); |
|
|
|
|
113
|
|
|
foreach ($finder as $file) { |
114
|
|
|
$filesLIst[] = $file->getRelativePathname(); |
115
|
|
|
} |
116
|
|
|
return $filesLIst; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/* |
120
|
|
|
* @param Finder $finder |
121
|
|
|
* @param String $installedBuildPath |
122
|
|
|
* @param String $upgradePackagePath |
|
|
|
|
123
|
|
|
* return mixed |
124
|
|
|
*/ |
125
|
|
|
private function getNewOrChangedFiles($finder, $installedBuildPath, $needstoBeUpgradedPath) |
|
|
|
|
126
|
|
|
{ |
127
|
|
|
$filesLIst = []; |
128
|
|
|
$finder->files()->in($needstoBeUpgradedPath); |
129
|
|
|
foreach ($finder as $file) { |
130
|
|
|
$fileName = $file->getRelativePathname(); |
131
|
|
|
if (!file_exists($installedBuildPath . $fileName)) |
132
|
|
|
$filesLIst[] = $fileName; |
133
|
|
|
} |
134
|
|
|
return $filesLIst; |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/* |
138
|
|
|
* Extracts zipped upgrade package |
139
|
|
|
* @param String $pathToZipPackage |
|
|
|
|
140
|
|
|
* |
141
|
|
|
*/ |
142
|
|
|
private function extractUpgradePackage($pathToUpgradePackage) |
143
|
|
|
{ |
144
|
|
|
$unzip = new ZipArchive; |
145
|
|
|
$out = $unzip->open($pathToUpgradePackage); |
146
|
|
|
|
147
|
|
|
if ($out === TRUE) { |
148
|
|
|
$unzip->extractTo($this->getExtractedPackagePath()); |
149
|
|
|
$unzip->close(); |
150
|
|
|
echo 'Upgrade Package unzipped successfully' . "\n"; |
151
|
|
|
} else { |
152
|
|
|
echo 'Something went wrong?'; |
153
|
|
|
} |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
|
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* @return string |
160
|
|
|
*/ |
161
|
|
|
protected function getExtractedPackagePath() |
162
|
|
|
{ |
163
|
|
|
return $this->etractedPackagePath; |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* @param string $upgradePackagePath |
|
|
|
|
168
|
|
|
* @param string version |
169
|
|
|
*/ |
170
|
|
|
public function setExtractedPackagePath($version) |
171
|
|
|
{ |
172
|
|
|
$this->etractedPackagePath = '/tmp/' . $version . '/'; |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
|
176
|
|
|
/** |
177
|
|
|
* clear packege for unzipped package |
178
|
|
|
*/ |
179
|
|
|
private function clearUpgradePackageDirectory($extractedPackagePath) |
180
|
|
|
{ |
181
|
|
|
$fs = new Filesystem(); |
182
|
|
|
$fs->remove($extractedPackagePath); |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
/** |
186
|
|
|
* Creates directory for extracting zip package |
187
|
|
|
* @return bool |
188
|
|
|
*/ |
189
|
|
|
private function initPackageDirectory($extractedPackagePath) |
190
|
|
|
{ |
191
|
|
|
|
192
|
|
|
$fs = new Filesystem(); |
193
|
|
|
|
194
|
|
|
if ($fs->exists($extractedPackagePath)) |
195
|
|
|
{ |
196
|
|
|
$this->clearUpgradePackageDirectory($extractedPackagePath); |
197
|
|
|
return true; |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
try { |
201
|
|
|
$fs->mkdir($extractedPackagePath); |
202
|
|
|
return true; |
203
|
|
|
} catch (IOExceptionInterface $e) { |
204
|
|
|
echo "An error occurred while creating upgrade package directory ".$e->getPath(); |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
} |
208
|
|
|
|
209
|
|
|
} |
210
|
|
|
|
This check marks private properties in classes that are never used. Those properties can be removed.