|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* main class running all the updates |
|
5
|
|
|
* |
|
6
|
|
|
* |
|
7
|
|
|
*/ |
|
8
|
|
|
class UpdateModules extends BuildTask |
|
|
|
|
|
|
9
|
|
|
{ |
|
10
|
|
|
protected $enabled = true; |
|
11
|
|
|
|
|
12
|
|
|
protected $title = "Update Modules"; |
|
13
|
|
|
|
|
14
|
|
|
protected $description = "Adds files necessary for publishing a module to GitHub. The list of modules is specified in standard config or else it retrieves a list of modules from GitHub."; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* e.g. |
|
18
|
|
|
* - moduleA |
|
19
|
|
|
* - moduleB |
|
20
|
|
|
* - moduleC |
|
21
|
|
|
* |
|
22
|
|
|
* |
|
23
|
|
|
* @var array |
|
24
|
|
|
*/ |
|
25
|
|
|
private static $modules_to_update = array(); |
|
|
|
|
|
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* e.g. |
|
29
|
|
|
* - ClassNameForUpdatingFileA |
|
30
|
|
|
* - ClassNameForUpdatingFileB |
|
31
|
|
|
* |
|
32
|
|
|
* @var array |
|
33
|
|
|
*/ |
|
34
|
|
|
private static $files_to_update = array(); |
|
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* e.g. |
|
37
|
|
|
* - ClassNameForUpdatingFileA |
|
38
|
|
|
* - ClassNameForUpdatingFileB |
|
39
|
|
|
* |
|
40
|
|
|
* @var array |
|
41
|
|
|
*/ |
|
42
|
|
|
private static $commands_to_run = array(); |
|
|
|
|
|
|
43
|
|
|
|
|
44
|
|
|
public static $unsolvedItems = array(); |
|
45
|
|
|
|
|
46
|
|
|
public function run($request) { |
|
47
|
|
|
increase_time_limit_to(3600); |
|
48
|
|
|
|
|
49
|
|
|
//Check temp module folder is empty |
|
50
|
|
|
$tempFolder = GitHubModule::Config()->get('absolute_temp_folder'); |
|
51
|
|
|
$tempDirFiles = scandir($tempFolder); |
|
52
|
|
|
if (count($tempDirFiles) > 2) { |
|
53
|
|
|
die ( '<h2>' . $tempFolder . ' is not empty, please delete or move files </h2>'); |
|
|
|
|
|
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
//Get list of all modules from GitHub |
|
57
|
|
|
$gitUserName = $this->Config()->get('git_user_name'); |
|
|
|
|
|
|
58
|
|
|
|
|
59
|
|
|
$modules = GitHubModule::getRepoList(); |
|
60
|
|
|
|
|
61
|
|
|
|
|
62
|
|
|
|
|
63
|
|
|
$updateComposerJson = $this->Config()->get('update_composer_json'); |
|
64
|
|
|
|
|
65
|
|
|
|
|
66
|
|
|
|
|
67
|
|
|
$limitedModules = $this->Config()->get('modules_to_update'); |
|
68
|
|
|
|
|
69
|
|
|
if($limitedModules && count($limitedModules)) { |
|
70
|
|
|
$modules = array_intersect($modules, $limitedModules); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
|
|
74
|
|
|
|
|
75
|
|
|
/* |
|
76
|
|
|
* Get files to add to modules |
|
77
|
|
|
* */ |
|
78
|
|
|
$files = ClassInfo::subclassesFor('AddFileToModule'); |
|
79
|
|
|
|
|
80
|
|
|
array_shift($files); |
|
81
|
|
|
$limitedFileClasses = $this->Config()->get('files_to_update'); |
|
82
|
|
|
if($limitedFileClasses && count($limitedFileClasses)) { |
|
83
|
|
|
$files = array_intersect($files, $limitedFileClasses); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/* |
|
87
|
|
|
* Get commands to run on modules |
|
88
|
|
|
* */ |
|
89
|
|
|
|
|
90
|
|
|
$commands = ClassInfo::subclassesFor('RunCommandLineMethodOnModule'); |
|
91
|
|
|
|
|
92
|
|
|
|
|
93
|
|
|
array_shift($commands); |
|
94
|
|
|
$limitedCommands = $this->Config()->get('commands_to_run'); |
|
95
|
|
|
if($limitedCommands && count($limitedCommands)) { |
|
96
|
|
|
$commands = array_intersect($commands, $limitedCommands); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
|
|
100
|
|
|
set_error_handler ('errorHandler', E_ALL); |
|
101
|
|
|
foreach($modules as $count => $module) { |
|
|
|
|
|
|
102
|
|
|
$this->currentModule = $module; |
|
|
|
|
|
|
103
|
|
|
try { |
|
104
|
|
|
|
|
105
|
|
|
$this->processOneModule($module, $count, $files, $commands, $updateComposerJson); |
|
106
|
|
|
} |
|
107
|
|
|
catch (Exception $e) { |
|
108
|
|
|
GeneralMethods::outputToScreen ("<li> Could not complete processing $module: " . $e->getMessage() . " </li>"); |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
|
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
restore_error_handler(); |
|
115
|
|
|
|
|
116
|
|
|
$this->writeLog(); |
|
117
|
|
|
//to do .. |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
protected function errorHandler(int $errno , string $errstr) { |
|
|
|
|
|
|
121
|
|
|
|
|
122
|
|
|
GeneralMethods::outputToScreen ("<li> Could not complete processing module: " . $errstr . " </li>"); |
|
123
|
|
|
|
|
124
|
|
|
UpdateModules::addUnsolvedProblem($this->currentModule, "Could not complete processing module: " . $errstr); |
|
125
|
|
|
|
|
126
|
|
|
return true; |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
protected function processOneModule($module, $count, $files, $commands, $updateComposerJson) { |
|
130
|
|
|
|
|
131
|
|
|
if ( stripos($module, 'silverstripe-') === false ) { |
|
132
|
|
|
$module = "silverstripe-" . $module; |
|
133
|
|
|
} |
|
134
|
|
|
echo "<h2>" . ($count+1) . ". ".$module."</h2>"; |
|
135
|
|
|
|
|
136
|
|
|
|
|
137
|
|
|
$moduleObject = GitHubModule::get_or_create_github_module($module); |
|
138
|
|
|
|
|
139
|
|
|
$this->checkUpdateTag($moduleObject); |
|
140
|
|
|
|
|
141
|
|
|
// Check if all necessary files are perfect on GitHub repo already, |
|
142
|
|
|
// if so we can skip that module. But! ... if there are commands to run |
|
143
|
|
|
// over the files in the repo, then we need to clone the repo anyhow, |
|
144
|
|
|
// so skip the check |
|
145
|
|
|
if (count($commands) == 0 && ! $updateComposerJson) { |
|
146
|
|
|
$moduleFilesOK = true; |
|
147
|
|
|
|
|
148
|
|
|
foreach($files as $file) { |
|
149
|
|
|
$fileObj = $file::create($moduleObject); |
|
150
|
|
|
$checkFileName = $fileObj->getFileLocation(); |
|
151
|
|
|
$GitHubFileText = $moduleObject -> getRawFileFromGithub($checkFileName); |
|
152
|
|
|
if ($GitHubFileText) { |
|
153
|
|
|
$fileCheck = $fileObj->compareWithText($GitHubFileText); |
|
154
|
|
|
if ( ! $fileCheck) { |
|
155
|
|
|
$moduleFilesOK = false; |
|
156
|
|
|
} |
|
157
|
|
|
} |
|
158
|
|
|
else { |
|
159
|
|
|
$moduleFilesOK = false; |
|
160
|
|
|
} |
|
161
|
|
|
} |
|
162
|
|
|
|
|
163
|
|
|
|
|
164
|
|
|
|
|
165
|
|
|
if ($moduleFilesOK) { |
|
166
|
|
|
GeneralMethods::outputToScreen ("<li> All files in $module OK, skipping to next module ... </li>"); |
|
167
|
|
|
continue; |
|
168
|
|
|
} |
|
169
|
|
|
} |
|
170
|
|
|
|
|
171
|
|
|
$repository = $moduleObject->checkOrSetGitCommsWrapper($forceNew = true); |
|
|
|
|
|
|
172
|
|
|
|
|
173
|
|
|
|
|
174
|
|
|
$this->moveOldReadMe($moduleObject); |
|
175
|
|
|
|
|
176
|
|
|
|
|
177
|
|
|
$checkConfigYML = $this->Config()->get('check_config_yml'); |
|
178
|
|
|
if ($checkConfigYML) $this->checkConfigYML($moduleObject); |
|
179
|
|
|
|
|
180
|
|
|
if ($updateComposerJson) { |
|
181
|
|
|
$composerJsonObj = new ComposerJson ($moduleObject); |
|
|
|
|
|
|
182
|
|
|
$composerJsonObj->updateJsonData(); |
|
183
|
|
|
$moduleObject->setDescription($composerJsonObj->getDescription()); |
|
184
|
|
|
} |
|
185
|
|
|
|
|
186
|
|
|
$excludedWords = $this->Config()->get('excluded_words'); |
|
187
|
|
|
|
|
188
|
|
|
|
|
189
|
|
|
if (count($excludedWords) > 0) |
|
190
|
|
|
{ |
|
191
|
|
|
$folder = GitHubModule::Config()->get('absolute_temp_folder') . '/' . $moduleObject->moduleName . '/'; |
|
192
|
|
|
|
|
193
|
|
|
$results = $this->checkDirExcludedWords($folder.'/'.$moduleObject->modulename, $excludedWords); |
|
194
|
|
|
|
|
195
|
|
|
|
|
196
|
|
|
if ($results && count ($results > 0)) |
|
|
|
|
|
|
197
|
|
|
{ |
|
198
|
|
|
$msg = "<h4>The following excluded words were found: </h4><ul>"; |
|
199
|
|
|
foreach ($results as $file => $words) { |
|
200
|
|
|
foreach ($words as $word) { |
|
201
|
|
|
$msg .= "<li>$word in $file</li>"; |
|
202
|
|
|
} |
|
203
|
|
|
} |
|
204
|
|
|
$msg .= '</ul>'; |
|
205
|
|
|
|
|
206
|
|
|
//trigger_error ("excluded words found in files(s)"); |
|
|
|
|
|
|
207
|
|
|
GeneralMethods::outputToScreen ($msg); |
|
208
|
|
|
UpdateModules::$unsolvedItems[$moduleObject->ModuleName] = $msg; |
|
209
|
|
|
} |
|
210
|
|
|
|
|
211
|
|
|
} |
|
212
|
|
|
|
|
213
|
|
|
|
|
214
|
|
|
foreach($files as $file) { |
|
215
|
|
|
//run file update |
|
216
|
|
|
|
|
217
|
|
|
$obj = $file::create($moduleObject); |
|
218
|
|
|
$obj->run(); |
|
219
|
|
|
} |
|
220
|
|
|
|
|
221
|
|
|
$moduleDir = $moduleObject->Directory(); |
|
222
|
|
|
|
|
223
|
|
|
foreach($commands as $command) { |
|
224
|
|
|
//run file update |
|
225
|
|
|
|
|
226
|
|
|
|
|
227
|
|
|
$obj = $command::create($moduleDir); |
|
228
|
|
|
$obj->run(); |
|
229
|
|
|
|
|
230
|
|
|
|
|
231
|
|
|
//run command |
|
232
|
|
|
} |
|
233
|
|
|
|
|
234
|
|
|
//Update Repository description |
|
235
|
|
|
//$moduleObject->updateGitHubInfo(array()); |
|
|
|
|
|
|
236
|
|
|
|
|
237
|
|
View Code Duplication |
if( ! $moduleObject->add()) { |
|
|
|
|
|
|
238
|
|
|
|
|
239
|
|
|
$msg = "Could not add files module to Repo"; |
|
240
|
|
|
GeneralMethods::outputToScreen ($msg); |
|
241
|
|
|
UpdateModules::$unsolvedItems[$moduleObject->ModuleName] = $msg; |
|
242
|
|
|
continue; |
|
243
|
|
|
|
|
244
|
|
|
} |
|
245
|
|
View Code Duplication |
if( ! $moduleObject->commit()) { |
|
|
|
|
|
|
246
|
|
|
$msg = "Could not commit files to Repo"; |
|
247
|
|
|
GeneralMethods::outputToScreen ($msg); |
|
248
|
|
|
UpdateModules::$unsolvedItems[$moduleObject->ModuleName] = $msg; |
|
249
|
|
|
continue; |
|
250
|
|
|
} |
|
251
|
|
|
|
|
252
|
|
View Code Duplication |
if( ! $moduleObject->push()) { |
|
|
|
|
|
|
253
|
|
|
$msg = "Could not push files to Repo"; |
|
254
|
|
|
GeneralMethods::outputToScreen ($msg); |
|
255
|
|
|
UpdateModules::$unsolvedItems[$moduleObject->ModuleName] = $msg; |
|
256
|
|
|
continue; |
|
257
|
|
|
} |
|
258
|
|
View Code Duplication |
if( ! $moduleObject->removeClone()) |
|
|
|
|
|
|
259
|
|
|
{ |
|
260
|
|
|
$msg = "Could not remove local copy of repo"; |
|
261
|
|
|
GeneralMethods::outputToScreen ($msg); |
|
262
|
|
|
UpdateModules::$unsolvedItems[$moduleObject->ModuleName] = $msg; |
|
263
|
|
|
} |
|
264
|
|
|
|
|
265
|
|
|
$addRepoToScrutinzer = $this->Config()->get('add_to_scrutinizer'); |
|
266
|
|
|
if ($addRepoToScrutinzer) { |
|
267
|
|
|
$moduleObject->addRepoToScrutinzer(); |
|
268
|
|
|
} |
|
269
|
|
|
|
|
270
|
|
|
} |
|
271
|
|
|
|
|
272
|
|
|
|
|
273
|
|
|
|
|
274
|
|
|
protected function renameTest($moduleObject) { |
|
275
|
|
|
|
|
276
|
|
|
$oldName = $moduleObject->Directory() . "/tests/ModuleTest.php"; |
|
277
|
|
|
|
|
278
|
|
|
if ( ! file_exists($oldName) ) |
|
279
|
|
|
{ |
|
280
|
|
|
print_r ($oldName); |
|
281
|
|
|
return false; |
|
282
|
|
|
} |
|
283
|
|
|
|
|
284
|
|
|
|
|
285
|
|
|
|
|
286
|
|
|
$newName = $moduleObject->Directory() . "tests/" . $moduleObject->ModuleName . "Test.php"; |
|
287
|
|
|
|
|
288
|
|
|
GeneralMethods::outputToScreen ("Renaming $oldName to $newName"); |
|
289
|
|
|
|
|
290
|
|
|
unlink ($newName); |
|
291
|
|
|
|
|
292
|
|
|
rename($oldName, $newName); |
|
293
|
|
|
|
|
294
|
|
|
|
|
295
|
|
|
} |
|
296
|
|
|
|
|
297
|
|
|
public static function addUnsolvedProblem($moduleName, $problemString) { |
|
298
|
|
|
if (!isset (UpdateModules::$unsolvedItems[$moduleName]) ) |
|
299
|
|
|
{ |
|
300
|
|
|
UpdateModules::$unsolvedItems[$moduleName] = array(); |
|
301
|
|
|
} |
|
302
|
|
|
array_push (UpdateModules::$unsolvedItems[$moduleName], $problemString); |
|
303
|
|
|
} |
|
304
|
|
|
|
|
305
|
|
|
protected function writeLog() { |
|
306
|
|
|
|
|
307
|
|
|
|
|
308
|
|
|
$debug = $this->Config()->get('debug'); |
|
|
|
|
|
|
309
|
|
|
|
|
310
|
|
|
$dateStr = date("Y/m/d H:i:s"); |
|
311
|
|
|
|
|
312
|
|
|
$html = '<h1> Modules checker report at ' .$dateStr . '</h1>'; |
|
313
|
|
|
|
|
314
|
|
|
if (count (UpdateModules::$unsolvedItems) == 0) { |
|
315
|
|
|
$html .= ' <h2> No unresolved problems in modules</h2>'; |
|
316
|
|
|
} |
|
317
|
|
|
|
|
318
|
|
|
else { |
|
319
|
|
|
$html .= ' |
|
320
|
|
|
<h2> Unresolved problems in modules</h2> |
|
321
|
|
|
|
|
322
|
|
|
<table border = 1> |
|
323
|
|
|
<tr><th>Module</th><th>Problem</th></tr>'; |
|
324
|
|
|
|
|
325
|
|
|
foreach (UpdateModules::$unsolvedItems as $moduleName => $problems) { |
|
326
|
|
|
|
|
327
|
|
|
|
|
328
|
|
|
if (is_array($problems)) { |
|
329
|
|
|
foreach ($problems as $problem) { |
|
330
|
|
|
|
|
331
|
|
|
$html .= '<tr><td>'.$moduleName.'</td><td>'. $problem .'</td></tr>'; |
|
332
|
|
|
} |
|
333
|
|
|
|
|
334
|
|
|
} |
|
335
|
|
|
else if (is_string($problems)) { |
|
336
|
|
|
$html .= '<tr><td>'.$moduleName.'</td><td>'. $problems.'</td></tr>'; |
|
337
|
|
|
} |
|
338
|
|
|
} |
|
339
|
|
|
$html .= '</table>'; |
|
340
|
|
|
|
|
341
|
|
|
|
|
342
|
|
|
} |
|
343
|
|
|
|
|
344
|
|
|
|
|
345
|
|
|
|
|
346
|
|
|
$logFolder = $this->Config()->get('logfolder'); |
|
347
|
|
|
|
|
348
|
|
|
$filename = $logFolder . date('U') . '.html'; |
|
349
|
|
|
|
|
350
|
|
|
GeneralMethods::outputToScreen ("Writing to $filename"); |
|
351
|
|
|
|
|
352
|
|
|
$result = file_put_contents ( $filename, $html); |
|
353
|
|
|
|
|
354
|
|
|
if ( ! $result ) |
|
355
|
|
|
{ |
|
356
|
|
|
GeneralMethods::outputToScreen ("Could not write log file"); |
|
357
|
|
|
} |
|
358
|
|
|
|
|
359
|
|
|
|
|
360
|
|
|
|
|
361
|
|
|
} |
|
362
|
|
|
|
|
363
|
|
|
protected function checkConfigYML($module) |
|
364
|
|
|
{ |
|
365
|
|
|
$configYml = ConfigYML::create($module)->reWrite(); |
|
|
|
|
|
|
366
|
|
|
|
|
367
|
|
|
} |
|
368
|
|
|
|
|
369
|
|
|
private function checkFile($module, $filename) { |
|
370
|
|
|
$folder = GitHubModule::Config()->get('absolute_temp_folder'); |
|
371
|
|
|
return file_exists($folder.'/'.$module.'/'.$filename); |
|
372
|
|
|
} |
|
373
|
|
|
|
|
374
|
|
|
private function checkReadMe($module) { |
|
375
|
|
|
return $this->checkFile($module, "README.MD"); |
|
376
|
|
|
} |
|
377
|
|
|
|
|
378
|
|
|
private function checkDirExcludedWords($directory, $wordArray) { |
|
379
|
|
|
$filesAndFolders = scandir ($directory); |
|
380
|
|
|
|
|
381
|
|
|
$problem_files = array(); |
|
382
|
|
|
foreach ($filesAndFolders as $fileOrFolder) { |
|
383
|
|
|
|
|
384
|
|
|
if ($fileOrFolder == '.' || $fileOrFolder == '..' || $fileOrFolder == '.git' ) { |
|
385
|
|
|
continue; |
|
386
|
|
|
} |
|
387
|
|
|
|
|
388
|
|
|
$fileOrFolderFullPath = $directory . '/' . $fileOrFolder; |
|
389
|
|
|
if (is_dir($fileOrFolderFullPath)) { |
|
390
|
|
|
$dir = $fileOrFolderFullPath; |
|
391
|
|
|
$problem_files = array_merge ($this->checkDirExcludedWords ($dir, $wordArray) , $problem_files); |
|
392
|
|
|
} |
|
393
|
|
|
if (is_file($fileOrFolderFullPath)) { |
|
394
|
|
|
$file = $fileOrFolderFullPath; |
|
395
|
|
|
$matchedWords = $this->checkFileExcludedWords($file, $wordArray); |
|
396
|
|
|
|
|
397
|
|
|
if ($matchedWords) { |
|
|
|
|
|
|
398
|
|
|
|
|
399
|
|
|
$problem_files[$file] = $matchedWords; |
|
400
|
|
|
} |
|
401
|
|
|
} |
|
402
|
|
|
} |
|
403
|
|
|
|
|
404
|
|
|
return $problem_files; |
|
405
|
|
|
} |
|
406
|
|
|
|
|
407
|
|
|
private function checkFileExcludedWords($fileName, $wordArray) { |
|
408
|
|
|
|
|
409
|
|
|
|
|
410
|
|
|
$matchedWords = array(); |
|
411
|
|
|
|
|
412
|
|
|
$fileName = str_replace ('////', '/', $fileName); |
|
413
|
|
|
if (filesize ($fileName) == 0 ) return $matchedWords; |
|
414
|
|
|
|
|
415
|
|
|
|
|
416
|
|
|
$fileContent = file_get_contents($fileName); |
|
417
|
|
View Code Duplication |
if (!$fileContent) { |
|
|
|
|
|
|
418
|
|
|
|
|
419
|
|
|
$msg = "Could not open $fileName to check for excluded words"; |
|
420
|
|
|
|
|
421
|
|
|
GeneralMethods::outputToScreen ($msg); |
|
422
|
|
|
UpdateModules::$unsolvedItems[$moduleObject->ModuleName] = $msg; |
|
|
|
|
|
|
423
|
|
|
} |
|
424
|
|
|
|
|
425
|
|
|
foreach ($wordArray as $word) { |
|
426
|
|
|
|
|
427
|
|
|
|
|
428
|
|
|
$matches = array(); |
|
|
|
|
|
|
429
|
|
|
$matchCount = preg_match_all('/' . $word . '/i', $fileContent); |
|
430
|
|
|
|
|
431
|
|
|
|
|
432
|
|
|
|
|
433
|
|
|
|
|
434
|
|
|
|
|
435
|
|
|
if ($matchCount > 0) { |
|
436
|
|
|
array_push ($matchedWords, $word); |
|
437
|
|
|
|
|
438
|
|
|
} |
|
439
|
|
|
} |
|
440
|
|
|
|
|
441
|
|
|
return $matchedWords; |
|
442
|
|
|
|
|
443
|
|
|
} |
|
444
|
|
|
|
|
445
|
|
|
private function checkUpdateTag($moduleObject) { |
|
446
|
|
|
|
|
447
|
|
|
$tagDelayString = $this->Config()->get('tag_delay'); |
|
448
|
|
|
$nextTag = null; |
|
|
|
|
|
|
449
|
|
|
|
|
450
|
|
|
if (!$tagDelayString) |
|
451
|
|
|
{ |
|
452
|
|
|
$tagDelayString = "-3 weeks"; |
|
453
|
|
|
} |
|
454
|
|
|
|
|
455
|
|
|
|
|
456
|
|
|
$tagDelay = strtotime($tagDelayString); |
|
457
|
|
|
if (!$tagDelay) { |
|
458
|
|
|
$tagDelay = strtotime("-3 weeks"); |
|
459
|
|
|
} |
|
460
|
|
|
|
|
461
|
|
|
$tag = $moduleObject->getLatestTag(); |
|
462
|
|
|
|
|
463
|
|
|
$commitTime = $moduleObject->getLatestCommitTime(); |
|
464
|
|
|
|
|
465
|
|
|
if (! $commitTime) // if no commits, cannot create a tag |
|
466
|
|
|
{ |
|
467
|
|
|
return false; |
|
468
|
|
|
} |
|
469
|
|
|
|
|
470
|
|
|
$createTag = false; |
|
|
|
|
|
|
471
|
|
|
|
|
472
|
|
|
|
|
473
|
|
|
$newTagString = ''; |
|
474
|
|
|
|
|
475
|
|
|
if ( ! $tag ) { |
|
476
|
|
|
$createTag = true; |
|
|
|
|
|
|
477
|
|
|
$newTagString = '1.0.0'; |
|
478
|
|
|
} |
|
479
|
|
|
|
|
480
|
|
|
|
|
481
|
|
|
|
|
482
|
|
|
else if ($tag && $commitTime > $tag['timestamp'] && $commitTime < $tagDelay) { |
|
483
|
|
|
$changeType = $moduleObject->getChangeTypeSinceLastTag(); |
|
484
|
|
|
|
|
485
|
|
|
die ($changeType); |
|
|
|
|
|
|
486
|
|
|
$newTagString = $this->findNextTag($tag, $changeType); |
|
|
|
|
|
|
487
|
|
|
} |
|
488
|
|
|
|
|
489
|
|
|
if ($newTagString) { |
|
490
|
|
|
|
|
491
|
|
|
GeneralMethods::outputToScreen ('<li> Creating new tag '.$newTagString.' ... </li>'); |
|
492
|
|
|
|
|
493
|
|
|
//git tag -a 0.0.1 -m "testing tag" |
|
494
|
|
|
$options = array ( |
|
495
|
|
|
'a' => $newTagString, |
|
496
|
|
|
'm' => $this->Config()->get('tag_create_message') |
|
497
|
|
|
); |
|
498
|
|
|
|
|
499
|
|
|
$moduleObject->createTag ($options); |
|
500
|
|
|
|
|
501
|
|
|
} |
|
502
|
|
|
|
|
503
|
|
|
return true; |
|
504
|
|
|
|
|
505
|
|
|
} |
|
506
|
|
|
|
|
507
|
|
|
protected function findNextTag ($tag, $changeType) |
|
508
|
|
|
{ |
|
509
|
|
|
|
|
510
|
|
|
switch ($changeType) { |
|
511
|
|
|
|
|
512
|
|
|
case 'MAJOR': |
|
513
|
|
|
$tag['tagparts'][0] = intval($tag['tagparts'][0]) + 1; |
|
514
|
|
|
$tag['tagparts'][1] = 0; |
|
515
|
|
|
$tag['tagparts'][2] = 0; |
|
516
|
|
|
break; |
|
517
|
|
|
|
|
518
|
|
|
case 'MINOR': |
|
|
|
|
|
|
519
|
|
|
|
|
520
|
|
|
$tag['tagparts'][1] = intval($tag['tagparts'][1]) + 1; |
|
521
|
|
|
$tag['tagparts'][2] = 0; |
|
522
|
|
|
break; |
|
523
|
|
|
|
|
524
|
|
|
default: |
|
525
|
|
|
case 'PATCH': |
|
|
|
|
|
|
526
|
|
|
$tag['tagparts'][2] = intval($tag['tagparts'][2]) + 1; |
|
527
|
|
|
break; |
|
528
|
|
|
} |
|
529
|
|
|
|
|
530
|
|
|
$newTagString = trim(implode ('.', $tag['tagparts'])); |
|
531
|
|
|
return $newTagString; |
|
532
|
|
|
} |
|
533
|
|
|
|
|
534
|
|
|
protected function moveOldReadMe($moduleObject) { |
|
535
|
|
|
$tempDir = GitHubModule::Config()->get('absolute_temp_folder'); |
|
536
|
|
|
$oldReadMe = $tempDir . '/' . $moduleObject->ModuleName . '/' .'README.md'; |
|
537
|
|
|
|
|
538
|
|
|
if (!file_exists($oldReadMe)) |
|
539
|
|
|
{ |
|
540
|
|
|
return false; |
|
541
|
|
|
} |
|
542
|
|
|
|
|
543
|
|
|
|
|
544
|
|
|
$oldreadmeDestinationFiles = array ( |
|
545
|
|
|
'docs/en/INDEX.md', |
|
546
|
|
|
'docs/en/README.old.md', |
|
547
|
|
|
); |
|
548
|
|
|
|
|
549
|
|
|
|
|
550
|
|
|
$copied = false; |
|
551
|
|
|
foreach ($oldreadmeDestinationFiles as $file) { |
|
552
|
|
|
$filePath = $tempDir . '/' . $moduleObject->ModuleName . '/' . $file; |
|
553
|
|
|
|
|
554
|
|
|
if (!file_exists($filePath)) { |
|
555
|
|
|
$copied = true; |
|
556
|
|
|
copy($oldReadMe, $filePath); |
|
557
|
|
|
} |
|
558
|
|
|
|
|
559
|
|
|
} |
|
560
|
|
|
if ($copied) |
|
561
|
|
|
{ |
|
562
|
|
|
unlink ($oldReadMe); |
|
563
|
|
|
} |
|
564
|
|
|
} |
|
565
|
|
|
|
|
566
|
|
|
|
|
567
|
|
|
} |
|
568
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.