You are here

public function FarmUpdate::rebuild in farmOS 2.x

Rebuild farmOS configuration.

Overrides FarmUpdateInterface::rebuild

File

modules/core/update/src/FarmUpdate.php, line 90

Class

FarmUpdate
Farm update service.

Namespace

Drupal\farm_update

Code

public function rebuild() : void {

  // Get a list of excluded config.
  $exclude_config = $this
    ->getExcludedItems();

  // Build a list of config to revert, without excluded config.
  $revert_config = array_diff($this
    ->getDifferentItems('type', 'system.all'), $exclude_config);

  // Iterate through config items and revert them.
  foreach ($revert_config as $name) {

    // Get the config type and bail if simple configuration.
    // The lister gives NULL if simple configuration.
    $type = $this->configList
      ->getTypeNameByConfigName($name);
    if ($type === NULL) {
      continue;
    }

    // Get the config short name.
    $shortname = $this
      ->getConfigShortname($type, $name);

    // Perform the operation.
    $result = $this->configUpdate
      ->revert($type, $shortname);

    // Log the result.
    if ($result) {
      $this->logger
        ->notice($this
        ->t('Reverted config: @config', [
        '@config' => $name,
      ]));
    }
    else {
      $this->logger
        ->error($this
        ->t('Failed to revert config: @config', [
        '@config' => $name,
      ]));
    }
  }
}