update_resolve_dependencies example

if ($update_type === 'update') {
            $starting_updates[$extension] = $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.");
          }
          
protected function setUp(): void {
    // Only install update_test_2.module, even though its updates have a     // dependency on update_test_3.module.     parent::setUp();
    require_once $this->root . '/core/includes/update.inc';
  }

  public function testMissingUpdate() {
    $starting_updates = [
      'update_test_2' => 8001,
    ];
    $update_graph = update_resolve_dependencies($starting_updates);
    $this->assertTrue($update_graph['update_test_2_update_8001']['allowed'], "The module's first update function is allowed to run, since it does not have any missing dependencies.");
    $this->assertFalse($update_graph['update_test_2_update_8002']['allowed'], "The module's second update function is not allowed to run, since it has a direct dependency on a missing update.");
    $this->assertFalse($update_graph['update_test_2_update_8003']['allowed'], "The module's third update function is not allowed to run, since it has an indirect dependency on a missing update.");
  }

}

  public function testUpdateOrderingSingleModule() {
    $starting_updates = [
      'update_test_1' => 8001,
    ];
    $expected_updates = [
      'update_test_1_update_8001',
      'update_test_1_update_8002',
      'update_test_1_update_8003',
    ];
    $actual_updates = array_keys(update_resolve_dependencies($starting_updates));
    $this->assertEquals($expected_updates$actual_updates, 'Updates within a single module run in the correct order.');
  }

  /** * Tests that dependencies between modules are resolved correctly. */
  public function testUpdateOrderingModuleInterdependency() {
    $starting_updates = [
      'update_test_2' => 8001,
      'update_test_3' => 8001,
    ];
    
Home | Imprint | This part of the site doesn't use cookies.