コード例 #1
0
 /**
  * @param \Drupal\Console\Style\DrupalStyle $io
  */
 private function runPostUpdates(DrupalStyle $io)
 {
     $postUpdates = $this->postUpdateRegistry->getPendingUpdateInformation();
     foreach ($postUpdates as $module_name => $module_updates) {
         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 {
                     $function = sprintf('%s_post_update_%s', $module_name, $update_index);
                     drupal_flush_all_caches();
                     update_invoke_post_update($function);
                 } catch (\Exception $e) {
                     watchdog_exception('update', $e);
                     $io->error($e->getMessage());
                 }
             }
         }
     }
 }
コード例 #2
0
 /**
  * @param \Drupal\Console\Style\DrupalStyle $io
  */
 private function populatePostUpdate(DrupalStyle $io)
 {
     $io->info($this->trans('commands.update.debug.messages.module-list-post-update'));
     $tableHeader = [$this->trans('commands.update.debug.messages.module'), $this->trans('commands.update.debug.messages.post-update'), $this->trans('commands.update.debug.messages.description')];
     $postUpdates = $this->postUpdateRegistry->getPendingUpdateInformation();
     $tableRows = [];
     foreach ($postUpdates as $module => $module_updates) {
         foreach ($module_updates['pending'] as $postUpdateFunction => $message) {
             $tableRows[] = [$module, $postUpdateFunction, $message];
         }
     }
     $io->table($tableHeader, $tableRows);
 }
コード例 #3
0
ファイル: DbUpdateController.php プロジェクト: aWEBoLabs/taxi
 /**
  * Renders a list of available database updates.
  *
  * @param \Symfony\Component\HttpFoundation\Request $request
  *   The current request.
  *
  * @return array
  *   A render array.
  */
 protected function selection(Request $request)
 {
     // Make sure there is no stale theme registry.
     $this->cache->deleteAll();
     $count = 0;
     $incompatible_count = 0;
     $build['start'] = array('#tree' => TRUE, '#type' => 'details');
     // Ensure system.module's updates appear first.
     $build['start']['system'] = array();
     $starting_updates = array();
     $incompatible_updates_exist = FALSE;
     $updates_per_module = [];
     foreach (['update', 'post_update'] as $update_type) {
         switch ($update_type) {
             case 'update':
                 $updates = update_get_update_list();
                 break;
             case 'post_update':
                 $updates = $this->postUpdateRegistry->getPendingUpdateInformation();
                 break;
         }
         foreach ($updates as $module => $update) {
             if (!isset($update['start'])) {
                 $build['start'][$module] = array('#type' => 'item', '#title' => $module . ' module', '#markup' => $update['warning'], '#prefix' => '<div class="messages messages--warning">', '#suffix' => '</div>');
                 $incompatible_updates_exist = TRUE;
                 continue;
             }
             if (!empty($update['pending'])) {
                 $updates_per_module += [$module => []];
                 $updates_per_module[$module] = array_merge($updates_per_module[$module], $update['pending']);
                 $build['start'][$module] = array('#type' => 'hidden', '#value' => $update['start']);
                 // Store the previous items in order to merge normal updates and
                 // post_update functions together.
                 $build['start'][$module] = array('#theme' => 'item_list', '#items' => $updates_per_module[$module], '#title' => $module . ' module');
                 if ($update_type === 'update') {
                     $starting_updates[$module] = $update['start'];
                 }
             }
             if (isset($update['pending'])) {
                 $count = $count + count($update['pending']);
             }
         }
     }
     // Find and label any incompatible updates.
     foreach (update_resolve_dependencies($starting_updates) as $data) {
         if (!$data['allowed']) {
             $incompatible_updates_exist = TRUE;
             $incompatible_count++;
             $module_update_key = $data['module'] . '_updates';
             if (isset($build['start'][$module_update_key]['#items'][$data['number']])) {
                 if ($data['missing_dependencies']) {
                     $text = $this->t('This update will been skipped due to the following missing dependencies:') . '<em>' . implode(', ', $data['missing_dependencies']) . '</em>';
                 } else {
                     $text = $this->t("This update will be skipped due to an error in the module's code.");
                 }
                 $build['start'][$module_update_key]['#items'][$data['number']] .= '<div class="warning">' . $text . '</div>';
             }
             // Move the module containing this update to the top of the list.
             $build['start'] = array($module_update_key => $build['start'][$module_update_key]) + $build['start'];
         }
     }
     // Warn the user if any updates were incompatible.
     if ($incompatible_updates_exist) {
         drupal_set_message($this->t('Some of the pending updates cannot be applied because their dependencies were not met.'), 'warning');
     }
     if (empty($count)) {
         drupal_set_message($this->t('No pending updates.'));
         unset($build);
         $build['links'] = array('#theme' => 'links', '#links' => $this->helpfulLinks($request));
         // No updates to run, so caches won't get flushed later.  Clear them now.
         drupal_flush_all_caches();
     } else {
         $build['help'] = array('#markup' => '<p>' . $this->t('The version of Drupal you are updating from has been automatically detected.') . '</p>', '#weight' => -5);
         if ($incompatible_count) {
             $build['start']['#title'] = $this->formatPlural($count, '1 pending update (@number_applied to be applied, @number_incompatible skipped)', '@count pending updates (@number_applied to be applied, @number_incompatible skipped)', array('@number_applied' => $count - $incompatible_count, '@number_incompatible' => $incompatible_count));
         } else {
             $build['start']['#title'] = $this->formatPlural($count, '1 pending update', '@count pending updates');
         }
         // @todo Simplify with https://www.drupal.org/node/2548095
         $base_url = str_replace('/update.php', '', $request->getBaseUrl());
         $url = (new Url('system.db_update', array('op' => 'run')))->setOption('base_url', $base_url);
         $build['link'] = array('#type' => 'link', '#title' => $this->t('Apply pending updates'), '#attributes' => array('class' => array('button', 'button--primary')), '#weight' => 5, '#url' => $url, '#access' => $url->access($this->currentUser()));
     }
     return $build;
 }
コード例 #4
0
ファイル: UpdateRegistryTest.php プロジェクト: aWEBoLabs/taxi
 /**
  * @covers ::getPendingUpdateInformation
  */
 public function testGetPendingUpdateInformationWithExistingUpdates()
 {
     $this->setupBasicModules();
     $key_value = $this->prophesize(KeyValueStoreInterface::class);
     $key_value->get('existing_updates', [])->willReturn(['module_a_post_update_a']);
     $key_value = $key_value->reveal();
     $update_registry = new UpdateRegistry('vfs://drupal', 'sites/default', ['module_a', 'module_b'], $key_value, FALSE);
     $expected = [];
     $expected['module_a']['pending']['b'] = 'Module A update B.';
     $expected['module_a']['start'] = 'b';
     $expected['module_b']['pending']['a'] = 'Module B update A.';
     $expected['module_b']['start'] = 'a';
     $this->assertEquals($expected, $update_registry->getPendingUpdateInformation());
 }