You are here

public function MySQLiSource::exportToFile in Backup and Migrate 8.4

Export this source to the given temp file. This should be the main back up function for this source.

Return value

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

Overrides SourceInterface::exportToFile

File

lib/backup_migrate_core/src/Source/MySQLiSource.php, line 42

Class

MySQLiSource
Class MySQLiSource.

Namespace

BackupMigrate\Core\Source

Code

public function exportToFile() {
  if ($connection = $this
    ->_getConnection()) {
    $file = $this
      ->getTempFileManager()
      ->create('mysql');
    $exclude = (array) $this
      ->confGet('exclude_tables');
    $nodata = (array) $this
      ->confGet('nodata_tables');
    $file
      ->write($this
      ->_getSQLHeader());
    $tables = $this
      ->_getTables();
    $lines = 0;
    foreach ($tables as $table) {

      // @TODO reenable this.
      //        if (_backup_migrate_check_timeout()) {
      //          return FALSE;
      //        }
      $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');
  }
}