diff --git a/src/Interfaces/SourceInterface.php b/src/Interfaces/SourceInterface.php index 8b64d68..0f8e247 100644 --- a/src/Interfaces/SourceInterface.php +++ b/src/Interfaces/SourceInterface.php @@ -5,6 +5,8 @@ interface SourceInterface { public function getDataRows($page = 1, $fieldsToRetrieve = []); + public function countDataRows(); + public function getFields(); } diff --git a/src/Objects/Migrator.php b/src/Objects/Migrator.php index c144c19..5897376 100644 --- a/src/Objects/Migrator.php +++ b/src/Objects/Migrator.php @@ -3,12 +3,12 @@ namespace RapidWeb\uxdm\Objects; use Psr\Cache\CacheItemPoolInterface; +use RapidWeb\CliProgressBar\ProgressBar; use RapidWeb\uxdm\Interfaces\DestinationInterface; use RapidWeb\uxdm\Interfaces\SourceInterface; use RapidWeb\uxdm\Objects\Exceptions\MissingFieldToMigrateException; use RapidWeb\uxdm\Objects\Exceptions\NoDestinationException; use RapidWeb\uxdm\Objects\Exceptions\NoSourceException; -use RapidWeb\CliProgressBar\ProgressBar; class Migrator { @@ -102,6 +102,7 @@ public function setSourceCache(CacheItemPoolInterface $sourceCachePool, $sourceC public function withProgressBar() { $this->showProgressBar = true; + return $this; } @@ -163,7 +164,6 @@ public function migrate() } for ($page = 1; $page < PHP_INT_MAX; $page++) { - $dataRows = $this->getSourceDataRows($page); if (!$dataRows) { @@ -224,7 +224,7 @@ public function migrate() private function advanceProgressBar($amount) { if ($this->showProgressBar) { - for ($i=0; $i < $amount; $i++) { + for ($i = 0; $i < $amount; $i++) { $this->progressBar->advance()->display(); } } diff --git a/src/Objects/Sources/CSVSource.php b/src/Objects/Sources/CSVSource.php index dbbc44b..7a98dce 100755 --- a/src/Objects/Sources/CSVSource.php +++ b/src/Objects/Sources/CSVSource.php @@ -74,6 +74,7 @@ public function countDataRows() { $file = new \SplFileObject($this->file, 'r'); $file->seek(PHP_INT_MAX); + return $file->key(); } } diff --git a/src/Objects/Sources/PDOSource.php b/src/Objects/Sources/PDOSource.php index 1a50e18..e4e4f45 100644 --- a/src/Objects/Sources/PDOSource.php +++ b/src/Objects/Sources/PDOSource.php @@ -133,7 +133,7 @@ public function countDataRows() $sql = $this->getSQL([]); $fromPos = strpos($sql, 'from'); $limitPos = strrpos($sql, 'limit'); - $sqlSuffix = substr($sql, $fromPos, $limitPos-$fromPos); + $sqlSuffix = substr($sql, $fromPos, $limitPos - $fromPos); $sql = 'select count(*) as countDataRows '.$sqlSuffix; diff --git a/src/Objects/Sources/WordPressPostSource.php b/src/Objects/Sources/WordPressPostSource.php index d0c2c82..bb7a8ff 100644 --- a/src/Objects/Sources/WordPressPostSource.php +++ b/src/Objects/Sources/WordPressPostSource.php @@ -148,7 +148,7 @@ public function countDataRows() $sql = $this->getPostSQL([]); $fromPos = strpos($sql, 'from'); $limitPos = strrpos($sql, 'limit'); - $sqlSuffix = substr($sql, $fromPos, $limitPos-$fromPos); + $sqlSuffix = substr($sql, $fromPos, $limitPos - $fromPos); $sql = 'count (*) '.$sqlSuffix; } diff --git a/src/Objects/Sources/WordPressUserSource.php b/src/Objects/Sources/WordPressUserSource.php index aef4659..63012f6 100644 --- a/src/Objects/Sources/WordPressUserSource.php +++ b/src/Objects/Sources/WordPressUserSource.php @@ -146,7 +146,7 @@ public function countDataRows() $sql = $this->getUserSQL([]); $fromPos = strpos($sql, 'from'); $limitPos = strrpos($sql, 'limit'); - $sqlSuffix = substr($sql, $fromPos, $limitPos-$fromPos); + $sqlSuffix = substr($sql, $fromPos, $limitPos - $fromPos); $sql = 'count (*) '.$sqlSuffix; } diff --git a/src/Objects/Sources/XMLSource.php b/src/Objects/Sources/XMLSource.php index d35b7df..a192d37 100755 --- a/src/Objects/Sources/XMLSource.php +++ b/src/Objects/Sources/XMLSource.php @@ -93,6 +93,7 @@ public function getFields() public function countDataRows() { $domNodeList = $this->xpath->query($this->xpathQuery); + return $domNodeList->length; } }