4 // Update the data-files within this repo to reflect a new version number.
6 // git checkout origin/master -b master-4.7.29
7 // ./tools/bin/scripts/set-version.php 4.7.29 --commit
8 // git commit -m "Update to version 4.7.29"
9 // git push origin master
11 /* *********************************************************************** */
14 $civicrm_root = dirname(dirname(dirname(__DIR__
)));
17 /* *********************************************************************** */
18 /* Parse inputs -- $oldVersion, $newVersion, $doCommit */
20 $oldVersion = (string) simplexml_load_file("xml/version.xml")->version_no
;
21 if (!isVersionValid($oldVersion)) {
22 fatal("failed to read old version from \"xml/version.xml\"\n");
25 $newVersion = @$argv[1];
26 if (!isVersionValid($newVersion)) {
27 fatal("failed to read new version\n");
38 fatal("Must specify --commit or --no-commit\n");
41 /* *********************************************************************** */
44 echo "Changing version from $oldVersion to $newVersion...\n";
46 $verName = makeVerName($newVersion);
47 $phpFile = initFile("CRM/Upgrade/Incremental/php/{$verName}.php", function () use ($verName) {
50 $camelNumber = $verName;
51 require 'CRM/Upgrade/Incremental/php/Template.php';
53 return ob_get_clean();
56 $sqlFile = initFile("CRM/Upgrade/Incremental/sql/{$newVersion}.mysql.tpl", function () use ($newVersion) {
57 return "{* file to handle db changes in $newVersion during upgrade *}\n";
60 updateFile("xml/version.xml", function ($content) use ($newVersion, $oldVersion) {
61 return str_replace($oldVersion, $newVersion, $content);
64 if (file_exists("civicrm-version.php")) {
65 updateFile("civicrm-version.php", function ($content) use ($newVersion, $oldVersion) {
66 return str_replace($oldVersion, $newVersion, $content);
70 updateFile("sql/civicrm_generated.mysql", function ($content) use ($newVersion, $oldVersion) {
71 return str_replace($oldVersion, $newVersion, $content);
75 $files = "xml/version.xml sql/civicrm_generated.mysql " . escapeshellarg($phpFile) . ' ' . escapeshellarg($sqlFile);
76 passthru("git add $files");
77 passthru("git commit $files -m " . escapeshellarg("Set version to $newVersion"));
80 /* *********************************************************************** */
81 /* Helper functions */
84 * Update the content of a file.
87 * @param callable $callback
88 * Function(string $originalContent) => string $newContent.
90 function updateFile($file, $callback) {
91 if (!file_exists($file)) {
92 die("File does not exist: $file\n");
94 echo "Update \"$file\"\n";
95 $content = file_get_contents($file);
96 $content = $callback($content);
97 file_put_contents($file, $content);
101 * Initialize a file (if it doesn't already exist).
102 * @param string $file
103 * @param callable $callback
104 * Function() => string $newContent.
106 function initFile($file, $callback) {
107 if (file_exists($file)) {
108 echo "File \"$file\" already exists.\n";
111 echo "Initialize \"$file\"\n";
112 $content = $callback();
113 file_put_contents($file, $content);
119 * Render a pretty string for a major/minor version number.
121 * @param string $version
126 function makeVerName($version) {
127 list ($a, $b) = explode('.', $version);
128 require_once 'CRM/Utils/EnglishNumber.php';
129 return CRM_Utils_EnglishNumber
::toCamelCase($a) . CRM_Utils_EnglishNumber
::toCamelCase($b);
132 function isVersionValid($v) {
133 return $v && preg_match('/^[0-9a-z\.\-]+$/', $v);
139 function fatal($error) {
141 echo "usage: set-version.php <new-version> [--commit|--no-commit]\n";
142 echo " With --commit, any changes will be committed automatically the current git branch.\n";
143 echo " With --no-commit, any changes will be left uncommitted.\n";