This repository was archived by the owner on Apr 17, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpake_helpers.php
76 lines (66 loc) · 1.96 KB
/
pake_helpers.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
/*
* Compose helper functions.
*
* @package Compose
* @author Ben Constable <ben@benconstable.co.uk>
* @version 1.0
*/
/*
* Get a property from the loaded properties file.
*
* @param string $key Property name
* @return mixed Property value or null
*/
function get_prop($key)
{
$props = pakeApp::get_instance()->get_properties();
return $props[$key];
}
/*
* Get the correct environment from the command line arguments.
* This is a very simple wrapper, but the code is used frequently.
*
* @param &array $args Pake command line arguments
*/
function get_environment(&$args)
{
return count($args) > 0 ? $args[0] : "staging";
}
/*
* Get an array containing the names and dates of all versions for
* an environment.
*
* @param &array $args Command line arguments
* @return array Array of version details, or null if none are found
* Each version is an array with following data:
* name => full version folder name
* date => DateTime object, containing the version date
*/
function get_versions(&$args)
{
$env = get_environment($args);
$ssh = get_prop("ssh");
$site = get_prop("site");
$remote_root = get_prop("remote_sites_root");
pake_echo_action("versions", "getting current versions in '$env' environment for $site");
$version_list = pake_sh("ssh $ssh ls $remote_root/$site/$env/.versions/");
if ($version_list !== "") {
$version_names = explode("\n", trim($version_list));
$versions = array();
date_default_timezone_set("Europe/London");
foreach ($version_names as $name) {
$versions[] = array(
"name" => $name,
"date" => new DateTime(substr(strstr($name, "~"), 1))
);
}
pake_echo_comment("Found " . count($versions) . " versions");
return $versions;
}
else {
pake_echo_error("No versions found");
return null;
}
}
?>