2

I'm confused on what those 2 methods does. I have a code like:

public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
{
    $setup->startSetup();

    $eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);
    ...
    ...
    $setup->endSetup();
}

Could someone explain that to me?

why do I need to call a function from an interface?

What's the purpose of it?

Thanks for any help.

1 Answer 1

2

As you can see, it just setting additional settings before you starting setup:

Magento\Framework\DB\Adapter\Pdo\Mysql

/**
 * Run additional environment before setup
 *
 * @return $this
 */
public function startSetup()
{
    $this->rawQuery("SET SQL_MODE=''");
    $this->rawQuery("SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0");
    $this->rawQuery("SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO'");

    return $this;
}

and than reverts it back:

/**
 * Run additional environment after setup
 *
 * @return $this
 */
public function endSetup()
{
    $this->rawQuery("SET SQL_MODE=IFNULL(@OLD_SQL_MODE,'')");
    $this->rawQuery("SET FOREIGN_KEY_CHECKS=IF(@OLD_FOREIGN_KEY_CHECKS=0, 0, 1)");

    return $this;
}
9
  • Thank you very much. Could you also tell me how $setup->startSetup(); reaches it's function if I'm calling an interface function? I really don't get it... :(
    – HELPME
    Commented Aug 16, 2018 at 8:37
  • @HELPME If you are using an interfaces in the __construct method the dependency injection works. It uses the ObjectManager class to locate corresponding class (for the specified interface) and adding this class. Commented Aug 16, 2018 at 8:38
  • And if I'm not using an interface in my __construct method? I have only eavSetupFactory, here..
    – HELPME
    Commented Aug 16, 2018 at 8:41
  • @HELPME You can obtain more info by inspecting the Magento\Framework\ObjectManager\ObjectManager class code. Specially the code of the methods create and get Commented Aug 16, 2018 at 8:41
  • @HELPME The install method of your module with all arguments has been called from the core magento installer, where this interface was specified in the constructor. By this way you can use the interface as an object in you code. Commented Aug 16, 2018 at 8:45

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.