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 /* *********************************************************************** */
13 if (php_sapi_name() == 'cli' ||
(is_numeric($_SERVER['argc']) && $_SERVER['argc'] > 0)) {
14 header("HTTP/1.0 404 Not Found");
17 $civicrm_root = dirname(dirname(dirname(__DIR__
)));
20 /* *********************************************************************** */
21 /* Parse inputs -- $oldVersion, $newVersion, $doCommit */
23 $oldVersion = (string) simplexml_load_file("xml/version.xml")->version_no
;
24 if (!isVersionValid($oldVersion)) {
25 fatal("failed to read old version from \"xml/version.xml\"\n");
28 $newVersion = @$argv[1];
29 if (!isVersionValid($newVersion)) {
30 fatal("failed to read new version\n");
41 fatal("Must specify --commit or --no-commit\n");
44 /* *********************************************************************** */
47 echo "Changing version from $oldVersion to $newVersion...\n";
49 $verName = makeVerName($newVersion);
50 $phpFile = initFile("CRM/Upgrade/Incremental/php/{$verName}.php", function () use ($verName) {
53 $camelNumber = $verName;
54 require 'CRM/Upgrade/Incremental/php/Template.php';
56 return ob_get_clean();
59 $sqlFile = initFile("CRM/Upgrade/Incremental/sql/{$newVersion}.mysql.tpl", function () use ($newVersion) {
60 return "{* file to handle db changes in $newVersion during upgrade *}\n";
63 updateFile("xml/version.xml", function ($content) use ($newVersion, $oldVersion) {
64 return str_replace($oldVersion, $newVersion, $content);
67 if (file_exists("civicrm-version.php")) {
68 updateFile("civicrm-version.php", function ($content) use ($newVersion, $oldVersion) {
69 return str_replace($oldVersion, $newVersion, $content);
73 updateFile("sql/civicrm_generated.mysql", function ($content) use ($newVersion, $oldVersion) {
74 return str_replace($oldVersion, $newVersion, $content);
77 updateFile("sql/test_data_second_domain.mysql", function ($content) use ($newVersion, $oldVersion) {
78 return str_replace($oldVersion, $newVersion, $content);
82 $files = "xml/version.xml sql/civicrm_generated.mysql sql/test_data_second_domain.mysql " . escapeshellarg($phpFile) . ' ' . escapeshellarg($sqlFile);
83 passthru("git add $files");
84 passthru("git commit $files -m " . escapeshellarg("Set version to $newVersion"));
87 /* *********************************************************************** */
88 /* Helper functions */
91 * Update the content of a file.
94 * @param callable $callback
95 * Function(string $originalContent) => string $newContent.
97 function updateFile($file, $callback) {
98 if (!file_exists($file)) {
99 die("File does not exist: $file\n");
101 echo "Update \"$file\"\n";
102 $content = file_get_contents($file);
103 $content = $callback($content);
104 file_put_contents($file, $content);
108 * Initialize a file (if it doesn't already exist).
109 * @param string $file
110 * @param callable $callback
111 * Function() => string $newContent.
113 function initFile($file, $callback) {
114 if (file_exists($file)) {
115 echo "File \"$file\" already exists.\n";
118 echo "Initialize \"$file\"\n";
119 $content = $callback();
120 file_put_contents($file, $content);
126 * Render a pretty string for a major/minor version number.
128 * @param string $version
133 function makeVerName($version) {
134 list ($a, $b) = explode('.', $version);
135 require_once 'CRM/Utils/EnglishNumber.php';
136 return CRM_Utils_EnglishNumber
::toCamelCase($a) . CRM_Utils_EnglishNumber
::toCamelCase($b);
139 function isVersionValid($v) {
140 return $v && preg_match('/^[0-9a-z\.\-]+$/', $v);
146 function fatal($error) {
148 echo "usage: set-version.php <new-version> [--commit|--no-commit]\n";
149 echo " With --commit, any changes will be committed automatically the current git branch.\n";
150 echo " With --no-commit, any changes will be left uncommitted.\n";