From fd81208978b5305d90fb0a8335bdbc4c5f72cd58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andre=CC=81=20R?= Date: Sun, 23 Dec 2018 16:03:32 +0100 Subject: [PATCH 01/28] Extract version info on packages if root or branch alias Also add license info. --- .../JsonComposerLockSystemInfoCollector.php | 41 ++++++++++++++++--- SystemInfo/Value/ComposerPackage.php | 35 +++++++++++++++- composer.json | 1 + 3 files changed, 70 insertions(+), 7 deletions(-) diff --git a/SystemInfo/Collector/JsonComposerLockSystemInfoCollector.php b/SystemInfo/Collector/JsonComposerLockSystemInfoCollector.php index cea9e8f3..8bfa8492 100644 --- a/SystemInfo/Collector/JsonComposerLockSystemInfoCollector.php +++ b/SystemInfo/Collector/JsonComposerLockSystemInfoCollector.php @@ -53,23 +53,39 @@ public function collect() } $packages = []; + $rootAliases = []; $lockData = json_decode(file_get_contents($this->lockFile), true); + foreach ($lockData['aliases'] as $alias) { + $rootAliases[$alias['package']] = $alias['alias']; + } + foreach ($lockData['packages'] as $packageData) { - $packages[$packageData['name']] = new Value\ComposerPackage([ + $package = new Value\ComposerPackage([ 'name' => $packageData['name'], - 'version' => $packageData['version'], + 'branch' => $packageData['version'], 'dateTime' => isset($packageData['time']) ? new \DateTime($packageData['time']) : null, 'homepage' => isset($packageData['homepage']) ? $packageData['homepage'] : '', 'reference' => isset($packageData['source']) ? $packageData['source']['reference'] : null, + 'license' => isset($packageData['license'][0]) ? $packageData['license'][0] : null, ]); - if (isset($lockData['stability-flags'][$packageData['name']])) { - $stabilityFlag = (int)$lockData['stability-flags'][$packageData['name']]; + if (isset($lockData['stability-flags'][$package->name])) { + $stabilityFlag = (int)$lockData['stability-flags'][$package->name]; if (isset($this->stabilities[$stabilityFlag])) { - $packages[$packageData['name']]->stability = $this->stabilities[$stabilityFlag]; + $package->stability = $this->stabilities[$stabilityFlag]; } } + + if (isset($rootAliases[$package->name])) { + $package->alias = $rootAliases[$package->name]; + } elseif (isset($packageData['extra']['branch-alias'][$package->branch])) { + $package->alias = $packageData['extra']['branch-alias'][$package->branch]; + } + + self::setNormalizedVersion($package); + + $packages[$packageData['name']] = $package; } ksort($packages, SORT_FLAG_CASE | SORT_STRING); @@ -79,4 +95,19 @@ public function collect() 'minimumStability' => isset($lockData['minimum-stability']) ? $lockData['minimum-stability'] : null, ]); } + + private static function setNormalizedVersion(Value\ComposerPackage $package) + { + $version = $package->alias ? $package->alias : $package->branch; + if ($version[0] === 'v') { + $version = substr($version, 1); + } + + if (strpos($version, 'x-dev')) { + $version = str_replace('-dev', '', $version); + $package->stability = 'dev'; + } + + $package->version = $version; + } } diff --git a/SystemInfo/Value/ComposerPackage.php b/SystemInfo/Value/ComposerPackage.php index 7053acca..2b455c4c 100644 --- a/SystemInfo/Value/ComposerPackage.php +++ b/SystemInfo/Value/ComposerPackage.php @@ -25,14 +25,45 @@ class ComposerPackage extends ValueObject implements SystemInfo public $name; /** - * Version. + * Tag or Branch. * - * Example: v2.7.10 + * Examples: v2.7.10, dev-master + * + * @var string + */ + public $branch; + + /** + * Alias. + * + * Examples: v2.7.x-dev + * + * @var string|null + */ + public $alias = null; + + /** + * Normilized version number. + * + * Uses root-alias or package-aliases if present to try to provide a version number even on branches. + * + * Examples: 2.7.10, 2.8.x * * @var string */ public $version; + /** + * License string. + * + * Only contains the first license on the package, if set. + * + * Examples: 'TTL-2.0', 'GPL-2.0-only' + * + * @var string|null + */ + public $license = null; + /** * Stability. * diff --git a/composer.json b/composer.json index 7bdff7c7..237c499a 100644 --- a/composer.json +++ b/composer.json @@ -10,6 +10,7 @@ } ], "require": { + "php": "^5.6 || ^7.0", "ezsystems/ezpublish-kernel": "~6.7.8 || ~6.13.4 || ^7.0", "ocramius/proxy-manager": "~1.0 || ~2.0", "symfony/proxy-manager-bridge": "^2.8.40 || ^3.4.11", From fe0d4013b08d556fabe8e8571713e6fe3c8100ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andre=CC=81=20R?= Date: Sun, 23 Dec 2018 16:21:47 +0100 Subject: [PATCH 02/28] Keep collected packages info around for reuse --- .../Collector/JsonComposerLockSystemInfoCollector.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/SystemInfo/Collector/JsonComposerLockSystemInfoCollector.php b/SystemInfo/Collector/JsonComposerLockSystemInfoCollector.php index 8bfa8492..b7b69ebd 100644 --- a/SystemInfo/Collector/JsonComposerLockSystemInfoCollector.php +++ b/SystemInfo/Collector/JsonComposerLockSystemInfoCollector.php @@ -34,6 +34,11 @@ class JsonComposerLockSystemInfoCollector implements SystemInfoCollector */ private $lockFile; + /** + * @var Value\ComposerSystemInfo The collected value, cached in case info is collected by other collectors. + */ + private $value; + public function __construct($lockFile) { $this->lockFile = $lockFile; @@ -48,6 +53,10 @@ public function __construct($lockFile) */ public function collect() { + if ($this->value) { + return $this->value; + } + if (!file_exists($this->lockFile)) { throw new Exception\ComposerLockFileNotFoundException($this->lockFile); } @@ -90,7 +99,7 @@ public function collect() ksort($packages, SORT_FLAG_CASE | SORT_STRING); - return new Value\ComposerSystemInfo([ + return $this->value = new Value\ComposerSystemInfo([ 'packages' => $packages, 'minimumStability' => isset($lockData['minimum-stability']) ? $lockData['minimum-stability'] : null, ]); From 84ad6c39dee9c72ca8fce0821675dbc231c3e35a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andre=CC=81=20R?= Date: Fri, 21 Dec 2018 20:30:42 +0100 Subject: [PATCH 03/28] Dashboard and eZ Platform info collector (for now not shown in admin) --- Resources/config/services.yml | 19 ++ .../themes/admin/dashboard/block/ez.html.twig | 100 +++++++++ .../Collector/EzSystemInfoCollector.php | 204 ++++++++++++++++++ .../JsonComposerLockSystemInfoCollector.php | 6 +- SystemInfo/Value/EzSystemInfo.php | 64 ++++++ 5 files changed, 390 insertions(+), 3 deletions(-) create mode 100644 Resources/views/themes/admin/dashboard/block/ez.html.twig create mode 100644 SystemInfo/Collector/EzSystemInfoCollector.php create mode 100644 SystemInfo/Value/EzSystemInfo.php diff --git a/Resources/config/services.yml b/Resources/config/services.yml index 0d276c2c..8175af14 100644 --- a/Resources/config/services.yml +++ b/Resources/config/services.yml @@ -8,6 +8,7 @@ parameters: support_tools.system_info.ezc.wrapper.class: EzSystems\EzSupportToolsBundle\SystemInfo\EzcSystemInfoWrapper support_tools.system_info.collector.composer.lock_file.class: EzSystems\EzSupportToolsBundle\SystemInfo\Collector\JsonComposerLockSystemInfoCollector support_tools.system_info.collector.database.doctrine.class: EzSystems\EzSupportToolsBundle\SystemInfo\Collector\DoctrineDatabaseSystemInfoCollector + support_tools.system_info.collector.system.ez.class: EzSystems\EzSupportToolsBundle\SystemInfo\Collector\EzSystemInfoCollector support_tools.system_info.collector.hardware.ezc.class: EzSystems\EzSupportToolsBundle\SystemInfo\Collector\EzcHardwareSystemInfoCollector support_tools.system_info.collector.php.ezc.class: EzSystems\EzSupportToolsBundle\SystemInfo\Collector\EzcPhpSystemInfoCollector support_tools.system_info.collector.symfony.kernel.config.class: EzSystems\EzSupportToolsBundle\SystemInfo\Collector\ConfigurationSymfonyKernelSystemInfoCollector @@ -34,6 +35,15 @@ services: # SystemInfoCollectors + support_tools.system_info.collector.system.ez: + class: "%support_tools.system_info.collector.system.ez.class%" + arguments: + - "@support_tools.system_info.collector.composer.lock_file" + - "%kernel.debug%" + # Can't tag this before v0.3 (2.5?) as it will blow up in admin UI for missing templates there + # And it does not look like there is anway to add it from this package, so maybe it needs to be made extensible(?) + #tags: [{ name: "support_tools.system_info.collector", identifier: "ez" }] + support_tools.system_info.collector.composer.lock_file: class: "%support_tools.system_info.collector.composer.lock_file.class%" arguments: @@ -77,3 +87,12 @@ services: class: "%support_tools.system_info.output_format.json.class%" tags: - { name: "support_tools.system_info.output_format", format: "json" } + + # Dashboard + ezplatform.adminui.dashboard.ez: + parent: EzSystems\EzPlatformAdminUi\Component\TwigComponent + arguments: + $template: '@@ezdesign/dashboard/block/ez.html.twig' + $parameters: { ez: "@=service('support_tools.system_info.collector.system.ez').collect()" } + tags: + - { name: ezplatform.admin_ui.component, group: 'dashboard-blocks', priority: 200 } diff --git a/Resources/views/themes/admin/dashboard/block/ez.html.twig b/Resources/views/themes/admin/dashboard/block/ez.html.twig new file mode 100644 index 00000000..283c2bdc --- /dev/null +++ b/Resources/views/themes/admin/dashboard/block/ez.html.twig @@ -0,0 +1,100 @@ +{% trans_default_domain 'dashboard' %} + +{# The messages here are on purpose not translated as some (+ additional) are inteded to be retrived from updates.ez.no in the future #} + +{% set badge = "" %} +{% set status %} + {% if not ez.release %} + + {% elseif not ez.debug and ez.stability != 'stable' %} + + {% elseif ez.isTrial %} + {% if ez.isEndOfLife %} + {% set badge = 'Trial' %} + + {% elseif ez.isEndOfMaintenance %} + {% set badge = 'Trial' %} + + {% else %} + {% set badge = 'Trial' %} + + {% endif %} + {% elseif not ez.isEnterpise %} + {# Want to edit these messages? If you are on GPL like any other modications make sure to share your modifcations(/exensions). + But to make sure everyone benefits please consider contributing it to ezsystems/ez-support-tools #} + {% if ez.isEndOfMaintenance %} + {# In the future with retrival of info from updates.ez.no we can detect missing security fixes and make error for that when public #} + {% set badge = 'GPL' %} + + {% else %} + {% set badge = 'GPL' %} + + {% endif %} + {% elseif ez.isEndOfLife %} + {# As we don't yet here know if subscription has expired this is a warning and not a error (subscription expiry on BUL would be a license violation, so similar like on TTL) #} + + {% endif %} +{% endset %} + + + +
+
+

+ {{ ez.name }}  + {{ ez.release }}{% if ez.stability != 'stable' %}{{ ez.release ? '-' : '' }}{{ ez.stability }}{% endif %} + {{ badge|raw }} +

+ + {{ status|raw }} +
diff --git a/SystemInfo/Collector/EzSystemInfoCollector.php b/SystemInfo/Collector/EzSystemInfoCollector.php new file mode 100644 index 00000000..ad4481d3 --- /dev/null +++ b/SystemInfo/Collector/EzSystemInfoCollector.php @@ -0,0 +1,204 @@ + '2017-12-20T23:59:59+00:00', + '2.1' => '2018-03-20T23:59:59+00:00', + '2.2' => '2018-06-20T23:59:59+00:00', + '2.3' => '2018-09-20T23:59:59+00:00', + '2.4' => '2018-12-20T23:59:59+00:00', + '2.5' => '2019-03-20T23:59:59+00:00',// Estimate at time of writing + ]; + + /** + * Dates for when releases are considered end of maintenance. + * + * Open source releases are considered end of life when this date ias 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 + * 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 + */ + const EOM = [ + '2.0' => '2018-03-20T23:59:59+00:00', + '2.1' => '2018-06-20T23:59:59+00:00', + '2.2' => '2018-09-20T23:59:59+00:00', + '2.3' => '2018-12-20T23:59:59+00:00', + '2.4' => '2019-03-20T23:59:59+00:00', + '2.5' => '2022-03-20T23:59:59+00:00',// Estimate at time of writing + ]; + + /** + * Dates for when Enterprise/Commerce installs are considered end of life. + * + * Meaning when they stop reciving security fixes and support. + * + * @see: https://support.ez.no/Public/Service-Life + */ + const EOL = [ + '2.0' => '2018-06-20T23:59:59+00:00', + '2.1' => '2018-09-20T23:59:59+00:00', + '2.2' => '2019-03-20T23:59:59+00:00',// Extended + '2.3' => '2019-03-20T23:59:59+00:00', + '2.4' => '2019-06-20T23:59:59+00:00', + '2.5' => '2023-03-20T23:59:59+00:00',// Estimate at time of writing + ]; + + /** + * Vendors we watch for stability and more. + */ + const PACKAGE_WATCH_REGEX = '/^(doctrine|ezsystems|silversolutions|symfony)\//'; + + /** + * Packages that identifies install as Enterpirse install. + */ + const ENTERPISE_PACKAGES = [ + 'ezsystems/ezplatform-page-builder', + 'ezsystems/flex-workflow', + 'ezsystems/landing-page-fieldtype-bundle' + ]; + + /** + * Packages that identifies install as Commerce install. + */ + const COMMERCE_PACKAGES = [ + 'silversolutions/silver.e-shop' + ]; + + /** + * @var \EzSystems\EzSupportToolsBundle\SystemInfo\Value\ComposerSystemInfo|null + */ + private $composerInfo; + + /** + * @var bool + */ + private $debug; + + public function __construct(JsonComposerLockSystemInfoCollector $composerCollector, $debug = false) + { + try { + $this->composerInfo = $composerCollector->collect(); + } catch (ComposerLockFileNotFoundException $e) { + // do nothing + } + $this->debug = $debug; + } + + /** + * Collects information about the eZ distrobution and version. + * + * @return Value\EzSystemInfo + */ + public function collect() + { + $ez = new EzSystemInfo(['debug' => $this->debug]); + if ($this->composerInfo === null) { + return $ez; + } + + // The most reliable way to get version is from kernel + // future updates should make sure to detect when kernel version selector is wrong compare to other packages + if (isset($this->composerInfo->packages['ezsystems/ezpublish-kernel'])) { + $ez->release = (string)(((float)$this->composerInfo->packages['ezsystems/ezpublish-kernel']->version) -5); + } + + if ($package = $this->getFirstPackage(self::ENTERPISE_PACKAGES)) { + $ez->isEnterpise = true; + $ez->isTrial = $package->license === 'TTL-2.0'; + $ez->name = 'eZ Platform Enterprise'; + } + + if ($package = $this->getFirstPackage(self::COMMERCE_PACKAGES)) { + $ez->isCommerce = true; + $ez->isTrial = $ez->isTrial || $package->license === 'TTL-2.0'; + $ez->name = 'eZ Commerce'; + } + + if (isset(self::EOM[$ez->release])) { + $ez->isEndOfMaintenance = strtotime(self::EOM[$ez->release]) < time(); + } + + if (isset(self::EOL[$ez->release])) { + if (!$ez->isEnterpise) { + $ez->isEndOfLife = $ez->isEndOfMaintenance; + } else { + $ez->isEndOfLife = strtotime(self::EOL[$ez->release]) < time(); + } + } + + $ez->stability = $this->getStability(); + + return $ez; + } + + + private function getStability() + { + $stabilityFlags = array_flip(JsonComposerLockSystemInfoCollector::STABILITIES); + + // Root package stability + $stabilityFlag = $this->composerInfo->minimumStability !== null ? + $stabilityFlags[$this->composerInfo->minimumStability] : + $stabilityFlags['stable']; + + // Check if any of the watche packages has lower stability then root + foreach ($this->composerInfo->packages as $name => $package) { + if (!preg_match(self::PACKAGE_WATCH_REGEX,$name)) { + continue; + } + + if ($package->stability === 'stable' || $package->stability === null ) { + continue; + } + + if ($stabilityFlags[$package->stability] > $stabilityFlag) { + $stabilityFlag = $stabilityFlags[$package->stability]; + } + } + + return JsonComposerLockSystemInfoCollector::STABILITIES[$stabilityFlag]; + } + + private function getFirstPackage($packageNames) + { + foreach ($packageNames as $packageName) { + if (isset($this->composerInfo->packages[$packageName])) { + return $this->composerInfo->packages[$packageName]; + } + } + } +} diff --git a/SystemInfo/Collector/JsonComposerLockSystemInfoCollector.php b/SystemInfo/Collector/JsonComposerLockSystemInfoCollector.php index b7b69ebd..40221e49 100644 --- a/SystemInfo/Collector/JsonComposerLockSystemInfoCollector.php +++ b/SystemInfo/Collector/JsonComposerLockSystemInfoCollector.php @@ -21,7 +21,7 @@ class JsonComposerLockSystemInfoCollector implements SystemInfoCollector * * Needed as long as we don't want to depend on Composer. */ - private $stabilities = [ + CONST STABILITIES = [ 0 => 'stable', 5 => 'RC', 10 => 'beta', @@ -81,8 +81,8 @@ public function collect() if (isset($lockData['stability-flags'][$package->name])) { $stabilityFlag = (int)$lockData['stability-flags'][$package->name]; - if (isset($this->stabilities[$stabilityFlag])) { - $package->stability = $this->stabilities[$stabilityFlag]; + if (isset(self::STABILITIES[$stabilityFlag])) { + $package->stability = self::STABILITIES[$stabilityFlag]; } } diff --git a/SystemInfo/Value/EzSystemInfo.php b/SystemInfo/Value/EzSystemInfo.php new file mode 100644 index 00000000..e8ef182a --- /dev/null +++ b/SystemInfo/Value/EzSystemInfo.php @@ -0,0 +1,64 @@ + Date: Thu, 3 Jan 2019 14:06:37 +0100 Subject: [PATCH 04/28] Update Resources/views/themes/admin/dashboard/block/ez.html.twig Co-Authored-By: andrerom --- Resources/views/themes/admin/dashboard/block/ez.html.twig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Resources/views/themes/admin/dashboard/block/ez.html.twig b/Resources/views/themes/admin/dashboard/block/ez.html.twig index 283c2bdc..772f97cd 100644 --- a/Resources/views/themes/admin/dashboard/block/ez.html.twig +++ b/Resources/views/themes/admin/dashboard/block/ez.html.twig @@ -54,7 +54,7 @@ {% set rand = random(3) %} {% if rand == 0 %} If you are in need of assistance, eZ Services like Consulting - and Training helps you get the most out your install. + and Training help you get the most out your install. {% elseif rand == 1 %} To simplify the work involved in upgrading, eZ Platform Cloud might be a good option. {% elseif rand == 2 %} From 204b3792c0db729ff3113eaf5e01e6b9f18f03c0 Mon Sep 17 00:00:00 2001 From: DominikaK Date: Thu, 3 Jan 2019 14:07:58 +0100 Subject: [PATCH 05/28] Update Resources/views/themes/admin/dashboard/block/ez.html.twig Co-Authored-By: andrerom --- Resources/views/themes/admin/dashboard/block/ez.html.twig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Resources/views/themes/admin/dashboard/block/ez.html.twig b/Resources/views/themes/admin/dashboard/block/ez.html.twig index 772f97cd..35e29aad 100644 --- a/Resources/views/themes/admin/dashboard/block/ez.html.twig +++ b/Resources/views/themes/admin/dashboard/block/ez.html.twig @@ -41,7 +41,7 @@ {% endif %} {% elseif not ez.isEnterpise %} - {# Want to edit these messages? If you are on GPL like any other modications make sure to share your modifcations(/exensions). + {# Want to edit these messages? If you are on GPL like any other modifications make sure to share your modifications(/extensions). But to make sure everyone benefits please consider contributing it to ezsystems/ez-support-tools #} {% if ez.isEndOfMaintenance %} {# In the future with retrival of info from updates.ez.no we can detect missing security fixes and make error for that when public #} From 4f1e78824f899a3c377f4ea4d402aa6ade90f4c1 Mon Sep 17 00:00:00 2001 From: DominikaK Date: Thu, 3 Jan 2019 14:08:10 +0100 Subject: [PATCH 06/28] Update Resources/views/themes/admin/dashboard/block/ez.html.twig Co-Authored-By: andrerom --- Resources/views/themes/admin/dashboard/block/ez.html.twig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Resources/views/themes/admin/dashboard/block/ez.html.twig b/Resources/views/themes/admin/dashboard/block/ez.html.twig index 35e29aad..e956bdb9 100644 --- a/Resources/views/themes/admin/dashboard/block/ez.html.twig +++ b/Resources/views/themes/admin/dashboard/block/ez.html.twig @@ -29,7 +29,7 @@ {% elseif ez.isEndOfMaintenance %} {% set badge = 'Trial' %} {% else %} From f4720893ac098028945e0bde8a17b812f92cb28f Mon Sep 17 00:00:00 2001 From: DominikaK Date: Thu, 3 Jan 2019 14:08:20 +0100 Subject: [PATCH 07/28] Update Resources/views/themes/admin/dashboard/block/ez.html.twig Co-Authored-By: andrerom --- Resources/views/themes/admin/dashboard/block/ez.html.twig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Resources/views/themes/admin/dashboard/block/ez.html.twig b/Resources/views/themes/admin/dashboard/block/ez.html.twig index e956bdb9..2593ac49 100644 --- a/Resources/views/themes/admin/dashboard/block/ez.html.twig +++ b/Resources/views/themes/admin/dashboard/block/ez.html.twig @@ -7,7 +7,7 @@ {% if not ez.release %} {% elseif not ez.debug and ez.stability != 'stable' %}