@@ -6,20 +6,20 @@ |
||
6 | 6 | interface PackageCache |
7 | 7 | { |
8 | 8 | |
9 | - /** |
|
10 | - * Generate or retrieve a package from the cache |
|
11 | - * |
|
12 | - * @param PackageGenerator $generator The generator to use to create cache entries. |
|
13 | - * @param string $identifier A unique identifier for the generator; used to partition the cache |
|
14 | - * @param string $sha The SHA of the commit to be deployed |
|
15 | - * @param string $repositoryDir The directory where the repository resides |
|
16 | - * @param DeploynautLogFile $log The log to write status output to, including package-generation commands |
|
17 | - */ |
|
18 | - public function getPackageFilename( |
|
19 | - PackageGenerator $generator, |
|
20 | - $identifier, |
|
21 | - $sha, |
|
22 | - $repositoryDir, |
|
23 | - DeploynautLogFile $log |
|
24 | - ); |
|
9 | + /** |
|
10 | + * Generate or retrieve a package from the cache |
|
11 | + * |
|
12 | + * @param PackageGenerator $generator The generator to use to create cache entries. |
|
13 | + * @param string $identifier A unique identifier for the generator; used to partition the cache |
|
14 | + * @param string $sha The SHA of the commit to be deployed |
|
15 | + * @param string $repositoryDir The directory where the repository resides |
|
16 | + * @param DeploynautLogFile $log The log to write status output to, including package-generation commands |
|
17 | + */ |
|
18 | + public function getPackageFilename( |
|
19 | + PackageGenerator $generator, |
|
20 | + $identifier, |
|
21 | + $sha, |
|
22 | + $repositoryDir, |
|
23 | + DeploynautLogFile $log |
|
24 | + ); |
|
25 | 25 | } |
@@ -3,8 +3,7 @@ |
||
3 | 3 | /** |
4 | 4 | * Represents a system for caching packages generated by a PackageGenerator |
5 | 5 | */ |
6 | -interface PackageCache |
|
7 | -{ |
|
6 | +interface PackageCache { |
|
8 | 7 | |
9 | 8 | /** |
10 | 9 | * Generate or retrieve a package from the cache |
@@ -9,61 +9,61 @@ |
||
9 | 9 | abstract class PackageGenerator |
10 | 10 | { |
11 | 11 | |
12 | - protected $cache; |
|
12 | + protected $cache; |
|
13 | 13 | |
14 | - /** |
|
15 | - * Generate the package file, saving to the given location |
|
16 | - * |
|
17 | - * @param string $baseDir string The base directory of the project, checked out from git. |
|
18 | - * @param $outputFilename string The filename to write to. |
|
19 | - * @param string $sha |
|
20 | - * |
|
21 | - * @return boolean True on success |
|
22 | - */ |
|
23 | - abstract public function generatePackage($sha, $baseDir, $outputFilename, DeploynautLogFile $log); |
|
14 | + /** |
|
15 | + * Generate the package file, saving to the given location |
|
16 | + * |
|
17 | + * @param string $baseDir string The base directory of the project, checked out from git. |
|
18 | + * @param $outputFilename string The filename to write to. |
|
19 | + * @param string $sha |
|
20 | + * |
|
21 | + * @return boolean True on success |
|
22 | + */ |
|
23 | + abstract public function generatePackage($sha, $baseDir, $outputFilename, DeploynautLogFile $log); |
|
24 | 24 | |
25 | - /** |
|
26 | - * Return a string that uniquely identifies this package generator. |
|
27 | - * |
|
28 | - * This will be used as part of cache keys; if meaningful changes to the operation of the generator are |
|
29 | - * made, then the identifier should change. Note there is no need to include the classname in the |
|
30 | - * identifier; callers to getIdentifier() should be responsible for disambiguating based on class. |
|
31 | - */ |
|
32 | - abstract public function getIdentifier(); |
|
25 | + /** |
|
26 | + * Return a string that uniquely identifies this package generator. |
|
27 | + * |
|
28 | + * This will be used as part of cache keys; if meaningful changes to the operation of the generator are |
|
29 | + * made, then the identifier should change. Note there is no need to include the classname in the |
|
30 | + * identifier; callers to getIdentifier() should be responsible for disambiguating based on class. |
|
31 | + */ |
|
32 | + abstract public function getIdentifier(); |
|
33 | 33 | |
34 | - public function getCache() |
|
35 | - { |
|
36 | - return $this->cache; |
|
37 | - } |
|
34 | + public function getCache() |
|
35 | + { |
|
36 | + return $this->cache; |
|
37 | + } |
|
38 | 38 | |
39 | - public function setCache(PackageCache $cache) |
|
40 | - { |
|
41 | - $this->cache = $cache; |
|
42 | - } |
|
39 | + public function setCache(PackageCache $cache) |
|
40 | + { |
|
41 | + $this->cache = $cache; |
|
42 | + } |
|
43 | 43 | |
44 | - /** |
|
45 | - * Generate or retrieve a package from the cache |
|
46 | - * |
|
47 | - * @param string $identifier A unique identifier for the generator; used to partition the cache |
|
48 | - * @param string $sha The SHA of the commit to be deployed |
|
49 | - * @param string $repositoryDir The directory where the repository resides |
|
50 | - * @param DeploynautLogFile $log The log to write status output to, including package-generation commands |
|
51 | - * |
|
52 | - * @return string |
|
53 | - */ |
|
54 | - public function getPackageFilename($identifier, $sha, $repositoryDir, DeploynautLogFile $log) |
|
55 | - { |
|
56 | - // Fetch through the cache |
|
57 | - if ($this->cache) { |
|
58 | - $identifier .= '-' . get_class($this) . '-' . $this->getIdentifier(); |
|
59 | - return $this->cache->getPackageFilename($this, $identifier, $sha, $repositoryDir, $log); |
|
44 | + /** |
|
45 | + * Generate or retrieve a package from the cache |
|
46 | + * |
|
47 | + * @param string $identifier A unique identifier for the generator; used to partition the cache |
|
48 | + * @param string $sha The SHA of the commit to be deployed |
|
49 | + * @param string $repositoryDir The directory where the repository resides |
|
50 | + * @param DeploynautLogFile $log The log to write status output to, including package-generation commands |
|
51 | + * |
|
52 | + * @return string |
|
53 | + */ |
|
54 | + public function getPackageFilename($identifier, $sha, $repositoryDir, DeploynautLogFile $log) |
|
55 | + { |
|
56 | + // Fetch through the cache |
|
57 | + if ($this->cache) { |
|
58 | + $identifier .= '-' . get_class($this) . '-' . $this->getIdentifier(); |
|
59 | + return $this->cache->getPackageFilename($this, $identifier, $sha, $repositoryDir, $log); |
|
60 | 60 | |
61 | - // Default, cacheless implementation |
|
62 | - } else { |
|
63 | - $filename = TEMP_FOLDER . '/' . $sha . '.tar.gz'; |
|
64 | - if ($this->generatePackage($sha, $repositoryDir, $filename, $log)) { |
|
65 | - return $filename; |
|
66 | - } |
|
67 | - } |
|
68 | - } |
|
61 | + // Default, cacheless implementation |
|
62 | + } else { |
|
63 | + $filename = TEMP_FOLDER . '/' . $sha . '.tar.gz'; |
|
64 | + if ($this->generatePackage($sha, $repositoryDir, $filename, $log)) { |
|
65 | + return $filename; |
|
66 | + } |
|
67 | + } |
|
68 | + } |
|
69 | 69 | } |
@@ -54,14 +54,14 @@ |
||
54 | 54 | public function getPackageFilename($identifier, $sha, $repositoryDir, DeploynautLogFile $log) |
55 | 55 | { |
56 | 56 | // Fetch through the cache |
57 | - if ($this->cache) { |
|
57 | + if($this->cache) { |
|
58 | 58 | $identifier .= '-' . get_class($this) . '-' . $this->getIdentifier(); |
59 | 59 | return $this->cache->getPackageFilename($this, $identifier, $sha, $repositoryDir, $log); |
60 | 60 | |
61 | 61 | // Default, cacheless implementation |
62 | 62 | } else { |
63 | 63 | $filename = TEMP_FOLDER . '/' . $sha . '.tar.gz'; |
64 | - if ($this->generatePackage($sha, $repositoryDir, $filename, $log)) { |
|
64 | + if($this->generatePackage($sha, $repositoryDir, $filename, $log)) { |
|
65 | 65 | return $filename; |
66 | 66 | } |
67 | 67 | } |
@@ -6,8 +6,7 @@ discard block |
||
6 | 6 | * |
7 | 7 | * These package generators can be used by applicable deployment backends. |
8 | 8 | */ |
9 | -abstract class PackageGenerator |
|
10 | -{ |
|
9 | +abstract class PackageGenerator { |
|
11 | 10 | |
12 | 11 | protected $cache; |
13 | 12 | |
@@ -31,13 +30,11 @@ discard block |
||
31 | 30 | */ |
32 | 31 | abstract public function getIdentifier(); |
33 | 32 | |
34 | - public function getCache() |
|
35 | - { |
|
33 | + public function getCache() { |
|
36 | 34 | return $this->cache; |
37 | 35 | } |
38 | 36 | |
39 | - public function setCache(PackageCache $cache) |
|
40 | - { |
|
37 | + public function setCache(PackageCache $cache) { |
|
41 | 38 | $this->cache = $cache; |
42 | 39 | } |
43 | 40 | |
@@ -51,8 +48,7 @@ discard block |
||
51 | 48 | * |
52 | 49 | * @return string |
53 | 50 | */ |
54 | - public function getPackageFilename($identifier, $sha, $repositoryDir, DeploynautLogFile $log) |
|
55 | - { |
|
51 | + public function getPackageFilename($identifier, $sha, $repositoryDir, DeploynautLogFile $log) { |
|
56 | 52 | // Fetch through the cache |
57 | 53 | if ($this->cache) { |
58 | 54 | $identifier .= '-' . get_class($this) . '-' . $this->getIdentifier(); |
@@ -8,86 +8,86 @@ |
||
8 | 8 | class SimplePackageGenerator extends PackageGenerator |
9 | 9 | { |
10 | 10 | |
11 | - protected $buildScript = "composer install --prefer-dist --no-dev"; |
|
11 | + protected $buildScript = "composer install --prefer-dist --no-dev"; |
|
12 | 12 | |
13 | - public function getParamMetadata() |
|
14 | - { |
|
15 | - return array( |
|
16 | - 'BuildScript' => array('title' => 'Build script'), |
|
17 | - ); |
|
18 | - } |
|
13 | + public function getParamMetadata() |
|
14 | + { |
|
15 | + return array( |
|
16 | + 'BuildScript' => array('title' => 'Build script'), |
|
17 | + ); |
|
18 | + } |
|
19 | 19 | |
20 | - public function getBuildScript() |
|
21 | - { |
|
22 | - return $this->buildScript; |
|
23 | - } |
|
20 | + public function getBuildScript() |
|
21 | + { |
|
22 | + return $this->buildScript; |
|
23 | + } |
|
24 | 24 | |
25 | - public function setBuildScript($buildScript) |
|
26 | - { |
|
27 | - $this->buildScript = $buildScript; |
|
28 | - } |
|
25 | + public function setBuildScript($buildScript) |
|
26 | + { |
|
27 | + $this->buildScript = $buildScript; |
|
28 | + } |
|
29 | 29 | |
30 | - public function getIdentifier() |
|
31 | - { |
|
32 | - // If the build script changes, don't re-use cached items |
|
33 | - return substr(sha1($this->buildScript), 0, 8); |
|
34 | - } |
|
30 | + public function getIdentifier() |
|
31 | + { |
|
32 | + // If the build script changes, don't re-use cached items |
|
33 | + return substr(sha1($this->buildScript), 0, 8); |
|
34 | + } |
|
35 | 35 | |
36 | - /** |
|
37 | - * Generate the package |
|
38 | - */ |
|
39 | - public function generatePackage($sha, $baseDir, $outputFilename, DeploynautLogFile $log) |
|
40 | - { |
|
41 | - $tempPath = TEMP_FOLDER . "/" . str_replace(".tar.gz", "", basename($outputFilename)); |
|
42 | - if (!file_exists($tempPath)) { |
|
43 | - mkdir($tempPath); |
|
44 | - } |
|
36 | + /** |
|
37 | + * Generate the package |
|
38 | + */ |
|
39 | + public function generatePackage($sha, $baseDir, $outputFilename, DeploynautLogFile $log) |
|
40 | + { |
|
41 | + $tempPath = TEMP_FOLDER . "/" . str_replace(".tar.gz", "", basename($outputFilename)); |
|
42 | + if (!file_exists($tempPath)) { |
|
43 | + mkdir($tempPath); |
|
44 | + } |
|
45 | 45 | |
46 | - $escapedTempPath = escapeshellarg($tempPath); |
|
47 | - $escapedOutputFile = escapeshellarg($outputFilename); |
|
48 | - $escapedTempDir = escapeshellarg(basename($tempPath)); |
|
46 | + $escapedTempPath = escapeshellarg($tempPath); |
|
47 | + $escapedOutputFile = escapeshellarg($outputFilename); |
|
48 | + $escapedTempDir = escapeshellarg(basename($tempPath)); |
|
49 | 49 | |
50 | - // Execute these in sequence until there's a failure |
|
51 | - $processes = array( |
|
52 | - // Export the relevant SHA into a temp folder |
|
53 | - new Process("git archive $sha | tar -x -C " . $escapedTempPath, $baseDir), |
|
54 | - // Run build script |
|
55 | - new Process($this->buildScript, $tempPath, null, null, 3600), |
|
56 | - // Compress the result |
|
57 | - new Process("tar -czf " . $escapedOutputFile . " " . $escapedTempDir, dirname($tempPath)), |
|
58 | - ); |
|
50 | + // Execute these in sequence until there's a failure |
|
51 | + $processes = array( |
|
52 | + // Export the relevant SHA into a temp folder |
|
53 | + new Process("git archive $sha | tar -x -C " . $escapedTempPath, $baseDir), |
|
54 | + // Run build script |
|
55 | + new Process($this->buildScript, $tempPath, null, null, 3600), |
|
56 | + // Compress the result |
|
57 | + new Process("tar -czf " . $escapedOutputFile . " " . $escapedTempDir, dirname($tempPath)), |
|
58 | + ); |
|
59 | 59 | |
60 | - // Call at the end, regardless of success or failure |
|
61 | - $cleanup = array( |
|
62 | - // Delete the temporary staging folder |
|
63 | - new Process("rm -rf " . $escapedTempPath), |
|
64 | - ); |
|
60 | + // Call at the end, regardless of success or failure |
|
61 | + $cleanup = array( |
|
62 | + // Delete the temporary staging folder |
|
63 | + new Process("rm -rf " . $escapedTempPath), |
|
64 | + ); |
|
65 | 65 | |
66 | - try { |
|
67 | - $this->executeProcesses($processes, $log); |
|
68 | - } catch (Exception $e) { |
|
69 | - // Execute cleanup on failure |
|
70 | - $this->executeProcesses($cleanup, $log); |
|
71 | - throw $e; |
|
72 | - } |
|
66 | + try { |
|
67 | + $this->executeProcesses($processes, $log); |
|
68 | + } catch (Exception $e) { |
|
69 | + // Execute cleanup on failure |
|
70 | + $this->executeProcesses($cleanup, $log); |
|
71 | + throw $e; |
|
72 | + } |
|
73 | 73 | |
74 | - // Execute cleanup on success |
|
75 | - $this->executeProcesses($cleanup, $log); |
|
76 | - return true; |
|
77 | - } |
|
74 | + // Execute cleanup on success |
|
75 | + $this->executeProcesses($cleanup, $log); |
|
76 | + return true; |
|
77 | + } |
|
78 | 78 | |
79 | - /** |
|
80 | - * Execute an array of processes, one after the other, throwing an exception on the first failure. |
|
81 | - * |
|
82 | - * @param array $processes An array of Symfony\Component\Process\Process objects |
|
83 | - * @param DeploynautLogFile $log The log to send output to |
|
84 | - */ |
|
85 | - protected function executeProcesses($processes, DeploynautLogFile $log) |
|
86 | - { |
|
87 | - foreach ($processes as $process) { |
|
88 | - $process->mustRun(function ($type, $buffer) use ($log) { |
|
89 | - $log->write($buffer); |
|
90 | - }); |
|
91 | - } |
|
92 | - } |
|
79 | + /** |
|
80 | + * Execute an array of processes, one after the other, throwing an exception on the first failure. |
|
81 | + * |
|
82 | + * @param array $processes An array of Symfony\Component\Process\Process objects |
|
83 | + * @param DeploynautLogFile $log The log to send output to |
|
84 | + */ |
|
85 | + protected function executeProcesses($processes, DeploynautLogFile $log) |
|
86 | + { |
|
87 | + foreach ($processes as $process) { |
|
88 | + $process->mustRun(function ($type, $buffer) use ($log) { |
|
89 | + $log->write($buffer); |
|
90 | + }); |
|
91 | + } |
|
92 | + } |
|
93 | 93 | } |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | public function generatePackage($sha, $baseDir, $outputFilename, DeploynautLogFile $log) |
40 | 40 | { |
41 | 41 | $tempPath = TEMP_FOLDER . "/" . str_replace(".tar.gz", "", basename($outputFilename)); |
42 | - if (!file_exists($tempPath)) { |
|
42 | + if(!file_exists($tempPath)) { |
|
43 | 43 | mkdir($tempPath); |
44 | 44 | } |
45 | 45 | |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | |
66 | 66 | try { |
67 | 67 | $this->executeProcesses($processes, $log); |
68 | - } catch (Exception $e) { |
|
68 | + } catch(Exception $e) { |
|
69 | 69 | // Execute cleanup on failure |
70 | 70 | $this->executeProcesses($cleanup, $log); |
71 | 71 | throw $e; |
@@ -84,8 +84,8 @@ discard block |
||
84 | 84 | */ |
85 | 85 | protected function executeProcesses($processes, DeploynautLogFile $log) |
86 | 86 | { |
87 | - foreach ($processes as $process) { |
|
88 | - $process->mustRun(function ($type, $buffer) use ($log) { |
|
87 | + foreach($processes as $process) { |
|
88 | + $process->mustRun(function($type, $buffer) use ($log) { |
|
89 | 89 | $log->write($buffer); |
90 | 90 | }); |
91 | 91 | } |
@@ -5,30 +5,25 @@ discard block |
||
5 | 5 | /** |
6 | 6 | * Generates the package directly on the deploynaut server |
7 | 7 | */ |
8 | -class SimplePackageGenerator extends PackageGenerator |
|
9 | -{ |
|
8 | +class SimplePackageGenerator extends PackageGenerator { |
|
10 | 9 | |
11 | 10 | protected $buildScript = "composer install --prefer-dist --no-dev"; |
12 | 11 | |
13 | - public function getParamMetadata() |
|
14 | - { |
|
12 | + public function getParamMetadata() { |
|
15 | 13 | return array( |
16 | 14 | 'BuildScript' => array('title' => 'Build script'), |
17 | 15 | ); |
18 | 16 | } |
19 | 17 | |
20 | - public function getBuildScript() |
|
21 | - { |
|
18 | + public function getBuildScript() { |
|
22 | 19 | return $this->buildScript; |
23 | 20 | } |
24 | 21 | |
25 | - public function setBuildScript($buildScript) |
|
26 | - { |
|
22 | + public function setBuildScript($buildScript) { |
|
27 | 23 | $this->buildScript = $buildScript; |
28 | 24 | } |
29 | 25 | |
30 | - public function getIdentifier() |
|
31 | - { |
|
26 | + public function getIdentifier() { |
|
32 | 27 | // If the build script changes, don't re-use cached items |
33 | 28 | return substr(sha1($this->buildScript), 0, 8); |
34 | 29 | } |
@@ -36,8 +31,7 @@ discard block |
||
36 | 31 | /** |
37 | 32 | * Generate the package |
38 | 33 | */ |
39 | - public function generatePackage($sha, $baseDir, $outputFilename, DeploynautLogFile $log) |
|
40 | - { |
|
34 | + public function generatePackage($sha, $baseDir, $outputFilename, DeploynautLogFile $log) { |
|
41 | 35 | $tempPath = TEMP_FOLDER . "/" . str_replace(".tar.gz", "", basename($outputFilename)); |
42 | 36 | if (!file_exists($tempPath)) { |
43 | 37 | mkdir($tempPath); |
@@ -82,8 +76,7 @@ discard block |
||
82 | 76 | * @param array $processes An array of Symfony\Component\Process\Process objects |
83 | 77 | * @param DeploynautLogFile $log The log to send output to |
84 | 78 | */ |
85 | - protected function executeProcesses($processes, DeploynautLogFile $log) |
|
86 | - { |
|
79 | + protected function executeProcesses($processes, DeploynautLogFile $log) { |
|
87 | 80 | foreach ($processes as $process) { |
88 | 81 | $process->mustRun(function ($type, $buffer) use ($log) { |
89 | 82 | $log->write($buffer); |
@@ -6,117 +6,117 @@ |
||
6 | 6 | class SizeRestrictedPackageCache implements PackageCache |
7 | 7 | { |
8 | 8 | |
9 | - protected $cacheSize; |
|
10 | - protected $baseDir; |
|
9 | + protected $cacheSize; |
|
10 | + protected $baseDir; |
|
11 | 11 | |
12 | - /** |
|
13 | - * Set the maximum number of items that will be stored in the package cache. |
|
14 | - * |
|
15 | - * If null, items will never be deleted. If set, cache entries will be touched whenever they are accessed, |
|
16 | - * and the least-recently-access items will be deleted. |
|
17 | - * |
|
18 | - * @param int $cacheSize the number of package files to keep. |
|
19 | - */ |
|
20 | - public function setCacheSize($cacheSize) |
|
21 | - { |
|
22 | - $this->cacheSize = $cacheSize; |
|
23 | - } |
|
12 | + /** |
|
13 | + * Set the maximum number of items that will be stored in the package cache. |
|
14 | + * |
|
15 | + * If null, items will never be deleted. If set, cache entries will be touched whenever they are accessed, |
|
16 | + * and the least-recently-access items will be deleted. |
|
17 | + * |
|
18 | + * @param int $cacheSize the number of package files to keep. |
|
19 | + */ |
|
20 | + public function setCacheSize($cacheSize) |
|
21 | + { |
|
22 | + $this->cacheSize = $cacheSize; |
|
23 | + } |
|
24 | 24 | |
25 | - /** |
|
26 | - * The base directory to store cached packages in. |
|
27 | - * The files will be stored in a subdirectory named after the identifier. |
|
28 | - * If base directory isn't set, the getPackageFilename() won't run. |
|
29 | - * |
|
30 | - * @param string $baseDir The base directory |
|
31 | - */ |
|
32 | - public function setBaseDir($baseDir) |
|
33 | - { |
|
34 | - $this->baseDir = realpath($baseDir); |
|
35 | - } |
|
25 | + /** |
|
26 | + * The base directory to store cached packages in. |
|
27 | + * The files will be stored in a subdirectory named after the identifier. |
|
28 | + * If base directory isn't set, the getPackageFilename() won't run. |
|
29 | + * |
|
30 | + * @param string $baseDir The base directory |
|
31 | + */ |
|
32 | + public function setBaseDir($baseDir) |
|
33 | + { |
|
34 | + $this->baseDir = realpath($baseDir); |
|
35 | + } |
|
36 | 36 | |
37 | - /** |
|
38 | - * Return the filename of the generated package, retrieving from cache or generating as necessary |
|
39 | - * |
|
40 | - * @param PackageGenerator $generator The generator to use to create cache entries. |
|
41 | - * @param string $identifier A unique identifier for the generator; used to partition the cache |
|
42 | - * @param string $sha The SHA of the commit to be deployed |
|
43 | - * @param string $repositoryDir The directory where the repository resides |
|
44 | - * @param DeploynautLogFile $log The log to write status output to, including package-generation commands |
|
45 | - * |
|
46 | - * @return string |
|
47 | - */ |
|
48 | - public function getPackageFilename( |
|
49 | - PackageGenerator $generator, |
|
50 | - $identifier, $sha, |
|
51 | - $repositoryDir, |
|
52 | - DeploynautLogFile $log |
|
53 | - ) { |
|
54 | - if (!$this->baseDir) { |
|
55 | - throw new \LogicException("Can't use PackageCache without setting BaseDir"); |
|
56 | - } |
|
37 | + /** |
|
38 | + * Return the filename of the generated package, retrieving from cache or generating as necessary |
|
39 | + * |
|
40 | + * @param PackageGenerator $generator The generator to use to create cache entries. |
|
41 | + * @param string $identifier A unique identifier for the generator; used to partition the cache |
|
42 | + * @param string $sha The SHA of the commit to be deployed |
|
43 | + * @param string $repositoryDir The directory where the repository resides |
|
44 | + * @param DeploynautLogFile $log The log to write status output to, including package-generation commands |
|
45 | + * |
|
46 | + * @return string |
|
47 | + */ |
|
48 | + public function getPackageFilename( |
|
49 | + PackageGenerator $generator, |
|
50 | + $identifier, $sha, |
|
51 | + $repositoryDir, |
|
52 | + DeploynautLogFile $log |
|
53 | + ) { |
|
54 | + if (!$this->baseDir) { |
|
55 | + throw new \LogicException("Can't use PackageCache without setting BaseDir"); |
|
56 | + } |
|
57 | 57 | |
58 | - $buildPath = $this->baseDir . '/' . $this->sanitiseDirName($identifier); |
|
59 | - $filename = "$buildPath/$sha.tar.gz"; |
|
58 | + $buildPath = $this->baseDir . '/' . $this->sanitiseDirName($identifier); |
|
59 | + $filename = "$buildPath/$sha.tar.gz"; |
|
60 | 60 | |
61 | - if (!file_exists($this->baseDir)) { |
|
62 | - if (!mkdir($this->baseDir)) { |
|
63 | - throw new \LogicException("Can't create base dir {$this->baseDir}"); |
|
64 | - } |
|
65 | - } |
|
66 | - if (!file_exists($buildPath)) { |
|
67 | - if (!mkdir($buildPath)) { |
|
68 | - throw new \LogicException("Can't create build path $buildPath"); |
|
69 | - } |
|
70 | - } |
|
61 | + if (!file_exists($this->baseDir)) { |
|
62 | + if (!mkdir($this->baseDir)) { |
|
63 | + throw new \LogicException("Can't create base dir {$this->baseDir}"); |
|
64 | + } |
|
65 | + } |
|
66 | + if (!file_exists($buildPath)) { |
|
67 | + if (!mkdir($buildPath)) { |
|
68 | + throw new \LogicException("Can't create build path $buildPath"); |
|
69 | + } |
|
70 | + } |
|
71 | 71 | |
72 | - if (file_exists($filename)) { |
|
73 | - $log->write("Using previously generated package $filename"); |
|
74 | - // This will ensure that our cache garbage collection will remove least-recently-accessed, |
|
75 | - // rather than oldest. |
|
76 | - touch($filename); |
|
77 | - return $filename; |
|
78 | - } else { |
|
79 | - if ($this->cacheSize) { |
|
80 | - $this->reduceDirSizeTo($buildPath, $this->cacheSize - 1, $log); |
|
81 | - } |
|
72 | + if (file_exists($filename)) { |
|
73 | + $log->write("Using previously generated package $filename"); |
|
74 | + // This will ensure that our cache garbage collection will remove least-recently-accessed, |
|
75 | + // rather than oldest. |
|
76 | + touch($filename); |
|
77 | + return $filename; |
|
78 | + } else { |
|
79 | + if ($this->cacheSize) { |
|
80 | + $this->reduceDirSizeTo($buildPath, $this->cacheSize - 1, $log); |
|
81 | + } |
|
82 | 82 | |
83 | - if ($generator->generatePackage($sha, $repositoryDir, $filename, $log)) { |
|
84 | - return $filename; |
|
85 | - } |
|
86 | - } |
|
87 | - } |
|
83 | + if ($generator->generatePackage($sha, $repositoryDir, $filename, $log)) { |
|
84 | + return $filename; |
|
85 | + } |
|
86 | + } |
|
87 | + } |
|
88 | 88 | |
89 | - /** |
|
90 | - * Take the identifier an make it safe to use as a directory name. |
|
91 | - * |
|
92 | - * @param string $identifier The unsanitised directory name. |
|
93 | - */ |
|
94 | - protected function sanitiseDirName($identifier) |
|
95 | - { |
|
96 | - $safe = preg_replace('/[^A-Za-z0-9_-]/', '', $identifier); |
|
97 | - return $safe ? $safe : 'null'; |
|
98 | - } |
|
89 | + /** |
|
90 | + * Take the identifier an make it safe to use as a directory name. |
|
91 | + * |
|
92 | + * @param string $identifier The unsanitised directory name. |
|
93 | + */ |
|
94 | + protected function sanitiseDirName($identifier) |
|
95 | + { |
|
96 | + $safe = preg_replace('/[^A-Za-z0-9_-]/', '', $identifier); |
|
97 | + return $safe ? $safe : 'null'; |
|
98 | + } |
|
99 | 99 | |
100 | - /** |
|
101 | - * Delete items in this directory until the number of items is <= $count. |
|
102 | - * Delete the oldest files first. |
|
103 | - * |
|
104 | - * @param string $dir The directory to remove items from |
|
105 | - * @param int $count The maximum number of .tar.gz files that can appear in that directory |
|
106 | - * @param DeploynautLogFile $log The log to send removal status messages to |
|
107 | - */ |
|
108 | - protected function reduceDirSizeTo($dir, $count, DeploynautLogFile $log) |
|
109 | - { |
|
110 | - $files = glob($dir . '/*.tar.gz'); |
|
111 | - if (sizeof($files) > $count) { |
|
112 | - usort($files, function ($a, $b) { |
|
113 | - return filemtime($a) > filemtime($b); |
|
114 | - }); |
|
100 | + /** |
|
101 | + * Delete items in this directory until the number of items is <= $count. |
|
102 | + * Delete the oldest files first. |
|
103 | + * |
|
104 | + * @param string $dir The directory to remove items from |
|
105 | + * @param int $count The maximum number of .tar.gz files that can appear in that directory |
|
106 | + * @param DeploynautLogFile $log The log to send removal status messages to |
|
107 | + */ |
|
108 | + protected function reduceDirSizeTo($dir, $count, DeploynautLogFile $log) |
|
109 | + { |
|
110 | + $files = glob($dir . '/*.tar.gz'); |
|
111 | + if (sizeof($files) > $count) { |
|
112 | + usort($files, function ($a, $b) { |
|
113 | + return filemtime($a) > filemtime($b); |
|
114 | + }); |
|
115 | 115 | |
116 | - for ($i = 0; $i < sizeof($files) - $count; $i++) { |
|
117 | - $log->write("Removing " . $files[$i] . " from package cache"); |
|
118 | - unlink($files[$i]); |
|
119 | - } |
|
120 | - } |
|
121 | - } |
|
116 | + for ($i = 0; $i < sizeof($files) - $count; $i++) { |
|
117 | + $log->write("Removing " . $files[$i] . " from package cache"); |
|
118 | + unlink($files[$i]); |
|
119 | + } |
|
120 | + } |
|
121 | + } |
|
122 | 122 | } |
@@ -51,36 +51,36 @@ discard block |
||
51 | 51 | $repositoryDir, |
52 | 52 | DeploynautLogFile $log |
53 | 53 | ) { |
54 | - if (!$this->baseDir) { |
|
54 | + if(!$this->baseDir) { |
|
55 | 55 | throw new \LogicException("Can't use PackageCache without setting BaseDir"); |
56 | 56 | } |
57 | 57 | |
58 | 58 | $buildPath = $this->baseDir . '/' . $this->sanitiseDirName($identifier); |
59 | 59 | $filename = "$buildPath/$sha.tar.gz"; |
60 | 60 | |
61 | - if (!file_exists($this->baseDir)) { |
|
62 | - if (!mkdir($this->baseDir)) { |
|
61 | + if(!file_exists($this->baseDir)) { |
|
62 | + if(!mkdir($this->baseDir)) { |
|
63 | 63 | throw new \LogicException("Can't create base dir {$this->baseDir}"); |
64 | 64 | } |
65 | 65 | } |
66 | - if (!file_exists($buildPath)) { |
|
67 | - if (!mkdir($buildPath)) { |
|
66 | + if(!file_exists($buildPath)) { |
|
67 | + if(!mkdir($buildPath)) { |
|
68 | 68 | throw new \LogicException("Can't create build path $buildPath"); |
69 | 69 | } |
70 | 70 | } |
71 | 71 | |
72 | - if (file_exists($filename)) { |
|
72 | + if(file_exists($filename)) { |
|
73 | 73 | $log->write("Using previously generated package $filename"); |
74 | 74 | // This will ensure that our cache garbage collection will remove least-recently-accessed, |
75 | 75 | // rather than oldest. |
76 | 76 | touch($filename); |
77 | 77 | return $filename; |
78 | 78 | } else { |
79 | - if ($this->cacheSize) { |
|
79 | + if($this->cacheSize) { |
|
80 | 80 | $this->reduceDirSizeTo($buildPath, $this->cacheSize - 1, $log); |
81 | 81 | } |
82 | 82 | |
83 | - if ($generator->generatePackage($sha, $repositoryDir, $filename, $log)) { |
|
83 | + if($generator->generatePackage($sha, $repositoryDir, $filename, $log)) { |
|
84 | 84 | return $filename; |
85 | 85 | } |
86 | 86 | } |
@@ -108,12 +108,12 @@ discard block |
||
108 | 108 | protected function reduceDirSizeTo($dir, $count, DeploynautLogFile $log) |
109 | 109 | { |
110 | 110 | $files = glob($dir . '/*.tar.gz'); |
111 | - if (sizeof($files) > $count) { |
|
112 | - usort($files, function ($a, $b) { |
|
111 | + if(sizeof($files) > $count) { |
|
112 | + usort($files, function($a, $b) { |
|
113 | 113 | return filemtime($a) > filemtime($b); |
114 | 114 | }); |
115 | 115 | |
116 | - for ($i = 0; $i < sizeof($files) - $count; $i++) { |
|
116 | + for($i = 0; $i < sizeof($files) - $count; $i++) { |
|
117 | 117 | $log->write("Removing " . $files[$i] . " from package cache"); |
118 | 118 | unlink($files[$i]); |
119 | 119 | } |
@@ -3,8 +3,7 @@ discard block |
||
3 | 3 | /** |
4 | 4 | * Class for calling the package generator and caching the results. |
5 | 5 | */ |
6 | -class SizeRestrictedPackageCache implements PackageCache |
|
7 | -{ |
|
6 | +class SizeRestrictedPackageCache implements PackageCache { |
|
8 | 7 | |
9 | 8 | protected $cacheSize; |
10 | 9 | protected $baseDir; |
@@ -17,8 +16,7 @@ discard block |
||
17 | 16 | * |
18 | 17 | * @param int $cacheSize the number of package files to keep. |
19 | 18 | */ |
20 | - public function setCacheSize($cacheSize) |
|
21 | - { |
|
19 | + public function setCacheSize($cacheSize) { |
|
22 | 20 | $this->cacheSize = $cacheSize; |
23 | 21 | } |
24 | 22 | |
@@ -29,8 +27,7 @@ discard block |
||
29 | 27 | * |
30 | 28 | * @param string $baseDir The base directory |
31 | 29 | */ |
32 | - public function setBaseDir($baseDir) |
|
33 | - { |
|
30 | + public function setBaseDir($baseDir) { |
|
34 | 31 | $this->baseDir = realpath($baseDir); |
35 | 32 | } |
36 | 33 | |
@@ -91,8 +88,7 @@ discard block |
||
91 | 88 | * |
92 | 89 | * @param string $identifier The unsanitised directory name. |
93 | 90 | */ |
94 | - protected function sanitiseDirName($identifier) |
|
95 | - { |
|
91 | + protected function sanitiseDirName($identifier) { |
|
96 | 92 | $safe = preg_replace('/[^A-Za-z0-9_-]/', '', $identifier); |
97 | 93 | return $safe ? $safe : 'null'; |
98 | 94 | } |
@@ -105,8 +101,7 @@ discard block |
||
105 | 101 | * @param int $count The maximum number of .tar.gz files that can appear in that directory |
106 | 102 | * @param DeploynautLogFile $log The log to send removal status messages to |
107 | 103 | */ |
108 | - protected function reduceDirSizeTo($dir, $count, DeploynautLogFile $log) |
|
109 | - { |
|
104 | + protected function reduceDirSizeTo($dir, $count, DeploynautLogFile $log) { |
|
110 | 105 | $files = glob($dir . '/*.tar.gz'); |
111 | 106 | if (sizeof($files) > $count) { |
112 | 107 | usort($files, function ($a, $b) { |
@@ -10,31 +10,31 @@ |
||
10 | 10 | */ |
11 | 11 | class CheckPipelineStatus extends Controller |
12 | 12 | { |
13 | - public function index() |
|
14 | - { |
|
15 | - // @TODO Check that we have been called via the daemon |
|
16 | - if (php_sapi_name() != "cli") { |
|
17 | - throw new Exception("CheckPipelineStatus must be run from the command-line."); |
|
18 | - } |
|
13 | + public function index() |
|
14 | + { |
|
15 | + // @TODO Check that we have been called via the daemon |
|
16 | + if (php_sapi_name() != "cli") { |
|
17 | + throw new Exception("CheckPipelineStatus must be run from the command-line."); |
|
18 | + } |
|
19 | 19 | |
20 | - $this->run(); |
|
21 | - } |
|
20 | + $this->run(); |
|
21 | + } |
|
22 | 22 | |
23 | - private function run() |
|
24 | - { |
|
25 | - // Note that a pipeline must be started prior to being picked up by this task |
|
26 | - $runningPipelines = Pipeline::get()->filter('Status', array('Running', 'Rollback')); |
|
23 | + private function run() |
|
24 | + { |
|
25 | + // Note that a pipeline must be started prior to being picked up by this task |
|
26 | + $runningPipelines = Pipeline::get()->filter('Status', array('Running', 'Rollback')); |
|
27 | 27 | |
28 | - printf( |
|
29 | - "%s Checking status of %d pipelines... ", |
|
30 | - "[" . date("Y-m-d H:i:s") . "]", |
|
31 | - $runningPipelines->count() |
|
32 | - ); |
|
28 | + printf( |
|
29 | + "%s Checking status of %d pipelines... ", |
|
30 | + "[" . date("Y-m-d H:i:s") . "]", |
|
31 | + $runningPipelines->count() |
|
32 | + ); |
|
33 | 33 | |
34 | - foreach ($runningPipelines as $pipeline) { |
|
35 | - $pipeline->checkPipelineStatus(); |
|
36 | - } |
|
34 | + foreach ($runningPipelines as $pipeline) { |
|
35 | + $pipeline->checkPipelineStatus(); |
|
36 | + } |
|
37 | 37 | |
38 | - echo "done!" . PHP_EOL; |
|
39 | - } |
|
38 | + echo "done!" . PHP_EOL; |
|
39 | + } |
|
40 | 40 | } |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | public function index() |
14 | 14 | { |
15 | 15 | // @TODO Check that we have been called via the daemon |
16 | - if (php_sapi_name() != "cli") { |
|
16 | + if(php_sapi_name() != "cli") { |
|
17 | 17 | throw new Exception("CheckPipelineStatus must be run from the command-line."); |
18 | 18 | } |
19 | 19 | |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | $runningPipelines->count() |
32 | 32 | ); |
33 | 33 | |
34 | - foreach ($runningPipelines as $pipeline) { |
|
34 | + foreach($runningPipelines as $pipeline) { |
|
35 | 35 | $pipeline->checkPipelineStatus(); |
36 | 36 | } |
37 | 37 |
@@ -8,10 +8,8 @@ discard block |
||
8 | 8 | * @package deploynaut |
9 | 9 | * @subpackage control |
10 | 10 | */ |
11 | -class CheckPipelineStatus extends Controller |
|
12 | -{ |
|
13 | - public function index() |
|
14 | - { |
|
11 | +class CheckPipelineStatus extends Controller { |
|
12 | + public function index() { |
|
15 | 13 | // @TODO Check that we have been called via the daemon |
16 | 14 | if (php_sapi_name() != "cli") { |
17 | 15 | throw new Exception("CheckPipelineStatus must be run from the command-line."); |
@@ -20,8 +18,7 @@ discard block |
||
20 | 18 | $this->run(); |
21 | 19 | } |
22 | 20 | |
23 | - private function run() |
|
24 | - { |
|
21 | + private function run() { |
|
25 | 22 | // Note that a pipeline must be started prior to being picked up by this task |
26 | 23 | $runningPipelines = Pipeline::get()->filter('Status', array('Running', 'Rollback')); |
27 | 24 |
@@ -7,14 +7,14 @@ |
||
7 | 7 | interface ConfirmationMessagingService |
8 | 8 | { |
9 | 9 | |
10 | - /** |
|
11 | - * Sends a message to the specified user |
|
12 | - * |
|
13 | - * @param PipelineData $source Source client step |
|
14 | - * @param string $message Plain text message |
|
15 | - * @param mixed $recipients Either a Member object, string, or array of strings or Member objects |
|
16 | - * @param array $arguments Additional arguments that may be configured |
|
17 | - * @return boolean True if success |
|
18 | - */ |
|
19 | - public function sendMessage($source, $message, $recipients, $arguments = array()); |
|
10 | + /** |
|
11 | + * Sends a message to the specified user |
|
12 | + * |
|
13 | + * @param PipelineData $source Source client step |
|
14 | + * @param string $message Plain text message |
|
15 | + * @param mixed $recipients Either a Member object, string, or array of strings or Member objects |
|
16 | + * @param array $arguments Additional arguments that may be configured |
|
17 | + * @return boolean True if success |
|
18 | + */ |
|
19 | + public function sendMessage($source, $message, $recipients, $arguments = array()); |
|
20 | 20 | } |
@@ -4,8 +4,7 @@ |
||
4 | 4 | * @package deploynaut |
5 | 5 | * @subpackage control |
6 | 6 | */ |
7 | -interface ConfirmationMessagingService |
|
8 | -{ |
|
7 | +interface ConfirmationMessagingService { |
|
9 | 8 | |
10 | 9 | /** |
11 | 10 | * Sends a message to the specified user |
@@ -3,27 +3,27 @@ |
||
3 | 3 | class DNAdmin extends ModelAdmin |
4 | 4 | { |
5 | 5 | |
6 | - /** |
|
7 | - * @var string |
|
8 | - */ |
|
9 | - public static $menu_title = "Deploynaut Projects"; |
|
6 | + /** |
|
7 | + * @var string |
|
8 | + */ |
|
9 | + public static $menu_title = "Deploynaut Projects"; |
|
10 | 10 | |
11 | - /** |
|
12 | - * @var string |
|
13 | - */ |
|
14 | - public static $url_segment = "naut"; |
|
11 | + /** |
|
12 | + * @var string |
|
13 | + */ |
|
14 | + public static $url_segment = "naut"; |
|
15 | 15 | |
16 | - /** |
|
17 | - * @var array |
|
18 | - */ |
|
19 | - public static $managed_models = array( |
|
20 | - 'DNProject' => array('title' => 'Projects'), |
|
21 | - 'DNDataTransfer' => array('title' => 'Transfers'), |
|
22 | - 'DNDataArchive' => array('title' => 'Archives'), |
|
23 | - ); |
|
16 | + /** |
|
17 | + * @var array |
|
18 | + */ |
|
19 | + public static $managed_models = array( |
|
20 | + 'DNProject' => array('title' => 'Projects'), |
|
21 | + 'DNDataTransfer' => array('title' => 'Transfers'), |
|
22 | + 'DNDataArchive' => array('title' => 'Archives'), |
|
23 | + ); |
|
24 | 24 | |
25 | - /** |
|
26 | - * @var int |
|
27 | - */ |
|
28 | - private static $menu_priority = 100; |
|
25 | + /** |
|
26 | + * @var int |
|
27 | + */ |
|
28 | + private static $menu_priority = 100; |
|
29 | 29 | } |
@@ -1,7 +1,6 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | -class DNAdmin extends ModelAdmin |
|
4 | -{ |
|
3 | +class DNAdmin extends ModelAdmin { |
|
5 | 4 | |
6 | 5 | /** |
7 | 6 | * @var string |
@@ -9,49 +9,49 @@ discard block |
||
9 | 9 | abstract class DeployForm_ValidatorBase extends Validator |
10 | 10 | { |
11 | 11 | |
12 | - /** |
|
13 | - * @param string $fieldName |
|
14 | - * @param string $message |
|
15 | - * @param string $messageType |
|
16 | - */ |
|
17 | - public function validationError($fieldName, $message, $messageType = '') |
|
18 | - { |
|
19 | - // Just make any error use the form message |
|
20 | - $this->form->sessionMessage($message, $messageType); |
|
21 | - parent::validationError($fieldName, $message, $messageType); |
|
22 | - } |
|
12 | + /** |
|
13 | + * @param string $fieldName |
|
14 | + * @param string $message |
|
15 | + * @param string $messageType |
|
16 | + */ |
|
17 | + public function validationError($fieldName, $message, $messageType = '') |
|
18 | + { |
|
19 | + // Just make any error use the form message |
|
20 | + $this->form->sessionMessage($message, $messageType); |
|
21 | + parent::validationError($fieldName, $message, $messageType); |
|
22 | + } |
|
23 | 23 | |
24 | - /** |
|
25 | - * Validate a commit sha |
|
26 | - * |
|
27 | - * @param string $sha |
|
28 | - * @param string $field |
|
29 | - * @return boolean |
|
30 | - */ |
|
31 | - protected function validateCommit($sha, $field) |
|
32 | - { |
|
33 | - // Check selected commit |
|
34 | - if (empty($sha)) { |
|
35 | - $this->validationError( |
|
36 | - $field, |
|
37 | - "No valid release selected", |
|
38 | - "required" |
|
39 | - ); |
|
40 | - return false; |
|
41 | - } |
|
24 | + /** |
|
25 | + * Validate a commit sha |
|
26 | + * |
|
27 | + * @param string $sha |
|
28 | + * @param string $field |
|
29 | + * @return boolean |
|
30 | + */ |
|
31 | + protected function validateCommit($sha, $field) |
|
32 | + { |
|
33 | + // Check selected commit |
|
34 | + if (empty($sha)) { |
|
35 | + $this->validationError( |
|
36 | + $field, |
|
37 | + "No valid release selected", |
|
38 | + "required" |
|
39 | + ); |
|
40 | + return false; |
|
41 | + } |
|
42 | 42 | |
43 | - // Check validity of commit |
|
44 | - if (!preg_match('/^[a-f0-9]{40}$/', $sha)) { |
|
45 | - $this->validationError( |
|
46 | - $field, |
|
47 | - "Invalid release SHA: " . Convert::raw2xml($sha), |
|
48 | - "error" |
|
49 | - ); |
|
50 | - return false; |
|
51 | - } |
|
43 | + // Check validity of commit |
|
44 | + if (!preg_match('/^[a-f0-9]{40}$/', $sha)) { |
|
45 | + $this->validationError( |
|
46 | + $field, |
|
47 | + "Invalid release SHA: " . Convert::raw2xml($sha), |
|
48 | + "error" |
|
49 | + ); |
|
50 | + return false; |
|
51 | + } |
|
52 | 52 | |
53 | - return true; |
|
54 | - } |
|
53 | + return true; |
|
54 | + } |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | /** |
@@ -63,27 +63,27 @@ discard block |
||
63 | 63 | class DeployForm_CommitValidator extends DeployForm_ValidatorBase |
64 | 64 | { |
65 | 65 | |
66 | - public function php($data) |
|
67 | - { |
|
68 | - // Check release method |
|
69 | - if (empty($data['SelectRelease']) |
|
70 | - || !in_array($data['SelectRelease'], array('Tag', 'Branch', 'Redeploy', 'SHA', 'FilteredCommits')) |
|
71 | - ) { |
|
72 | - $method = empty($data['SelectRelease']) ? '(blank)' : $data['SelectRelease']; |
|
73 | - $this->validationError( |
|
74 | - 'SelectRelease', |
|
75 | - "Bad release selection method: $method", |
|
76 | - "error" |
|
77 | - ); |
|
78 | - return false; |
|
79 | - } |
|
66 | + public function php($data) |
|
67 | + { |
|
68 | + // Check release method |
|
69 | + if (empty($data['SelectRelease']) |
|
70 | + || !in_array($data['SelectRelease'], array('Tag', 'Branch', 'Redeploy', 'SHA', 'FilteredCommits')) |
|
71 | + ) { |
|
72 | + $method = empty($data['SelectRelease']) ? '(blank)' : $data['SelectRelease']; |
|
73 | + $this->validationError( |
|
74 | + 'SelectRelease', |
|
75 | + "Bad release selection method: $method", |
|
76 | + "error" |
|
77 | + ); |
|
78 | + return false; |
|
79 | + } |
|
80 | 80 | |
81 | - // Check sha |
|
82 | - return $this->validateCommit( |
|
83 | - $this->form->getSelectedBuild($data), |
|
84 | - 'SelectRelease' |
|
85 | - ); |
|
86 | - } |
|
81 | + // Check sha |
|
82 | + return $this->validateCommit( |
|
83 | + $this->form->getSelectedBuild($data), |
|
84 | + 'SelectRelease' |
|
85 | + ); |
|
86 | + } |
|
87 | 87 | } |
88 | 88 | |
89 | 89 | /** |
@@ -95,13 +95,13 @@ discard block |
||
95 | 95 | class DeployForm_PipelineValidator extends DeployForm_ValidatorBase |
96 | 96 | { |
97 | 97 | |
98 | - public function php($data) |
|
99 | - { |
|
100 | - return $this->validateCommit( |
|
101 | - $this->form->getSelectedBuild($data), |
|
102 | - 'FilteredCommits' |
|
103 | - ); |
|
104 | - } |
|
98 | + public function php($data) |
|
99 | + { |
|
100 | + return $this->validateCommit( |
|
101 | + $this->form->getSelectedBuild($data), |
|
102 | + 'FilteredCommits' |
|
103 | + ); |
|
104 | + } |
|
105 | 105 | } |
106 | 106 | |
107 | 107 | /** |
@@ -113,240 +113,240 @@ discard block |
||
113 | 113 | class DeployForm extends Form |
114 | 114 | { |
115 | 115 | |
116 | - /** |
|
117 | - * @param DNRoot $controller |
|
118 | - * @param string $name |
|
119 | - * @param DNEnvironment $environment |
|
120 | - * @param DNProject $project |
|
121 | - */ |
|
122 | - public function __construct($controller, $name, DNEnvironment $environment, DNProject $project) |
|
123 | - { |
|
124 | - if ($environment->HasPipelineSupport()) { |
|
125 | - list($field, $validator, $actions) = $this->setupPipeline($environment, $project); |
|
126 | - } else { |
|
127 | - list($field, $validator, $actions) = $this->setupSimpleDeploy($project); |
|
128 | - } |
|
129 | - parent::__construct($controller, $name, new FieldList($field), $actions, $validator); |
|
130 | - } |
|
116 | + /** |
|
117 | + * @param DNRoot $controller |
|
118 | + * @param string $name |
|
119 | + * @param DNEnvironment $environment |
|
120 | + * @param DNProject $project |
|
121 | + */ |
|
122 | + public function __construct($controller, $name, DNEnvironment $environment, DNProject $project) |
|
123 | + { |
|
124 | + if ($environment->HasPipelineSupport()) { |
|
125 | + list($field, $validator, $actions) = $this->setupPipeline($environment, $project); |
|
126 | + } else { |
|
127 | + list($field, $validator, $actions) = $this->setupSimpleDeploy($project); |
|
128 | + } |
|
129 | + parent::__construct($controller, $name, new FieldList($field), $actions, $validator); |
|
130 | + } |
|
131 | 131 | |
132 | - /** |
|
133 | - * @param DNProject $project |
|
134 | - * |
|
135 | - * @return array |
|
136 | - */ |
|
137 | - protected function setupSimpleDeploy(DNProject $project) |
|
138 | - { |
|
139 | - // without a pipeline simply allow any commit to be selected |
|
140 | - $field = $this->buildCommitSelector($project); |
|
141 | - $validator = new DeployForm_CommitValidator(); |
|
142 | - $actions = new FieldList( |
|
143 | - new FormAction('showDeploySummary', 'Plan deployment', 'Show deployment plan'), |
|
144 | - new FormAction('doDeploy', 'Do deploy', 'Do deploy') |
|
145 | - ); |
|
146 | - return array($field, $validator, $actions); |
|
147 | - } |
|
132 | + /** |
|
133 | + * @param DNProject $project |
|
134 | + * |
|
135 | + * @return array |
|
136 | + */ |
|
137 | + protected function setupSimpleDeploy(DNProject $project) |
|
138 | + { |
|
139 | + // without a pipeline simply allow any commit to be selected |
|
140 | + $field = $this->buildCommitSelector($project); |
|
141 | + $validator = new DeployForm_CommitValidator(); |
|
142 | + $actions = new FieldList( |
|
143 | + new FormAction('showDeploySummary', 'Plan deployment', 'Show deployment plan'), |
|
144 | + new FormAction('doDeploy', 'Do deploy', 'Do deploy') |
|
145 | + ); |
|
146 | + return array($field, $validator, $actions); |
|
147 | + } |
|
148 | 148 | |
149 | - /** |
|
150 | - * @param DNEnvironment $environment |
|
151 | - * @param DNProject $project |
|
152 | - * |
|
153 | - * @return array |
|
154 | - * @throws Exception |
|
155 | - */ |
|
156 | - protected function setupPipeline(DNEnvironment $environment, DNProject $project) |
|
157 | - { |
|
158 | - // Determine if commits are filtered |
|
159 | - $canBypass = Permission::check(DNRoot::DEPLOYNAUT_BYPASS_PIPELINE); |
|
160 | - $canDryrun = $environment->DryRunEnabled && Permission::check(DNRoot::DEPLOYNAUT_DRYRUN_PIPELINE); |
|
161 | - $commits = $environment->getDependentFilteredCommits(); |
|
162 | - if (empty($commits)) { |
|
163 | - // There are no filtered commits, so show all commits |
|
164 | - $field = $this->buildCommitSelector($project); |
|
165 | - $validator = new DeployForm_CommitValidator(); |
|
166 | - } elseif ($canBypass) { |
|
167 | - // Build hybrid selector that allows users to follow pipeline or use any commit |
|
168 | - $field = $this->buildCommitSelector($project, $commits); |
|
169 | - $validator = new DeployForm_CommitValidator(); |
|
170 | - } else { |
|
171 | - // Restrict user to only select pipeline filtered commits |
|
172 | - $field = $this->buildPipelineField($commits); |
|
173 | - $validator = new DeployForm_PipelineValidator(); |
|
174 | - } |
|
149 | + /** |
|
150 | + * @param DNEnvironment $environment |
|
151 | + * @param DNProject $project |
|
152 | + * |
|
153 | + * @return array |
|
154 | + * @throws Exception |
|
155 | + */ |
|
156 | + protected function setupPipeline(DNEnvironment $environment, DNProject $project) |
|
157 | + { |
|
158 | + // Determine if commits are filtered |
|
159 | + $canBypass = Permission::check(DNRoot::DEPLOYNAUT_BYPASS_PIPELINE); |
|
160 | + $canDryrun = $environment->DryRunEnabled && Permission::check(DNRoot::DEPLOYNAUT_DRYRUN_PIPELINE); |
|
161 | + $commits = $environment->getDependentFilteredCommits(); |
|
162 | + if (empty($commits)) { |
|
163 | + // There are no filtered commits, so show all commits |
|
164 | + $field = $this->buildCommitSelector($project); |
|
165 | + $validator = new DeployForm_CommitValidator(); |
|
166 | + } elseif ($canBypass) { |
|
167 | + // Build hybrid selector that allows users to follow pipeline or use any commit |
|
168 | + $field = $this->buildCommitSelector($project, $commits); |
|
169 | + $validator = new DeployForm_CommitValidator(); |
|
170 | + } else { |
|
171 | + // Restrict user to only select pipeline filtered commits |
|
172 | + $field = $this->buildPipelineField($commits); |
|
173 | + $validator = new DeployForm_PipelineValidator(); |
|
174 | + } |
|
175 | 175 | |
176 | - // Generate actions allowed for this user |
|
177 | - $actions = new FieldList( |
|
178 | - FormAction::create('startPipeline', "Begin the release process on " . $environment->Name) |
|
179 | - ->addExtraClass('btn btn-primary') |
|
180 | - ->setAttribute('onclick', "return confirm('This will begin a release pipeline. Continue?');") |
|
181 | - ); |
|
182 | - if ($canDryrun) { |
|
183 | - $actions->push( |
|
184 | - FormAction::create('doDryRun', "Dry-run release process") |
|
185 | - ->addExtraClass('btn btn-info') |
|
186 | - ->setAttribute( |
|
187 | - 'onclick', |
|
188 | - "return confirm('This will begin a release pipeline, but with the following exclusions:\\n" . |
|
189 | - " - No messages will be sent\\n" . |
|
190 | - " - No capistrano actions will be invoked\\n" . |
|
191 | - " - No deployments or snapshots will be created.');" |
|
192 | - ) |
|
193 | - ); |
|
194 | - } |
|
195 | - if ($canBypass) { |
|
196 | - $actions->push( |
|
197 | - FormAction::create('showDeploySummary', "Direct deployment (bypass pipeline)") |
|
198 | - ->addExtraClass('btn btn-warning') |
|
199 | - ->setAttribute( |
|
200 | - 'onclick', |
|
201 | - "return confirm('This will start a direct deployment, bypassing the pipeline " . |
|
202 | - "process in place.\\n\\nAre you sure this is necessary?');" |
|
203 | - ) |
|
204 | - ); |
|
205 | - return array($field, $validator, $actions); |
|
206 | - } |
|
207 | - return array($field, $validator, $actions); |
|
208 | - } |
|
176 | + // Generate actions allowed for this user |
|
177 | + $actions = new FieldList( |
|
178 | + FormAction::create('startPipeline', "Begin the release process on " . $environment->Name) |
|
179 | + ->addExtraClass('btn btn-primary') |
|
180 | + ->setAttribute('onclick', "return confirm('This will begin a release pipeline. Continue?');") |
|
181 | + ); |
|
182 | + if ($canDryrun) { |
|
183 | + $actions->push( |
|
184 | + FormAction::create('doDryRun', "Dry-run release process") |
|
185 | + ->addExtraClass('btn btn-info') |
|
186 | + ->setAttribute( |
|
187 | + 'onclick', |
|
188 | + "return confirm('This will begin a release pipeline, but with the following exclusions:\\n" . |
|
189 | + " - No messages will be sent\\n" . |
|
190 | + " - No capistrano actions will be invoked\\n" . |
|
191 | + " - No deployments or snapshots will be created.');" |
|
192 | + ) |
|
193 | + ); |
|
194 | + } |
|
195 | + if ($canBypass) { |
|
196 | + $actions->push( |
|
197 | + FormAction::create('showDeploySummary', "Direct deployment (bypass pipeline)") |
|
198 | + ->addExtraClass('btn btn-warning') |
|
199 | + ->setAttribute( |
|
200 | + 'onclick', |
|
201 | + "return confirm('This will start a direct deployment, bypassing the pipeline " . |
|
202 | + "process in place.\\n\\nAre you sure this is necessary?');" |
|
203 | + ) |
|
204 | + ); |
|
205 | + return array($field, $validator, $actions); |
|
206 | + } |
|
207 | + return array($field, $validator, $actions); |
|
208 | + } |
|
209 | 209 | |
210 | - /** |
|
211 | - * Construct fields to select any commit |
|
212 | - * |
|
213 | - * @param DNProject $project |
|
214 | - * @param DataList|null $pipelineCommits Optional list of pipeline-filtered commits to include |
|
215 | - * @return FormField |
|
216 | - */ |
|
217 | - protected function buildCommitSelector($project, $pipelineCommits = null) |
|
218 | - { |
|
219 | - // Branches |
|
220 | - $branches = array(); |
|
221 | - foreach ($project->DNBranchList() as $branch) { |
|
222 | - $sha = $branch->SHA(); |
|
223 | - $name = $branch->Name(); |
|
224 | - $branchValue = sprintf("%s (%s, %s old)", |
|
225 | - $name, |
|
226 | - substr($sha, 0, 8), |
|
227 | - $branch->LastUpdated()->TimeDiff() |
|
228 | - ); |
|
229 | - $branches[$sha . '-' . $name] = $branchValue; |
|
230 | - } |
|
210 | + /** |
|
211 | + * Construct fields to select any commit |
|
212 | + * |
|
213 | + * @param DNProject $project |
|
214 | + * @param DataList|null $pipelineCommits Optional list of pipeline-filtered commits to include |
|
215 | + * @return FormField |
|
216 | + */ |
|
217 | + protected function buildCommitSelector($project, $pipelineCommits = null) |
|
218 | + { |
|
219 | + // Branches |
|
220 | + $branches = array(); |
|
221 | + foreach ($project->DNBranchList() as $branch) { |
|
222 | + $sha = $branch->SHA(); |
|
223 | + $name = $branch->Name(); |
|
224 | + $branchValue = sprintf("%s (%s, %s old)", |
|
225 | + $name, |
|
226 | + substr($sha, 0, 8), |
|
227 | + $branch->LastUpdated()->TimeDiff() |
|
228 | + ); |
|
229 | + $branches[$sha . '-' . $name] = $branchValue; |
|
230 | + } |
|
231 | 231 | |
232 | - // Tags |
|
233 | - $tags = array(); |
|
234 | - foreach ($project->DNTagList()->setLimit(null) as $tag) { |
|
235 | - $sha = $tag->SHA(); |
|
236 | - $name = $tag->Name(); |
|
237 | - $tagValue = sprintf("%s (%s, %s old)", |
|
238 | - $name, |
|
239 | - substr($sha, 0, 8), |
|
240 | - $branch->LastUpdated()->TimeDiff() |
|
241 | - ); |
|
242 | - $tags[$sha . '-' . $tag] = $tagValue; |
|
243 | - } |
|
244 | - $tags = array_reverse($tags); |
|
232 | + // Tags |
|
233 | + $tags = array(); |
|
234 | + foreach ($project->DNTagList()->setLimit(null) as $tag) { |
|
235 | + $sha = $tag->SHA(); |
|
236 | + $name = $tag->Name(); |
|
237 | + $tagValue = sprintf("%s (%s, %s old)", |
|
238 | + $name, |
|
239 | + substr($sha, 0, 8), |
|
240 | + $branch->LastUpdated()->TimeDiff() |
|
241 | + ); |
|
242 | + $tags[$sha . '-' . $tag] = $tagValue; |
|
243 | + } |
|
244 | + $tags = array_reverse($tags); |
|
245 | 245 | |
246 | - // Past deployments |
|
247 | - $redeploy = array(); |
|
248 | - foreach ($project->DNEnvironmentList() as $dnEnvironment) { |
|
249 | - $envName = $dnEnvironment->Name; |
|
250 | - foreach ($dnEnvironment->DeployHistory() as $deploy) { |
|
251 | - $sha = $deploy->SHA; |
|
252 | - if (!isset($redeploy[$envName])) { |
|
253 | - $redeploy[$envName] = array(); |
|
254 | - } |
|
255 | - if (!isset($redeploy[$envName][$sha])) { |
|
256 | - $pastValue = sprintf("%s (deployed %s)", |
|
257 | - substr($sha, 0, 8), |
|
258 | - $deploy->obj('LastEdited')->Ago() |
|
259 | - ); |
|
260 | - $redeploy[$envName][$sha] = $pastValue; |
|
261 | - } |
|
262 | - } |
|
263 | - } |
|
246 | + // Past deployments |
|
247 | + $redeploy = array(); |
|
248 | + foreach ($project->DNEnvironmentList() as $dnEnvironment) { |
|
249 | + $envName = $dnEnvironment->Name; |
|
250 | + foreach ($dnEnvironment->DeployHistory() as $deploy) { |
|
251 | + $sha = $deploy->SHA; |
|
252 | + if (!isset($redeploy[$envName])) { |
|
253 | + $redeploy[$envName] = array(); |
|
254 | + } |
|
255 | + if (!isset($redeploy[$envName][$sha])) { |
|
256 | + $pastValue = sprintf("%s (deployed %s)", |
|
257 | + substr($sha, 0, 8), |
|
258 | + $deploy->obj('LastEdited')->Ago() |
|
259 | + ); |
|
260 | + $redeploy[$envName][$sha] = $pastValue; |
|
261 | + } |
|
262 | + } |
|
263 | + } |
|
264 | 264 | |
265 | - // Merge fields |
|
266 | - $releaseMethods = array(); |
|
267 | - if ($pipelineCommits) { |
|
268 | - $releaseMethods[] = new SelectionGroup_Item( |
|
269 | - 'FilteredCommits', |
|
270 | - $this->buildPipelineField($pipelineCommits), |
|
271 | - 'Deploy a commit prepared for this pipeline' |
|
272 | - ); |
|
273 | - } |
|
274 | - if (!empty($branches)) { |
|
275 | - $releaseMethods[] = new SelectionGroup_Item( |
|
276 | - 'Branch', |
|
277 | - new DropdownField('Branch', 'Select a branch', $branches), |
|
278 | - 'Deploy the latest version of a branch' |
|
279 | - ); |
|
280 | - } |
|
281 | - if ($tags) { |
|
282 | - $releaseMethods[] = new SelectionGroup_Item( |
|
283 | - 'Tag', |
|
284 | - new DropdownField('Tag', 'Select a tag', $tags), |
|
285 | - 'Deploy a tagged release' |
|
286 | - ); |
|
287 | - } |
|
288 | - if ($redeploy) { |
|
289 | - $releaseMethods[] = new SelectionGroup_Item( |
|
290 | - 'Redeploy', |
|
291 | - new GroupedDropdownField('Redeploy', 'Redeploy', $redeploy), |
|
292 | - 'Redeploy a release that was previously deployed (to any environment)' |
|
293 | - ); |
|
294 | - } |
|
265 | + // Merge fields |
|
266 | + $releaseMethods = array(); |
|
267 | + if ($pipelineCommits) { |
|
268 | + $releaseMethods[] = new SelectionGroup_Item( |
|
269 | + 'FilteredCommits', |
|
270 | + $this->buildPipelineField($pipelineCommits), |
|
271 | + 'Deploy a commit prepared for this pipeline' |
|
272 | + ); |
|
273 | + } |
|
274 | + if (!empty($branches)) { |
|
275 | + $releaseMethods[] = new SelectionGroup_Item( |
|
276 | + 'Branch', |
|
277 | + new DropdownField('Branch', 'Select a branch', $branches), |
|
278 | + 'Deploy the latest version of a branch' |
|
279 | + ); |
|
280 | + } |
|
281 | + if ($tags) { |
|
282 | + $releaseMethods[] = new SelectionGroup_Item( |
|
283 | + 'Tag', |
|
284 | + new DropdownField('Tag', 'Select a tag', $tags), |
|
285 | + 'Deploy a tagged release' |
|
286 | + ); |
|
287 | + } |
|
288 | + if ($redeploy) { |
|
289 | + $releaseMethods[] = new SelectionGroup_Item( |
|
290 | + 'Redeploy', |
|
291 | + new GroupedDropdownField('Redeploy', 'Redeploy', $redeploy), |
|
292 | + 'Redeploy a release that was previously deployed (to any environment)' |
|
293 | + ); |
|
294 | + } |
|
295 | 295 | |
296 | - $releaseMethods[] = new SelectionGroup_Item( |
|
297 | - 'SHA', |
|
298 | - new Textfield('SHA', 'Please specify the full SHA'), |
|
299 | - 'Deploy a specific SHA' |
|
300 | - ); |
|
296 | + $releaseMethods[] = new SelectionGroup_Item( |
|
297 | + 'SHA', |
|
298 | + new Textfield('SHA', 'Please specify the full SHA'), |
|
299 | + 'Deploy a specific SHA' |
|
300 | + ); |
|
301 | 301 | |
302 | - $field = new TabbedSelectionGroup('SelectRelease', $releaseMethods); |
|
303 | - $field->setValue(reset($releaseMethods)->getValue()); |
|
304 | - return $field; |
|
305 | - } |
|
302 | + $field = new TabbedSelectionGroup('SelectRelease', $releaseMethods); |
|
303 | + $field->setValue(reset($releaseMethods)->getValue()); |
|
304 | + return $field; |
|
305 | + } |
|
306 | 306 | |
307 | - /** |
|
308 | - * Generate fields necessary to select from a filtered commit list |
|
309 | - * |
|
310 | - * @param DataList $commits List of commits |
|
311 | - * @return FormField |
|
312 | - */ |
|
313 | - protected function buildPipelineField($commits) |
|
314 | - { |
|
315 | - // Get filtered commits |
|
316 | - $filteredCommits = array(); |
|
317 | - foreach ($commits as $commit) { |
|
318 | - $title = sprintf( |
|
319 | - "%s (%s, %s old)", |
|
320 | - $commit->Message, |
|
321 | - substr($commit->SHA, 0, 8), |
|
322 | - $commit->dbObject('Created')->TimeDiff() |
|
323 | - ); |
|
324 | - $filteredCommits[$commit->SHA] = $title; |
|
325 | - } |
|
326 | - if ($filteredCommits) { |
|
327 | - return new DropdownField('FilteredCommits', '', $filteredCommits); |
|
328 | - } else { |
|
329 | - return DropdownField::create('FilteredCommits)', '') |
|
330 | - ->setEmptyString('No deployments available') |
|
331 | - ->performDisabledTransformation(); |
|
332 | - } |
|
333 | - } |
|
307 | + /** |
|
308 | + * Generate fields necessary to select from a filtered commit list |
|
309 | + * |
|
310 | + * @param DataList $commits List of commits |
|
311 | + * @return FormField |
|
312 | + */ |
|
313 | + protected function buildPipelineField($commits) |
|
314 | + { |
|
315 | + // Get filtered commits |
|
316 | + $filteredCommits = array(); |
|
317 | + foreach ($commits as $commit) { |
|
318 | + $title = sprintf( |
|
319 | + "%s (%s, %s old)", |
|
320 | + $commit->Message, |
|
321 | + substr($commit->SHA, 0, 8), |
|
322 | + $commit->dbObject('Created')->TimeDiff() |
|
323 | + ); |
|
324 | + $filteredCommits[$commit->SHA] = $title; |
|
325 | + } |
|
326 | + if ($filteredCommits) { |
|
327 | + return new DropdownField('FilteredCommits', '', $filteredCommits); |
|
328 | + } else { |
|
329 | + return DropdownField::create('FilteredCommits)', '') |
|
330 | + ->setEmptyString('No deployments available') |
|
331 | + ->performDisabledTransformation(); |
|
332 | + } |
|
333 | + } |
|
334 | 334 | |
335 | - /** |
|
336 | - * Get the build selected from the given data |
|
337 | - * |
|
338 | - * @param array $data |
|
339 | - * @return string SHA of selected build |
|
340 | - */ |
|
341 | - public function getSelectedBuild($data) |
|
342 | - { |
|
343 | - if (isset($data['SelectRelease']) && !empty($data[$data['SelectRelease']])) { |
|
344 | - // Filter out the tag/branch name if required |
|
345 | - $array = explode('-', $data[$data['SelectRelease']]); |
|
346 | - return reset($array); |
|
347 | - } |
|
348 | - if (isset($data['FilteredCommits']) && !empty($data['FilteredCommits'])) { |
|
349 | - return $data['FilteredCommits']; |
|
350 | - } |
|
351 | - } |
|
335 | + /** |
|
336 | + * Get the build selected from the given data |
|
337 | + * |
|
338 | + * @param array $data |
|
339 | + * @return string SHA of selected build |
|
340 | + */ |
|
341 | + public function getSelectedBuild($data) |
|
342 | + { |
|
343 | + if (isset($data['SelectRelease']) && !empty($data[$data['SelectRelease']])) { |
|
344 | + // Filter out the tag/branch name if required |
|
345 | + $array = explode('-', $data[$data['SelectRelease']]); |
|
346 | + return reset($array); |
|
347 | + } |
|
348 | + if (isset($data['FilteredCommits']) && !empty($data['FilteredCommits'])) { |
|
349 | + return $data['FilteredCommits']; |
|
350 | + } |
|
351 | + } |
|
352 | 352 | } |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | protected function validateCommit($sha, $field) |
32 | 32 | { |
33 | 33 | // Check selected commit |
34 | - if (empty($sha)) { |
|
34 | + if(empty($sha)) { |
|
35 | 35 | $this->validationError( |
36 | 36 | $field, |
37 | 37 | "No valid release selected", |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | } |
42 | 42 | |
43 | 43 | // Check validity of commit |
44 | - if (!preg_match('/^[a-f0-9]{40}$/', $sha)) { |
|
44 | + if(!preg_match('/^[a-f0-9]{40}$/', $sha)) { |
|
45 | 45 | $this->validationError( |
46 | 46 | $field, |
47 | 47 | "Invalid release SHA: " . Convert::raw2xml($sha), |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | public function php($data) |
67 | 67 | { |
68 | 68 | // Check release method |
69 | - if (empty($data['SelectRelease']) |
|
69 | + if(empty($data['SelectRelease']) |
|
70 | 70 | || !in_array($data['SelectRelease'], array('Tag', 'Branch', 'Redeploy', 'SHA', 'FilteredCommits')) |
71 | 71 | ) { |
72 | 72 | $method = empty($data['SelectRelease']) ? '(blank)' : $data['SelectRelease']; |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | */ |
122 | 122 | public function __construct($controller, $name, DNEnvironment $environment, DNProject $project) |
123 | 123 | { |
124 | - if ($environment->HasPipelineSupport()) { |
|
124 | + if($environment->HasPipelineSupport()) { |
|
125 | 125 | list($field, $validator, $actions) = $this->setupPipeline($environment, $project); |
126 | 126 | } else { |
127 | 127 | list($field, $validator, $actions) = $this->setupSimpleDeploy($project); |
@@ -159,11 +159,11 @@ discard block |
||
159 | 159 | $canBypass = Permission::check(DNRoot::DEPLOYNAUT_BYPASS_PIPELINE); |
160 | 160 | $canDryrun = $environment->DryRunEnabled && Permission::check(DNRoot::DEPLOYNAUT_DRYRUN_PIPELINE); |
161 | 161 | $commits = $environment->getDependentFilteredCommits(); |
162 | - if (empty($commits)) { |
|
162 | + if(empty($commits)) { |
|
163 | 163 | // There are no filtered commits, so show all commits |
164 | 164 | $field = $this->buildCommitSelector($project); |
165 | 165 | $validator = new DeployForm_CommitValidator(); |
166 | - } elseif ($canBypass) { |
|
166 | + } elseif($canBypass) { |
|
167 | 167 | // Build hybrid selector that allows users to follow pipeline or use any commit |
168 | 168 | $field = $this->buildCommitSelector($project, $commits); |
169 | 169 | $validator = new DeployForm_CommitValidator(); |
@@ -179,7 +179,7 @@ discard block |
||
179 | 179 | ->addExtraClass('btn btn-primary') |
180 | 180 | ->setAttribute('onclick', "return confirm('This will begin a release pipeline. Continue?');") |
181 | 181 | ); |
182 | - if ($canDryrun) { |
|
182 | + if($canDryrun) { |
|
183 | 183 | $actions->push( |
184 | 184 | FormAction::create('doDryRun', "Dry-run release process") |
185 | 185 | ->addExtraClass('btn btn-info') |
@@ -192,7 +192,7 @@ discard block |
||
192 | 192 | ) |
193 | 193 | ); |
194 | 194 | } |
195 | - if ($canBypass) { |
|
195 | + if($canBypass) { |
|
196 | 196 | $actions->push( |
197 | 197 | FormAction::create('showDeploySummary', "Direct deployment (bypass pipeline)") |
198 | 198 | ->addExtraClass('btn btn-warning') |
@@ -218,7 +218,7 @@ discard block |
||
218 | 218 | { |
219 | 219 | // Branches |
220 | 220 | $branches = array(); |
221 | - foreach ($project->DNBranchList() as $branch) { |
|
221 | + foreach($project->DNBranchList() as $branch) { |
|
222 | 222 | $sha = $branch->SHA(); |
223 | 223 | $name = $branch->Name(); |
224 | 224 | $branchValue = sprintf("%s (%s, %s old)", |
@@ -231,7 +231,7 @@ discard block |
||
231 | 231 | |
232 | 232 | // Tags |
233 | 233 | $tags = array(); |
234 | - foreach ($project->DNTagList()->setLimit(null) as $tag) { |
|
234 | + foreach($project->DNTagList()->setLimit(null) as $tag) { |
|
235 | 235 | $sha = $tag->SHA(); |
236 | 236 | $name = $tag->Name(); |
237 | 237 | $tagValue = sprintf("%s (%s, %s old)", |
@@ -245,14 +245,14 @@ discard block |
||
245 | 245 | |
246 | 246 | // Past deployments |
247 | 247 | $redeploy = array(); |
248 | - foreach ($project->DNEnvironmentList() as $dnEnvironment) { |
|
248 | + foreach($project->DNEnvironmentList() as $dnEnvironment) { |
|
249 | 249 | $envName = $dnEnvironment->Name; |
250 | - foreach ($dnEnvironment->DeployHistory() as $deploy) { |
|
250 | + foreach($dnEnvironment->DeployHistory() as $deploy) { |
|
251 | 251 | $sha = $deploy->SHA; |
252 | - if (!isset($redeploy[$envName])) { |
|
252 | + if(!isset($redeploy[$envName])) { |
|
253 | 253 | $redeploy[$envName] = array(); |
254 | 254 | } |
255 | - if (!isset($redeploy[$envName][$sha])) { |
|
255 | + if(!isset($redeploy[$envName][$sha])) { |
|
256 | 256 | $pastValue = sprintf("%s (deployed %s)", |
257 | 257 | substr($sha, 0, 8), |
258 | 258 | $deploy->obj('LastEdited')->Ago() |
@@ -264,28 +264,28 @@ discard block |
||
264 | 264 | |
265 | 265 | // Merge fields |
266 | 266 | $releaseMethods = array(); |
267 | - if ($pipelineCommits) { |
|
267 | + if($pipelineCommits) { |
|
268 | 268 | $releaseMethods[] = new SelectionGroup_Item( |
269 | 269 | 'FilteredCommits', |
270 | 270 | $this->buildPipelineField($pipelineCommits), |
271 | 271 | 'Deploy a commit prepared for this pipeline' |
272 | 272 | ); |
273 | 273 | } |
274 | - if (!empty($branches)) { |
|
274 | + if(!empty($branches)) { |
|
275 | 275 | $releaseMethods[] = new SelectionGroup_Item( |
276 | 276 | 'Branch', |
277 | 277 | new DropdownField('Branch', 'Select a branch', $branches), |
278 | 278 | 'Deploy the latest version of a branch' |
279 | 279 | ); |
280 | 280 | } |
281 | - if ($tags) { |
|
281 | + if($tags) { |
|
282 | 282 | $releaseMethods[] = new SelectionGroup_Item( |
283 | 283 | 'Tag', |
284 | 284 | new DropdownField('Tag', 'Select a tag', $tags), |
285 | 285 | 'Deploy a tagged release' |
286 | 286 | ); |
287 | 287 | } |
288 | - if ($redeploy) { |
|
288 | + if($redeploy) { |
|
289 | 289 | $releaseMethods[] = new SelectionGroup_Item( |
290 | 290 | 'Redeploy', |
291 | 291 | new GroupedDropdownField('Redeploy', 'Redeploy', $redeploy), |
@@ -314,7 +314,7 @@ discard block |
||
314 | 314 | { |
315 | 315 | // Get filtered commits |
316 | 316 | $filteredCommits = array(); |
317 | - foreach ($commits as $commit) { |
|
317 | + foreach($commits as $commit) { |
|
318 | 318 | $title = sprintf( |
319 | 319 | "%s (%s, %s old)", |
320 | 320 | $commit->Message, |
@@ -323,7 +323,7 @@ discard block |
||
323 | 323 | ); |
324 | 324 | $filteredCommits[$commit->SHA] = $title; |
325 | 325 | } |
326 | - if ($filteredCommits) { |
|
326 | + if($filteredCommits) { |
|
327 | 327 | return new DropdownField('FilteredCommits', '', $filteredCommits); |
328 | 328 | } else { |
329 | 329 | return DropdownField::create('FilteredCommits)', '') |
@@ -340,12 +340,12 @@ discard block |
||
340 | 340 | */ |
341 | 341 | public function getSelectedBuild($data) |
342 | 342 | { |
343 | - if (isset($data['SelectRelease']) && !empty($data[$data['SelectRelease']])) { |
|
343 | + if(isset($data['SelectRelease']) && !empty($data[$data['SelectRelease']])) { |
|
344 | 344 | // Filter out the tag/branch name if required |
345 | 345 | $array = explode('-', $data[$data['SelectRelease']]); |
346 | 346 | return reset($array); |
347 | 347 | } |
348 | - if (isset($data['FilteredCommits']) && !empty($data['FilteredCommits'])) { |
|
348 | + if(isset($data['FilteredCommits']) && !empty($data['FilteredCommits'])) { |
|
349 | 349 | return $data['FilteredCommits']; |
350 | 350 | } |
351 | 351 | } |
@@ -6,16 +6,14 @@ discard block |
||
6 | 6 | * @package deploynaut |
7 | 7 | * @subpackage control |
8 | 8 | */ |
9 | -abstract class DeployForm_ValidatorBase extends Validator |
|
10 | -{ |
|
9 | +abstract class DeployForm_ValidatorBase extends Validator { |
|
11 | 10 | |
12 | 11 | /** |
13 | 12 | * @param string $fieldName |
14 | 13 | * @param string $message |
15 | 14 | * @param string $messageType |
16 | 15 | */ |
17 | - public function validationError($fieldName, $message, $messageType = '') |
|
18 | - { |
|
16 | + public function validationError($fieldName, $message, $messageType = '') { |
|
19 | 17 | // Just make any error use the form message |
20 | 18 | $this->form->sessionMessage($message, $messageType); |
21 | 19 | parent::validationError($fieldName, $message, $messageType); |
@@ -28,8 +26,7 @@ discard block |
||
28 | 26 | * @param string $field |
29 | 27 | * @return boolean |
30 | 28 | */ |
31 | - protected function validateCommit($sha, $field) |
|
32 | - { |
|
29 | + protected function validateCommit($sha, $field) { |
|
33 | 30 | // Check selected commit |
34 | 31 | if (empty($sha)) { |
35 | 32 | $this->validationError( |
@@ -60,11 +57,9 @@ discard block |
||
60 | 57 | * @package deploynaut |
61 | 58 | * @subpackage control |
62 | 59 | */ |
63 | -class DeployForm_CommitValidator extends DeployForm_ValidatorBase |
|
64 | -{ |
|
60 | +class DeployForm_CommitValidator extends DeployForm_ValidatorBase { |
|
65 | 61 | |
66 | - public function php($data) |
|
67 | - { |
|
62 | + public function php($data) { |
|
68 | 63 | // Check release method |
69 | 64 | if (empty($data['SelectRelease']) |
70 | 65 | || !in_array($data['SelectRelease'], array('Tag', 'Branch', 'Redeploy', 'SHA', 'FilteredCommits')) |
@@ -92,11 +87,9 @@ discard block |
||
92 | 87 | * @package deploynaut |
93 | 88 | * @subpackage control |
94 | 89 | */ |
95 | -class DeployForm_PipelineValidator extends DeployForm_ValidatorBase |
|
96 | -{ |
|
90 | +class DeployForm_PipelineValidator extends DeployForm_ValidatorBase { |
|
97 | 91 | |
98 | - public function php($data) |
|
99 | - { |
|
92 | + public function php($data) { |
|
100 | 93 | return $this->validateCommit( |
101 | 94 | $this->form->getSelectedBuild($data), |
102 | 95 | 'FilteredCommits' |
@@ -110,8 +103,7 @@ discard block |
||
110 | 103 | * @package deploynaut |
111 | 104 | * @subpackage control |
112 | 105 | */ |
113 | -class DeployForm extends Form |
|
114 | -{ |
|
106 | +class DeployForm extends Form { |
|
115 | 107 | |
116 | 108 | /** |
117 | 109 | * @param DNRoot $controller |
@@ -119,8 +111,7 @@ discard block |
||
119 | 111 | * @param DNEnvironment $environment |
120 | 112 | * @param DNProject $project |
121 | 113 | */ |
122 | - public function __construct($controller, $name, DNEnvironment $environment, DNProject $project) |
|
123 | - { |
|
114 | + public function __construct($controller, $name, DNEnvironment $environment, DNProject $project) { |
|
124 | 115 | if ($environment->HasPipelineSupport()) { |
125 | 116 | list($field, $validator, $actions) = $this->setupPipeline($environment, $project); |
126 | 117 | } else { |
@@ -134,8 +125,7 @@ discard block |
||
134 | 125 | * |
135 | 126 | * @return array |
136 | 127 | */ |
137 | - protected function setupSimpleDeploy(DNProject $project) |
|
138 | - { |
|
128 | + protected function setupSimpleDeploy(DNProject $project) { |
|
139 | 129 | // without a pipeline simply allow any commit to be selected |
140 | 130 | $field = $this->buildCommitSelector($project); |
141 | 131 | $validator = new DeployForm_CommitValidator(); |
@@ -153,8 +143,7 @@ discard block |
||
153 | 143 | * @return array |
154 | 144 | * @throws Exception |
155 | 145 | */ |
156 | - protected function setupPipeline(DNEnvironment $environment, DNProject $project) |
|
157 | - { |
|
146 | + protected function setupPipeline(DNEnvironment $environment, DNProject $project) { |
|
158 | 147 | // Determine if commits are filtered |
159 | 148 | $canBypass = Permission::check(DNRoot::DEPLOYNAUT_BYPASS_PIPELINE); |
160 | 149 | $canDryrun = $environment->DryRunEnabled && Permission::check(DNRoot::DEPLOYNAUT_DRYRUN_PIPELINE); |
@@ -214,8 +203,7 @@ discard block |
||
214 | 203 | * @param DataList|null $pipelineCommits Optional list of pipeline-filtered commits to include |
215 | 204 | * @return FormField |
216 | 205 | */ |
217 | - protected function buildCommitSelector($project, $pipelineCommits = null) |
|
218 | - { |
|
206 | + protected function buildCommitSelector($project, $pipelineCommits = null) { |
|
219 | 207 | // Branches |
220 | 208 | $branches = array(); |
221 | 209 | foreach ($project->DNBranchList() as $branch) { |
@@ -310,8 +298,7 @@ discard block |
||
310 | 298 | * @param DataList $commits List of commits |
311 | 299 | * @return FormField |
312 | 300 | */ |
313 | - protected function buildPipelineField($commits) |
|
314 | - { |
|
301 | + protected function buildPipelineField($commits) { |
|
315 | 302 | // Get filtered commits |
316 | 303 | $filteredCommits = array(); |
317 | 304 | foreach ($commits as $commit) { |
@@ -338,8 +325,7 @@ discard block |
||
338 | 325 | * @param array $data |
339 | 326 | * @return string SHA of selected build |
340 | 327 | */ |
341 | - public function getSelectedBuild($data) |
|
342 | - { |
|
328 | + public function getSelectedBuild($data) { |
|
343 | 329 | if (isset($data['SelectRelease']) && !empty($data[$data['SelectRelease']])) { |
344 | 330 | // Filter out the tag/branch name if required |
345 | 331 | $array = explode('-', $data[$data['SelectRelease']]); |
@@ -6,104 +6,104 @@ |
||
6 | 6 | class DeploynautLogFile |
7 | 7 | { |
8 | 8 | |
9 | - protected $logFile; |
|
10 | - |
|
11 | - protected $basePath; |
|
12 | - |
|
13 | - /** |
|
14 | - * @param string $logFile The log filename |
|
15 | - * @param string|null $basePath Base path of where logs reside. Defaults to DEPLOYNAUT_LOG_PATH |
|
16 | - */ |
|
17 | - public function __construct($logFile, $basePath = null) |
|
18 | - { |
|
19 | - $this->logFile = $logFile; |
|
20 | - $this->basePath = $basePath ?: DEPLOYNAUT_LOG_PATH; |
|
21 | - } |
|
22 | - |
|
23 | - /** |
|
24 | - * Set the log filename |
|
25 | - * @param string $filename |
|
26 | - */ |
|
27 | - public function setLogFile($filename) |
|
28 | - { |
|
29 | - $this->logFile = $filename; |
|
30 | - } |
|
31 | - |
|
32 | - /** |
|
33 | - * Set the base path of where logs reside |
|
34 | - * @param string $path |
|
35 | - */ |
|
36 | - public function setBasePath($path) |
|
37 | - { |
|
38 | - $this->basePath = $path; |
|
39 | - } |
|
40 | - |
|
41 | - /** |
|
42 | - * Return the un-sanitised log path. |
|
43 | - * @return string |
|
44 | - */ |
|
45 | - public function getRawFilePath() |
|
46 | - { |
|
47 | - return $this->basePath . '/' . $this->logFile; |
|
48 | - } |
|
49 | - |
|
50 | - /** |
|
51 | - * Get the sanitised log path. |
|
52 | - * @return string |
|
53 | - */ |
|
54 | - public function getSanitisedLogFilePath() |
|
55 | - { |
|
56 | - return $this->basePath . '/' . strtolower(FileNameFilter::create()->filter($this->logFile)); |
|
57 | - } |
|
58 | - |
|
59 | - /** |
|
60 | - * Return log file path, assuming it exists. Returns NULL if nothing found. |
|
61 | - * @return string|null |
|
62 | - */ |
|
63 | - public function getLogFilePath() |
|
64 | - { |
|
65 | - $path = $this->getSanitisedLogFilePath(); |
|
66 | - |
|
67 | - // for backwards compatibility on old logs |
|
68 | - if (!file_exists($path)) { |
|
69 | - $path = $this->getRawFilePath(); |
|
70 | - |
|
71 | - if (!file_exists($path)) { |
|
72 | - return null; |
|
73 | - } |
|
74 | - } |
|
75 | - |
|
76 | - return $path; |
|
77 | - } |
|
78 | - |
|
79 | - /** |
|
80 | - * Write a message line into the log file. |
|
81 | - * @param string $message |
|
82 | - */ |
|
83 | - public function write($message) |
|
84 | - { |
|
85 | - // Make sure we write into the old path for existing logs. New logs use the sanitised file path instead. |
|
86 | - $path = file_exists($this->getRawFilePath()) ? $this->getRawFilePath() : $this->getSanitisedLogFilePath(); |
|
87 | - |
|
88 | - error_log('['.date('Y-m-d H:i:s').'] ' . $message .PHP_EOL, 3, $path); |
|
89 | - @chmod($path, 0666); |
|
90 | - } |
|
91 | - |
|
92 | - /** |
|
93 | - * Does the log file exist? |
|
94 | - * @return bool |
|
95 | - */ |
|
96 | - public function exists() |
|
97 | - { |
|
98 | - return (bool)$this->getLogFilePath(); |
|
99 | - } |
|
100 | - |
|
101 | - /** |
|
102 | - * Return the content of the log file. |
|
103 | - * @return string |
|
104 | - */ |
|
105 | - public function content() |
|
106 | - { |
|
107 | - return $this->exists() ? file_get_contents($this->getLogFilePath()) : 'Log has not been created yet.'; |
|
108 | - } |
|
9 | + protected $logFile; |
|
10 | + |
|
11 | + protected $basePath; |
|
12 | + |
|
13 | + /** |
|
14 | + * @param string $logFile The log filename |
|
15 | + * @param string|null $basePath Base path of where logs reside. Defaults to DEPLOYNAUT_LOG_PATH |
|
16 | + */ |
|
17 | + public function __construct($logFile, $basePath = null) |
|
18 | + { |
|
19 | + $this->logFile = $logFile; |
|
20 | + $this->basePath = $basePath ?: DEPLOYNAUT_LOG_PATH; |
|
21 | + } |
|
22 | + |
|
23 | + /** |
|
24 | + * Set the log filename |
|
25 | + * @param string $filename |
|
26 | + */ |
|
27 | + public function setLogFile($filename) |
|
28 | + { |
|
29 | + $this->logFile = $filename; |
|
30 | + } |
|
31 | + |
|
32 | + /** |
|
33 | + * Set the base path of where logs reside |
|
34 | + * @param string $path |
|
35 | + */ |
|
36 | + public function setBasePath($path) |
|
37 | + { |
|
38 | + $this->basePath = $path; |
|
39 | + } |
|
40 | + |
|
41 | + /** |
|
42 | + * Return the un-sanitised log path. |
|
43 | + * @return string |
|
44 | + */ |
|
45 | + public function getRawFilePath() |
|
46 | + { |
|
47 | + return $this->basePath . '/' . $this->logFile; |
|
48 | + } |
|
49 | + |
|
50 | + /** |
|
51 | + * Get the sanitised log path. |
|
52 | + * @return string |
|
53 | + */ |
|
54 | + public function getSanitisedLogFilePath() |
|
55 | + { |
|
56 | + return $this->basePath . '/' . strtolower(FileNameFilter::create()->filter($this->logFile)); |
|
57 | + } |
|
58 | + |
|
59 | + /** |
|
60 | + * Return log file path, assuming it exists. Returns NULL if nothing found. |
|
61 | + * @return string|null |
|
62 | + */ |
|
63 | + public function getLogFilePath() |
|
64 | + { |
|
65 | + $path = $this->getSanitisedLogFilePath(); |
|
66 | + |
|
67 | + // for backwards compatibility on old logs |
|
68 | + if (!file_exists($path)) { |
|
69 | + $path = $this->getRawFilePath(); |
|
70 | + |
|
71 | + if (!file_exists($path)) { |
|
72 | + return null; |
|
73 | + } |
|
74 | + } |
|
75 | + |
|
76 | + return $path; |
|
77 | + } |
|
78 | + |
|
79 | + /** |
|
80 | + * Write a message line into the log file. |
|
81 | + * @param string $message |
|
82 | + */ |
|
83 | + public function write($message) |
|
84 | + { |
|
85 | + // Make sure we write into the old path for existing logs. New logs use the sanitised file path instead. |
|
86 | + $path = file_exists($this->getRawFilePath()) ? $this->getRawFilePath() : $this->getSanitisedLogFilePath(); |
|
87 | + |
|
88 | + error_log('['.date('Y-m-d H:i:s').'] ' . $message .PHP_EOL, 3, $path); |
|
89 | + @chmod($path, 0666); |
|
90 | + } |
|
91 | + |
|
92 | + /** |
|
93 | + * Does the log file exist? |
|
94 | + * @return bool |
|
95 | + */ |
|
96 | + public function exists() |
|
97 | + { |
|
98 | + return (bool)$this->getLogFilePath(); |
|
99 | + } |
|
100 | + |
|
101 | + /** |
|
102 | + * Return the content of the log file. |
|
103 | + * @return string |
|
104 | + */ |
|
105 | + public function content() |
|
106 | + { |
|
107 | + return $this->exists() ? file_get_contents($this->getLogFilePath()) : 'Log has not been created yet.'; |
|
108 | + } |
|
109 | 109 | } |
@@ -65,10 +65,10 @@ discard block |
||
65 | 65 | $path = $this->getSanitisedLogFilePath(); |
66 | 66 | |
67 | 67 | // for backwards compatibility on old logs |
68 | - if (!file_exists($path)) { |
|
68 | + if(!file_exists($path)) { |
|
69 | 69 | $path = $this->getRawFilePath(); |
70 | 70 | |
71 | - if (!file_exists($path)) { |
|
71 | + if(!file_exists($path)) { |
|
72 | 72 | return null; |
73 | 73 | } |
74 | 74 | } |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | // Make sure we write into the old path for existing logs. New logs use the sanitised file path instead. |
86 | 86 | $path = file_exists($this->getRawFilePath()) ? $this->getRawFilePath() : $this->getSanitisedLogFilePath(); |
87 | 87 | |
88 | - error_log('['.date('Y-m-d H:i:s').'] ' . $message .PHP_EOL, 3, $path); |
|
88 | + error_log('[' . date('Y-m-d H:i:s') . '] ' . $message . PHP_EOL, 3, $path); |
|
89 | 89 | @chmod($path, 0666); |
90 | 90 | } |
91 | 91 |
@@ -3,8 +3,7 @@ discard block |
||
3 | 3 | /** |
4 | 4 | * Simple support class for reading and writing deploynaut job logs |
5 | 5 | */ |
6 | -class DeploynautLogFile |
|
7 | -{ |
|
6 | +class DeploynautLogFile { |
|
8 | 7 | |
9 | 8 | protected $logFile; |
10 | 9 | |
@@ -14,8 +13,7 @@ discard block |
||
14 | 13 | * @param string $logFile The log filename |
15 | 14 | * @param string|null $basePath Base path of where logs reside. Defaults to DEPLOYNAUT_LOG_PATH |
16 | 15 | */ |
17 | - public function __construct($logFile, $basePath = null) |
|
18 | - { |
|
16 | + public function __construct($logFile, $basePath = null) { |
|
19 | 17 | $this->logFile = $logFile; |
20 | 18 | $this->basePath = $basePath ?: DEPLOYNAUT_LOG_PATH; |
21 | 19 | } |
@@ -24,8 +22,7 @@ discard block |
||
24 | 22 | * Set the log filename |
25 | 23 | * @param string $filename |
26 | 24 | */ |
27 | - public function setLogFile($filename) |
|
28 | - { |
|
25 | + public function setLogFile($filename) { |
|
29 | 26 | $this->logFile = $filename; |
30 | 27 | } |
31 | 28 | |
@@ -33,8 +30,7 @@ discard block |
||
33 | 30 | * Set the base path of where logs reside |
34 | 31 | * @param string $path |
35 | 32 | */ |
36 | - public function setBasePath($path) |
|
37 | - { |
|
33 | + public function setBasePath($path) { |
|
38 | 34 | $this->basePath = $path; |
39 | 35 | } |
40 | 36 | |
@@ -42,8 +38,7 @@ discard block |
||
42 | 38 | * Return the un-sanitised log path. |
43 | 39 | * @return string |
44 | 40 | */ |
45 | - public function getRawFilePath() |
|
46 | - { |
|
41 | + public function getRawFilePath() { |
|
47 | 42 | return $this->basePath . '/' . $this->logFile; |
48 | 43 | } |
49 | 44 | |
@@ -51,8 +46,7 @@ discard block |
||
51 | 46 | * Get the sanitised log path. |
52 | 47 | * @return string |
53 | 48 | */ |
54 | - public function getSanitisedLogFilePath() |
|
55 | - { |
|
49 | + public function getSanitisedLogFilePath() { |
|
56 | 50 | return $this->basePath . '/' . strtolower(FileNameFilter::create()->filter($this->logFile)); |
57 | 51 | } |
58 | 52 | |
@@ -60,8 +54,7 @@ discard block |
||
60 | 54 | * Return log file path, assuming it exists. Returns NULL if nothing found. |
61 | 55 | * @return string|null |
62 | 56 | */ |
63 | - public function getLogFilePath() |
|
64 | - { |
|
57 | + public function getLogFilePath() { |
|
65 | 58 | $path = $this->getSanitisedLogFilePath(); |
66 | 59 | |
67 | 60 | // for backwards compatibility on old logs |
@@ -80,8 +73,7 @@ discard block |
||
80 | 73 | * Write a message line into the log file. |
81 | 74 | * @param string $message |
82 | 75 | */ |
83 | - public function write($message) |
|
84 | - { |
|
76 | + public function write($message) { |
|
85 | 77 | // Make sure we write into the old path for existing logs. New logs use the sanitised file path instead. |
86 | 78 | $path = file_exists($this->getRawFilePath()) ? $this->getRawFilePath() : $this->getSanitisedLogFilePath(); |
87 | 79 | |
@@ -93,8 +85,7 @@ discard block |
||
93 | 85 | * Does the log file exist? |
94 | 86 | * @return bool |
95 | 87 | */ |
96 | - public function exists() |
|
97 | - { |
|
88 | + public function exists() { |
|
98 | 89 | return (bool)$this->getLogFilePath(); |
99 | 90 | } |
100 | 91 | |
@@ -102,8 +93,7 @@ discard block |
||
102 | 93 | * Return the content of the log file. |
103 | 94 | * @return string |
104 | 95 | */ |
105 | - public function content() |
|
106 | - { |
|
96 | + public function content() { |
|
107 | 97 | return $this->exists() ? file_get_contents($this->getLogFilePath()) : 'Log has not been created yet.'; |
108 | 98 | } |
109 | 99 | } |