Skip to content

Commit

Permalink
Merge branch 'release/4.4.16' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonkelly committed Jul 18, 2023
2 parents 273dfd3 + 3841d61 commit 7a89c83
Show file tree
Hide file tree
Showing 92 changed files with 1,056 additions and 391 deletions.
47 changes: 34 additions & 13 deletions CHANGELOG.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/craftcms-sass/_mixins.scss
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ $radioSize: 16px;
@mixin modal {
border-radius: $largeBorderRadius;
background-color: $white;
box-shadow: 0 25px 100px transparentize($grey900, 0.5);
box-shadow: 0 25px 100px transparentize($grey900, 0.5) !important;
}

@mixin light-on-dark-text() {
Expand Down
17 changes: 11 additions & 6 deletions src/base/Element.php
Original file line number Diff line number Diff line change
Expand Up @@ -2163,11 +2163,7 @@ public function __get($name)

// If this is a field, make sure the value has been normalized before returning the CustomFieldBehavior value
if ($this->fieldByHandle($name) !== null) {
$value = $this->getFieldValue($name);
if (is_object($value) && (!interface_exists(UnitEnum::class) || !$value instanceof UnitEnum)) {
$value = clone $value;
}
return $value;
return $this->clonedFieldValue($name);
}

return parent::__get($name);
Expand Down Expand Up @@ -2297,7 +2293,7 @@ public function fields(): array
foreach ($fieldLayout->getCustomFieldElements() as $layoutElement) {
$field = $layoutElement->getField();
if (!isset($fields[$field->handle])) {
$fields[$field->handle] = fn() => $this->getFieldValue($field->handle);
$fields[$field->handle] = fn() => $this->clonedFieldValue($field->handle);
}
}
}
Expand Down Expand Up @@ -4023,6 +4019,15 @@ public function setFieldValues(array $values): void
}
}

private function clonedFieldValue(string $fieldHandle): mixed
{
$value = $this->getFieldValue($fieldHandle);
if (is_object($value) && (!interface_exists(UnitEnum::class) || !$value instanceof UnitEnum)) {
return clone $value;
}
return $value;
}

/**
* @inheritdoc
*/
Expand Down
7 changes: 5 additions & 2 deletions src/base/ElementInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -487,8 +487,11 @@ public static function defaultTableAttributes(string $source): array;
* This method aids in the eager-loading of elements when performing an element query. The returned array should
* contain the following keys:
* - `elementType` – the fully qualified class name of the element type that should be eager-loaded
* - `map` – an array of element ID mappings, where each element is a sub-array with `source` and `target` keys.
* - `criteria` *(optional)* – Any criteria parameters that should be applied to the element query when fetching the eager-loaded elements.
* - `map` – an array of element ID mappings, where each element is a sub-array with `source` and `target` keys
* - `criteria` *(optional)* – any criteria parameters that should be applied to the element query when fetching the
* eager-loaded elements
* - `createElement` *(optional)* - an element factory function, which will be passed the element query, the current
* query result data, and the first source element that the result was eager-loaded for
*
* ```php
* use craft\db\Query;
Expand Down
30 changes: 15 additions & 15 deletions src/config/GeneralConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,9 @@ class GeneralConfig extends BaseConfig
*
* ```php Static Config
* // Nothing bug GIFs!
* 'allowedFileExtensions' => [
* ->allowedFileExtensions([
* 'gif',
* ],
* ])
* ```
*
* @see extraAllowedFileExtensions
Expand Down Expand Up @@ -393,7 +393,7 @@ class GeneralConfig extends BaseConfig
*
* ::: code
* ```php Static Config
* 'autosaveDrafts' => false,
* ->autosaveDrafts(false)
* ```
* ```shell Environment Override
* CRAFT_AUTOSAVE_DRAFTS=false
Expand Down Expand Up @@ -827,7 +827,7 @@ class GeneralConfig extends BaseConfig
* ::: code
* ```php Static Config
* // One week
* 'defaultTokenDuration' => 604800,
* ->defaultTokenDuration(604800)
* ```
* ```shell Environment Override
* # One week
Expand Down Expand Up @@ -1232,7 +1232,7 @@ class GeneralConfig extends BaseConfig
*
* ::: code
* ```php Static Config
* 'extraLastNamePrefixes' => ['Dal', 'Van Der'],
* ->extraLastNamePrefixes(['Dal', 'Van Der'])
* ```
* ```shell Environment Override
* CRAFT_EXTRA_LAST_NAME_PREFIXES="Dal,Van Der"
Expand All @@ -1249,7 +1249,7 @@ class GeneralConfig extends BaseConfig
*
* ::: code
* ```php Static Config
* 'extraNameSalutations' => ['Lady', 'Sire'],
* ->extraNameSalutations(['Lady', 'Sire'])
* ```
* ```shell Environment Override
* CRAFT_EXTRA_NAME_SALUTATIONS=Lady,Sire
Expand All @@ -1266,7 +1266,7 @@ class GeneralConfig extends BaseConfig
*
* ::: code
* ```php Static Config
* 'extraNameSuffixes' => ['CCNA', 'OBE'],
* ->extraNameSuffixes(['CCNA', 'OBE'])
* ```
* ```shell Environment Override
* CRAFT_EXTRA_NAME_SUFFIXES=CCNA,OBE
Expand Down Expand Up @@ -1471,7 +1471,7 @@ class GeneralConfig extends BaseConfig
* ::: code
* ```php Static Config
* // 1 day
* 'invalidLoginWindowDuration' => 86400,
* ->invalidLoginWindowDuration(86400)
* ```
* ```shell Environment Override
* # 1 day
Expand All @@ -1493,7 +1493,7 @@ class GeneralConfig extends BaseConfig
* ::: code
* ```php Static Config
* // 1 day
* 'invalidUserTokenPath' => 'nope',
* ->invalidUserTokenPath('nope')
* ```
* ```shell Environment Override
* # 1 day
Expand Down Expand Up @@ -1752,7 +1752,7 @@ class GeneralConfig extends BaseConfig
* ::: code
* ```php Static Config
* // 25MB
* 'maxUploadFileSize' => 26214400,
* ->maxUploadFileSize(26214400)
* ```
* ```shell Environment Override
* # 25MB
Expand Down Expand Up @@ -2128,7 +2128,7 @@ class GeneralConfig extends BaseConfig
* ::: code
* ```php Static Config
* // 1 hour
* 'previewTokenDuration' => 3600,
* ->previewTokenDuration(3600)
* ```
* ```shell Environment Override
* # 1 hour
Expand Down Expand Up @@ -2177,7 +2177,7 @@ class GeneralConfig extends BaseConfig
* ::: code
* ```php Static Config
* // 2 weeks
* 'purgePendingUsersDuration' => 1209600,
* ->purgePendingUsersDuration(1209600)
* ```
* ```shell Environment Override
* # 2 weeks
Expand All @@ -2199,7 +2199,7 @@ class GeneralConfig extends BaseConfig
* ::: code
* ```php Static Config
* // 1 week
* 'purgeStaleUserSessionDuration' => 604800,
* ->purgeStaleUserSessionDuration(604800)
* ```
* ```shell Environment Override
* # 1 week
Expand Down Expand Up @@ -3011,7 +3011,7 @@ class GeneralConfig extends BaseConfig
* ::: code
* ```php Static Config
* // 3 hours
* 'userSessionDuration' => 10800,
* ->userSessionDuration(10800)
* ```
* ```shell Environment Override
* # 3 hours
Expand Down Expand Up @@ -3053,7 +3053,7 @@ class GeneralConfig extends BaseConfig
* ::: code
* ```php Static Config
* // 1 hour
* 'verificationCodeDuration' => 3600,
* ->verificationCodeDuration(3600)
* ```
* ```shell Environment Override
* # 1 hour
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.4.15',
'version' => '4.4.16',
'schemaVersion' => '4.4.0.4',
'minVersionRequired' => '3.7.11',
'basePath' => dirname(__DIR__), // Defines the @app alias
Expand Down
2 changes: 1 addition & 1 deletion src/console/controllers/SetupController.php
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ public function actionDbCreds(): int

if (!$this->password && $this->interactive) {
$envPassword = App::env('CRAFT_DB_PASSWORD');
if ($envPassword && $this->confirm('Use the password provided by $DB_PASSWORD?', true)) {
if ($envPassword && $this->confirm('Use the password provided by $CRAFT_DB_PASSWORD?', true)) {
$this->password = $envPassword;
} else {
$this->stdout('Database password: ');
Expand Down
10 changes: 7 additions & 3 deletions src/controllers/AssetsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -1108,19 +1108,23 @@ public function actionGenerateTransform(?int $transformId = null): Response
if ($transformId) {
$transformer = Craft::createObject(ImageTransformer::class);
$transformIndexModel = $transformer->getTransformIndexModelById($transformId);
$assetId = $transformIndexModel->assetId;
$transform = $transformIndexModel->getTransform();
$assetId = $transformIndexModel?->assetId;
$transform = $transformIndexModel?->getTransform();
} else {
$assetId = $this->request->getRequiredBodyParam('assetId');
$handle = $this->request->getRequiredBodyParam('handle');
$transform = ImageTransforms::normalizeTransform($handle);
$transformer = $transform->getImageTransformer();
$transformer = $transform?->getImageTransformer();
}
} catch (\Exception $exception) {
Craft::$app->getErrorHandler()->logException($exception);
throw new ServerErrorHttpException('Image transform cannot be created.', 0, $exception);
}

if (!$transform || !$transformer) {
throw new NotFoundHttpException();
}

$asset = Asset::findOne(['id' => $assetId]);

if (!$asset) {
Expand Down
6 changes: 1 addition & 5 deletions src/controllers/LivePreviewController.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,12 @@ class LivePreviewController extends Controller
*/
public function beforeAction($action): bool
{
if (!parent::beforeAction($action)) {
return false;
}

// Mark this as a Live Preview request
if ($action->id === 'preview') {
$this->request->setIsLivePreview(true);
}

return true;
return parent::beforeAction($action);
}

/**
Expand Down
12 changes: 11 additions & 1 deletion src/db/QueryBatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,20 @@ public function __construct(
public function count(): int
{
try {
return $this->query->count(db: $this->db);
$count = $this->query->count(db: $this->db);
} catch (QueryAbortedException) {
return 0;
}

// Query::count() doesn't take the offset and limit into account
if (isset($this->query->offset)) {
$count = max($count - (int)$this->query->offset, 0);
}
if (isset($this->query->limit)) {
$count = min((int)$this->query->limit, $count);
}

return $count;
}

/**
Expand Down
12 changes: 12 additions & 0 deletions src/elements/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,18 @@ public function getOwner(): ?ElementInterface
return $this->_owner;
}

/**
* Sets the owner element.
*
* @param ElementInterface|null $owner
* @since 4.4.16
*/
public function setOwner(?ElementInterface $owner): void
{
$this->_owner = $owner;
$this->ownerId = $owner?->id;
}

/**
* @inheritdoc
*/
Expand Down
2 changes: 1 addition & 1 deletion src/elements/MatrixBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ public function getOwner(): ElementInterface
public function setOwner(?ElementInterface $owner = null): void
{
$this->_owner = $owner;
$this->ownerId = $owner->id;
$this->ownerId = $owner?->id;
}

/**
Expand Down
6 changes: 6 additions & 0 deletions src/elements/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use craft\elements\actions\UnsuspendUsers;
use craft\elements\conditions\ElementConditionInterface;
use craft\elements\conditions\users\UserCondition;
use craft\elements\db\AddressQuery;
use craft\elements\db\ElementQueryInterface;
use craft\elements\db\UserQuery;
use craft\events\AuthenticateUserEvent;
Expand Down Expand Up @@ -474,6 +475,11 @@ public static function eagerLoadingMap(array $sourceElements, string $handle): a
return [
'elementType' => Address::class,
'map' => $map,
'createElement' => function(AddressQuery $query, array $result, self $source) {
// set the addresses' owners to the source user elements
// (must get set before behaviors - see https://github.com/craftcms/cms/issues/13400)
return $query->createElement(['owner' => $source] + $result);
},
];
}

Expand Down
7 changes: 0 additions & 7 deletions src/fields/Categories.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,6 @@ protected function inputHtml(mixed $value, ?ElementInterface $element = null): s
return parent::inputHtml($value, $element);
}

public function getEagerLoadingMap(array $sourceElements): array|null|false
{
$map = parent::getEagerLoadingMap($sourceElements);
$map['criteria']['orderBy'] = ['structureelements.lft' => SORT_ASC];
return $map;
}

/**
* @inheritdoc
*/
Expand Down
36 changes: 19 additions & 17 deletions src/fields/Matrix.php
Original file line number Diff line number Diff line change
Expand Up @@ -801,27 +801,29 @@ public function validateBlocks(ElementInterface $element): void
$blocks = $value->all();
}

$allBlocksValidate = true;
$scenario = $element->getScenario();
if ($value instanceof MatrixBlockQuery) {
$allBlocksValidate = true;
$scenario = $element->getScenario();

foreach ($blocks as $i => $block) {
/** @var MatrixBlock $block */
if (
$scenario === Element::SCENARIO_ESSENTIALS ||
($block->enabled && $scenario === Element::SCENARIO_LIVE)
) {
$block->setScenario($scenario);
}
foreach ($blocks as $i => $block) {
/** @var MatrixBlock $block */
if (
$scenario === Element::SCENARIO_ESSENTIALS ||
($block->enabled && $scenario === Element::SCENARIO_LIVE)
) {
$block->setScenario($scenario);
}

if (!$block->validate()) {
$element->addModelErrors($block, "$this->handle[$i]");
$allBlocksValidate = false;
if (!$block->validate()) {
$element->addModelErrors($block, "$this->handle[$i]");
$allBlocksValidate = false;
}
}
}

if (!$allBlocksValidate) {
// Just in case the blocks weren't already cached
$value->setCachedResult($blocks);
if (!$allBlocksValidate) {
// Just in case the blocks weren't already cached
$value->setCachedResult($blocks);
}
}

if (
Expand Down
8 changes: 0 additions & 8 deletions src/fields/conditions/EmptyFieldConditionRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,6 @@ class EmptyFieldConditionRule extends BaseConditionRule implements FieldConditio
*/
public string $operator = self::OPERATOR_NOT_EMPTY;

/**
* @inheritdoc
*/
public static function supportsProjectConfig(): bool
{
return true;
}

/**
* @inheritdoc
*/
Expand Down
Loading

0 comments on commit 7a89c83

Please sign in to comment.