Skip to content

Commit

Permalink
Merge branch '4.x' of https://github.com/craftcms/cms into 5.x
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonkelly committed Jan 8, 2025
2 parents 73808a2 + 6f32d9b commit ec7fd94
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Unreleased

- Fixed a bug where the control panel could display a notice about the Craft CMS license belonging to a different domain, even when accessing the control panel from the correct domain. ([#16396](https://github.com/craftcms/cms/issues/16396))
- Fixed a bug where field layout elements’ action menus could have an empty action group.

## 5.5.9 - 2025-01-06
Expand Down
2 changes: 1 addition & 1 deletion src/base/ApplicationTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ public function getEditionHandle(): string
*/
public function getLicensedEdition(): ?CmsEdition
{
$licenseInfo = $this->getCache()->get('licenseInfo') ?: [];
$licenseInfo = $this->getCache()->get(App::licenseInfoCacheKey()) ?: [];

if (!isset($licenseInfo['craft']['edition'])) {
return null;
Expand Down
4 changes: 2 additions & 2 deletions src/base/FieldInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -315,9 +315,9 @@ public function useFieldset(): bool;
public function getInputHtml(mixed $value, ?ElementInterface $element): string;

/**
* Returns a static (non-editable) version of the field’s input HTML.
* Returns a read-only version of the field’s input HTML.
*
* This function is called to output field values when viewing element drafts.
* This method is called to output field values when viewing element revisions.
*
* @param mixed $value The field’s value
* @param ElementInterface $element The element the field is associated with
Expand Down
5 changes: 3 additions & 2 deletions src/helpers/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,8 @@ public static function processResponseHeaders(array $headers): void

// license info
if (isset($headers['x-craft-license-info'])) {
$oldLicenseInfo = $cache->get('licenseInfo') ?: [];
$licenseInfoCacheKey = App::licenseInfoCacheKey();
$oldLicenseInfo = $cache->get($licenseInfoCacheKey) ?: [];
$licenseInfo = [];
$allCombinedInfo = array_filter(explode(',', reset($headers['x-craft-license-info'])));
foreach ($allCombinedInfo as $combinedInfo) {
Expand Down Expand Up @@ -235,7 +236,7 @@ public static function processResponseHeaders(array $headers): void
'timestamp' => $timestamp,
];
}
$cache->set('licenseInfo', $licenseInfo, $duration);
$cache->set($licenseInfoCacheKey, $licenseInfo, $duration);
}
}

Expand Down
20 changes: 18 additions & 2 deletions src/helpers/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -1295,6 +1295,21 @@ public static function createFormattingLocale(): Locale
return Craft::$app->getLocale();
}

/**
* Returns the cache key that licensing info should be stored with.
*
* @return string
* @internal
*/
public static function licenseInfoCacheKey(): string
{
$request = Craft::$app->getRequest();
if ($request->getIsConsoleRequest()) {
return 'licenseInfo';
}
return sprintf('licenseInfo@%s', $request->getHostName());
}

/**
* Returns all known licensing issues.
*
Expand All @@ -1312,7 +1327,8 @@ public static function licensingIssues(bool $withUnresolvables = true, bool $fet

$updatesService = Craft::$app->getUpdates();
$cache = Craft::$app->getCache();
$isInfoCached = $cache->exists('licenseInfo') && $updatesService->getIsUpdateInfoCached();
$licenseInfoCacheKey = static::licenseInfoCacheKey();
$isInfoCached = $cache->exists($licenseInfoCacheKey) && $updatesService->getIsUpdateInfoCached();

if (!$isInfoCached) {
if (!$fetch) {
Expand All @@ -1324,7 +1340,7 @@ public static function licensingIssues(bool $withUnresolvables = true, bool $fet

$issues = [];

$allLicenseInfo = $cache->get('licenseInfo') ?: [];
$allLicenseInfo = $cache->get($licenseInfoCacheKey) ?: [];
$pluginsService = Craft::$app->getPlugins();
$generalConfig = Craft::$app->getConfig()->getGeneral();
$consoleUrl = rtrim(Craft::$app->getPluginStore()->craftIdEndpoint, '/');
Expand Down
7 changes: 4 additions & 3 deletions src/services/Plugins.php
Original file line number Diff line number Diff line change
Expand Up @@ -1013,7 +1013,7 @@ public function getPluginInfo(string $handle): array
$info['hasCpSettings'] = ($plugin !== null && $plugin->hasCpSettings);
$info['licenseKey'] = $pluginInfo['licenseKey'] ?? null;

$licenseInfo = Craft::$app->getCache()->get('licenseInfo') ?? [];
$licenseInfo = Craft::$app->getCache()->get(App::licenseInfoCacheKey()) ?? [];
$pluginCacheKey = StringHelper::ensureLeft($handle, 'plugin-');
$info['licenseId'] = $licenseInfo[$pluginCacheKey]['id'] ?? null;
$info['licensedEdition'] = $licenseInfo[$pluginCacheKey]['edition'] ?? null;
Expand Down Expand Up @@ -1195,10 +1195,11 @@ public function setPluginLicenseKey(string $handle, ?string $licenseKey = null):

// Clear the plugin's cached license key status
$cache = Craft::$app->getCache();
$licenseInfo = $cache->get('licenseInfo') ?? [];
$cacheKey = App::licenseInfoCacheKey();
$licenseInfo = $cache->get($cacheKey) ?? [];
if (isset($licenseInfo[$handle])) {
unset($licenseInfo[$handle]);
$cache->set('licenseInfo', $licenseInfo);
$cache->set($cacheKey, $licenseInfo);
}

return true;
Expand Down
2 changes: 1 addition & 1 deletion src/web/twig/variables/Cp.php
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ public function settings(): array
public function areAlertsCached(): bool
{
// The license key status gets cached on each Craftnet request
return (Craft::$app->getCache()->get('licenseInfo') !== false);
return (Craft::$app->getCache()->get(App::licenseInfoCacheKey()) !== false);
}

/**
Expand Down

0 comments on commit ec7fd94

Please sign in to comment.