init
This commit is contained in:
+136
@@ -0,0 +1,136 @@
|
||||
<?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;
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\Component\ComponentRegistrarInterface
|
||||
*/
|
||||
protected $componentRegistrar;
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\Filesystem\Directory\ReadFactory
|
||||
*/
|
||||
protected $readFactory;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param \Magento\Framework\App\Helper\Context $context
|
||||
* @param ProductMetadataInterface $productMetadata
|
||||
* @param ScheduleFactory $scheduleFactory
|
||||
* @param \Magento\Framework\Stdlib\DateTime\DateTime $datetime
|
||||
* @param \Magento\Framework\Component\ComponentRegistrarInterface $componentRegistrar
|
||||
* @param \Magento\Framework\Filesystem\Directory\ReadFactory $readFactory
|
||||
*/
|
||||
public function __construct(
|
||||
\Magento\Framework\App\Helper\Context $context,
|
||||
ProductMetadataInterface $productMetadata,
|
||||
ScheduleFactory $scheduleFactory,
|
||||
\Magento\Framework\Stdlib\DateTime\DateTime $datetime,
|
||||
\Magento\Framework\Component\ComponentRegistrarInterface $componentRegistrar,
|
||||
\Magento\Framework\Filesystem\Directory\ReadFactory $readFactory
|
||||
)
|
||||
{
|
||||
parent::__construct($context);
|
||||
$this->productMetaData = $productMetadata;
|
||||
$this->scheduleFactory = $scheduleFactory;
|
||||
$this->dateTime = $datetime;
|
||||
$this->componentRegistrar = $componentRegistrar;
|
||||
$this->readFactory = $readFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getCurrentServerUser()
|
||||
{
|
||||
if (function_exists('get_current_user')) {
|
||||
return get_current_user();
|
||||
}
|
||||
// Try POSIX (Linux/Unix)
|
||||
if (function_exists('posix_geteuid') && function_exists('posix_getpwuid')) {
|
||||
$userInfo = posix_getpwuid(posix_geteuid());
|
||||
if (!empty($userInfo['name'])) {
|
||||
return $userInfo['name'];
|
||||
}
|
||||
}
|
||||
// Try environment variables
|
||||
$user = getenv('USER') ?: getenv('USERNAME');
|
||||
if (!empty($user)) {
|
||||
return $user;
|
||||
}
|
||||
// Fallback: unknown
|
||||
return 'unknown';
|
||||
}
|
||||
|
||||
/**
|
||||
* @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();
|
||||
}
|
||||
}
|
||||
+141
@@ -0,0 +1,141 @@
|
||||
<?php
|
||||
|
||||
namespace WeltPixel\Backend\Helper;
|
||||
|
||||
use Magento\Framework\View\Design\Theme\ThemeProviderInterface;
|
||||
use \Magento\Store\Api\StoreRepositoryInterface;
|
||||
use \Magento\Store\Model\StoreManagerInterface;
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.TooManyFields)
|
||||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
||||
*/
|
||||
class Utility extends \Magento\Framework\App\Helper\AbstractHelper
|
||||
{
|
||||
|
||||
/** @var ThemeProviderInterface */
|
||||
protected $themeProvider;
|
||||
|
||||
/** @var StoreRepositoryInterface */
|
||||
protected $storeRepository;
|
||||
|
||||
/**
|
||||
* @var StoreManagerInterface
|
||||
*/
|
||||
protected $storeManager;
|
||||
|
||||
/** @var array */
|
||||
protected $storeThemesLocales = [];
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param \Magento\Framework\App\Helper\Context $context
|
||||
* @param ThemeProviderInterface $themeProvider
|
||||
* @param StoreRepositoryInterface $storeRepository
|
||||
* @param StoreManagerInterface $storeManager
|
||||
*/
|
||||
public function __construct(
|
||||
\Magento\Framework\App\Helper\Context $context,
|
||||
ThemeProviderInterface $themeProvider,
|
||||
StoreRepositoryInterface $storeRepository,
|
||||
StoreManagerInterface $storeManager
|
||||
)
|
||||
{
|
||||
parent::__construct($context);
|
||||
$this->themeProvider = $themeProvider;
|
||||
$this->storeRepository = $storeRepository;
|
||||
$this->storeManager = $storeManager;
|
||||
}
|
||||
|
||||
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 = [];
|
||||
$isSingleStoreMode = $this->storeManager->isSingleStoreMode();
|
||||
foreach ($stores as $store) {
|
||||
$storeId = $store["store_id"];
|
||||
$websiteId = $store["website_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
|
||||
);
|
||||
|
||||
if ($isSingleStoreMode) {
|
||||
$themeId = $this->scopeConfig->getValue(
|
||||
\Magento\Framework\View\DesignInterface::XML_PATH_THEME_ID,
|
||||
\Magento\Store\Model\ScopeInterface::SCOPE_WEBSITE,
|
||||
$websiteId
|
||||
);
|
||||
$locale = $this->scopeConfig->getValue(
|
||||
\Magento\Directory\Helper\Data::XML_PATH_DEFAULT_LOCALE,
|
||||
\Magento\Store\Model\ScopeInterface::SCOPE_WEBSITE,
|
||||
$websiteId
|
||||
);
|
||||
}
|
||||
|
||||
$theme = $this->themeProvider->getThemeById($themeId);
|
||||
$result[$theme->getThemePath().'/'.$locale] = $storeCode;
|
||||
}
|
||||
|
||||
$this->storeThemesLocales = $result;
|
||||
return $this->storeThemesLocales;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return false|\Magento\Csp\Helper\CspNonceProvider
|
||||
*/
|
||||
public function getCspNonceProvider()
|
||||
{
|
||||
if (class_exists(\Magento\Csp\Helper\CspNonceProvider::class)) {
|
||||
return \Magento\Framework\App\ObjectManager::getInstance()->get(\Magento\Csp\Helper\CspNonceProvider::class);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user