1 config.inc public ConfigDatabaseStorage::importArchive($file_uri)

Import an archive of configuration files into the config storage managed by this object.

Parameters

string $file_uri: The URI of the tar archive file to import.

Return value

bool: TRUE on success, FALSE otherwise.

Throws

ConfigStorageException

Overrides ConfigStorageInterface::importArchive

File

core/includes/config.inc, line 1551
This is the API for configuration storage.

Class

ConfigDatabaseStorage
Defines the database storage controller.

Code

public function importArchive($file_uri) {
  $realpath = backdrop_realpath($file_uri);

  try {
    $archiver = new ArchiverTar($realpath);
    // Only extract JSON files, ignoring anything else in the archive.
    $file_list = preg_grep('/.json$/', $archiver->listContents());
    $temp_directory = file_create_filename('config', file_directory_temp());
    file_prepare_directory($temp_directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);
    if ($file_list) {
      $archiver->extract($temp_directory, $file_list);
      foreach ($file_list as $file) {
        $config_name = basename($file, '.json');
        $file_contents = file_get_contents($temp_directory . '/' . $file);
        $config_data = $this->decode($file_contents);
        $this->write($config_name, $config_data);
      }
    }
    file_unmanaged_delete_recursive($temp_directory);
  }
  catch (\Exception $e) {
    watchdog('config', 'Could not extract the archive @uri: @error', array(
      '@uri' => $file_uri,
      '@error' => $e->getMessage(),
    ), WATCHDOG_ERROR);
    throw new ConfigStorageException($e->getMessage(), 0, $e);
  }
  return TRUE;
}