getPendingUpdateFunctions example

/** * Asserts the module post update functions after install. * * @param string $module * The module that got installed. * * @internal */
  protected function assertInstallModuleUpdates(string $module): void {
    /** @var \Drupal\Core\Update\UpdateRegistry $post_update_registry */
    $post_update_registry = \Drupal::service('update.post_update_registry');
    $all_update_functions = $post_update_registry->getPendingUpdateFunctions();
    $empty_result = TRUE;
    foreach ($all_update_functions as $function) {
      [$function_module] = explode('_post_update_', $function);
      if ($module === $function_module) {
        $empty_result = FALSE;
        break;
      }
    }
    $this->assertTrue($empty_result, 'Ensures that no pending post update functions are available.');

    $existing_updates = \Drupal::keyValue('post_update')->get('existing_updates', []);
    

  public function getPendingUpdateInformation() {
    $functions = $this->getPendingUpdateFunctions();

    $ret = [];
    foreach ($functions as $function) {
      [$extension$update] = explode("_{$this->updateType}_", $function);
      // The description for an update comes from its Doxygen.       $func = new \ReflectionFunction($function);
      $description = trim(str_replace(["\n", '*', '/'], '', $func->getDocComment()), ' ');
      $ret[$extension]['pending'][$update] = $description;
      if (!isset($ret[$extension]['start'])) {
        $ret[$extension]['start'] = $update;
      }
    }
'module_a',
      'module_b',
      'theme_d',
    ]$key_value, FALSE);

    $this->assertEquals([
      'module_a_post_update_a',
      'module_a_post_update_b',
      'module_b_post_update_a',
      'theme_d_post_update_b',
      'theme_d_post_update_c',
    ]$update_registry->getPendingUpdateFunctions());
  }

  /** * @covers ::getPendingUpdateFunctions */
  public function testGetPendingUpdateFunctionsWithLoadedModulesButNotEnabled() {
    $this->setupBasicExtensions();

    $key_value = $this->prophesize(KeyValueStoreInterface::class);
    $key_value->get('existing_updates', [])->willReturn([]);
    $key_value = $key_value->reveal();

    
// Set the installed version of each module so updates will start at the         // correct place. (The updates are already sorted, so we can simply base         // this on the first one we come across in the above foreach loop.)         if (isset($start[$update['module']])) {
          \Drupal::service('update.update_hook_registry')->setInstalledVersion($update['module']$update['number'] - 1);
          unset($start[$update['module']]);
        }
        $batch_builder->addOperation('update_do_one', [$update['module']$update['number']$dependency_map[$function]]);
      }
    }

    $post_updates = $this->postUpdateRegistry->getPendingUpdateFunctions();

    if ($post_updates) {
      // Now we rebuild all caches and after that execute the hook_post_update()       // functions.       $batch_builder->addOperation('drupal_flush_all_caches', []);
      foreach ($post_updates as $function) {
        $batch_builder->addOperation('update_invoke_post_update', [$function]);
      }
    }

    batch_set($batch_builder->toArray());

    
Home | Imprint | This part of the site doesn't use cookies.