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 "Updating from $oldVersion to $newVersion...\n";
46 updateFile("xml/version.xml", function ($content) use ($newVersion, $oldVersion) {
47 return str_replace($oldVersion, $newVersion, $content);
50 updateFile("sql/civicrm_generated.mysql", function ($content) use ($newVersion, $oldVersion) {
51 return str_replace($oldVersion, $newVersion, $content);
54 $sqlFile = "CRM/Upgrade/Incremental/sql/{$newVersion}.mysql.tpl";
55 if (!file_exists($sqlFile)) {
56 echo "Create \"$sqlFile\"\n";
57 file_put_contents($sqlFile, "{* file to handle db changes in $newVersion during upgrade *}\n");
61 $files = "xml/version.xml sql/civicrm_generated.mysql " . escapeshellarg($sqlFile);
62 passthru("git add $files");
63 passthru("git commit $files -m " . escapeshellarg("Set version to $newVersion"));
66 /* *********************************************************************** */
67 /* Helper functions */
69 function updateFile($file, $callback) {
70 if (!file_exists($file)) {
71 die("File does not exist: $file\n");
73 echo "Update \"$file\"\n";
74 $content = file_get_contents($file);
75 $content = $callback($content);
76 file_put_contents($file, $content);
79 function isVersionValid($v) {
80 return $v && preg_match('/^[0-9a-z\.\-]+$/', $v);
86 function fatal($error) {
88 echo "usage: set-version.php <new-version> [--commit|--no-commit]\n";
89 echo " With --commit, any changes will be committed automatically the current git branch.\n";
90 echo " With --no-commit, any changes will be left uncommitted.\n";