public function MigrateSourceCSV::computeCount in Migrate 6.2
Same name and namespace in other branches
- 7.2 plugins/sources/csv.inc \MigrateSourceCSV::computeCount()
Return a count of all available source records.
File
- plugins/
sources/ csv.inc, line 129 - Define a MigrateSource for importing from comma separated values files.
Class
- MigrateSourceCSV
- Implementation of MigrateSource, to handle imports from CSV files.
Code
public function computeCount() {
// If the data may have embedded newlines, the file line count won't reflect
// the number of CSV records (one record will span multiple lines). We need
// to scan with fgetcsv to get the true count.
if (!empty($this->options['embedded_newlines'])) {
$this->csvHandle = fopen($this->file, 'r');
// Skip all but the last header
for ($i = 0; $i < $this->headerRows; $i++) {
fgets($this->csvHandle);
}
$count = 0;
while ($this
->getNextLine()) {
$count++;
}
fclose($this->csvHandle);
$this->csvHandle = NULL;
}
else {
// TODO. If this takes too much time/memory, use exec('wc -l')
$count = count(file($this->file));
$count -= $this->headerRows;
}
return $count;
}