-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathurl_shortener.php
More file actions
78 lines (66 loc) 路 1.84 KB
/
Copy pathurl_shortener.php
File metadata and controls
78 lines (66 loc) 路 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
namespace Deployer;
tasK('feature:urlshortener', function () {
if (!featureRequested()) {
return;
}
if (!isUrlShortener()) {
return;
}
$symlinkDir = get('deploy_path') . "/current/" . get('web_path');
runExtended("cd " . get('deploy_path_url_shortener') . " && ln -sf $symlinkDir " . get('feature'));
})
->select('type=feature-branch-deployment')
->desc('Add the feature branch symlink for the shortened url')
->once()
;
/**
* Check if the url shortener function is activated
*
* @return bool
*/
function isUrlShortener(): bool
{
return (has('feature_url_shortener') && get('feature_url_shortener'));
}
/**
* Initialize the url shortener function and adjust deploy_path & public_urls
* @param ?string $feature
* @return void
* @throws \Deployer\Exception\Exception
*/
function initUrlShortener(?string $feature = null): void
{
if (!isUrlShortener()) {
return;
}
debug('Adjust host configuration because of url shortener function');
set('deploy_path_url_shortener', get('deploy_path'));
set('deploy_path', get('deploy_path') . '/' . get('feature_url_shortener_path') . $feature);
$publicUrls = [];
foreach (get('public_urls') as $publicUrl) {
$publicUrls[] = rtrim($publicUrl, '/') . '/' . $feature . '/';
}
set('public_urls', $publicUrls);
}
/**
* @param $feature
* @return string
*/
function getUrlShortenerPath($feature): string
{
return get('deploy_path_url_shortener') . "/$feature";
}
/**
* Remove the url shortener symlink to the feature branch instance
*
* @param $feature
* @return void
* @throws \Deployer\Exception\Exception
* @throws \Deployer\Exception\RunException
* @throws \Deployer\Exception\TimeoutException
*/
function removeUrlShortenerPath($feature): void
{
runExtended("rm -f " . getUrlShortenerPath($feature));
}