Skip to content

12893-License-check-for-unavailable-version+better-error-displaying #54

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
30 changes: 27 additions & 3 deletions Block/Adminhtml/Linv.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,38 @@ public function __construct(
*/
public function getItems()
{
$path = '/g'.'en'.'er'.'al'.'/l'.'in'.'v';
$condition = '=';
$value = 1;

return $this->fetchConfigData($path, $condition, $value);
}

/**
* @return array
*/
public function getMessages() {
$path = '/g'.'en'.'er'.'al'.'/l'.'in'.'v'.'me'.'ss'.'ag'.'e';
$condition = '!=';
$value = '';

return $this->fetchConfigData($path, $condition, $value);
}

/**
* @param string $path
* @param string $condition
* @param $value
* @return array
*/
private function fetchConfigData(string $path, string $condition, $value) {
$connection = $this->resource->getConnection();
$table = $this->resource->getTableName('core_config_data');
$path = '/g'.'en'.'er'.'al'.'/l'.'in'.'v';

$select = $connection->select()
->from([$table])
->where( 'path LIKE ?', '%' . $path )
->where('value = ?',1);
->where('value ' . $condition . ' ?', $value);
$items = $connection->fetchAll($select);
$result = [];

Expand All @@ -66,7 +91,6 @@ public function getItems()
if ($module && !$section->isEnabled()) {
$result[] = $module;
}

}
return $result;
}
Expand Down
13 changes: 13 additions & 0 deletions Model/Section.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,19 @@ final public function validate($data)
return false;
}

/**
* @param $data
* @return false|string
*/
final public function getErrorMessage($data)
{
if (isset($data[$this->getModule(). '_errorMsg'])) {
return (string)$data[$this->getModule(). '_errorMsg'];
}

return false;
}

/**
* @param string $id
* @param string $k
Expand Down
18 changes: 14 additions & 4 deletions Model/Section/Info.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Magento\Framework\App\ProductMetadataInterface;
use Magento\Store\Model\StoreManagerInterface;
use Magento\Framework\HTTP\Client\Curl;
use Magefan\Community\Model\GetModuleVersion;

/**
* Class Section Info
Expand All @@ -31,21 +32,28 @@ final class Info
*/
private $curl;

/**
* @var GetModuleVersion
*/
private $modelModuleVersion;

/**
* Info constructor.
* @param ProductMetadataInterface $metadata
* @param StoreManagerInterface $storeManager
* @param Curl $curl
* @param array $data
* @param GetModuleVersion $modelModuleVersion
*/
final public function __construct(
ProductMetadataInterface $metadata,
StoreManagerInterface $storeManager,
Curl $curl
Curl $curl,
GetModuleVersion $modelModuleVersion
) {
$this->metadata = $metadata;
$this->storeManager = $storeManager;
$this->curl = $curl;
$this->modelModuleVersion = $modelModuleVersion;
}

/**
Expand Down Expand Up @@ -84,9 +92,11 @@ private function getSectionsParam(array $sections)
{
$result = [];
foreach ($sections as $section) {
$result[$section->getModule()] = [
$module = $section->getModule();
$result[$module] = [
'key' => $section->getKey(),
'section' => $section->getName()
'section' => $section->getName(),
'version' => $this->modelModuleVersion->execute('Magefan_' . $module)
];
}
return $result;
Expand Down
11 changes: 11 additions & 0 deletions Model/SetLinvFlag.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,15 @@ public function execute($module, $value)
$this->configWriter->save($module . '/g'.'en'.'er'.'al'.'/l'.'in'.'v', $value, ScopeConfigInterface::SCOPE_TYPE_DEFAULT, 0);
$this->cacheTypeList->cleanType(Config::TYPE_IDENTIFIER);
}

/**
* @param $module
* @param $message
* @return void
*/
public function addMessage($module, $message)
{
$this->configWriter->save($module . '/g'.'en'.'er'.'al'.'/l'.'in'.'v'.'me'.'ss'.'ag'.'e', $message, ScopeConfigInterface::SCOPE_TYPE_DEFAULT, 0);
$this->cacheTypeList->cleanType(Config::TYPE_IDENTIFIER);
}
}
15 changes: 11 additions & 4 deletions Observer/ConfigObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,24 +106,31 @@ final public function execute(\Magento\Framework\Event\Observer $observer)
}
$module = $section->getName();
$data = $this->info->load([$section]);
$errorMessage = $section->getErrorMessage($data);

if (!$section->validate($data)) {
$groups['general']['fields']['enabled']['value'] = 0;
$this->setLinvFlag->execute($module, 1);
$request->setPostValue('groups', $groups);

$this->messageManager->addError(
implode(array_reverse(
if ($errorMessage) {
$this->setLinvFlag->addMessage($module, $errorMessage);
$this->messageManager->addError($errorMessage);
} else {
$message = implode(array_reverse(
[
'.','d','e','l','b','a','s','i','d',' ','y','l','l','a','c','i','t','a','m',
'o','t','u','a',' ','n','e','e','b',' ','s','a','h',' ','n','o','i','s','n',
'e','t','x','e',' ','e','h','T',' ','.','d','i','l','a','v','n','i',' ','r',
'o',' ','y','t','p','m','e',' ','s','i',' ','y','e','K',' ','t','c','u','d',
'o','r','P'
]
))
);
));
$this->setLinvFlag->addMessage($module, $message);
$this->messageManager->addError($message);
}
} else {
$this->setLinvFlag->addMessage($module, '');
$this->setLinvFlag->execute($module, 0);
}
}
Expand Down
12 changes: 11 additions & 1 deletion view/adminhtml/templates/linv.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@
*
* @var $block \Magefan\Community\Block\Adminhtml\Linv
*/
$items = $block->getItems();
$messages = $block->getMessages();
?>
<?php if ($items = $block->getItems()) { ?>

<div class="messages">
<div class="message message-notice notice" style="margin: 20px 3rem;">
<div class="message message-notice notice" style="margin: 20px 3rem;">+
<div data-ui-id="messages-message-notice" class="linv">
<?= 'Important! So' . 'me ' . 'Mag'.'efan'.' Ex'.'tensions'.' a'.'re'.' dis'.'abl'.'ed d'.'ue '.'to i'.'nva'.'lid'.' Product K'.'ey: ' ?>
<div style="margin-left: 30px">
Expand All @@ -30,6 +32,14 @@
<?= 'Ple' . 'ase che' . 'ck exten' . 'sions config' . 'uration' ?>.
</div>
</div>
<?php foreach ($messages as $key => $message) { ?>
<div class="message message-notice notice" style="margin: 20px 3rem;">+
<div data-ui-id="messages-message-notice" class="linv">
<?= 'Important!' . 'Mag'.'efan'.' Ex'.'tension '. $block->escapeHtml($result = preg_replace('/([A-Z])/', ' $1', $name)) .' a'.'re'.' dis'.'abl'.'ed' ?>
<?= $message ?>
</div>
</div>
<?php } ?>
</div>

<?php } ?>