Adamw has uploaded a new change for review.
https://gerrit.wikimedia.org/r/109437
Change subject: Rework the version stamp code to use the same file as in
production
......................................................................
Rework the version stamp code to use the same file as in production
Change-Id: I4aec03b8378d3f071487e89df8c826c45417416f
---
M .gitignore
M Core/Context.php
M Core/DataStores/StompDataStore.php
M Maintenance/generate-version.sh
4 files changed, 21 insertions(+), 26 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/wikimedia/fundraising/SmashPig
refs/changes/37/109437/1
diff --git a/.gitignore b/.gitignore
index eea3e05..8bcf162 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,5 @@
+.version-stamp
+
# Configuration
composer.phar
config.php
diff --git a/Core/Context.php b/Core/Context.php
index c525271..f954f2a 100644
--- a/Core/Context.php
+++ b/Core/Context.php
@@ -10,6 +10,9 @@
class Context {
protected static $instance;
+ protected $contextId;
+ protected $sourceRevision = 'unknown';
+
public static function init() {
if ( !Context::$instance ) {
Context::$instance = new Context();
@@ -39,13 +42,17 @@
return $old;
}
- protected $contextId;
-
public function __construct( $cid = null ) {
if ( !$cid ) {
$this->contextId = sprintf( 'SPCID-%010d', mt_rand(
10000, pow( 2, 31 ) - 1 ) );
} else {
$this->contextId = $cid;
+ }
+
+ $versionStampPath = __DIR__ . "/../.version-stamp";
+ $versionId = file_get_contents( $versionStampPath );
+ if ( $versionId !== false ) {
+ $this->sourceRevision = trim( $versionId );
}
}
@@ -58,4 +65,8 @@
public function getContextId() {
return $this->contextId;
}
-}
\ No newline at end of file
+
+ public function getSourceRevision() {
+ return $this->sourceRevision;
+ }
+}
diff --git a/Core/DataStores/StompDataStore.php
b/Core/DataStores/StompDataStore.php
index 01e8a66..01786a6 100644
--- a/Core/DataStores/StompDataStore.php
+++ b/Core/DataStores/StompDataStore.php
@@ -110,13 +110,6 @@
);
}
- global $smashpig_version;
- if (isset($smashpig_version)) {
- $version = $smashpig_version;
- } else {
- $version = "unknown";
- }
-
$headers = array(
'persistent' => 'true', // So the message
doesn't disappear when the server restarts
'php-message-class' => $objClass, // Sneakyness! No
parameter can have '-' in it's name so this is safe!
@@ -125,7 +118,7 @@
'source_type' => "listener",
'source_host' => gethostname(),
'source_run_id' => getmypid(),
- 'source_version' => $version,
+ 'source_version' => Context::get()->getSourceRevision(),
'source_enqueued_time' => time(),
);
diff --git a/Maintenance/generate-version.sh b/Maintenance/generate-version.sh
index cecf864..5d25ca3 100755
--- a/Maintenance/generate-version.sh
+++ b/Maintenance/generate-version.sh
@@ -1,21 +1,10 @@
#!/bin/bash
#
-# This script should be run manually before deploying to production. When
-# run with no arguments, it will create a file SmashPig/version.php,
-# if you wish to store the output elsewhere, pass the file path as argument 1.
+# This script can be run manually, to populate the .version-stamp file.
#
-# Also, config.php must require the generated file. If the version is
-# not found at runtime, the string "unknown" will be used instead.
+# If the version is not found at runtime, the string "unknown" is used instead.
-if [ "x$1" == "x" ]; then
- root_dir="$(dirname $0)/.."
- dest="$root_dir/version.php"
-else
- dest="$1"
-fi
+dest="$(dirname $0)/../.version-stamp"
head_rev=$(git rev-parse --verify HEAD)
-cat > $dest <<EOF
-<?php
-\$smashpig_version = "$head_rev";
-EOF
+echo -n "$head_rev" > $dest
--
To view, visit https://gerrit.wikimedia.org/r/109437
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I4aec03b8378d3f071487e89df8c826c45417416f
Gerrit-PatchSet: 1
Gerrit-Project: wikimedia/fundraising/SmashPig
Gerrit-Branch: master
Gerrit-Owner: Adamw <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits