Skip to content

Commit

Permalink
NEW Get the version for an individual module
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Feb 16, 2022
1 parent 6922549 commit 92cdc6a
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 5 deletions.
19 changes: 16 additions & 3 deletions docs/en/02_Developer_Guides/01_Templates/02_Common_Variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,18 +123,18 @@ on a per-page basis.
If you don’t want to include the title tag use `$MetaTags(false)`.
[/notice]

By default `$MetaTags` renders:
By default `$MetaTags` renders (assuming 4.11.0 is the current version of silverstripe/framework):

```ss
<title>Title of the Page</title>
<meta name="generator" content="SilverStripe - https://www.silverstripe.org">
<meta name="generator" content="Silverstripe CMS 4.11">
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
```

`$MetaTags(false)` will render

```ss
<meta name="generator" content="SilverStripe - https://www.silverstripe.org">
<meta name="generator" content="Silverstripe CMS 4.11">
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
```

Expand All @@ -145,6 +145,19 @@ $MetaTags(false)
<title>$Title - Bob's Fantasy Football</title>
```

### Disabling the meta generator tag

The meta generator tag include the current version of `silverstripe/framework`. This version number
provides aggregate installation numbers to the product team who maintain Silverstripe CMS which is
used to make informed product decisions.

If it's felt this creates a security concern for your website, then the meta generator tag can be configured off via

```yml
SilverStripe\CMS\Model\SiteTree
show_meta_generator: false
```
### Modifying Meta Tags
You can override the `MetaComponents()` method on your `SiteTree` sub-classes or make use of the `MetaComponents` extension point to manipulate the underlying data that is rendered by `$MetaTags`. Example (for `Page` class):
Expand Down
12 changes: 12 additions & 0 deletions docs/en/04_Changelogs/4.11.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,18 @@ In accordance with our [PHP support policy](/Getting_Started/Server_Requirements

## Features and enhancements {#features-and-enhancements}

### Meta generator tag now shows framework version number

The meta generator tag, which can be seen in the meta tags when you view source on a regular page, now includes the framework version truncated to show just the major and minor version, e.g. 4.11.

This version number will provide aggregate installation numbers to the product team who maintain Silverstripe CMS which will be used to make informed product decisions.

If it's felt this creates a security concern for your website, then the meta generator tag can be configured off via

```yml
SilverStripe\CMS\Model\SiteTree
show_meta_generator: false
```
## Bugfixes {#bugfixes}
Expand Down
21 changes: 19 additions & 2 deletions src/Core/Manifest/VersionProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use SilverStripe\Core\Config\Config;
use Psr\SimpleCache\CacheInterface;
use SilverStripe\Core\Config\Configurable;
use SilverStripe\Core\Convert;
use SilverStripe\Core\Injector\Injectable;
use SilverStripe\Core\Injector\Injector;

/**
Expand All @@ -25,8 +25,8 @@
*/
class VersionProvider
{

use Configurable;
use Injectable;

/**
* @var array
Expand Down Expand Up @@ -62,6 +62,23 @@ public function getVersion()
return implode(', ', $ret);
}

/**
* Get the version of a specific module
* Will strip out the leading "module name" from the returned value
*
* @param string $module - e.g. silverstripe/framework
* @return string - e.g. 4.10
*/
public function getModuleVersion(string $module): string
{
$previousModules = $this->getModules();
Config::modify()->set(self::class, 'modules', [$module => 'MODULE_NAME']);
$version = $this->getVersion();
$version = str_replace('MODULE_NAME: ', '', $version);
Config::modify()->set(self::class, 'modules', $previousModules);
return $version;
}

/**
* Filter modules to only use the last module from a git repo, for example
*
Expand Down
14 changes: 14 additions & 0 deletions tests/php/Core/Manifest/VersionProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,4 +188,18 @@ public function testGetModulesFromComposerLock()
$result = $mock->getVersion();
$this->assertStringContainsString('Some Package: 1.2.3', $result);
}

public function testGetModuleVersion()
{
$provider = $this->getMockProvider(__DIR__ . '/fixtures/VersionProviderTest/composer.recipe-core.testlock');
Config::modify()->set(VersionProvider::class, 'modules', [
'silverstripe/framework' => 'Framework',
'silverstripe/recipe-core' => 'Core Recipe'
]);
$this->assertSame('1.2.3', $provider->getModuleVersion('silverstripe/framework'));
// assert that the temporary config changes in getModuleVersion() had no side-effects
$result = $provider->getVersion();
$this->assertStringNotContainsString('Framework: 1.2.3', $result);
$this->assertStringContainsString('Core Recipe: 7.7.7', $result);
}
}

0 comments on commit 92cdc6a

Please sign in to comment.