Core/ModuleStateFixer.php
public function cleanUpExtensions(){

        //get all extions from all metadata
        $oxModuleList = $this->moduleList;
        $aModules = $oxModuleList->getList();

        //get extensions from metadata file
        $moduleClassesMf = [];
        foreach ($aModules as $module) {
            $extensions = $module->getExtensions();
            foreach ($extensions as $moduleClass) {
                $moduleClassesMf[$moduleClass] = 1;
            }
        }

        //get all extesions from db
        $extensionChainDb = Registry::getConfig()->getConfigParam('aModules');
        $extensionChainDb = $oxModuleList->parseModuleChains($extensionChainDb);

        //calculate trash as extensions that are only in db
        foreach ($extensionChainDb as $oxidClass => &$arrayOfExtendingClasses) {

            foreach ($arrayOfExtendingClasses as $key => $extendingClass){
                if (!isset($moduleClassesMf[$extendingClass])) {
                    $this->output->warning("module extension trash found: '$extendingClass'' (registered for $oxidClass)");
                    unset($arrayOfExtendingClasses[$key]);
                }
            }
            $arrayOfExtendingClasses = array_values($arrayOfExtendingClasses);
            if (empty($arrayOfExtendingClasses)) {
                unset($extensionChainDb[$oxidClass]);
            }
        }

        if (!$this->dryRun) {
            $extensionChainDb = $this->buildModuleChains($extensionChainDb);
            $this->_saveToConfig('aModules', $extensionChainDb);
        }

    }
public function cleanUpExtensions(){

        //get all extions from all metadata
        $oxModuleList = $this->moduleList;
        $aModules = $oxModuleList->getList();

        //get extensions from metadata file
        $moduleClassesMf = [];
        foreach ($aModules as $module) {
            $extensions = $module->getExtensions();
            foreach ($extensions as $moduleClass) {
                $moduleClassesMf[$moduleClass] = 1;
            }
        }

        //get all extesions from db
        $extensionChainDb = Registry::getConfig()->getConfigParam('aModules');
        $extensionChainDb = $oxModuleList->parseModuleChains($extensionChainDb);

        //calculate trash as extensions that are only in db
        foreach ($extensionChainDb as $oxidClass => &$arrayOfExtendingClasses) {

            foreach ($arrayOfExtendingClasses as $key => $extendingClass){
                if (!isset($moduleClassesMf[$extendingClass])) {
                    $this->output->warning("module extension trash found: '$extendingClass'' (registered for $oxidClass)");
                    unset($arrayOfExtendingClasses[$key]);
                }
            }
            $arrayOfExtendingClasses = array_values($arrayOfExtendingClasses);
            if (empty($arrayOfExtendingClasses)) {
                unset($extensionChainDb[$oxidClass]);
            }
        }

        if (!$this->dryRun) {
            $extensionChainDb = $this->buildModuleChains($extensionChainDb);
            $this->_saveToConfig('aModules', $extensionChainDb);
        }

    }
remove extensions that are not registered by any module