Skip to content

Commit

Permalink
Stop hard-coding version information in constants.php
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
flodolo committed Nov 14, 2015
1 parent 4551662 commit b7dbe66
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 44 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ app/config/sources/*.txt
cache/*.cache
cache/lastdataupdate.txt
cache/stats_*.json
cache/version.txt
composer.lock
composer.phar
logs/*.log
Expand Down
13 changes: 9 additions & 4 deletions app/inc/constants.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
<?php

// Bump this constant with each new release
const VERSION = '3.10';

// Constants for the project
define('DATA_ROOT', realpath($server_config['root']) . '/');
define('HG', realpath($server_config['local_hg']) . '/');
Expand All @@ -21,6 +18,14 @@
define('CACHE_PATH', INSTALL_ROOT . 'cache/');
define('APP_SCHEME', isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off' ? 'https://' : 'http://');

if (file_exists(CACHE_PATH . 'version.txt')) {
define('VERSION', file_get_contents(CACHE_PATH . 'version.txt'));
define('BETA_VERSION', strstr(VERSION, 'dev'));
} else {
define('VERSION', 'unknown.dev');
define('BETA_VERSION', true);
}

if (file_exists(CACHE_PATH . 'lastdataupdate.txt')) {
define('CACHE_TIME', time() - filemtime(CACHE_PATH . 'lastdataupdate.txt'));
} else {
Expand All @@ -29,7 +34,7 @@
}

// Special modes for the app
define('DEBUG', strstr(VERSION, 'dev') || isset($_GET['debug']));
define('DEBUG', BETA_VERSION || isset($_GET['debug']));
define('LOCAL_DEV', isset($server_config['dev']) && $server_config['dev']);

// Set perf_check=true in config.ini to log page time generation and memory used while in DEBUG mode
Expand Down
80 changes: 48 additions & 32 deletions app/scripts/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,38 +23,6 @@ function echogreen() {
echo -e "$GREEN$*$NORMAL"
}

# Store current directory path to be able to call this script from anywhere
DIR=$(dirname "$0")
# Convert .ini file in bash variables
eval $(cat $DIR/../config/config.ini | $DIR/ini_to_bash.py)

# Generate sources (gaia versions, supported locales)
echogreen "Generate list of locales and supported Gaia versions"
$DIR/generate_sources $config

# Check if we have sources
echogreen "Checking if Transvision sources are available..."
if ! $(ls $config/sources/*.txt &> /dev/null)
then
echored "CRITICAL ERROR: no sources available, aborting."
echored "Check the value for l10nwebservice in your config.ini"
exit
fi

# Create all bash variables
source $DIR/bash_variables.sh

# Make sure that we have the file structure ($folders is defined in bash_variables.sh)
echogreen "Checking folders..."
for folder in "${folders[@]}"
do
if [ ! -d $folder ]
then
echogreen "Creating folder: $folder"
mkdir -p "$folder"
fi
done

function createSymlinks() {
branches=( trunk aurora beta release )

Expand Down Expand Up @@ -262,6 +230,54 @@ function initGaiaRepo () {
fi
}

# Store current directory path to be able to call this script from anywhere
DIR=$(dirname "$0")
# Convert .ini file in bash variables
eval $(cat $DIR/../config/config.ini | $DIR/ini_to_bash.py)

# Generate sources (gaia versions, supported locales)
echogreen "Generate list of locales and supported Gaia versions"
$DIR/generate_sources $config

# Check if we have sources
echogreen "Checking if Transvision sources are available..."
if ! $(ls $config/sources/*.txt &> /dev/null)
then
echored "CRITICAL ERROR: no sources available, aborting."
echored "Check the value for l10nwebservice in your config.ini"
exit
fi

# Create all bash variables
source $DIR/bash_variables.sh

# Make sure that we have the file structure ($folders is defined in bash_variables.sh)
echogreen "Checking folders..."
for folder in "${folders[@]}"
do
if [ ! -d $folder ]
then
echogreen "Creating folder: $folder"
mkdir -p "$folder"
fi
done

# Store version information in cache
DEV_VERSION="dev"
if [ ! -d ${install}/.git ]
then
CURRENT_TIP="unknown"
else
cd "${install}"
CURRENT_TIP=$(git rev-parse HEAD)
LATEST_TAG=$(git for-each-ref refs/tags --sort='-committerdate' --format='%(objectname)' --count=1)
if [ "${CURRENT_TIP}" = "${LATEST_TAG}" ]
then
DEV_VERSION=""
fi
fi
echo "${CURRENT_TIP:0:7}${DEV_VERSION}" > "${install}/cache/version.txt"

checkoutSilme

initDesktopSourceRepo "central"
Expand Down
10 changes: 2 additions & 8 deletions app/views/templates/base.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,7 @@
</div>
';

if (strpos(VERSION, 'dev') !== false) {
$beta_version = true;
$title_productname = 'Transvision Beta';
} else {
$beta_version = false;
$title_productname = 'Transvision';
}
$title_productname = BETA_VERSION ? 'Transvision Beta' : 'Transvision';

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

0 comments on commit b7dbe66

Please sign in to comment.