/** * @param \Drupal\Console\Style\DrupalStyle $io * @param $updates */ private function runUpdates(DrupalStyle $io, $updates) { foreach ($updates as $module_name => $module_updates) { $modulePath = $this->getApplication()->getSite()->getModulePath($this->module); $this->site->loadLegacyFile($modulePath . '/' . $this->module . '.install', false); foreach ($module_updates['pending'] as $update_number => $update) { if ($this->module != 'all' && $this->update_n !== null && $this->update_n != $update_number) { continue; } if ($this->update_n > $module_updates['start']) { $io->info($this->trans('commands.update.execute.messages.executing-required-previous-updates')); } for ($update_index = $module_updates['start']; $update_index <= $update_number; $update_index++) { $io->info(sprintf($this->trans('commands.update.execute.messages.executing-update'), $update_index, $module_name)); try { $this->moduleHandler->invoke($module_name, 'update_' . $update_index); } catch (\Exception $e) { watchdog_exception('update', $e); $io->error($e->getMessage()); } drupal_set_installed_schema_version($module_name, $update_index); } } } }
/** * Test invoke methods when module is enabled. * * @covers ::invoke */ public function testInvokeModuleEnabled() { $this->assertTrue($this->moduleHandler->invoke('module_handler_test', 'hook', array(TRUE)), 'Installed module runs hook.'); $this->assertFalse($this->moduleHandler->invoke('module_handler_test', 'hook', array(FALSE)), 'Installed module runs hook.'); $this->assertNull($this->moduleHandler->invoke('module_handler_test_fake', 'hook', array(FALSE)), 'Installed module runs hook.'); }