Creating an upgrade data script (UpgradeData.php)

The upgrade data script is the last one to execute. We will use it to demonstrate the example of creating the sample entries for our Department and Employee entities.

We start by creating the app/code/Foggyline/Office/Setup/UpgradeData.php file with (partial) content as follows:

namespace Foggyline\Office\Setup; use Magento\Framework\Setup\UpgradeDataInterface; use Magento\Framework\Setup\ModuleContextInterface; use Magento\Framework\Setup\ModuleDataSetupInterface; class UpgradeData implements UpgradeDataInterface { protected $departmentFactory; protected $employeeFactory; public function __construct( \Foggyline\Office\Model\DepartmentFactory $departmentFactory, \Foggyline\Office\Model\EmployeeFactory ...

Get Magento 2 Developer's Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.