I am using php shell_exec method to run the magento commands in my controller.
Below is my controller code.
<?php
namespace Vendor\Module\Controller\Adminhtml\Migrate;
use Psr\Log\LoggerInterface;
class Index extends \Magento\Backend\App\Action
{
protected $resultPageFactory;
protected $migrationHelper;
protected $logger;
public function __construct(
\Magento\Backend\App\Action\Context $context,
\Magento\Framework\View\Result\PageFactory $resultPageFactory,
LoggerInterface $logger
) {
$this->resultPageFactory = $resultPageFactory;
$this->logger = $logger;
parent::__construct($context);
}
/**
* Execute view action
*
* @return \Magento\Framework\Controller\ResultInterface
*/
public function execute()
{
$commandCache = "php bin/magento cache:enable";
shell_exec($commandCache);
try{
$m2version = 2.3.4;
$commandRepo = "composer config repositories.magento composer https://repo.magento.com";
$this->logger->info('--commandRepo--'.$commandRepo);
shell_exec($commandRepo);
$commandVersion = "composer require magento/data-migration-tool:".$m2version;
shell_exec($commandVersion);
}catch(\Exception $e){
$this->logger->info('--exception--'.json_encode($e->getMessage()));
}
}
}
In the above code, cache enable command is working, but I am downloading data-migration tool using composer, but that command is not working, if I run the command manually in shell prompt, its working.
Is there anything else I have to make change?
Can someone please help me on this. Thanks in advance!!