Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

ENHANCEMENT: If silverstripe_version is empty, attempts to retrieve it from composer.lock file #289

Closed
wants to merge 4 commits into from

2 participants

@purplespider

Is there an issue with this request? Or should I have submitted it to the 3.1 branch? Sorry if something isn't quite right with my contribution etiquette!

@chillu
Owner

It was close :) I've moved it to framework instead, otherwise it won't work in admin/assets etc.
Also made the logic a bit more flexible in terms of module configuration (not duplicating everything for cms and framework). See silverstripe/silverstripe-framework@2b6d735 and 0f8d7a0

@chillu chillu closed this
@purplespider

Thanks Ingo, that makes a lot of sense! How does this update find it's way into 3.1?

@chillu
Owner

We're merging 3.0 into 3.1 frequently

@srizzling srizzling referenced this pull request from a commit in srizzling/silverstripe-behat-extension
@chillu chillu Removed CMSMain->CMSVersion(), using LeftAndMain instead
Implementation got more complex (see silverstripe/silverstripe-cms#289),
including composer.lock file support. So trying to to duplicate too much.
0f8d7a0
@tractorcow tractorcow referenced this pull request from a commit in tractorcow/silverstripe-framework
@chillu chillu Using composer.lock for LeftAndMain->CMSVersion() 2b6d735
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 38 additions and 5 deletions.
  1. +38 −5 code/controllers/CMSMain.php
View
43 code/controllers/CMSMain.php
@@ -1302,20 +1302,53 @@ public function duplicatewithchildren($request) {
/**
* Return the version number of this application.
- * Uses the subversion path information in <mymodule>/silverstripe_version
+ * Uses the number in <mymodule>/silverstripe_version
* (automacially replaced by build scripts).
- *
+ * If silverstripe_version is empty,
+ * then attempts to get it from composer.lock
+ *
* @return string
*/
public function CMSVersion() {
$cmsVersion = file_get_contents(CMS_PATH . '/silverstripe_version');
- if(!$cmsVersion) $cmsVersion = _t('LeftAndMain.VersionUnknown', 'Unknown');
-
$frameworkVersion = file_get_contents(FRAMEWORK_PATH . '/silverstripe_version');
+
+ // Tries to obtain version number from composer.lock if it exists
+ if(!$cmsVersion || !$frameworkVersion) {
+ $composerLockPath = BASE_PATH . '/composer.lock';
+ if (file_exists($composerLockPath)) {
+ $cache = SS_Cache::factory('CMSMain_CMSVersion');
+ $cacheKey = filemtime($composerLockPath);
+ $jsonVersions = $cache->load($cacheKey);
+ if(!$jsonVersions && $jsonData = file_get_contents($composerLockPath)) {
+ if ($lockdata = json_decode($jsonData)) {
+ if (isset($lockdata->packages)) {
+ $arrayVersions = array();
+ foreach ($lockdata->packages as $package) {
+ if ($package->name == "silverstripe/cms" && !$cmsVersion && isset($package->version)) {
+ $arrayVersions['cms'] = $package->version;
+ }
+ if ($package->name == "silverstripe/framework" && !$frameworkVersion && isset($package->version)) {
+ $arrayVersions['framework'] = $package->version;
+ }
+ }
+ $jsonVersions = json_encode($arrayVersions);
+ $cache->save($jsonVersions, $cacheKey);
+ }
+ }
+
+ }
+ $versions = json_decode($jsonVersions);
+ $cmsVersion = $versions->cms;
+ $frameworkVersion = $versions->framework;
+ }
+ }
+
+ if(!$cmsVersion) $cmsVersion = _t('LeftAndMain.VersionUnknown', 'Unknown');
if(!$frameworkVersion) $frameworkVersion = _t('LeftAndMain.VersionUnknown', 'Unknown');
return sprintf(
- "CMS: %s Framework: %s",
+ "CMS: %s, Framework: %s",
$cmsVersion,
$frameworkVersion
);
Something went wrong with that request. Please try again.