My Client wants me to write code to :
- programmatically upload a customized module and then
- enable the module(
php bin/magento module:enable VENDORNAME_MODULENAME) and then - upgrade the system(
php bin/magento setup:upgrade).
I successfully did the first 2 steps, but unable to do the 3rd one. Can anyone share sample code to programmatically run setup upgrade in Magento 2?
<?php use Magento\Framework\App\Bootstrap; include('../app/bootstrap.php'); $bootstrap = Bootstrap::create(BP, $_SERVER); $objectManager = $bootstrap->getObjectManager(); $modules = array('VENDORNAME_MODULENAME'); try{ // Code to enable the module $objectManager->create('Magento\Framework\Module')->setIsEnabled(true,$modules); // Code to setup upgrade(php bin/magento setup:upgrade) ....... }catch(Exception $e){ $msg = 'Error : '.$e->getMessage();die(); }