Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/craftcms/cms into 5.0
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/web/assets/cp/dist/cp.js
#	src/web/assets/cp/dist/cp.js.map
  • Loading branch information
brandonkelly committed Dec 11, 2023
2 parents 4235d4e + ca6d5b4 commit d4e1f45
Show file tree
Hide file tree
Showing 15 changed files with 85 additions and 41 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@
- Improved performance for sites with lots of custom fields in non-global contexts. ([#13992](https://github.com/craftcms/cms/issues/13992))
- Queue job info is now broadcasted to other browser tabs opened to the same control panel. ([#13990](https://github.com/craftcms/cms/issues/13990))
- Added `craft\db\Connection::onAfterTransaction()`.
- Added `craft\errors\MutexException`. ([#13985](https://github.com/craftcms/cms/pull/13985))
- Added `craft\fieldlayoutelements\TextField::$inputType`. ([#13988](https://github.com/craftcms/cms/issues/13988))
- Deprecated `craft\fieldlayoutelements\TextField::$type`. `$inputType` should be used instead. ([#13988](https://github.com/craftcms/cms/issues/13988))
- Fixed a bug where WebP image transforms weren’t respecting transform quality settings. ([#13998](https://github.com/craftcms/cms/issues/13998))
- Fixed a bug where `craft\base\ApplicationTrait::onAfterRequest()` callbacks weren’t necessarily triggered if an `EVENT_AFTER_REQUEST` handler got in the way.
- Fixed a bug where keyboard shortcuts could stop working. ([#14011](https://github.com/craftcms/cms/issues/14011))
- Fixed a bug where the `craft\services\Elements::EVENT_AUTHORIZE_VIEW` event wasn’t always triggered when editing elements. ([#13981](https://github.com/craftcms/cms/issues/13981)))
- Fixed a bug that prevented Live Preview from opening for edited entries, when the `autosaveDrafts` config setting was disabled. ([#13921](https://github.com/craftcms/cms/issues/13921))
- Fixed a bug where JavaScript-based slug generation wasn’t working consistently with PHP. ([#13971](https://github.com/craftcms/cms/pull/13971))
- Fixed a privilege escalation vulnerability.

## 4.5.11.1 - 2023-11-23
Expand Down
4 changes: 1 addition & 3 deletions src/config/GeneralConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -387,9 +387,7 @@ class GeneralConfig extends BaseConfig
/**
* @var bool Whether drafts should be saved automatically as they are edited.
*
* ::: warning
* Disabling this will also disable Live Preview.
* :::
* Note that drafts *will* be autosaved while Live Preview is open, regardless of this setting.
*
* ::: code
* ```shell Environment Override
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/ElementsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -1933,7 +1933,7 @@ private function _element(?int $elementId = null, ?string $elementUid = null, ?b
return null;
}

if (!$element->canView(static::currentUser())) {
if (!$elementsService->canView($element, static::currentUser())) {
throw new ForbiddenHttpException('User not authorized to edit this element.');
}

Expand Down
4 changes: 2 additions & 2 deletions src/controllers/EntriesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use craft\elements\Entry;
use craft\enums\PropagationMethod;
use craft\errors\InvalidElementException;
use craft\errors\MutexException;
use craft\errors\UnsupportedSiteException;
use craft\helpers\ArrayHelper;
use craft\helpers\Cp;
Expand All @@ -21,7 +22,6 @@
use craft\models\Section;
use craft\models\Section_SiteSettings;
use Throwable;
use yii\base\Exception;
use yii\web\BadRequestHttpException;
use yii\web\ForbiddenHttpException;
use yii\web\NotFoundHttpException;
Expand Down Expand Up @@ -311,7 +311,7 @@ public function actionSaveEntry(bool $duplicate = false): ?Response
$lockKey = "entry:$entry->id";
$mutex = Craft::$app->getMutex();
if (!$mutex->acquire($lockKey, 15)) {
throw new Exception('Could not acquire a lock to save the entry.');
throw new MutexException($lockKey, 'Could not acquire a lock to save the entry.');
}
}

Expand Down
40 changes: 40 additions & 0 deletions src/errors/MutexException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace craft\errors;

use Throwable;
use yii\base\Exception;

/**
* Mutex Exception
*
* @author Pixel & Tonic, Inc. <[email protected]>
* @since 4.5.12
*/
class MutexException extends Exception
{
/**
* Constructor
*
* @param string $name
* @param string $message
* @param int $code
* @param Throwable|null $previous
*/
public function __construct(
public string $name,
string $message = '',
int $code = 0,
?Throwable $previous = null,
) {
parent::__construct($message, $code, $previous);
}

/**
* @inheritdoc
*/
public function getName()
{
return 'Mutex Exception';
}
}
5 changes: 3 additions & 2 deletions src/helpers/FileHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
namespace craft\helpers;

use Craft;
use craft\errors\MutexException;
use craft\errors\SiteNotFoundException;
use FilesystemIterator;
use RecursiveDirectoryIterator;
Expand Down Expand Up @@ -725,10 +726,10 @@ public static function useFileLocks(): bool
$mutex = Craft::$app->getMutex();
$name = uniqid('test_lock', true);
if (!$mutex->acquire($name)) {
throw new Exception('Unable to acquire test lock.');
throw new MutexException($name, 'Unable to acquire test lock.');
}
if (!$mutex->release($name)) {
throw new Exception('Unable to release test lock.');
throw new MutexException($name, 'Unable to release test lock.');
}
self::$_useFileLocks = true;
} catch (Throwable $e) {
Expand Down
3 changes: 2 additions & 1 deletion src/helpers/Sequence.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Craft;
use craft\db\Query;
use craft\db\Table;
use craft\errors\MutexException;
use Throwable;
use yii\db\Exception;

Expand Down Expand Up @@ -50,7 +51,7 @@ public static function next(string $name, ?int $length = null): int|string
$lockName = 'seq--' . str_replace(['/', '\\'], '-', $name);

if (!$mutex->acquire($lockName, 3)) {
throw new Exception('Could not acquire a lock for the sequence "' . $name . '".');
throw new MutexException($lockName, sprintf('Could not acquire a lock for the sequence "%s".', $name));
}

try {
Expand Down
5 changes: 3 additions & 2 deletions src/queue/Queue.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Craft;
use craft\db\Connection;
use craft\db\Table;
use craft\errors\MutexException;
use craft\helpers\App;
use craft\helpers\ArrayHelper;
use craft\helpers\Db;
Expand Down Expand Up @@ -911,7 +912,7 @@ private function _status(array|false $payload): int
* @param callable $callback
* @param int|null $timeout
* @param bool $throwException
* @throws Exception
* @throws MutexException
*/
private function _lock(callable $callback, ?int $timeout = null, bool $throwException = true): void
{
Expand All @@ -922,7 +923,7 @@ private function _lock(callable $callback, ?int $timeout = null, bool $throwExce
$mutexName = sprintf('%s::%s', __CLASS__, $channel);
if (!$this->mutex->acquire($mutexName, $timeout ?? $this->mutexTimeout)) {
if ($throwException) {
throw new Exception("Could not acquire a mutex lock for the queue ($channel).");
throw new MutexException($mutexName, "Could not acquire a mutex lock for the queue ($channel).");
}
return;
}
Expand Down
5 changes: 3 additions & 2 deletions src/services/AssetIndexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use craft\errors\FsException;
use craft\errors\MissingAssetException;
use craft\errors\MissingVolumeFolderException;
use craft\errors\MutexException;
use craft\errors\VolumeException;
use craft\helpers\Assets as AssetsHelper;
use craft\helpers\DateTimeHelper;
Expand Down Expand Up @@ -301,7 +302,7 @@ public function processIndexSession(AssetIndexingSession $indexingSession): Asse
$lockName = 'idx--' . $indexingSession->id . '--';

if (!$mutex->acquire($lockName, 3)) {
throw new Exception('Could not acquire a lock for the indexing session "' . $indexingSession->id . '".');
throw new MutexException($lockName, sprintf('Could not acquire a lock for the indexing session "%s".', $indexingSession->id));
}

$indexEntry = $this->getNextIndexEntry($indexingSession);
Expand Down Expand Up @@ -837,7 +838,7 @@ protected function incrementProcessedEntryCount(AssetIndexingSession $session):
$lockName = 'idx--update-' . $session->id . '--';

if (!$mutex->acquire($lockName, 5)) {
throw new Exception('Could not acquire a lock for the indexing session "' . $session->id . '".');
throw new MutexException($lockName, sprintf('Could not acquire a lock for the indexing session "%s".', $session->id));
}

/** @var AssetIndexingSessionRecord $record */
Expand Down
4 changes: 2 additions & 2 deletions src/services/Revisions.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use craft\db\Query;
use craft\db\Table;
use craft\errors\InvalidElementException;
use craft\errors\MutexException;
use craft\events\RevisionEvent;
use craft\helpers\ArrayHelper;
use craft\helpers\DateTimeHelper;
Expand All @@ -21,7 +22,6 @@
use craft\queue\jobs\PruneRevisions;
use Throwable;
use yii\base\Component;
use yii\base\Exception;
use yii\base\InvalidArgumentException;

/**
Expand Down Expand Up @@ -77,7 +77,7 @@ public function createRevision(ElementInterface $canonical, ?int $creatorId = nu
$lockKey = 'revision:' . $canonical->id;
$mutex = Craft::$app->getMutex();
if (!$mutex->acquire($lockKey, 3)) {
throw new Exception('Could not acquire a lock to save a revision for element ' . $canonical->id);
throw new MutexException($lockKey, sprintf('Could not acquire a lock to save a revision for element %s', $canonical->id));
}

$db = Craft::$app->getDb();
Expand Down
3 changes: 2 additions & 1 deletion src/services/Structures.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use craft\base\ElementInterface;
use craft\db\Query;
use craft\db\Table;
use craft\errors\MutexException;
use craft\errors\StructureNotFoundException;
use craft\events\MoveElementEvent;
use craft\models\Structure;
Expand Down Expand Up @@ -503,7 +504,7 @@ private function _doIt(int $structureId, ElementInterface $element, StructureEle
$lockName = 'structure:' . $structureId;
$mutex = Craft::$app->getMutex();
if (!$mutex->acquire($lockName, $this->mutexTimeout)) {
throw new Exception('Unable to acquire a lock for the structure ' . $structureId);
throw new MutexException($lockName, sprintf('Unable to acquire a lock for the structure %s', $structureId));
}

$elementRecord = null;
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.

33 changes: 15 additions & 18 deletions src/web/assets/cp/src/js/ElementEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -1053,30 +1053,25 @@ Craft.ElementEditor = Garnish.Base.extend(
return this.preview;
},

openPreview: function () {
openPreview: async function () {
if (Garnish.hasAttr(this.$previewBtn, 'aria-disabled')) {
return;
}

this.$previewBtn.attr('aria-disabled', true);
this.$previewBtn.addClass('loading');

this.queue.push(
() =>
new Promise((resolve, reject) => {
this.openingPreview = true;
this.ensureIsDraftOrRevision(true)
.then(() => {
this.scrollY = window.scrollY;
this.$previewBtn.removeAttr('aria-disabled');
this.$previewBtn.removeClass('loading');
this.getPreview().open();
this.openingPreview = false;
resolve();
})
.catch(reject);
})
);
try {
await this.checkForm();
this.openingPreview = true;
await this.ensureIsDraftOrRevision(true);
this.scrollY = window.scrollY;
this.getPreview().open();
} finally {
this.$previewBtn.removeAttr('aria-disabled');
this.$previewBtn.removeClass('loading');
this.openingPreview = false;
}
},

ensureIsDraftOrRevision: function (onlyIfChanged) {
Expand Down Expand Up @@ -1170,7 +1165,9 @@ Craft.ElementEditor = Garnish.Base.extend(
typeof this.$container.data('initialSerializedValue') ===
'undefined'
) {
this.timeout = setTimeout(this.checkForm.bind(this), 500);
setTimeout(() => {
this.checkForm(force).then(resolve).catch(reject);
}, 500);
return;
}

Expand Down
10 changes: 5 additions & 5 deletions src/web/assets/cp/src/js/SlugGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ Craft.SlugGenerator = Craft.BaseInputGenerator.extend({
// Remove inner-word punctuation
sourceVal = sourceVal.replace(/['"\[\]\(\)\{\}:]/g, '');

// Make it lowercase
if (!Craft.allowUppercaseInSlug) {
sourceVal = sourceVal.toLowerCase();
}

if (Craft.limitAutoSlugsToAscii) {
// Convert extended ASCII characters to basic ASCII
sourceVal = Craft.asciiString(sourceVal, this.settings.charMap);
}

// Make it lowercase
if (!Craft.allowUppercaseInSlug) {
sourceVal = sourceVal.toLowerCase();
}

// Get the "words". Split on anything that is not alphanumeric.
// Reference: http://www.regular-expressions.info/unicode.html
var words = Craft.filterArray(
Expand Down

0 comments on commit d4e1f45

Please sign in to comment.