Toward CRM-15762: Handle status changes for older versions; and fix bug updating...
[civicrm-core.git] / tools / scripts / releaser / releaser_json.php
index d1915ce5a4d2987d4748da32729e8b2e43e78e13..dff8019bb5e1d309aa652250527a54d944ec65c7 100644 (file)
@@ -5,18 +5,28 @@
 
 
 /**
- * Analyze the given json data to find the current stable major version string,
- * and print that major version string to STDOUT.
+ * Analyze the given json data to find the latest major version which a) has the
+ * given status, and b) is older than the given major version, and print that
+ * major version string to STDOUT.
  *
  * @param string $json JSON string from latest.civicrm.org/versions.json
+ * @param string $status A status to search for, e.g., 'stable', 'lts'
+ * @param string $compare_version A version string, which must be newer than
+ *  any matching version string.
+ *
  * @return void
  */
-function print_current_stable_version($json) {
+function print_previous_status_version($json, $status, $compare_version) {
   $versions = json_decode($json, TRUE);
-  foreach ($versions as $major_version => $version) {
-    if ($version['status'] == 'stable') {
-      echo $major_version;
-      return;
+  $major_versions = array_keys($versions);
+  usort($major_versions, 'version_compare');
+  $sorted_major_versions = array_reverse($major_versions);
+  foreach ($sorted_major_versions as $major_version) {
+    if (version_compare($major_version, $compare_version) == -1) {
+      if ($versions[$major_version]['status'] == $status) {
+        echo $major_version;
+        return;
+      }
     }
   }
 }
@@ -30,6 +40,8 @@ function print_current_stable_version($json) {
  * @param string $release_properties_json JSON string containing properties
  *  for the new release, as seen in latest.civicrm.org/versions.json
  *  {$major_version:{'releases':[$release_properties_json]}}
+ *
+ * @return Void
  */
 function add_release($json, $major_version, $release_properties_json) {
   $versions = json_decode($json, TRUE);
@@ -51,6 +63,8 @@ function add_release($json, $major_version, $release_properties_json) {
  * @param string $major_version A major version string, e.g. 1.1
  * @param string $status The correct status for the major version, e.g.,
  *  'stable', 'eol'
+ *
+ * @return Void
  */
 function update_version_status($json, $major_version, $status) {
   $versions = json_decode($json, TRUE);