Skip to content

Commit

Permalink
exposed new IbexaSystemInfo properties, code refactoring, nitpicks
Browse files Browse the repository at this point in the history
  • Loading branch information
konradoboza committed Oct 24, 2020
1 parent 9e83427 commit fef7f86
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 69 deletions.
20 changes: 10 additions & 10 deletions src/bundle/Resources/translations/systeminfo.en.xliff
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,15 @@
<target state="new">Has Commerce</target>
<note>key: ibexa.has_commerce</note>
</trans-unit>
<trans-unit id="0dcca35f98d237af5d5430cd3b2388ea75617598" resname="ibexa.is_eom">
<source>Is End of Maintenance</source>
<target state="new">Is End of Maintenance</target>
<note>key: ibexa.is_eom</note>
<trans-unit id="4a9e6f9b28c3203784cb5f01ebe73e67661cc823" resname="ibexa.eom">
<source>End of Maintenance</source>
<target state="new">End of Maintenance</target>
<note>key: ibexa.eom</note>
</trans-unit>
<trans-unit id="c2b139f900c61df24d9fb77a3c639d937372cf10" resname="ibexa.is_eol">
<source>Is End of Life</source>
<target state="new">Is End of Life</target>
<note>key: ibexa.is_eol</note>
<trans-unit id="ed1f723e05fbc74c1c90cfc6f64c2bcda6f4bb9d" resname="ibexa.eol">
<source>End of Life</source>
<target state="new">End of Life</target>
<note>key: ibexa.eol</note>
</trans-unit>
<trans-unit id="804e14084add4426182add3b4a0a710506ef742b" resname="ibexa.is_trial">
<source>Is Trial</source>
Expand Down Expand Up @@ -221,10 +221,10 @@
<target state="new">System Information</target>
<note>key: systeminfo</note>
</trans-unit>
<trans-unit id="7dd1b2ca71037e00112dfe0297383f47c6904c77" resname="tab.name.my_ibexa">
<trans-unit id="7dd1b2ca71037e00112dfe0297383f47c6904c77" resname="tab.name.ibexa">
<source>My Ibexa</source>
<target state="new">My Ibexa</target>
<note>key: tab.name.my_ibexa</note>
<note>key: tab.name.ibexa</note>
</trans-unit>
<trans-unit id="a2a92e9d0e41ea4a14c99ab0f702d5df3ea017c3" resname="tab.name.composer">
<source>Composer</source>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% trans_default_domain "systeminfo" %}

<!-- Tab name: {{ 'tab.name.my_ibexa'|trans|desc('My Ibexa') }} -->
<!-- Tab name: {{ 'tab.name.ibexa'|trans|desc('My Ibexa') }} -->

<section class="ez-fieldgroup">
<h2 class="ez-fieldgroup__name">{{ 'ibexa.product'|trans|desc('Product') }}</h2>
Expand Down Expand Up @@ -32,33 +32,35 @@
</td>
</tr>
<tr class="ez-table__row">
<td class="ez-table__cell">{{ 'ibexa.is_eom'|trans|desc('Is End of Maintenance') }}</td>
<td class="ez-table__cell">{{ 'ibexa.is_trial'|trans|desc('Is Trial') }}</td>
<td class="ez-table__cell">
<svg class="ez-icon ez-icon--small">
<use xlink:href="{{ ez_icon_path((info.isEndOfMaintenance == true) ? 'checkmark' : 'discard') }}"></use>
<use xlink:href="{{ ez_icon_path((info.isTrial == true) ? 'checkmark' : 'discard') }}"></use>
</svg>
</td>
</tr>
<tr class="ez-table__row">
<td class="ez-table__cell">{{ 'ibexa.is_eol'|trans|desc('Is End of Life') }}</td>
<td class="ez-table__cell">{{ 'ibexa.eom'|trans|desc('End of Maintenance') }}*</td>
<td class="ez-table__cell">
<svg class="ez-icon ez-icon--small">
<use xlink:href="{{ ez_icon_path((info.isEndOfLife == true) ? 'checkmark' : 'discard') }}"></use>
</svg>
{{ info.endOfMaintenanceDate is empty ? '' : info.endOfMaintenanceDate|date('F Y') }}
</td>
</tr>
<tr class="ez-table__row">
<td class="ez-table__cell">{{ 'ibexa.is_trial'|trans|desc('Is Trial') }}</td>
<td class="ez-table__cell">{{ 'ibexa.eol'|trans|desc('End of Life') }}*</td>
<td class="ez-table__cell">
<svg class="ez-icon ez-icon--small">
<use xlink:href="{{ ez_icon_path((info.isTrial == true) ? 'checkmark' : 'discard') }}"></use>
</svg>
{{ info.endOfLifeDate is empty ? '' : info.endOfLifeDate|date('F Y') }}
</td>
</tr>
<tr class="ez-table__row">
<td class="ez-table__cell">{{ 'ibexa.stability'|trans|desc('Stability') }}</td>
<td class="ez-table__cell">{{ info.stability }}</td>
</tr>
<tr class="ez-table__row">
<td colspan="2">
<hr/>
* you can read more about Service Life <a target="_blank" href="https://support.ibexa.co/Public/Service-Life">here</a>
</td>
</tr>
</tbody>
</table>
</div>
Expand Down
122 changes: 74 additions & 48 deletions src/bundle/SystemInfo/Collector/IbexaSystemInfoCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,27 @@

use EzSystems\EzPlatformCoreBundle\EzPlatformCoreBundle;
use EzSystems\EzSupportToolsBundle\SystemInfo\Exception\ComposerLockFileNotFoundException;
use EzSystems\EzSupportToolsBundle\SystemInfo\Value\ComposerPackage;
use EzSystems\EzSupportToolsBundle\SystemInfo\Value\IbexaSystemInfo;
use DateTime;

/**
* Collects information about the eZ installation.
* Collects information about the Ibexa installation.
*
* @internal This class will greatly change in the future and should not be used as a api, planned:
* @internal This class will greatly change in the future and should not be used as an API, planned:
* - Get most of this information off updates.ez.no
* - Probably run this as a nightly cronjob to gather summary info
* - Be able to provide warnings to admins when something (config/system setup) is not optimal
* - Be able to give information if important updates are avaiable to install
* - Or be able to tell if install is greatly outdated
* - Be able to give heads up when install is approaching end of life.
* - Be able to give information if important updates are available to the installation
* - Or be able to tell if installation is greatly outdated
* - Be able to give heads up when installation is approaching its End of Life.
*/
class IbexaSystemInfoCollector implements SystemInfoCollector
{
/**
* Estimated release dates for given releases.
*
* Mainly for usage for trail to calculate TTL expiry.
* Mainly for usage for trial to calculate TTL expiry.
*/
const RELEASES = [
'2.5' => '2019-03-29T16:59:59+00:00',
Expand All @@ -37,17 +38,17 @@ class IbexaSystemInfoCollector implements SystemInfoCollector
];

/**
* Dates for when releases are considered end of maintenance.
* Dates for when releases are considered End of Maintenance.
*
* Open source releases are considered end of life when this date ias reached.
* Open source releases are considered End of Life when this date is reached.
*
* @Note: Only enterprise/commerce installs recives fixes for security
* issues before the issues are disclosed. Also be aware the link
* below is covering Enterprise/Commerce releases, lenght of
* @Note: Only Enterprise/Commerce installations receive fixes for security
* issues before the issues are disclosed. Also, be aware the link
* below is covering Enterprise/Commerce releases, length of
* maintenance for LTS releases may not be as long for open source
* releases as it depends on community maintenance efforts.
*
* @see: https://support.ez.no/Public/Service-Life
* @see: https://support.ibexa.co/Public/Service-Life
*/
const EOM = [
'2.5' => '2022-03-29T23:59:59+00:00',
Expand All @@ -57,11 +58,11 @@ class IbexaSystemInfoCollector implements SystemInfoCollector
];

/**
* Dates for when Enterprise/Commerce installs are considered end of life.
* Dates for when Enterprise/Commerce installations are considered End of Life.
*
* Meaning when they stop reciving security fixes and support.
* Meaning, when they stop receiving security fixes and support.
*
* @see: https://support.ez.no/Public/Service-Life
* @see: https://support.ibexa.co/Public/Service-Life
*/
const EOL = [
'2.5' => '2024-03-29T23:59:59+00:00',
Expand All @@ -76,16 +77,16 @@ class IbexaSystemInfoCollector implements SystemInfoCollector
const PACKAGE_WATCH_REGEX = '/^(doctrine|ezsystems|silversolutions|symfony)\//';

/**
* Packages that identifies install as Enterpirse install.
* Packages that identify installation as "Enterprise".
*/
const ENTERPISE_PACKAGES = [
const ENTERPRISE_PACKAGES = [
'ezsystems/ezplatform-page-builder',
'ezsystems/flex-workflow',
'ezsystems/landing-page-fieldtype-bundle',
];

/**
* Packages that identifies install as Commerce install.
* Packages that identify installation as "Commerce".
*/
const COMMERCE_PACKAGES = [
'silversolutions/silver.e-shop',
Expand Down Expand Up @@ -117,63 +118,86 @@ public function __construct(SystemInfoCollector $composerCollector, $debug = fal
}

/**
* Collects information about the Ibexa distrobution and version.
* Collects information about the Ibexa distribution and version.
*
* @return \EzSystems\EzSupportToolsBundle\SystemInfo\Value\IbexaSystemInfo
* @throws \Exception
*/
public function collect()
public function collect(): IbexaSystemInfo
{
$ez = new IbexaSystemInfo(['debug' => $this->debug, 'composerInfo' => $this->composerInfo]);
$ibexa = new IbexaSystemInfo(['debug' => $this->debug, 'composerInfo' => $this->composerInfo]);
if ($this->composerInfo === null) {
return $ez;
return $ibexa;
}

$ez->release = EzPlatformCoreBundle::VERSION;
$ibexa->release = EzPlatformCoreBundle::VERSION;
// try to extract version number, but prepare for unexpected string
[$majorVersion, $minorVersion] = array_pad(explode('.', $ez->release), 2, '');
$eZRelease = "{$majorVersion}.{$minorVersion}";
[$majorVersion, $minorVersion] = array_pad(explode('.', $ibexa->release), 2, '');
$ibexaRelease = "{$majorVersion}.{$minorVersion}";

// In case someone switches from TTL to BUL, make sure we only identify install as Trial if this is present,
// In case someone switches from TTL to BUL, make sure we only identify installation as Trial if this is present,
// as well as TTL packages
$hasTTLComposerRepo = \in_array('https://updates.ez.no/ttl', $this->composerInfo->repositoryUrls);

if ($package = $this->getFirstPackage(self::ENTERPISE_PACKAGES)) {
$ez->isEnterpise = true;
$ez->isTrial = $hasTTLComposerRepo && $package->license === 'TTL-2.0';
$ez->name = 'Ibexa DXP';
if ($package = $this->getFirstPackage(self::ENTERPRISE_PACKAGES)) {
$ibexa->isEnterpise = true;
$ibexa->isTrial = $hasTTLComposerRepo && $package->license === 'TTL-2.0';
$ibexa->name = 'Ibexa DXP';
}

if ($package = $this->getFirstPackage(self::COMMERCE_PACKAGES)) {
$ez->isCommerce = true;
$ez->isTrial = $ez->isTrial || $hasTTLComposerRepo && $package->license === 'TTL-2.0';
$ez->name = 'Ibexa Commerce';
$ibexa->isCommerce = true;
$ibexa->isTrial = $ibexa->isTrial || $hasTTLComposerRepo && $package->license === 'TTL-2.0';
$ibexa->name = 'Ibexa Commerce';
}

if ($ez->isTrial && isset(self::RELEASES[$eZRelease])) {
$months = (new DateTime(self::RELEASES[$eZRelease]))->diff(new DateTime())->m;
$ez->isEndOfMaintenance = $months > 3;
if ($ibexa->isTrial && isset(self::RELEASES[$ibexaRelease])) {
$months = (new DateTime(self::RELEASES[$ibexaRelease]))->diff(new DateTime())->m;
$ibexa->isEndOfMaintenance = $months > 3;
// @todo We need to detect this in a better way, this is temporary until some of the work described in class doc is done.
$ez->isEndOfLife = $months > 6;
$ibexa->isEndOfLife = $months > 6;
} else {
if (isset(self::EOM[$eZRelease])) {
$ez->isEndOfMaintenance = strtotime(self::EOM[$eZRelease]) < time();
if (isset(self::EOM[$ibexaRelease])) {
$ibexa->isEndOfMaintenance = strtotime(self::EOM[$ibexaRelease]) < time();
}

if (isset(self::EOL[$eZRelease])) {
if (!$ez->isEnterpise) {
$ez->isEndOfLife = $ez->isEndOfMaintenance;
if (isset(self::EOL[$ibexaRelease])) {
if (!$ibexa->isEnterpise) {
$ibexa->isEndOfLife = $ibexa->isEndOfMaintenance;
} else {
$ez->isEndOfLife = strtotime(self::EOL[$eZRelease]) < time();
$ibexa->isEndOfLife = strtotime(self::EOL[$ibexaRelease]) < time();
}
}
}

$ez->stability = $this->getStability();
$ibexa->endOfMaintenanceDate = $this->getEOMDate($ibexaRelease);
$ibexa->endOfLifeDate = $this->getEOLDate($ibexaRelease);
$ibexa->stability = $this->getStability();

return $ez;
return $ibexa;
}

private function getStability()
/**
* @throws \Exception
*/
private function getEOMDate(string $ibexaRelease) : ?\DateTime
{
return isset(self::EOM[$ibexaRelease]) ?
new DateTime(self::EOM[$ibexaRelease]) :
null;
}

/**
* @throws \Exception
*/
private function getEOLDate(string $ibexaRelease) : ?\DateTime
{
return isset(self::EOL[$ibexaRelease]) ?
new DateTime(self::EOL[$ibexaRelease]) :
null;
}

private function getStability(): string
{
$stabilityFlags = array_flip(JsonComposerLockSystemInfoCollector::STABILITIES);

Expand All @@ -182,7 +206,7 @@ private function getStability()
$stabilityFlags[$this->composerInfo->minimumStability] :
$stabilityFlags['stable'];

// Check if any of the watche packages has lower stability then root
// Check if any of the watched packages has lower stability than root
foreach ($this->composerInfo->packages as $name => $package) {
if (!preg_match(self::PACKAGE_WATCH_REGEX, $name)) {
continue;
Expand All @@ -200,12 +224,14 @@ private function getStability()
return JsonComposerLockSystemInfoCollector::STABILITIES[$stabilityFlag];
}

private function getFirstPackage($packageNames)
private function getFirstPackage($packageNames): ?ComposerPackage
{
foreach ($packageNames as $packageName) {
if (isset($this->composerInfo->packages[$packageName])) {
return $this->composerInfo->packages[$packageName];
}
}

return null;
}
}
10 changes: 10 additions & 0 deletions src/bundle/SystemInfo/Value/IbexaSystemInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,21 @@ class IbexaSystemInfo extends ValueObject implements SystemInfo
*/
public $isEndOfMaintenance = true;

/**
* @var \DateTime
*/
public $endOfMaintenanceDate;

/**
* @var bool
*/
public $isEndOfLife = true;

/**
* @var \DateTime
*/
public $endOfLifeDate;

/**
* @var bool
*/
Expand Down

0 comments on commit fef7f86

Please sign in to comment.