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 6, 2025
2 parents 22d6cd1 + 9c2ab9a commit b27c462
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 17 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

- Fixed a bug where custom fields could cause validation errors when running the `users/create` command.
- Fixed a bug where deleting a volume folder wasn’t fully deleting asset data in descendant folders.
- Fixed a JavaScript error that could occur if there was a problem applying changes to field layout elements. ([#16380](https://github.com/craftcms/cms/issues/16380))
- Fixed a bug where field layout designers were validating field names, handles, and instructions, even if they weren’t overridden within the field instance. ([#16380](https://github.com/craftcms/cms/issues/16380))

Expand Down
4 changes: 2 additions & 2 deletions src/console/controllers/UsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ public function actionCreate(): int

$user = new User($attributesFromArgs);

if (!$user->validate(array_keys($attributesFromArgs))) {
if (!empty($attributesFromArgs) && !$user->validate(array_keys($attributesFromArgs))) {
$this->stderr('Invalid arguments:' . PHP_EOL . ' - ' . implode(PHP_EOL . ' - ', $user->getErrorSummary(true)) . PHP_EOL, Console::FG_RED);
return ExitCode::USAGE;
}
Expand Down Expand Up @@ -234,7 +234,7 @@ public function actionCreate(): int

$this->stdout('Saving the user ... ');

if (!Craft::$app->getElements()->saveElement($user)) {
if (!Craft::$app->getElements()->saveElement($user, false)) {
$this->stderr('failed:' . PHP_EOL . ' - ' . implode(PHP_EOL . ' - ', $user->getErrorSummary(true)) . PHP_EOL, Console::FG_RED);

return ExitCode::USAGE;
Expand Down
26 changes: 11 additions & 15 deletions src/services/Assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -308,16 +308,19 @@ public function renameFolderById(int $folderId, string $newName): string
*/
public function deleteFoldersByIds(int|array $folderIds, bool $deleteDir = true): void
{
$folders = [];
$allFolderIds = [];

foreach ((array)$folderIds as $folderId) {
$folder = $this->getFolderById((int)$folderId);
if (!$folder) {
continue;
}

$folders[] = $folder;
$allFolderIds[] = $folder->id;
$descendants = $this->getAllDescendantFolders($folder, withParent: false);
array_push($allFolderIds, ...array_map(fn(VolumeFolder $folder) => $folder->id, $descendants));

// Delete the directory on the filesystem
if ($folder->path && $deleteDir) {
$volume = $folder->getVolume();
try {
Expand All @@ -329,25 +332,18 @@ public function deleteFoldersByIds(int|array $folderIds, bool $deleteDir = true)
}
}

/** @var Asset[] $assets */
$assets = Asset::find()->folderId($folderIds)->all();

// Delete the elements
$assetQuery = Asset::find()->folderId($allFolderIds);
$elementService = Craft::$app->getElements();

foreach ($assets as $asset) {
foreach ($assetQuery->each() as $asset) {
/** @var Asset $asset */
$asset->keepFileOnDelete = !$deleteDir;
$elementService->deleteElement($asset, true);
}

foreach ($folders as $folder) {
$descendants = $this->getAllDescendantFolders($folder);
usort($descendants, static fn($a, $b) => substr_count($a->path, '/') < substr_count($b->path, '/'));

foreach ($descendants as $descendant) {
VolumeFolderRecord::deleteAll(['id' => $descendant->id]);
}
VolumeFolderRecord::deleteAll(['id' => $folder->id]);
}
// Delete the folder records
VolumeFolderRecord::deleteAll(['id' => $allFolderIds]);
}

/**
Expand Down

0 comments on commit b27c462

Please sign in to comment.