You are here

public function MySQLiSource::exportToFile in Backup and Migrate 5.0.x

Export this source to the given temp file.

This should be the main back up function for this source.

Return value

\Drupal\backup_migrate\Core\File\BackupFileReadableInterface A backup file with the contents of the source dumped to it.

Overrides SourceInterface::exportToFile

File

src/Core/Source/MySQLiSource.php, line 47

Class

MySQLiSource
@package Drupal\backup_migrate\Core\Source

Namespace

Drupal\backup_migrate\Core\Source

Code

public function exportToFile() {
  if ($connection = $this
    ->_getConnection()) {
    $adapter = new DrupalTempFileAdapter(\Drupal::service('file_system'));
    $tempfilemanager = new TempFileManager($adapter);
    $this
      ->setTempFileManager($tempfilemanager);
    $file = $this
      ->getTempFileManager()
      ->create('mysql');
    $exclude = (array) $this
      ->confGet('exclude_tables');
    $nodata = (array) $this
      ->confGet('nodata_tables');
    $file
      ->write($this
      ->_getSqlHeader());
    $tables = $this
      ->getRawTables();
    $lines = 0;
    foreach ($tables as $table) {

      // @todo reenable this.
      // @code
      // if (_backup_migrate_check_timeout()) {
      //   return FALSE;
      // }
      // @endcode
      $table = $this
        ->plugins()
        ->call('beforeDbTableBackup', $table, [
        'source' => $this,
      ]);
      if ($table['name'] && !isset($exclude[$table['name']]) && empty($table['exclude'])) {
        $file
          ->write($this
          ->_getTableCreateSql($table));
        $lines++;
        if (empty($table['nodata']) && !in_array($table['name'], $nodata)) {
          $lines += $this
            ->_dumpTableSqlToFile($file, $table);
        }
      }
    }
    $file
      ->write($this
      ->_getSqlFooter());
    $file
      ->close();
    return $file;
  }
  else {

    // @todo Throw exception.
    return $this
      ->getTempFileManager()
      ->create('mysql');
  }
}