-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #183 from bold-commerce/Q1-472
A merchant should be shown a notification in m2 when there's a new version of the module
- Loading branch information
Showing
24 changed files
with
737 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Bold\Checkout\Block\System\Config\Form\Field; | ||
|
||
use Bold\Checkout\Block\System\Config\Form\Field; | ||
use Bold\Checkout\Model\ModuleInfo\LatestModuleVersionProvider; | ||
use Bold\Checkout\Model\ModuleInfo\ModuleComposerVersionProvider; | ||
use Magento\Backend\Block\Template\Context; | ||
use Magento\Framework\Data\Form\Element\AbstractElement; | ||
|
||
/** | ||
* Module latest available version field. | ||
*/ | ||
class LatestVersion extends Field | ||
{ | ||
protected $unsetScope = true; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $moduleName; | ||
|
||
/** | ||
* @var LatestModuleVersionProvider | ||
*/ | ||
private $latestModuleVersionProvider; | ||
|
||
/** | ||
* @param Context $context | ||
* @param ModuleComposerVersionProvider $moduleVersionProvider | ||
* @param array $data | ||
*/ | ||
public function __construct( | ||
Context $context, | ||
LatestModuleVersionProvider $latestModuleVersionProvider, | ||
string $moduleName = '', | ||
array $data = [] | ||
) { | ||
parent::__construct($context, $data); | ||
$this->moduleName = $moduleName; | ||
$this->latestModuleVersionProvider = $latestModuleVersionProvider; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
protected function _renderValue(AbstractElement $element) | ||
{ | ||
$version = $this->latestModuleVersionProvider->getVersion($this->moduleName); | ||
$element->setText($version); | ||
|
||
return parent::_renderValue($element); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
namespace Bold\Checkout\Cron; | ||
|
||
use Bold\Checkout\Model\Config; | ||
use Bold\Checkout\Model\ModuleInfo\InstalledModulesProvider; | ||
use Magento\Framework\MessageQueue\PublisherInterface; | ||
|
||
/** | ||
* Cron job to check module updates availability. | ||
*/ | ||
class GetLatestModuleVersions | ||
{ | ||
/** | ||
* @var PublisherInterface | ||
*/ | ||
private $publisher; | ||
|
||
/** | ||
* @var InstalledModulesProvider | ||
*/ | ||
private $installedModulesProvider; | ||
|
||
/** | ||
* @var Config | ||
*/ | ||
private $config; | ||
|
||
/** | ||
* @param InstalledModulesProvider $installedModulesProvider | ||
* @param PublisherInterface $publisher | ||
* @param Config $config | ||
*/ | ||
public function __construct( | ||
InstalledModulesProvider $installedModulesProvider, | ||
PublisherInterface $publisher, | ||
Config $config | ||
) { | ||
$this->installedModulesProvider = $installedModulesProvider; | ||
$this->publisher = $publisher; | ||
$this->config = $config; | ||
} | ||
|
||
/** | ||
* Add a queue job. | ||
* | ||
* @return void | ||
*/ | ||
public function execute(): void | ||
{ | ||
if ($this->config->isUpdatesCheckEnabled()) { | ||
$moduleList = array_unique(array_values($this->installedModulesProvider->getModuleList())); | ||
$this->publisher->publish('bold.checkout.module.check', $moduleList); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Bold\Checkout\Model\ModuleInfo; | ||
|
||
use Magento\Framework\App\Cache\TypeListInterface; | ||
use Magento\Framework\App\Config\ScopeConfigInterface; | ||
use Magento\Framework\App\Config\Storage\WriterInterface; | ||
|
||
/** | ||
* Get composer latest module version. | ||
*/ | ||
class Config | ||
{ | ||
private const PATH_MODULE_VERSION = 'checkout/bold_checkout/latest_version_%s'; | ||
|
||
/** | ||
* @var ScopeConfigInterface | ||
*/ | ||
private $scopeConfig; | ||
|
||
/** | ||
* @var WriterInterface | ||
*/ | ||
private $writer; | ||
|
||
/** | ||
* @var TypeListInterface | ||
*/ | ||
private $cacheTypeList; | ||
|
||
/** | ||
* @param ScopeConfigInterface $scopeConfig | ||
* @param WriterInterface $writer | ||
* @param TypeListInterface $cacheTypeList | ||
*/ | ||
public function __construct( | ||
ScopeConfigInterface $scopeConfig, | ||
WriterInterface $writer, | ||
TypeListInterface $cacheTypeList | ||
) { | ||
$this->scopeConfig = $scopeConfig; | ||
$this->writer = $writer; | ||
$this->cacheTypeList = $cacheTypeList; | ||
} | ||
|
||
/** | ||
* Get composer latest module version. | ||
* | ||
* @param string $module | ||
* @return string | ||
*/ | ||
public function getLatestModuleVersion(string $module): string | ||
{ | ||
return $this->scopeConfig->getValue($this->getModuleVersionPath($module)) ?? '0.0.0'; | ||
} | ||
|
||
/** | ||
* Set composer latest module version. | ||
* | ||
* @param string $module | ||
* @param string $version | ||
*/ | ||
public function setLatestModuleVersion(string $module, string $version): void | ||
{ | ||
$this->writer->save($this->getModuleVersionPath($module), $version); | ||
$this->cacheTypeList->cleanType('config'); | ||
$this->scopeConfig->clean(); | ||
} | ||
|
||
/** | ||
* Generate config path for module version data. | ||
* | ||
* @param string $module | ||
* @return string | ||
*/ | ||
private function getModuleVersionPath(string $module): string | ||
{ | ||
return sprintf(self::PATH_MODULE_VERSION, strtolower($module)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Bold\Checkout\Model\ModuleInfo; | ||
|
||
/** | ||
* Get all installed Bold modules. | ||
*/ | ||
class InstalledModulesProvider | ||
{ | ||
/** | ||
* @var array | ||
*/ | ||
private $moduleList; | ||
|
||
/** | ||
* @param array $moduleList | ||
*/ | ||
public function __construct( | ||
array $moduleList = [] | ||
) { | ||
$this->moduleList = $moduleList; | ||
} | ||
|
||
/** | ||
* Get installed modules list. | ||
* | ||
* @return string[] | ||
*/ | ||
public function getModuleList(): array | ||
{ | ||
return $this->moduleList; | ||
} | ||
} |
Oops, something went wrong.