You are here

class ConfigurationUpdateGenerator in Update helper 8

Same name in this branch
  1. 8 src/Generator/ConfigurationUpdateGenerator.php \Drupal\update_helper\Generator\ConfigurationUpdateGenerator
  2. 8 modules/update_helper_checklist/src/Generator/ConfigurationUpdateGenerator.php \Drupal\update_helper_checklist\Generator\ConfigurationUpdateGenerator

Configuration update generator for generate:configuration:update command.

@package Drupal\update_helper\Generator

Hierarchy

Expanded class hierarchy of ConfigurationUpdateGenerator

1 file declares its use of ConfigurationUpdateGenerator
GenerateConfigurationUpdateCommand.php in src/Command/GenerateConfigurationUpdateCommand.php
1 string reference to 'ConfigurationUpdateGenerator'
console.services.yml in ./console.services.yml
console.services.yml
1 service uses ConfigurationUpdateGenerator
update_helper.update_generator in ./console.services.yml
Drupal\update_helper\Generator\ConfigurationUpdateGenerator

File

src/Generator/ConfigurationUpdateGenerator.php, line 15

Namespace

Drupal\update_helper\Generator
View source
class ConfigurationUpdateGenerator extends Generator {

  /**
   * Drupal\update_helper\ConfigHandler definition.
   *
   * @var \Drupal\update_helper\ConfigHandler
   */
  protected $configHandler;

  /**
   * Drupal\Core\Extension\ModuleHandler definition.
   *
   * @var \Drupal\Core\Extension\ModuleHandler
   */
  protected $moduleHandler;

  /**
   * Configuration update generator.
   *
   * @param \Drupal\update_helper\ConfigHandler $config_handler
   *   Config handler service.
   * @param \Drupal\Core\Extension\ModuleHandler $module_handler
   *   Module handler service.
   */
  public function __construct(ConfigHandler $config_handler, ModuleHandler $module_handler) {
    $this->configHandler = $config_handler;
    $this->moduleHandler = $module_handler;
  }

  /**
   * Get update hook function name.
   *
   * @param string $module_name
   *   Module name.
   * @param string $update_number
   *   Update number.
   *
   * @return string
   *   Returns update hook function name.
   */
  protected function getUpdateFunctionName($module_name, $update_number) {
    return $module_name . '_update_' . $update_number;
  }

  /**
   * Generate patch file for listed modules in module defined for command.
   *
   * @param string $module_name
   *   Module name where patch will be placed.
   * @param string $update_number
   *   Update number that will be used.
   * @param string $module_list
   *   Comma separated list of modules.
   * @param bool $from_active
   *   Flag if configuration should be updated from active to Yml file configs.
   *
   * @return bool
   *   Return if patch file is generated.
   */
  public function generate($module_name, $update_number, $module_list, $from_active) {
    if ($module_list) {
      $modules = explode(',', $module_list);
    }
    else {
      $modules = array_filter($this->moduleHandler
        ->getModuleList(), function (Extension $extension) {
        return $extension
          ->getType() == 'module';
      });
      $modules = array_keys($modules);
    }

    // Get patch data and save it into file.
    $patch_data = $this->configHandler
      ->generatePatchFile($modules, $from_active);
    if (!empty($patch_data)) {
      $patch_file_path = $this->configHandler
        ->getPatchFile($module_name, $this
        ->getUpdateFunctionName($module_name, $update_number), TRUE);
      if (file_put_contents($patch_file_path, $patch_data)) {
        $this->fileQueue
          ->addFile($patch_file_path);
        $new_code_line = count(file($patch_file_path));
        $this->countCodeLines
          ->addCountCodeLines($new_code_line);
        return TRUE;
      }
    }
    return FALSE;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ConfigurationUpdateGenerator::$configHandler protected property Drupal\update_helper\ConfigHandler definition.
ConfigurationUpdateGenerator::$moduleHandler protected property Drupal\Core\Extension\ModuleHandler definition.
ConfigurationUpdateGenerator::generate public function Generate patch file for listed modules in module defined for command.
ConfigurationUpdateGenerator::getUpdateFunctionName protected function Get update hook function name.
ConfigurationUpdateGenerator::__construct public function Configuration update generator.