Skip to content

Commit

Permalink
Merge branch 'release/4.2.3' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonkelly committed Aug 26, 2022
2 parents 42335c5 + 8f5a0ce commit 2ee1ed6
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 33 deletions.
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Release Notes for Craft CMS 4

## 4.2.3 - 2022-08-26

### Changed
- If a plugin’s license key is set to an empty environment variable, its trial license key will now be stored in `.env` rather than the project config. ([#11830](https://github.com/craftcms/cms/issues/11830))

### Fixed
- Fixed a PHP error that occurred when garbage collection was run on web requests. ([#11829](https://github.com/craftcms/cms/issues/11829))

## 4.2.2 - 2022-08-23

### Added
Expand All @@ -22,7 +30,7 @@
- Fixed PHP warnings that would occur when passing `0` into `craft\helpers\DateTimeHelper::humanDuration()`. ([#11787](https://github.com/craftcms/cms/issues/11787))
- Fixed a bug where selected assets weren’t getting automatically replaced when an image was edited and “Save as a new asset” was chosen. ([#11805](https://github.com/craftcms/cms/issues/11805))
- Fixed a JavaScript error that occurred when editing a user via a slideout, if the user had any addresses. ([#11810](https://github.com/craftcms/cms/issues/11810))
- Fixed a beg where some invalid slideout submissions weren’t being handled properly. ([#11812](https://github.com/craftcms/cms/issues/11812))
- Fixed a bug where some invalid slideout submissions weren’t being handled properly. ([#11812](https://github.com/craftcms/cms/issues/11812))
- Fixed a bug where `craft\helpers\DateTimeHelper::toDateInterval()` was returning negative interval durations when integers were passed in. ([#11814](https://github.com/craftcms/cms/pull/11814))
- Fixed a bug where `iframeResizer.contentWindow.js` was getting loaded for all preview requests, not just Live Preview, and even when `useIframeResizer` was disabled. ([#11778](https://github.com/craftcms/cms/issues/11778))
- Fixed a bug where deleted relations and Matrix blocks could persist if the edit form was submitted before they had been fully animated away. ([#11789](https://github.com/craftcms/cms/issues/11789))
Expand Down
2 changes: 1 addition & 1 deletion src/config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
return [
'id' => 'CraftCMS',
'name' => 'Craft CMS',
'version' => '4.2.2',
'version' => '4.2.3',
'schemaVersion' => '4.0.0.9',
'minVersionRequired' => '3.7.11',
'basePath' => dirname(__DIR__), // Defines the @app alias
Expand Down
55 changes: 33 additions & 22 deletions src/services/Gc.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use craft\base\BlockElementInterface;
use craft\base\ElementInterface;
use craft\config\GeneralConfig;
use craft\console\Application as ConsoleApplication;
use craft\db\Connection;
use craft\db\Query;
use craft\db\Table;
Expand Down Expand Up @@ -157,7 +158,7 @@ public function hardDeleteVolumes(): void
return;
}

Console::stdout(" > deleting trashed volumes and their folders ... ");
$this->_stdout(" > deleting trashed volumes and their folders ... ");
$condition = $this->_hardDeleteCondition();

$volumes = (new Query())->select(['id'])->from([Table::VOLUMES])->where($condition)->all();
Expand All @@ -177,7 +178,7 @@ public function hardDeleteVolumes(): void
}

Volume::deleteAll(['id' => $volumeIds]);
Console::stdout("done\n", Console::FG_GREEN);
$this->_stdout("done\n", Console::FG_GREEN);
}

/**
Expand All @@ -204,7 +205,7 @@ public function hardDeleteElements(): void
}
}

Console::stdout(' > deleting trashed elements ... ');
$this->_stdout(' > deleting trashed elements ... ');

if ($normalElementTypes) {
Db::delete(Table::ELEMENTS, [
Expand Down Expand Up @@ -247,7 +248,7 @@ public function hardDeleteElements(): void
$this->db->createCommand($sql, $params)->execute();
}

Console::stdout("done\n", Console::FG_GREEN);
$this->_stdout("done\n", Console::FG_GREEN);
}

/**
Expand All @@ -268,9 +269,9 @@ public function hardDelete(array|string $tables): void
}

foreach ($tables as $table) {
Console::stdout(" > deleting trashed rows in the `$table` table ... ");
$this->_stdout(" > deleting trashed rows in the `$table` table ... ");
Db::delete($table, $condition);
Console::stdout("done\n", Console::FG_GREEN);
$this->_stdout("done\n", Console::FG_GREEN);
}
}

Expand All @@ -286,7 +287,7 @@ public function hardDelete(array|string $tables): void
public function deletePartialElements(string $elementType, string $table, string $fk): void
{
/** @var string|ElementInterface $elementType */
Console::stdout(sprintf(' > deleting partial %s data in the `%s` table ... ', $elementType::lowerDisplayName(), $table));
$this->_stdout(sprintf(' > deleting partial %s data in the `%s` table ... ', $elementType::lowerDisplayName(), $table));

$elementsTable = Table::ELEMENTS;

Expand All @@ -311,7 +312,7 @@ public function deletePartialElements(string $elementType, string $table, string
}

$this->db->createCommand($sql, ['type' => $elementType])->execute();
Console::stdout("done\n", Console::FG_GREEN);
$this->_stdout("done\n", Console::FG_GREEN);
}

private function _purgeUnsavedDrafts()
Expand All @@ -320,9 +321,9 @@ private function _purgeUnsavedDrafts()
return;
}

Console::stdout(' > purging unsaved drafts that have gone stale ... ');
$this->_stdout(' > purging unsaved drafts that have gone stale ... ');
Craft::$app->getDrafts()->purgeUnsavedDrafts();
Console::stdout("done\n", Console::FG_GREEN);
$this->_stdout("done\n", Console::FG_GREEN);
}

private function _purgePendingUsers()
Expand All @@ -331,9 +332,9 @@ private function _purgePendingUsers()
return;
}

Console::stdout(' > purging pending users with stale activation codes ... ');
$this->_stdout(' > purging pending users with stale activation codes ... ');
Craft::$app->getUsers()->purgeExpiredPendingUsers();
Console::stdout("done\n", Console::FG_GREEN);
$this->_stdout("done\n", Console::FG_GREEN);
}

/**
Expand All @@ -346,6 +347,8 @@ private function _purgePendingUsers()
*/
public function removeEmptyTempFolders(): void
{
$this->_stdout(' > removing empty temp folders ... ');

$emptyFolders = (new Query())
->from(['folders' => Table::VOLUMEFOLDERS])
->select(['folders.id', 'folders.path'])
Expand All @@ -366,6 +369,7 @@ public function removeEmptyTempFolders(): void
}

VolumeFolder::deleteAll(['id' => array_keys($emptyFolders)]);
$this->_stdout("done\n", Console::FG_GREEN);
}

/**
Expand All @@ -387,22 +391,22 @@ private function _deleteStaleSessions(): void
return;
}

Console::stdout(' > deleting stale user sessions ... ');
$this->_stdout(' > deleting stale user sessions ... ');
$interval = DateTimeHelper::secondsToInterval($this->_generalConfig->purgeStaleUserSessionDuration);
$expire = DateTimeHelper::currentUTCDateTime();
$pastTime = $expire->sub($interval);
Db::delete(Table::SESSIONS, ['<', 'dateUpdated', Db::prepareDateForDb($pastTime)]);
Console::stdout("done\n", Console::FG_GREEN);
$this->_stdout("done\n", Console::FG_GREEN);
}

/**
* Deletes any feature announcement rows that have gone stale.
*/
private function _deleteStaleAnnouncements(): void
{
Console::stdout(' > deleting stale feature announcements ... ');
$this->_stdout(' > deleting stale feature announcements ... ');
Db::delete(Table::ANNOUNCEMENTS, ['<', 'dateRead', Db::prepareDateForDb(new DateTime('7 days ago'))]);
Console::stdout("done\n", Console::FG_GREEN);
$this->_stdout("done\n", Console::FG_GREEN);
}


Expand All @@ -411,7 +415,7 @@ private function _deleteStaleAnnouncements(): void
*/
private function _deleteOrphanedDraftsAndRevisions(): void
{
Console::stdout(' > deleting orphaned drafts and revisions ... ');
$this->_stdout(' > deleting orphaned drafts and revisions ... ');

$elementsTable = Table::ELEMENTS;

Expand All @@ -436,14 +440,14 @@ private function _deleteOrphanedDraftsAndRevisions(): void
$this->db->createCommand($sql)->execute();
}

Console::stdout("done\n", Console::FG_GREEN);
$this->_stdout("done\n", Console::FG_GREEN);
}

private function _deleteOrphanedSearchIndexes(): void
{
Console::stdout(' > deleting orphaned search indexes ... ');
$this->_stdout(' > deleting orphaned search indexes ... ');
Craft::$app->getSearch()->deleteOrphanedIndexes();
Console::stdout("done\n", Console::FG_GREEN);
$this->_stdout("done\n", Console::FG_GREEN);
}

private function _gcCache(): void
Expand Down Expand Up @@ -471,15 +475,15 @@ private function _gcCache(): void
return;
}

Console::stdout(' > garbage-collecting data caches ... ');
$this->_stdout(' > garbage-collecting data caches ... ');

if ($hasForceArg) {
$cache->gc(true);
} else {
$cache->gc();
}

Console::stdout("done\n", Console::FG_GREEN);
$this->_stdout("done\n", Console::FG_GREEN);
}

/**
Expand All @@ -504,4 +508,11 @@ private function _hardDeleteCondition(?string $tableAlias = null): array

return $condition;
}

private function _stdout(string $string, ...$format): void
{
if (Craft::$app instanceof ConsoleApplication) {
Console::stdout($string, ...$format);
}
}
}
21 changes: 14 additions & 7 deletions src/services/Plugins.php
Original file line number Diff line number Diff line change
Expand Up @@ -1152,7 +1152,8 @@ public function getPluginIconSvg(string $handle): string
*/
public function getPluginLicenseKey(string $handle): ?string
{
return $this->normalizePluginLicenseKey(App::parseEnv($this->getStoredPluginInfo($handle)['licenseKey'] ?? null));
$licenseKey = $this->getStoredPluginInfo($handle)['licenseKey'] ?? null;
return $this->normalizePluginLicenseKey(App::parseEnv($licenseKey));
}

/**
Expand All @@ -1171,13 +1172,19 @@ public function setPluginLicenseKey(string $handle, ?string $licenseKey = null):
// Validate the license key
$normalizedLicenseKey = $this->normalizePluginLicenseKey($licenseKey);

// Set the plugin’s license key in the project config
Craft::$app->getProjectConfig()->set(ProjectConfig::PATH_PLUGINS . '.' . $handle . '.licenseKey', $normalizedLicenseKey, "Set license key for plugin “{$handle}");
// If the license key is set to an empty environment variable, set the environment variable's value
$oldLicenseKey = $this->getStoredPluginInfo($handle)['licenseKey'] ?? null;
if (preg_match('/^\$(\w+)$/', $oldLicenseKey, $matches) && App::env($matches[1]) === '') {
Craft::$app->getConfig()->setDotEnvVar($matches[1], $normalizedLicenseKey);
} else {
// Set the plugin's license key in the project config
Craft::$app->getProjectConfig()->set(sprintf('%s.%s.licenseKey', ProjectConfig::PATH_PLUGINS, $handle), $normalizedLicenseKey, "Set license key for plugin “{$handle}");

// Update our cache of it
$this->loadPlugins();
if (isset($this->_storedPluginInfo[$handle])) {
$this->_storedPluginInfo[$handle]['licenseKey'] = $normalizedLicenseKey;
// Update our cache of it
$this->loadPlugins();
if (isset($this->_storedPluginInfo[$handle])) {
$this->_storedPluginInfo[$handle]['licenseKey'] = $normalizedLicenseKey;
}
}

// If we've cached the plugin’s license key status, update the cache
Expand Down
2 changes: 1 addition & 1 deletion src/web/assets/cp/dist/cp.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/web/assets/cp/dist/cp.js.map

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions src/web/assets/cp/src/js/PreviewFileModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,9 @@ Craft.PreviewFileModal = Garnish.Modal.extend(
}

this.$container.removeClass('zilch');
this.$container.attr('data-asset-id', this.assetId);
this.$container.append(response.data.previewHtml);

this._addBumperButtons();
Craft.appendHeadHtml(response.data.headHtml);
Craft.appendBodyHtml(response.data.bodyHtml);
Expand Down

0 comments on commit 2ee1ed6

Please sign in to comment.