Skip to content

Commit

Permalink
Fix: Remove orphaned blocks button deletes valid blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
hissy committed Jan 8, 2025
1 parent 4d8d220 commit be63add
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions concrete/controllers/panel/add.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Concrete\Controller\Backend\UserInterface\Page as BackendInterfacePageController;
use Concrete\Core\Application\EditResponse;
use Concrete\Core\Application\Service\Urls;
use Concrete\Core\Area\Area;
use Concrete\Core\Block\Block;
use Concrete\Core\Block\BlockType\BlockType;
use Concrete\Core\Block\BlockType\BlockTypeList;
Expand Down Expand Up @@ -270,13 +271,14 @@ public function removeOrphanedBlock()
if (!$orphanedBlockFound) {
$errorList->add(t("The given block is not orphaned."));
} else {
$block = Block::getByID($blockId);

$arID = $request->request->get('arId');
$areaHandle = Area::getAreaHandleFromID($arID);
$block = Block::getByID($blockId, $this->page, $areaHandle);
if (!$block instanceof Block) {
//$errorList->add(t("Error while removing orphaned block."));
} else {
// returns false because the area no longer exists in the theme.
$block->deleteBlock(true);
$block->deleteBlock();
}
}
}
Expand Down Expand Up @@ -313,15 +315,16 @@ public function removeOrphanedBlocks()
if (count($arrOrphanedBlocks) === 0) {
$errorList->add(t("There are no blocks to remove."));
} else {
foreach ($this->getOrphanedBlockIds($usedAreas) as $arrOrphanedBlock) {
foreach ($arrOrphanedBlocks as $arrOrphanedBlock) {
$bID = (int)$arrOrphanedBlock["bID"];
$block = Block::getByID($bID);
$arHandle = $arrOrphanedBlock["arHandle"];
$block = Block::getByID($bID, $this->page, $arHandle);

if (!$block instanceof Block) {
$errorList->add(t("Error while removing orphaned block."));
} else {
// returns false because the area no longer exists in the theme.
$block->deleteBlock(true);
$block->deleteBlock();
}
}
}
Expand Down

0 comments on commit be63add

Please sign in to comment.