extractList example


  public function submitForm(array &$form, FormStateInterface $form_state) {
    if ($path = $form_state->getValue('import_tarball')) {
      $this->configStorage->deleteAll();
      try {
        $archiver = new ArchiveTar($path, 'gz');
        $files = [];
        foreach ($archiver->listContent() as $file) {
          $files[] = $file['filename'];
        }
        $archiver->extractList($files$this->settings->get('config_sync_directory'), '', FALSE, FALSE);
        $this->messenger()->addStatus($this->t('Your configuration files were successfully uploaded and are ready for import.'));
        $form_state->setRedirect('config.sync');
      }
      catch (\Exception $e) {
        $this->messenger()->addError($this->t('Could not extract the contents of the tar file. The error message is <em>@message</em>', ['@message' => $e->getMessage()]));
      }
      $this->fileSystem->unlink($path);
    }
  }

}
    // creating a new archive with everything but the removed     // file.
    return $this;
  }

  /** * {@inheritdoc} */
  public function extract($path, array $files = []) {
    if ($files) {
      $this->tar->extractList($files$path, '', FALSE, FALSE);
    }
    else {
      $this->tar->extract($path, FALSE, FALSE);
    }

    return $this;
  }

  /** * {@inheritdoc} */
  
file_put_contents("$path/{$this->profile}.info.yml", Yaml::encode($info));

    // Create config/sync directory and extract tarball contents to it.     mkdir($config_sync_directory, 0777, TRUE);
    $files = [];
    $list = $archiver->listContent();
    if (is_array($list)) {
      /** @var array $list */
      foreach ($list as $file) {
        $files[] = $file['filename'];
      }
      $archiver->extractList($files$config_sync_directory);
    }

    // Add the module that is providing the database driver to the list of     // modules that can not be uninstalled in the core.extension configuration.     if (file_exists($config_sync_directory . '/core.extension.yml')) {
      $core_extension = Yaml::decode(file_get_contents($config_sync_directory . '/core.extension.yml'));
      $module = Database::getConnection()->getProvider();
      if ($module !== 'core') {
        $core_extension['module'][$module] = 0;
        $core_extension['module'] = module_config_sort($core_extension['module']);
        file_put_contents($config_sync_directory . '/core.extension.yml', Yaml::encode($core_extension));
      }
Home | Imprint | This part of the site doesn't use cookies.