Skip to content

Commit

Permalink
affected row count
Browse files Browse the repository at this point in the history
  • Loading branch information
Joe Green committed Mar 5, 2015
1 parent 27fc5ff commit 3de3c70
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/DbSync/DbSync.php
Expand Up @@ -48,11 +48,15 @@ protected function diffAndIntersect(array $array, array $only, array $except)
public function compareDatabase(array $onlyTables = array(), array $exceptTables = array(), array $onlySync = array(), array $exceptSync = array(), array $onlyComparison = array(), array $exceptComparison = array(), $where = null)
{
$tables = $this->diffAndIntersect($this->source->showTables(), $onlyTables, $exceptTables);


$affectedRows = 0;

foreach($tables as $table)
{
$this->compareTable($table, $table, $onlySync, $exceptSync, $onlyComparison, $exceptComparison, $where);
$affectedRows += $this->compareTable($table, $table, $onlySync, $exceptSync, $onlyComparison, $exceptComparison, $where);
}

return $affectedRows;
}

public function compareTable($sourcetable, $desttable, array $onlySync = array(), array $exceptSync = array(), array $onlyComparison = array(), array $exceptComparison = array(), $where = null)
Expand All @@ -71,6 +75,8 @@ public function compareTable($sourcetable, $desttable, array $onlySync = array()
}

$this->comparison->setTable($sourcetable, $desttable, $comparisonColumns, $syncColumns, $where);

$affectedRows = 0;

foreach($this->comparison as $row => $select)
{
Expand All @@ -82,12 +88,15 @@ public function compareTable($sourcetable, $desttable, array $onlySync = array()
if($this->execute)
{
$rows = $this->sync->sync($desttable, $select);

$affectedRows += $rows;

$this->output->info("\tExecuted. Rows written: " . intval($rows));
}
}

}

return $affectedRows;
}

private static function buildConnection($connection)
Expand Down

0 comments on commit 3de3c70

Please sign in to comment.