84f7e9c7a128e6ef21e274984957ba58a4d406e6
[civicrm-core.git] / tools / scripts / releaser / releaser_json.php
1 <?php
2 /**
3 * JSON handling functions for use by releaser script.
4 */
5
6
7 /**
8 * Analyze the given json data to find the current stable major version string,
9 * and print that major version string to STDOUT.
10 *
11 * @param string $json JSON string from latest.civicrm.org/versions.json
12 * @return void
13 */
14 function print_current_stable_version($json) {
15 $versions = json_decode($json, TRUE);
16 foreach ($versions as $major_version => $version) {
17 if ($version['status'] == 'stable') {
18 echo $major_version;
19 return;
20 }
21 }
22 }
23
24 /**
25 * Add a new release to the given JSON data,
26 * and print the modified JSON string to STDOUT.
27 *
28 * @param string $json JSON string from latest.civicrm.org/versions.json
29 * @param string $major_version A major version string, e.g. 1.1
30 * @param string $release_properties_json JSON string containing properties
31 * for the new release, as seen in latest.civicrm.org/versions.json
32 * {$major_version:{'releases':[$release_properties_json]}}
33 */
34 function add_release($json, $major_version, $release_properties_json) {
35 $versions = json_decode($json, TRUE);
36 $release_properties = json_decode($release_properties_json, TRUE);
37 if (array_key_exists('security', $release_properties)) {
38 mylog($release_properties, '$release_properties');
39 if ($release_properties['security'] == 'false') {
40 unset($release_properties['security']);
41 }
42 }
43 $versions[$major_version]['releases'][] = $release_properties;
44 echo json_encode($versions);
45 }
46
47 /**
48 * Modify the status for a given major version in the given JSON data,
49 * and print the modified JSON string to STDOUT.
50 *
51 * @param string $json JSON string from latest.civicrm.org/versions.json
52 * @param string $major_version A major version string, e.g. 1.1
53 * @param string $status The correct status for the major version, e.g.,
54 * 'stable', 'eol'
55 */
56 function update_version_status($json, $major_version, $status) {
57 $versions = json_decode($json, TRUE);
58 $versions[$major_version]['status'] = $status;
59 echo json_encode($versions);
60 }