0

In Magento 1, we could simply,

umask(0);
Mage::app('default');
Mage::getSingleton('core/session', array('name' => 'frontend'));

if (empty($sessionCustomer)) {
  $sessionCustomer = Mage::getSingleton("customer/session");
  myLog("Tried to get session.\n");
}

$eml = $sessionCustomer->getCustomer()->getEmail();

In Magento 2, we are supposed to do this,

function getCustomerId() {
    require __Dir__ . '/app/bootstrap.php';
    $bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $_SERVER);
    myLog("Ready to createApplication()\n"); // This logs
    $app = $bootstrap->createApplication('GetMageEml');
    myLog("Returned GetMageEml app\n"); // This doesn't log
    return $bootstrap->run($app);
}

So the code silently fails on

    $app = $bootstrap->createApplication('GetMageEml');

I'm running all of this from root directory of Magento which is one directory above bootstrap.php.

I have tried many code combinations in GetMageEml.php, but $bootstrap->createApplication() was never successful. My current version of GetMageEml.php is,

<?php
use Magento\Framework\App\Helper\AbstractHelper;
protected $objectManager;
protected $customerSession;

class GetMageEml extends \Magento\Framework\App\Helper\AbstractHelper {

    public function __construct(
        \Magento\Framework\ObjectManagerInterface $objectManager,
            \Psr\Log\LoggerInterface $logger
    ) {
            $this->logger = $logger;
            $this->objectManager = $objectManager; 
            $this->customerSession = $this->objectManager->create('Magento\Customer\Model\SessionFactory')->create();
    }

    public function getCustomerSession()
    {
       return $this->customerSession;     
    }

    public function launch() {
        $this->logger->debug("Test whether the AIO logger is functional\n");
        $customer = $this->_customerSession->create();
        return array($customer->getCustomer()->getEmail(), $this->getCustomerSession()->isLoggedIn());
    }   
}
?> 

So I have 2 questions. The first question is whether the failure of

$app = $bootstrap->createApplication('GetMageEml');

is logged somewhere. It is not logged in the Apache log, my log, or the logs at Dir . /var/log that Magento uses. When something like this fails, you would think it logs somewhere. Where is that log?

The second question, is why does the line,

$app = $bootstrap->createApplication('GetMageEml');

fail?

//********************* Update *****************************

The system had no logging because it was missing the line,

require '/var/www/html/magento2/GetMageEml.php';

With logging, it almost worked, but the class injection had constant context issues according the apache log. I tried about 50 things to try to fix this. Then I found instructions that said when the class injection was changed that the command,

php bin/magento setup:di:compile

needed to be run. The command ran fine, and it said that it completed successfully. Yet, it completely ruined the shopping cart in that both the frontend and backend have the error,

Permission denied in /var/www/html/magento2/vendor/colinmollenhour/cache-backend-file/File.php on line 663

Neither the admin or shopping cart displays. Both the shopping cart and admin fail with the same error.

I'll probably go back to Magento 1 which seems more stable.

2 Answers 2

0

It might create an Issue because you are using

$this->_customerSession and in constructor you are passing $this->customerSession

and still, If it creates an issue put ini_set('display_errors', 1); in your script and check you will get some exception

0

In Bootstrap you have

public function createApplication($type, $arguments = [])
{
    try {
        $this->initObjectManager();
        $application = $this->objectManager->create($type, $arguments);
        if (!($application instanceof AppInterface)) {
            throw new \InvalidArgumentException("The provided class doesn't implement AppInterface: {$type}");
        }
        return $application;
    } catch (\Exception $e) {
        $this->terminate($e);
    }
}

And the APP that you want to create is defined as

class GetMageEml extends \Magento\Framework\App\Helper\AbstractHelper

as neither implements Magento\Framework\AppInterface I would expect this to fail at the instanceof check inside the createApplication method.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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