Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove old database object #21

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions src/ExportModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,13 @@ class ExportModel
*/
protected DbFactory $database;

/**
* Source connection for the export step.
*
* @var ConnectionManager
*/
protected ConnectionManager $exportSourceCM;

/**
* Source connection for the import step.
*
Expand All @@ -98,15 +105,23 @@ class ExportModel
* @param $storage
* @param ConnectionManager $importSourceCM
*/
public function __construct($db, $map, $storage, ConnectionManager $importSourceCM)
public function __construct($exportSourceCM, $map, $storage, ConnectionManager $importSourceCM)
{
$this->database = $db;
$this->mapStructure = $map;
$this->storage = $storage;

$exportSourceCM->newConnection();
$importSourceCM->newConnection();

$this->exportSourceCM = $exportSourceCM;
$this->importSourceCM = $importSourceCM;
}

public function dbExport(): Connection
{
return $this->exportSourceCM->connection();
}

/**
* Provide the import database.
*
Expand Down Expand Up @@ -211,13 +226,8 @@ public function export(string $tableName, string $query, array $map = [], array
return;
}

// Do the export.
$query = $this->processQuery($query);
$data = $this->executeQuery($query); // @todo Use new db layer.
if (empty($data)) {
$this->comment("Error: No data found in $tableName.");
return;
}
$data = $this->exportSourceCM->connection()->raw($query);

$structure = $this->mapStructure[$tableName];

Expand Down
5 changes: 1 addition & 4 deletions src/Functions/core.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,8 @@ function exportModelFactory(
Storage $storage,
ConnectionManager $importSourceCM
): ExportModel {
// Wire old database / model mess.
$info = $exportSourceCM->getAllInfo();
$db = new DbFactory($info, 'pdo');
$map = loadStructure();
$model = new ExportModel($db, $map, $storage, $importSourceCM);
$model = new ExportModel($exportSourceCM, $map, $storage, $importSourceCM);

// Set model properties.
$model->srcPrefix = $request->get('src-prefix') ?? '';
Expand Down