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);
74 updateFile("sql/test_data_second_domain.mysql", function ($content) use ($newVersion, $oldVersion) {
75 return str_replace($oldVersion, $newVersion, $content);
79 $files = "xml/version.xml sql/civicrm_generated.mysql sql/test_data_second_domain.mysql " . escapeshellarg($phpFile) . ' ' . escapeshellarg($sqlFile);
80 passthru("git add $files");
81 passthru("git commit $files -m " . escapeshellarg("Set version to $newVersion"));
84 /* *********************************************************************** */
85 /* Helper functions */
88 * Update the content of a file.
91 * @param callable $callback
92 * Function(string $originalContent) => string $newContent.
94 function updateFile($file, $callback) {
95 if (!file_exists($file)) {
96 die("File does not exist: $file\n");
98 echo "Update \"$file\"\n";
99 $content = file_get_contents($file);
100 $content = $callback($content);
101 file_put_contents($file, $content);
105 * Initialize a file (if it doesn't already exist).
106 * @param string $file
107 * @param callable $callback
108 * Function() => string $newContent.
110 function initFile($file, $callback) {
111 if (file_exists($file)) {
112 echo "File \"$file\" already exists.\n";
115 echo "Initialize \"$file\"\n";
116 $content = $callback();
117 file_put_contents($file, $content);
123 * Render a pretty string for a major/minor version number.
125 * @param string $version
130 function makeVerName($version) {
131 list ($a, $b) = explode('.', $version);
132 require_once 'CRM/Utils/EnglishNumber.php';
133 return CRM_Utils_EnglishNumber
::toCamelCase($a) . CRM_Utils_EnglishNumber
::toCamelCase($b);
136 function isVersionValid($v) {
137 return $v && preg_match('/^[0-9a-z\.\-]+$/', $v);
143 function fatal($error) {
145 echo "usage: set-version.php <new-version> [--commit|--no-commit]\n";
146 echo " With --commit, any changes will be committed automatically the current git branch.\n";
147 echo " With --no-commit, any changes will be left uncommitted.\n";