Skip to content

Commit

Permalink
Fixed a MySQL error when deleting an asset folder that had more than …
Browse files Browse the repository at this point in the history
…15 subfolders.

Partially address #8073
  • Loading branch information
andris-sevcenko committed Jun 17, 2021
1 parent 8a38fbe commit f3ed81f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -12,6 +12,7 @@
- Fixed an infinite recursion bug that could occur when validating date values.
- Fixed a bug where it wasn’t possible to choose the parent entry when creating new Structure section entries. ([#8074](https://github.com/craftcms/cms/issues/8074))
- Fixed a bug where element selection fields could get multiple “Choose” buttons. ([#8074](https://github.com/craftcms/cms/issues/8074))
- Fixed a MySQL error when deleting an asset folder that had more than 15 subfolders. ([#8073](https://github.com/craftcms/cms/issues/8073))

## 3.7.0-beta.1 - 2021-06-15

Expand Down
13 changes: 12 additions & 1 deletion src/services/Assets.php
Expand Up @@ -316,8 +316,11 @@ public function renameFolderById(int $folderId, string $newName): string
*/
public function deleteFoldersByIds($folderIds, bool $deleteDir = true)
{
$folders = [];

foreach ((array)$folderIds as $folderId) {
$folder = $this->getFolderById($folderId);
$folders[] = $folder;

if ($folder) {
if ($deleteDir) {
Expand All @@ -335,7 +338,15 @@ public function deleteFoldersByIds($folderIds, bool $deleteDir = true)
$elementService->deleteElement($asset, true);
}

VolumeFolderRecord::deleteAll(['id' => $folderIds]);
foreach ($folders as $folder) {
$descendants = $this->getAllDescendantFolders($folder);
usort($descendants, function ($a, $b) { return substr_count($a->path, '/') < substr_count($b->path, '/');});

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

/**
Expand Down
8 changes: 8 additions & 0 deletions src/volumes/Local.php
Expand Up @@ -170,4 +170,12 @@ protected function createAdapter(): LocalAdapter
],
]);
}

public function deleteDirectory(string $path)
{
// SIC
return null;//parent::deleteDirectory($path); // TODO: Change the autogenerated stub
}


}

0 comments on commit f3ed81f

Please sign in to comment.