doSyncStep example


  public function import() {
    if ($this->hasUnprocessedConfigurationChanges()) {
      $sync_steps = $this->initialize();

      foreach ($sync_steps as $step) {
        $context = [];
        do {
          $this->doSyncStep($step$context);
        } while ($context['finished'] < 1);
      }
    }
    return $this;
  }

  /** * Calls a config import step. * * @param string|callable $sync_step * The step to do. Either a method on the ConfigImporter class or a * callable. * @param array $context * A batch context array. If the config importer is not running in a batch * the only array key that is used is $context['finished']. A process needs * to set $context['finished'] = 1 when it is done. * * @throws \InvalidArgumentException * Exception thrown if the $sync_step can not be called. */
$this->assertTrue($state['entity_state::delete'], 'ConfigEntity::isSyncing() returns TRUE');
  }

  /** * Tests that the isConfigSyncing flag is cleanup after an invalid step. */
  public function testInvalidStep() {
    $this->assertFalse(\Drupal::isConfigSyncing(), 'Before an import \Drupal::isConfigSyncing() returns FALSE');
    $context = [];
    $config_importer = $this->configImporter();
    try {
      $config_importer->doSyncStep('a_non_existent_step', $context);
      $this->fail('Expected \InvalidArgumentException thrown');
    }
    catch (\InvalidArgumentException $e) {
      // Expected exception; just continue testing.     }
    $this->assertFalse(\Drupal::isConfigSyncing(), 'After an invalid step \Drupal::isConfigSyncing() returns FALSE');
  }

  /** * Tests that the isConfigSyncing flag is set correctly during a custom step. */
  

  public static function process(ConfigImporter $config_importer$sync_step, &$context) {
    if (!isset($context['sandbox']['config_importer'])) {
      $context['sandbox']['config_importer'] = $config_importer;
    }

    $config_importer = $context['sandbox']['config_importer'];
    $config_importer->doSyncStep($sync_step$context);
    if ($errors = $config_importer->getErrors()) {
      if (!isset($context['results']['errors'])) {
        $context['results']['errors'] = [];
      }
      $context['results']['errors'] = array_merge($errors$context['results']['errors']);
    }
  }

  /** * Finish batch. * * This function is a static function to avoid serializing the ConfigSync * object unnecessarily. * * @param bool $success * Indicate that the batch API tasks were all completed successfully. * @param array $results * An array of all the results that were updated in update_do_one(). * @param array $operations * A list of the operations that had not been completed by the batch API. */
Home | Imprint | This part of the site doesn't use cookies.