Skip to content

Commit fc5569f

Browse files
110: Extension has no version (#133)
1 parent 164e57a commit fc5569f

File tree

1 file changed

+43
-14
lines changed
  • app/code/Meta/BusinessExtension/Model/System

1 file changed

+43
-14
lines changed

app/code/Meta/BusinessExtension/Model/System/Config.php

Lines changed: 43 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@
1919

2020
use Magento\Config\Model\ResourceModel\Config as ResourceConfig;
2121
use Magento\Framework\App\Cache\TypeListInterface;
22+
use Magento\Framework\App\CacheInterface;
23+
use Magento\Framework\App\Config as AppConfig;
2224
use Magento\Framework\App\Config\ScopeConfigInterface;
25+
use Magento\Framework\Composer\ComposerInformation;
2326
use Magento\Framework\Exception\NoSuchEntityException;
24-
use Magento\Framework\Module\ModuleListInterface;
2527
use Magento\Store\Model\ScopeInterface;
2628
use Magento\Store\Model\StoreManagerInterface;
2729

@@ -30,7 +32,8 @@
3032
*/
3133
class Config
3234
{
33-
private const MODULE_NAME = 'Meta_BusinessExtension';
35+
private const VERSION_CACHE_KEY = 'meta-business-extension-version';
36+
private const EXTENSION_PACKAGE_NAME = 'meta/meta-for-magento2';
3437

3538
private const XML_PATH_FACEBOOK_BUSINESS_EXTENSION_ACTIVE = 'facebook/business_extension/active';
3639
public const XML_PATH_FACEBOOK_BUSINESS_EXTENSION_INSTALLED = 'facebook/business_extension/installed';
@@ -111,36 +114,51 @@ class Config
111114
private $resourceConfig;
112115

113116
/**
114-
* @var ModuleListInterface
117+
* @var TypeListInterface
115118
*/
116-
private $moduleList;
119+
private $cacheTypeList;
117120

118121
/**
119-
* @var TypeListInterface
122+
* @var CacheInterface
120123
*/
121-
private $cacheTypeList;
124+
private $cache;
125+
126+
/**
127+
* @var ComposerInformation
128+
*/
129+
private $composerInformation;
130+
131+
/**
132+
* Extension version
133+
*
134+
* @var string
135+
*/
136+
private $version;
122137

123138
/**
124139
* @method __construct
125140
* @param StoreManagerInterface $storeManager
126141
* @param ScopeConfigInterface $scopeConfig
127142
* @param ResourceConfig $resourceConfig
128-
* @param ModuleListInterface $moduleList
129143
* @param TypeListInterface $cacheTypeList
144+
* @param CacheInterface $cache
145+
* @param ComposerInformation $composerInformation
130146
* @SuppressWarnings(PHPMD.ExcessivePublicCount)
131147
*/
132148
public function __construct(
133149
StoreManagerInterface $storeManager,
134150
ScopeConfigInterface $scopeConfig,
135151
ResourceConfig $resourceConfig,
136-
ModuleListInterface $moduleList,
137-
TypeListInterface $cacheTypeList
152+
TypeListInterface $cacheTypeList,
153+
CacheInterface $cache,
154+
ComposerInformation $composerInformation
138155
) {
139156
$this->storeManager = $storeManager;
140157
$this->scopeConfig = $scopeConfig;
141158
$this->resourceConfig = $resourceConfig;
142-
$this->moduleList = $moduleList;
143159
$this->cacheTypeList = $cacheTypeList;
160+
$this->cache = $cache;
161+
$this->composerInformation = $composerInformation;
144162
}
145163

146164
/**
@@ -154,13 +172,24 @@ public function getAppId()
154172
}
155173

156174
/**
157-
* Get module version
175+
* Get extension version
158176
*
159-
* @return mixed
177+
* @return string
160178
*/
161-
public function getModuleVersion()
179+
public function getModuleVersion(): string
162180
{
163-
return $this->moduleList->getOne(self::MODULE_NAME)['setup_version'];
181+
$this->version = $this->version ?: $this->cache->load(self::VERSION_CACHE_KEY);
182+
if (!$this->version) {
183+
$installedPackages = $this->composerInformation->getInstalledMagentoPackages();
184+
$extensionVersion = $installedPackages[self::EXTENSION_PACKAGE_NAME]['version'] ?? null;
185+
if (!empty($extensionVersion)) {
186+
$this->version = $extensionVersion;
187+
} else {
188+
$this->version = 'dev';
189+
}
190+
$this->cache->save($this->version, self::VERSION_CACHE_KEY, [AppConfig::CACHE_TAG]);
191+
}
192+
return $this->version;
164193
}
165194

166195
/**

0 commit comments

Comments
 (0)