Skip to content

Commit b7dbe66

Browse files
committed
Stop hard-coding version information in constants.php
* setup.sh: Move main thread code after function declarations * setup.sh: Store version information in cache * constants.php: Use cached information to determine BETA vs PROD version, update base.php template
1 parent 4551662 commit b7dbe66

File tree

4 files changed

+60
-44
lines changed

4 files changed

+60
-44
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ app/config/sources/*.txt
55
cache/*.cache
66
cache/lastdataupdate.txt
77
cache/stats_*.json
8+
cache/version.txt
89
composer.lock
910
composer.phar
1011
logs/*.log

app/inc/constants.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
<?php
22

3-
// Bump this constant with each new release
4-
const VERSION = '3.10';
5-
63
// Constants for the project
74
define('DATA_ROOT', realpath($server_config['root']) . '/');
85
define('HG', realpath($server_config['local_hg']) . '/');
@@ -21,6 +18,14 @@
2118
define('CACHE_PATH', INSTALL_ROOT . 'cache/');
2219
define('APP_SCHEME', isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off' ? 'https://' : 'http://');
2320

21+
if (file_exists(CACHE_PATH . 'version.txt')) {
22+
define('VERSION', file_get_contents(CACHE_PATH . 'version.txt'));
23+
define('BETA_VERSION', strstr(VERSION, 'dev'));
24+
} else {
25+
define('VERSION', 'unknown.dev');
26+
define('BETA_VERSION', true);
27+
}
28+
2429
if (file_exists(CACHE_PATH . 'lastdataupdate.txt')) {
2530
define('CACHE_TIME', time() - filemtime(CACHE_PATH . 'lastdataupdate.txt'));
2631
} else {
@@ -29,7 +34,7 @@
2934
}
3035

3136
// Special modes for the app
32-
define('DEBUG', strstr(VERSION, 'dev') || isset($_GET['debug']));
37+
define('DEBUG', BETA_VERSION || isset($_GET['debug']));
3338
define('LOCAL_DEV', isset($server_config['dev']) && $server_config['dev']);
3439

3540
// Set perf_check=true in config.ini to log page time generation and memory used while in DEBUG mode

app/scripts/setup.sh

Lines changed: 48 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -23,38 +23,6 @@ function echogreen() {
2323
echo -e "$GREEN$*$NORMAL"
2424
}
2525

26-
# Store current directory path to be able to call this script from anywhere
27-
DIR=$(dirname "$0")
28-
# Convert .ini file in bash variables
29-
eval $(cat $DIR/../config/config.ini | $DIR/ini_to_bash.py)
30-
31-
# Generate sources (gaia versions, supported locales)
32-
echogreen "Generate list of locales and supported Gaia versions"
33-
$DIR/generate_sources $config
34-
35-
# Check if we have sources
36-
echogreen "Checking if Transvision sources are available..."
37-
if ! $(ls $config/sources/*.txt &> /dev/null)
38-
then
39-
echored "CRITICAL ERROR: no sources available, aborting."
40-
echored "Check the value for l10nwebservice in your config.ini"
41-
exit
42-
fi
43-
44-
# Create all bash variables
45-
source $DIR/bash_variables.sh
46-
47-
# Make sure that we have the file structure ($folders is defined in bash_variables.sh)
48-
echogreen "Checking folders..."
49-
for folder in "${folders[@]}"
50-
do
51-
if [ ! -d $folder ]
52-
then
53-
echogreen "Creating folder: $folder"
54-
mkdir -p "$folder"
55-
fi
56-
done
57-
5826
function createSymlinks() {
5927
branches=( trunk aurora beta release )
6028

@@ -262,6 +230,54 @@ function initGaiaRepo () {
262230
fi
263231
}
264232

233+
# Store current directory path to be able to call this script from anywhere
234+
DIR=$(dirname "$0")
235+
# Convert .ini file in bash variables
236+
eval $(cat $DIR/../config/config.ini | $DIR/ini_to_bash.py)
237+
238+
# Generate sources (gaia versions, supported locales)
239+
echogreen "Generate list of locales and supported Gaia versions"
240+
$DIR/generate_sources $config
241+
242+
# Check if we have sources
243+
echogreen "Checking if Transvision sources are available..."
244+
if ! $(ls $config/sources/*.txt &> /dev/null)
245+
then
246+
echored "CRITICAL ERROR: no sources available, aborting."
247+
echored "Check the value for l10nwebservice in your config.ini"
248+
exit
249+
fi
250+
251+
# Create all bash variables
252+
source $DIR/bash_variables.sh
253+
254+
# Make sure that we have the file structure ($folders is defined in bash_variables.sh)
255+
echogreen "Checking folders..."
256+
for folder in "${folders[@]}"
257+
do
258+
if [ ! -d $folder ]
259+
then
260+
echogreen "Creating folder: $folder"
261+
mkdir -p "$folder"
262+
fi
263+
done
264+
265+
# Store version information in cache
266+
DEV_VERSION="dev"
267+
if [ ! -d ${install}/.git ]
268+
then
269+
CURRENT_TIP="unknown"
270+
else
271+
cd "${install}"
272+
CURRENT_TIP=$(git rev-parse HEAD)
273+
LATEST_TAG=$(git for-each-ref refs/tags --sort='-committerdate' --format='%(objectname)' --count=1)
274+
if [ "${CURRENT_TIP}" = "${LATEST_TAG}" ]
275+
then
276+
DEV_VERSION=""
277+
fi
278+
fi
279+
echo "${CURRENT_TIP:0:7}${DEV_VERSION}" > "${install}/cache/version.txt"
280+
265281
checkoutSilme
266282

267283
initDesktopSourceRepo "central"

app/views/templates/base.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,7 @@
5555
</div>
5656
';
5757

58-
if (strpos(VERSION, 'dev') !== false) {
59-
$beta_version = true;
60-
$title_productname = 'Transvision Beta';
61-
} else {
62-
$beta_version = false;
63-
$title_productname = 'Transvision';
64-
}
58+
$title_productname = BETA_VERSION ? 'Transvision Beta' : 'Transvision';
6559

6660
if (file_exists(CACHE_PATH . 'lastdataupdate.txt')) {
6761
$last_update = "<p>Data last updated: " .
@@ -96,7 +90,7 @@
9690
<a href="" class="menu-button" id="links-top-button" title="Hide Transvision Menu"><span>menu</span></a>
9791
</div>
9892
<?php
99-
if ($beta_version) {
93+
if (BETA_VERSION) {
10094
print "<div id='beta-badge'><span>BETA VERSION</span></div>\n";
10195
}
10296
?>

0 commit comments

Comments
 (0)