2

While running php bin/magento maintenance:enable after upgrading Magento to 2.4.1, I find the error message Class Magento\PageCache\Observer\SwitchPageCacheOnMaintenance does not exist How to fix this?

1

The observer class SwitchPageCacheOnMaintenance should not be exist on your code app/code/Magento/PageCache/etc/events.xml

This observer is removed for the reason Unable to enable maintenance mode when env.php is read-only See Github issue https://github.com/magento/magento2/issues/24229 and PR https://github.com/devamitbera/magento2/commit/acd42b86af5425d799750f0ceb6c529cd17abba6#diff-7d28e4e5cde9c3dc49e562bbf8f1517313d78b8fe37e5fbcef1b55c9374d318f

This issue happen bcoz of the upgrade does not run successfully

To remove this observer from your code. Create an events.xml on your custom module and this module should events depends on Magento_PageCache from module.xml

events.xml code should be:

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
    <event name="maintenance_mode_changed">
        <observer name="page_cache_switcher_for_maintenance"
                  disabled="true" />
    </event>
</config>

using disabled="true" code you can disabled an observer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.