init
This commit is contained in:
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
|
||||
namespace WeltPixel\Backend\Helper;
|
||||
|
||||
use Magento\Framework\App\ProductMetadataInterface;
|
||||
use Magento\Cron\Model\ScheduleFactory;
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.TooManyFields)
|
||||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
||||
*/
|
||||
class Developer extends \Magento\Framework\App\Helper\AbstractHelper
|
||||
{
|
||||
|
||||
/**
|
||||
* @var ProductMetadataInterface
|
||||
*/
|
||||
protected $productMetaData;
|
||||
|
||||
/**
|
||||
* @var ScheduleFactory
|
||||
*/
|
||||
protected $scheduleFactory;
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\Stdlib\DateTime\DateTime
|
||||
*/
|
||||
protected $dateTime;
|
||||
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param \Magento\Framework\App\Helper\Context $context
|
||||
* @param ProductMetadataInterface $productMetadata
|
||||
* @param ScheduleFactory $scheduleFactory
|
||||
* @param \Magento\Framework\Stdlib\DateTime\DateTime $datetime
|
||||
*/
|
||||
public function __construct(
|
||||
\Magento\Framework\App\Helper\Context $context,
|
||||
ProductMetadataInterface $productMetadata,
|
||||
ScheduleFactory $scheduleFactory,
|
||||
\Magento\Framework\Stdlib\DateTime\DateTime $datetime
|
||||
)
|
||||
{
|
||||
parent::__construct($context);
|
||||
$this->productMetaData = $productMetadata;
|
||||
$this->scheduleFactory = $scheduleFactory;
|
||||
$this->dateTime = $datetime;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getCurrentServerUser()
|
||||
{
|
||||
return get_current_user();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getCurrentServerUserGroup()
|
||||
{
|
||||
if (function_exists('posix_getegid')) {
|
||||
$groupid = posix_getegid();
|
||||
$groupinfo = posix_getgrgid($groupid);
|
||||
|
||||
if (is_array($groupinfo)) {
|
||||
return $groupinfo['name'];
|
||||
}
|
||||
}
|
||||
|
||||
return '-';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getMagentoEdition()
|
||||
{
|
||||
return $this->productMetaData->getEdition() . ' ( ' . $this->productMetaData->getVersion() . ' )';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $pageSize
|
||||
* @return \Magento\Cron\Model\ResourceModel\Schedule\Collection mixed
|
||||
*/
|
||||
public function getLatestCronJobs($pageSize)
|
||||
{
|
||||
$scheduleCollection = $this->scheduleFactory->create()->getCollection();
|
||||
$scheduleCollection->setOrder('schedule_id', 'DESC')
|
||||
->setPageSize($pageSize);
|
||||
|
||||
return $scheduleCollection;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getServerTime()
|
||||
{
|
||||
return $this->dateTime->gmtDate();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,175 @@
|
||||
<?php
|
||||
|
||||
namespace WeltPixel\Backend\Helper;
|
||||
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.TooManyFields)
|
||||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
||||
*/
|
||||
class License extends \Magento\Framework\App\Helper\AbstractHelper
|
||||
{
|
||||
|
||||
/** @var \WeltPixel\Backend\Model\License */
|
||||
protected $license;
|
||||
|
||||
/**
|
||||
* @var \WeltPixel\Backend\Model\LicenseFactory
|
||||
*/
|
||||
protected $licenseFactory;
|
||||
|
||||
/**
|
||||
* @var \Magento\Backend\Model\UrlInterface
|
||||
*/
|
||||
protected $backendUrl;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param \Magento\Framework\App\Helper\Context $context
|
||||
* @param \WeltPixel\Backend\Model\License $license
|
||||
* @param \WeltPixel\Backend\Model\LicenseFactory $licenseFactory ,
|
||||
* @param \Magento\Backend\Model\UrlInterface $backendUrl
|
||||
*/
|
||||
public function __construct(
|
||||
\Magento\Framework\App\Helper\Context $context,
|
||||
\WeltPixel\Backend\Model\License $license,
|
||||
\WeltPixel\Backend\Model\LicenseFactory $licenseFactory,
|
||||
\Magento\Backend\Model\UrlInterface $backendUrl
|
||||
)
|
||||
{
|
||||
parent::__construct($context);
|
||||
$this->license = $license;
|
||||
$this->licenseFactory = $licenseFactory;
|
||||
$this->backendUrl = $backendUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getMdsL()
|
||||
{
|
||||
return $this->license->getMdsL();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getModulesListForDisplay()
|
||||
{
|
||||
$modulesList = $this->getMdsL();
|
||||
foreach ($modulesList as $key => $options) {
|
||||
if (version_compare($options['version'], \WeltPixel\Backend\Model\License::LICENSE_VERSION) < 0) {
|
||||
unset($modulesList[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
return $modulesList;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $license
|
||||
* @param $module
|
||||
* @return bool
|
||||
*/
|
||||
public function isLcVd($license, $module)
|
||||
{
|
||||
return $this->license->isLcVd($license, $module);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param array $licenseOptions
|
||||
* @param array $userFriendlyNames
|
||||
* @param bool $usePrefix
|
||||
* @return string
|
||||
*/
|
||||
public function getLicenseErrorMessage($licenseOptions, $userFriendlyNames, $usePrefix = true)
|
||||
{
|
||||
$moduleName = isset($userFriendlyNames[$licenseOptions['module_name']]) ? $userFriendlyNames[$licenseOptions['module_name']] : $licenseOptions['module_name'];
|
||||
$msgPrefix = '';
|
||||
if ($usePrefix) {
|
||||
$msgPrefix = '<b>' . $moduleName . '</b>' . ' => ';
|
||||
}
|
||||
$defaultMsg = 'This license key is invalid, please add a valid license key. If you believe this is a mistake contact us at <a href="mailto:support@weltpixel.com">support@weltpixel.com</a>';
|
||||
|
||||
$license = $licenseOptions['license'];
|
||||
$licenseDetails = $this->license->getLicenseDetails($license);
|
||||
if (count($licenseDetails) != 5) return $msgPrefix . $defaultMsg;
|
||||
|
||||
$licenseModuleName = isset($userFriendlyNames[$licenseDetails[1]]) ? $userFriendlyNames[$licenseDetails[1]] : $licenseDetails[1];
|
||||
if ($licenseDetails['1'] != $licenseOptions['module_name']) {
|
||||
return $msgPrefix . 'Current license is for ' . $licenseModuleName . ' and is being used on a ' . $moduleName . ' installation.';
|
||||
}
|
||||
$magentoVersion = $this->license->getMagentoVersion();
|
||||
$magentoParsedVersion = $magentoVersion;
|
||||
if ($magentoVersion != "\x63\x6f\x6d\x6d\x75\x6e\x69\x74\x79") {
|
||||
$magentoParsedVersion = "\x65\x6e\x74\x65\x72\x70\x72\x69\x73\x65";
|
||||
}
|
||||
if (($magentoParsedVersion != $licenseDetails[3]) && ($magentoVersion != "community")) {
|
||||
return $msgPrefix . 'Current license is for ' . $licenseDetails[3] . ' and it not valid when used on ' . $magentoVersion;
|
||||
}
|
||||
$domain = $this->license->getMagentoDomain();
|
||||
$isDomainValid = $this->license->checkDomainValidity($domain, $licenseDetails[2]);
|
||||
if (!$isDomainValid) {
|
||||
return $msgPrefix . 'Your license domain ' . $licenseDetails[2] . ' does not match current domain ' . $domain;
|
||||
}
|
||||
|
||||
return $msgPrefix . $defaultMsg;
|
||||
}
|
||||
|
||||
/**
|
||||
* @TODO might need to check and remove if some modules were meanwhile disabled
|
||||
* @return void
|
||||
*/
|
||||
public function checkAndUpdate()
|
||||
{
|
||||
$modules = $this->getMdsL();
|
||||
foreach ($modules as $name => $options) {
|
||||
$license = $this->licenseFactory->create();
|
||||
try {
|
||||
$license->load($name, 'module_name');
|
||||
|
||||
$license->setModuleName($name);
|
||||
$license->setLicenseKey($options['license']);
|
||||
$license->save();
|
||||
} catch (\Exception $ex) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function updMdsInf()
|
||||
{
|
||||
$this->license->updMdsInf();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool|string
|
||||
*/
|
||||
public function getLicenseMessage()
|
||||
{
|
||||
if ($this->_request->isAjax()) {
|
||||
return false;
|
||||
}
|
||||
$messages = [];
|
||||
$modules = $this->getModulesListForDisplay();
|
||||
|
||||
$userFriendlyNames = $this->license->getUserFriendlyModuleNames();
|
||||
foreach ($modules as $name => $options) {
|
||||
if (!$this->isLcVd($options['license'], $options['module_name'])) {
|
||||
$invalidReasonMsg = $this->getLicenseErrorMessage($options, $userFriendlyNames);
|
||||
|
||||
$messages[] = $invalidReasonMsg;
|
||||
}
|
||||
}
|
||||
|
||||
if (count($messages)) {
|
||||
$moduleList = implode('<br/>', $messages);
|
||||
return __('License missing or invalid for the following WeltPixel module(s):') . '<br/>' . $moduleList . '<br/><br/>' .
|
||||
__('You can enter the license key(s)') . ' ' . '<a href="' . $this->backendUrl->getUrl('weltpixel_backend/licenses/index') . '">'
|
||||
. __('here.') . '</a><br/>' . __('License key can be found under My Downloadable Products section of your weltpixel.com account.');
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
|
||||
namespace WeltPixel\Backend\Helper;
|
||||
|
||||
use Magento\Framework\View\Design\Theme\ThemeProviderInterface;
|
||||
use \Magento\Store\Api\StoreRepositoryInterface;
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.TooManyFields)
|
||||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
||||
*/
|
||||
class Utility extends \Magento\Framework\App\Helper\AbstractHelper
|
||||
{
|
||||
|
||||
/** @var ThemeProviderInterface */
|
||||
protected $themeProvider;
|
||||
|
||||
/** @var StoreRepositoryInterface */
|
||||
protected $storeRepository;
|
||||
|
||||
/** @var array */
|
||||
protected $storeThemesLocales = [];
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param \Magento\Framework\App\Helper\Context $context
|
||||
* @param ThemeProviderInterface $themeProvider
|
||||
* @param StoreRepositoryInterface $storeRepository
|
||||
*/
|
||||
public function __construct(
|
||||
\Magento\Framework\App\Helper\Context $context,
|
||||
ThemeProviderInterface $themeProvider,
|
||||
StoreRepositoryInterface $storeRepository
|
||||
)
|
||||
{
|
||||
parent::__construct($context);
|
||||
$this->themeProvider = $themeProvider;
|
||||
$this->storeRepository = $storeRepository;
|
||||
}
|
||||
|
||||
public function isPearlThemeUsed($storeCode = null)
|
||||
{
|
||||
$themeId = $this->scopeConfig->getValue(
|
||||
\Magento\Framework\View\DesignInterface::XML_PATH_THEME_ID,
|
||||
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
|
||||
$storeCode
|
||||
);
|
||||
|
||||
$theme = $this->themeProvider->getThemeById($themeId);
|
||||
$isPearlTheme = $this->_validatePearlTheme($theme);
|
||||
return $isPearlTheme;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Magento\Theme\Model\Theme $theme
|
||||
* @return bool
|
||||
*/
|
||||
protected function _validatePearlTheme($theme)
|
||||
{
|
||||
$pearlThemePath = 'Pearl/weltpixel';
|
||||
do {
|
||||
if ($theme->getThemePath() == $pearlThemePath) {
|
||||
return true;
|
||||
}
|
||||
$theme = $theme->getParentTheme();
|
||||
} while ($theme);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getStoreThemesLocales() {
|
||||
if (count($this->storeThemesLocales)) {
|
||||
return $this->storeThemesLocales;
|
||||
}
|
||||
|
||||
$stores = $this->storeRepository->getList();
|
||||
$result = [];
|
||||
foreach ($stores as $store) {
|
||||
$storeId = $store["store_id"];
|
||||
if (!$storeId) continue;
|
||||
$storeCode = $store["code"];
|
||||
$themeId = $this->scopeConfig->getValue(
|
||||
\Magento\Framework\View\DesignInterface::XML_PATH_THEME_ID,
|
||||
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
|
||||
$storeCode
|
||||
);
|
||||
|
||||
$locale = $this->scopeConfig->getValue(
|
||||
\Magento\Directory\Helper\Data::XML_PATH_DEFAULT_LOCALE,
|
||||
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
|
||||
$storeCode
|
||||
);
|
||||
|
||||
$theme = $this->themeProvider->getThemeById($themeId);
|
||||
$result[$theme->getThemePath().'/'.$locale] = $storeCode;
|
||||
}
|
||||
|
||||
$this->storeThemesLocales = $result;
|
||||
return $this->storeThemesLocales;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user