concrete/src/Area/GlobalArea.php
public static function deleteEmptyAreas()
    {
        $app = Application::getFacadeApplication();
        $siteService = $app->make(SiteService::class);
        $multilingualSectionIDs = [];
        $sites = $siteService->getList();
        foreach ($sites as $site) {
            $multilingualSectionIDs = array_merge(MultilingualSection::getIDList($site));
        }
        $multilingualSections = [];
        foreach (array_unique($multilingualSectionIDs) as $multilingualSectionID) {
            $multilingualSections[] = MultilingualSection::getByID($multilingualSectionID);
        }

        $stackList = new StackList();
        $stackList->filterByGlobalAreas();

        /** @var \Concrete\Core\Page\Stack\Stack[] $globalAreaStacks */
        $globalAreaStacks = $stackList->getResults();

        foreach ($globalAreaStacks as $stack) {
            $stackAlternatives = [];
            if ($stack->isNeutralStack()) {
                $stackAlternatives[] = $stack;
            } else {
                $stackAlternatives[] = $stack->getNeutralStack();
            }
            foreach ($multilingualSections as $multilingualSection) {
                $stackAlternative = $stackAlternatives[0]->getLocalizedStack($multilingualSection);
                if ($stackAlternative !== null) {
                    $stackAlternatives[] = $stackAlternative;
                }
            }
            $hasBlocks = false;
            foreach ($stackAlternatives as $stackAlternative) {
                // get list of all available page versions, we only delete areas if they never had any content
                $versionList = new VersionList($stackAlternative);
                $versions = $versionList->get();

                foreach ($versions as $version) {
                    $pageVersion = Page::getByID($version->getCollectionID(), $version->getVersionID());
                    $totalBlocks = count($pageVersion->getBlockIDs());

                    if ($totalBlocks > 0) {
                        $hasBlocks = true;
                        break 2;
                    }
                }
            }

            if (!$hasBlocks) {
                $stackAlternatives[0]->delete();
            }
        }
    }
public static function deleteEmptyAreas()
    {
        $app = Application::getFacadeApplication();
        $siteService = $app->make(SiteService::class);
        $multilingualSectionIDs = [];
        $sites = $siteService->getList();
        foreach ($sites as $site) {
            $multilingualSectionIDs = array_merge(MultilingualSection::getIDList($site));
        }
        $multilingualSections = [];
        foreach (array_unique($multilingualSectionIDs) as $multilingualSectionID) {
            $multilingualSections[] = MultilingualSection::getByID($multilingualSectionID);
        }

        $stackList = new StackList();
        $stackList->filterByGlobalAreas();

        /** @var \Concrete\Core\Page\Stack\Stack[] $globalAreaStacks */
        $globalAreaStacks = $stackList->getResults();

        foreach ($globalAreaStacks as $stack) {
            $stackAlternatives = [];
            if ($stack->isNeutralStack()) {
                $stackAlternatives[] = $stack;
            } else {
                $stackAlternatives[] = $stack->getNeutralStack();
            }
            foreach ($multilingualSections as $multilingualSection) {
                $stackAlternative = $stackAlternatives[0]->getLocalizedStack($multilingualSection);
                if ($stackAlternative !== null) {
                    $stackAlternatives[] = $stackAlternative;
                }
            }
            $hasBlocks = false;
            foreach ($stackAlternatives as $stackAlternative) {
                // get list of all available page versions, we only delete areas if they never had any content
                $versionList = new VersionList($stackAlternative);
                $versions = $versionList->get();

                foreach ($versions as $version) {
                    $pageVersion = Page::getByID($version->getCollectionID(), $version->getVersionID());
                    $totalBlocks = count($pageVersion->getBlockIDs());

                    if ($totalBlocks > 0) {
                        $hasBlocks = true;
                        break 2;
                    }
                }
            }

            if (!$hasBlocks) {
                $stackAlternatives[0]->delete();
            }
        }
    }
public static function deleteEmptyAreas ( ) { $ app = Application :: getFacadeApplication ( ) ; $ siteService = $ app -> make ( SiteService :: class ) ; $ multilingualSectionIDs = [ ] ; $ sites = $ siteService -> getList ( ) ; foreach ( $ sites as $ site ) { $ multilingualSectionIDs = array_merge ( MultilingualSection :: getIDList ( $ site ) ) ; } $ multilingualSections = [ ] ; foreach ( array_unique ( $ multilingualSectionIDs ) as $ multilingualSectionID ) { $ multilingualSections [ ] = MultilingualSection :: getByID ( $ multilingualSectionID ) ; } $ stackList = new StackList ( ) ; $ stackList -> filterByGlobalAreas ( ) ; /** @var \Concrete\Core\Page\Stack\Stack[] $globalAreaStacks */ $ globalAreaStacks = $ stackList -> getResults ( ) ; foreach ( $ globalAreaStacks as $ stack ) { $ stackAlternatives = [ ] ; if ( $ stack -> isNeutralStack ( ) ) { $ stackAlternatives [ ] = $ stack ; } else { $ stackAlternatives [ ] = $ stack -> getNeutralStack ( ) ; } foreach ( $ multilingualSections as $ multilingualSection ) { $ stackAlternative = $ stackAlternatives [ 0 ] -> getLocalizedStack ( $ multilingualSection ) ; if ( $ stackAlternative !== null ) { $ stackAlternatives [ ] = $ stackAlternative ; } } $ hasBlocks = false ; foreach ( $ stackAlternatives as $ stackAlternative ) { // get list of all available page versions, we only delete areas if they never had any content $ versionList = new VersionList ( $ stackAlternative ) ; $ versions = $ versionList -> get ( ) ; foreach ( $ versions as $ version ) { $ pageVersion = Page :: getByID ( $ version -> getCollectionID ( ) , $ version -> getVersionID ( ) ) ; $ totalBlocks = count ( $ pageVersion -> getBlockIDs ( ) ) ; if ( $ totalBlocks > 0 ) { $ hasBlocks = true ; break 2 ; } } } if ( ! $ hasBlocks ) { $ stackAlternatives [ 0 ] -> delete ( ) ; } } }
Searches for global areas without any blocks in it and deletes them.
This will have a positive impact on the performance as every global area is rendered for every page.
Searches for global areas without any blocks in it and deletes them . This will have a positive impact on the performance as every global area is rendered for every page .