Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NEW Showing framework/CMS version on module report #55

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions css/sitesummary.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
display:block;
}

/* Due to a rule applied to `.cms .ss-gridfield > div` we have to be specific here */
.cms .ss-gridfield > div.site-summary__clearfix {
margin: 0;
clear: both;
}

.gridfield-button-link {
margin-bottom: 12px;
}
42 changes: 42 additions & 0 deletions src/Forms/GridFieldHtmlFragment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

/**
* Facilitates adding arbitrary HTML to grid fields
*
* @package forms
* @subpackage fields-gridfield
*/

class GridFieldHtmlFragment implements GridField_HTMLProvider
{
/**
* Fragment to write the html fragment to.
* @var string
*/
protected $targetFragment;

/**
* An HTML fragment to render
* @var string
*/
protected $htmlFragment;

/**
* @param string $targetFragment Fragment to write the html fragment to.
* @param string $htmlFragment An HTML fragment to render
*/
public function __construct($targetFragment, $htmlFragment)
{
$this->targetFragment = $targetFragment;
$this->htmlFragment = $htmlFragment;
}

/**
* @param GridField $gridField
* @return array
*/
public function getHTMLFragments($gridField)
{
return [$this->targetFragment => $this->htmlFragment];
}
}
68 changes: 48 additions & 20 deletions src/Reports/SiteSummary.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,7 @@ public function title()
return _t(__CLASS__ . '.TITLE', 'Installed modules');
}

public function description()
{
return _t(
__CLASS__ . '.DESCRIPTION',
<<<DESC
Provides information about what SilverStripe modules are installed,
giving an insight to project statistics such as how big the installation is,
what it would take to upgrade it, and what functionality is available
to both editors and users.
DESC
);
}

public function sourceRecords($params)
public function sourceRecords()
{
$packageList = Package::get();
$typeFilters = Config::inst()->get(UpdatePackageInfo::class, 'allowed_types');
Expand Down Expand Up @@ -68,20 +55,61 @@ public function getReportField()
{
Requirements::css('silverstripe-maintenance/css/sitesummary.css');

/** @var GridField $gridField */
$gridField = parent::getReportField();
/** @var GridField $grid */
$grid = parent::getReportField();

$config = $gridField->getConfig();
/** @var GridFieldConfig $config */
$config = $grid->getConfig();

/** @var GridFieldExportButton $exportButton */
$exportButton = $config->getComponentByType(GridFieldExportButton::class);
$exportButton->setExportColumns(Package::create()->summaryFields());

$versionHtml = ArrayData::create([
'Title' => _t(__CLASS__ . '.VERSION', 'Version'),
'Version' => $this->resolveCmsVersion(),
])->renderWith('SiteSummary_VersionHeader');

$config->addComponents(
Injector::inst()->create('GridFieldButtonRow', 'before'),
Injector::inst()->create('GridFieldLinkButton', 'https://addons.silverstripe.org', 'buttons-before-left')
Injector::inst()->create(GridFieldButtonRow::class, 'before'),
Injector::inst()->create(
GridFieldLinkButton::class,
'https://addons.silverstripe.org',
'buttons-before-left'
),
Injector::inst()->create(GridFieldHtmlFragment::class, 'header', $versionHtml)
);

return $gridField;
return $grid;
}

/**
* Extract CMS and Framework version details from the records in the report
*
* @return string
*/
protected function resolveCmsVersion()
{
$versionModules = [
'silverstripe/framework' => 'Framework',
'silverstripe/cms' => 'CMS',
];
$this->extend('updateVersionModules', $versionModules);

$records = $this->sourceRecords()->filter('Name', array_keys($versionModules));
$versionParts = [];

foreach ($versionModules as $name => $label) {
$record = $records->find('Name', $name);
if (!$record) {
$version = _t(__CLASS__.'.VersionUnknown', 'Unknown');
} else {
$version = $record->Version;
}

$versionParts[] = "$label $version";
}

return implode(', ', $versionParts);
}
}
2 changes: 2 additions & 0 deletions templates/SiteSummary_VersionHeader.ss
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<div class="site-summary__clearfix"></div>
<h3>{$Title.XML}: {$Version.XML}</h3>