The InstallData script

The InstallData script is used when we wish to add new data to existing tables. This script is run only when a module is enabled. Once enabled, the module gets a corresponding entry under the setup_module.data_version table column. This entry prevents the InstallData script to run on any subsequent setup:upgrade command execution, where the module's setup_version remains the same.

Let's create the <MAGELICIOUS_DIR>/Core/Setup/InstallData.php file with the following content:

use MagentoFrameworkSetupInstallDataInterface;
use MagentoFrameworkSetupModuleContextInterface;
use MagentoFrameworkSetupModuleDataSetupInterface;

class InstallData implements InstallDataInterface {
public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context) {
$setup->startSetup();
echo 'InstallData->install()' . PHP_EOL;
$setup->endSetup();
}
}

Chances are, we will be interacting with this type of script more often than not. Replacing the echo line with modified pieces of the equivalent Magento InstallData script might give us a better understanding of the possibilities behind these scripts.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.140.185.147