Skip to content

Commit 7398c3b

Browse files
authored
Merge pull request #16946 from craftcms/feature/pt-2668-update-axios-in-craft-4-and-5
Update axios to ^1.8.4
2 parents 41e3c20 + 1bb0536 commit 7398c3b

File tree

25 files changed

+95
-84
lines changed

25 files changed

+95
-84
lines changed

CHANGELOG-WIP.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,4 @@
4141
- User caches are no longer invalidated on login attempts or when user management actions are taken. ([#16937](https://github.com/craftcms/cms/pull/16937))
4242
- Updated Yii to 2.0.52.
4343
- Updated yii2-debug to 2.1.26.
44+
- Updated Axios to 1.8.4.

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## Unreleased
44

55
- Fixed a bug where relations weren’t always propagating to newly-added sites for sections correctly. ([#16924](https://github.com/craftcms/cms/pull/16924))
6+
- Fixed a bug where Assets fields set to restrict assets to a single location were relocating assets on element propagation. ([#12767](https://github.com/craftcms/cms/issues/12767), [#16936](https://github.com/craftcms/cms/issues/16936))
67

78
## 4.14.11.1 - 2025-03-19
89

package-lock.json

Lines changed: 25 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"@selectize/selectize": "selectize/selectize.js#master",
3434
"@types/jquery": "^3.5.7",
3535
"accounting": "^0.4.1",
36-
"axios": "^0.28.1",
36+
"axios": "^1.8.4",
3737
"blueimp-file-upload": "^10.31.0",
3838
"d3": "^4.11.0",
3939
"d3-format": "^1.4.4",

src/fields/Assets.php

Lines changed: 45 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -629,53 +629,55 @@ public function afterElementSave(ElementInterface $element, bool $isNew): void
629629
}
630630
}
631631

632-
// Are there any related assets?
633-
/** @var AssetQuery $query */
634-
/** @var Asset[] $assets */
635-
$assets = $query->all();
636-
637-
if (!empty($assets)) {
638-
// Only enforce the restricted asset location for canonical elements
639-
if ($this->restrictLocation && $isCanonical) {
640-
if (!$this->allowSubfolders) {
641-
$rootRestrictedFolderId = $getUploadFolderId();
642-
} else {
643-
$rootRestrictedFolderId = $this->_uploadFolder($element, true, false)->id;
644-
}
645-
646-
$assetsToMove = array_filter($assets, function(Asset $asset) use ($rootRestrictedFolderId, $assetsService) {
647-
if ($asset->folderId === $rootRestrictedFolderId) {
648-
return false;
649-
}
632+
if (!$element->propagating || $this->localizeRelations) {
633+
// Are there any related assets?
634+
/** @var AssetQuery $query */
635+
/** @var Asset[] $assets */
636+
$assets = $query->all();
637+
638+
if (!empty($assets)) {
639+
// Only enforce the restricted asset location for canonical elements
640+
if ($this->restrictLocation && $isCanonical) {
650641
if (!$this->allowSubfolders) {
651-
return true;
642+
$rootRestrictedFolderId = $getUploadFolderId();
643+
} else {
644+
$rootRestrictedFolderId = $this->_uploadFolder($element, true, false)->id;
652645
}
653-
$rootRestrictedFolder = $assetsService->getFolderById($rootRestrictedFolderId);
654-
return (
655-
$asset->volumeId !== $rootRestrictedFolder->volumeId ||
656-
!str_starts_with($asset->folderPath, $rootRestrictedFolder->path)
657-
);
658-
});
659-
} else {
660-
// Find the files with temp sources and just move those.
661-
/** @var Asset[] $assetsToMove */
662-
$assetsToMove = $assetsService->createTempAssetQuery()
663-
->id(array_map(fn(Asset $asset) => $asset->id, $assets))
664-
->all();
665-
}
666646

667-
if (!empty($assetsToMove)) {
668-
$uploadFolder = $assetsService->getFolderById($getUploadFolderId());
647+
$assetsToMove = array_filter($assets, function(Asset $asset) use ($rootRestrictedFolderId, $assetsService) {
648+
if ($asset->folderId === $rootRestrictedFolderId) {
649+
return false;
650+
}
651+
if (!$this->allowSubfolders) {
652+
return true;
653+
}
654+
$rootRestrictedFolder = $assetsService->getFolderById($rootRestrictedFolderId);
655+
return (
656+
$asset->volumeId !== $rootRestrictedFolder->volumeId ||
657+
!str_starts_with($asset->folderPath, $rootRestrictedFolder->path)
658+
);
659+
});
660+
} else {
661+
// Find the files with temp sources and just move those.
662+
/** @var Asset[] $assetsToMove */
663+
$assetsToMove = $assetsService->createTempAssetQuery()
664+
->id(array_map(fn(Asset $asset) => $asset->id, $assets))
665+
->all();
666+
}
669667

670-
// Resolve all conflicts by keeping both
671-
foreach ($assetsToMove as $asset) {
672-
$asset->avoidFilenameConflicts = true;
673-
try {
674-
$assetsService->moveAsset($asset, $uploadFolder);
675-
} catch (FsObjectNotFoundException $e) {
676-
// Don't freak out about that.
677-
Craft::warning('Couldn’t move asset because the file doesn’t exist: ' . $e->getMessage());
678-
Craft::$app->getErrorHandler()->logException($e);
668+
if (!empty($assetsToMove)) {
669+
$uploadFolder = $assetsService->getFolderById($getUploadFolderId());
670+
671+
// Resolve all conflicts by keeping both
672+
foreach ($assetsToMove as $asset) {
673+
$asset->avoidFilenameConflicts = true;
674+
try {
675+
$assetsService->moveAsset($asset, $uploadFolder);
676+
} catch (FsObjectNotFoundException $e) {
677+
// Don't freak out about that.
678+
Craft::warning('Couldn’t move asset because the file doesn’t exist: ' . $e->getMessage());
679+
Craft::$app->getErrorHandler()->logException($e);
680+
}
679681
}
680682
}
681683
}

src/web/assets/axios/dist/axios.js

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/*! Axios v1.8.4 Copyright (c) 2025 Matt Zabriskie and contributors */

src/web/assets/axios/webpack.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
/* globals module, require, __dirname */
33
const {getConfig} = require('@craftcms/webpack');
44
const CopyWebpackPlugin = require('copy-webpack-plugin');
5+
const path = require('node:path');
56

67
module.exports = getConfig({
78
context: __dirname,
@@ -10,7 +11,7 @@ module.exports = getConfig({
1011
new CopyWebpackPlugin({
1112
patterns: [
1213
{
13-
from: require.resolve('axios/dist/axios.js'),
14+
from: path.resolve('node_modules/axios/dist/axios.js'),
1415
},
1516
],
1617
}),

src/web/assets/craftsupport/dist/css/CraftSupportWidget.css.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/web/assets/dashboard/dist/css/Dashboard.css.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)