You are here

public function BackupDatabaseLocalAdapter::export in Backup Database 8

@inherit

Overrides BackupDatabaseAdapterInterface::export

File

src/Adapter/BackupDatabaseLocalAdapter.php, line 33
Contains \Drupal\backup_db\Adapter\BackupDatabaseLocalAdapter

Class

BackupDatabaseLocalAdapter
BackupDatabaseLocalAdapter class.

Namespace

Drupal\backup_db\Adapter

Code

public function export() {
  $handler = $this->client
    ->getFileHandler();
  $handler
    ->setupFile($this->client
    ->getSettings());
  $file = $handler
    ->getFile();
  $user = \Drupal::currentUser();

  // Create a file entity.
  $entity = entity_create('file', array(
    'uri' => $file
      ->getFileUri(),
    'uid' => $user
      ->id(),
    'status' => FILE_STATUS_PERMANENT,
  ));
  $entity
    ->save();

  // Insert history entry.
  if ($entity
    ->id()) {
    backup_db_history_insert(array(
      'fid' => $entity
        ->id(),
      'name' => $file
        ->getFileName(),
      'uri' => $file
        ->getFileUri(),
    ));
    $export = $this->client
      ->dump();
    $export
      ->start($file
      ->getFileUri());
  }
  else {
    \Drupal::logger('backup_db')
      ->error('File entity could not be created.');
  }
  return $entity
    ->id();
}