/** * {@inheritdoc} */ public function extract($path, array $files = array()) { if ($files) { $this->tar->extractList($files, $path); } else { $this->tar->extract($path); } return $this; }
/** * {@inheritdoc} */ protected function setUpSyncForm() { // Create a new sync directory. drupal_mkdir($this->sync_dir); // Extract the tarball into the sync directory. $archiver = new ArchiveTar($this->tarball, 'gz'); $files = array(); foreach ($archiver->listContent() as $file) { $files[] = $file['filename']; } $archiver->extractList($files, $this->sync_dir); // Change the user.settings::register so that we can test that // standard_install() does not override it. $sync = new FileStorage($this->sync_dir); $user_settings = $sync->read('user.settings'); $user_settings['register'] = USER_REGISTER_ADMINISTRATORS_ONLY; $sync->write('user.settings', $user_settings); $this->drupalPostForm(NULL, array('sync_directory' => drupal_realpath($this->sync_dir)), 'Save and continue'); }
/** * {@inheritdoc} */ 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 = array(); foreach ($archiver->listContent() as $file) { $files[] = $file['filename']; } $archiver->extractList($files, config_get_config_directory(CONFIG_STAGING_DIRECTORY)); drupal_set_message($this->t('Your configuration files were successfully uploaded, ready for import.')); $form_state->setRedirect('config.sync'); } catch (\Exception $e) { drupal_set_message($this->t('Could not extract the contents of the tar file. The error message is <em>@message</em>', array('@message' => $e->getMessage())), 'error'); } drupal_unlink($path); } }
/** * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { global $config_directories, $install_state; $sync_directory = $form_state->getValue('sync_directory'); if ($sync_directory != config_get_config_directory(CONFIG_SYNC_DIRECTORY)) { $settings['config_directories'][CONFIG_SYNC_DIRECTORY] = (object) array('value' => $sync_directory, 'required' => TRUE); drupal_rewrite_settings($settings); $config_directories[CONFIG_SYNC_DIRECTORY] = $sync_directory; } if ($path = $form_state->getValue('import_tarball')) { // Ensure that we have an empty directory if we're going. $sync = new FileStorage($sync_directory); $sync->deleteAll(); try { $archiver = new ArchiveTar($path, 'gz'); $files = array(); foreach ($archiver->listContent() as $file) { $files[] = $file['filename']; } $archiver->extractList($files, config_get_config_directory(CONFIG_SYNC_DIRECTORY)); drupal_set_message($this->t('Your configuration files were successfully uploaded, ready for import.')); } catch (\Exception $e) { drupal_set_message($this->t('Could not extract the contents of the tar file. The error message is <em>@message</em>', array('@message' => $e->getMessage())), 'error'); } drupal_unlink($path); } // Change the langcode to the site default langcode provided by the // configuration. $config_storage = new FileStorage(config_get_config_directory(CONFIG_SYNC_DIRECTORY)); $install_state['parameters']['langcode'] = $config_storage->read('system.site')['langcode']; }