Skip to content
Snippets Groups Projects
Commit 16ddf1bf authored by liliancatanoi90's avatar liliancatanoi90 Committed by Alex Andrascu
Browse files

Issue #2945253 by liliancatanoi90, mlahde, Dinu Rodnitchi: Restoring wrong...

Issue #2945253 by liliancatanoi90, mlahde, Dinu Rodnitchi: Restoring wrong type of file gives "Restore Complete."
parent fce6019c
No related branches found
No related tags found
No related merge requests found
......@@ -147,7 +147,10 @@ class BackupMigrate implements BackupMigrateInterface {
$file = $this->plugins()->call('beforeRestore', $file);
// Do the actual source restore.
$source->importFromFile($file);
$import_result = $source->importFromFile($file);
if(!$import_result) {
throw new BackupMigrateException('The file could not be imported.');
}
// Run each of the installed plugins which implements the 'beforeBackup' operation.
$this->plugins()->call('afterRestore');
......
......@@ -5,7 +5,7 @@ namespace Drupal\backup_migrate\Plugin\BackupMigrateSource;
use BackupMigrate\Core\Config\Config;
use BackupMigrate\Core\Filter\DBExcludeFilter;
use BackupMigrate\Core\Main\BackupMigrateInterface;
use BackupMigrate\Core\Source\MySQLiSource;
use BackupMigrate\Drupal\Source\DrupalMySQLiSource;
use BackupMigrate\Drupal\EntityPlugins\SourcePluginBase;
/**
......@@ -37,7 +37,7 @@ class DefaultDBSourcePlugin extends SourcePluginBase {
foreach ($info as $key => $value) {
$conf->set($key, $value);
}
return new MySQLiSource($conf);
return new DrupalMySQLiSource($conf);
}
return NULL;
......
......@@ -3,7 +3,7 @@
namespace Drupal\backup_migrate\Plugin\BackupMigrateSource;
use BackupMigrate\Core\Config\Config;
use BackupMigrate\Core\Source\MySQLiSource;
use BackupMigrate\Drupal\Source\DrupalMySQLiSource;
use BackupMigrate\Core\Main\BackupMigrateInterface;
use BackupMigrate\Drupal\EntityPlugins\SourcePluginBase;
use BackupMigrate\Drupal\Source\DrupalSiteArchiveSource;
......@@ -34,7 +34,7 @@ class EntireSiteSourcePlugin extends SourcePluginBase {
if ($info['driver'] == 'mysql') {
$conf = $this->getConfig();
$conf->set('directory', DRUPAL_ROOT);
$this->db_source = new MySQLiSource(new Config($info));
$this->db_source = new DrupalMySQLiSource(new Config($info));
return new DrupalSiteArchiveSource($conf, $this->db_source);
}
......
<?php
namespace BackupMigrate\Drupal\Source;
use BackupMigrate\Core\Config\Config;
use BackupMigrate\Core\Source\MySQLiSource;
use BackupMigrate\Core\File\BackupFileReadableInterface;
/**
* Class DrupalMySQLiSource.
*
* @package BackupMigrate\Drupal\Source
*/
class DrupalMySQLiSource extends MySQLiSource {
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)) {
// if (_backup_migrate_check_timeout()) {
// return FALSE;
// }
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;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment