/** * 1. Run dependent modules upgrades * 2. Run module upgrades on installed stores * 3. Run module upgrades on new stores * * @return void */ public function up() { $oldStores = $this->module->getOldStores(); $newStores = $this->module->getNewStores(); if (!count($oldStores) && !count($newStores)) { return; } foreach ($this->module->getDepends() as $moduleCode) { if (0 !== strpos($moduleCode, 'Swissup')) { continue; } $this->getModuleObject($moduleCode)->up(); } $saved = false; // upgrade currently installed version to the latest data_version if (count($oldStores)) { foreach ($this->getUpgradesToRun() as $version => $filename) { $this->resolve($filename)->setStoreIds($oldStores)->upgrade(); $this->module->setDataVersion($version)->save(); $saved = true; } } // install module to the new stores if (count($newStores)) { foreach ($this->getUpgradesToRun(0) as $version => $filename) { $this->resolve($filename)->setStoreIds($newStores)->upgrade(); $this->module->setDataVersion($version)->save(); $saved = true; } } if (!$saved) { $this->module->save(); } }