You are here

public function DrupalMySQLiSource::importFromFile in Backup and Migrate 5.0.x

Import to this source from the given backup file.

This is the main restore function for this source.

Parameters

\Drupal\backup_migrate\Core\File\BackupFileReadableInterface $file: The file to read the backup from. It will not be opened for reading.

Return value

bool|int

Overrides MySQLiSource::importFromFile

File

src/Drupal/Source/DrupalMySQLiSource.php, line 18

Class

DrupalMySQLiSource
@package Drupal\backup_migrate\Drupal\Source

Namespace

Drupal\backup_migrate\Drupal\Source

Code

public function importFromFile(BackupFileReadableInterface $file) {
  $num = 0;
  if ($conn = $this
    ->_getConnection()) {

    // Open (or rewind) the file.
    $file
      ->openForRead();

    // Read one line at a time and run the query.
    while ($line = $this
      ->_readSqlCommand($file)) {

      // @todo Why was this commented out?
      // @code
      // if (_backup_migrate_check_timeout()) {
      //   return FALSE;
      // }
      // @endcode
      if ($line) {

        // Execute the sql query from the file.
        $stmt = $conn
          ->prepare($line);
        if (!$stmt) {
          return FALSE;
        }
        $stmt
          ->execute();
        $num++;
      }
    }

    // Close the file, we're done reading it.
    $file
      ->close();
  }
  return $num;
}