Skip to content

Commit

Permalink
Bug #8, Fixes for csv-import commandline PHP script [iet:10328304]
Browse files Browse the repository at this point in the history
  • Loading branch information
nfreear committed Apr 13, 2018
1 parent df85371 commit 963b5ae
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
4 changes: 3 additions & 1 deletion bin/csv-import.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@
if ($argc > 1) {
$csvfile = CSV_DIR . '/' . clean_param($argv[ $argc - 1 ], PARAM_PATH);
} else {
$csvfile = CSV_DIR . CSV_FILENAME;
cli_writeln('Error. Missing CSV file.');
exit( 1 );
// Was: $csvfile = CSV_DIR . CSV_FILENAME;
}

$lineCount = OuUser::countFileLines($csvfile);
Expand Down
13 changes: 11 additions & 2 deletions db/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,20 @@ public static function insertFromCsv($filename = '../example.csv', $ignore_headi
}

/** Return the number of new-lines in a text file (including CSV files).
* @param string $filename (Was default: '../example.csv')
* @return int Line count.
* @link https://stackoverflow.com/questions/2162497/efficiently-counting-the-number-of-lines-of-a-text-file-200mb
*/
public static function countFileLines($filename = '../example.csv')
public static function countFileLines($filename = null)
{
$linecount = 0;
$handle = fopen($filename, 'r');

if (! $handle) {
echo "Error, missing file: $filename\n";
exit(1);
}

while (! feof($handle)) {
$line = fgets($handle);
$linecount++;
Expand Down Expand Up @@ -314,7 +321,9 @@ public static function getRedirectUrl($profile, $action = null)
if (! isset($profile->teslainstrument)) {
self::debug([ __FUNCTION__, 'Undefined instrument', $profile ]);
}
if (! $redirects) { return null; }
if (! $redirects) {
return null;
}

$url = $redirects[ $instrument ]->url;

Expand Down

0 comments on commit 963b5ae

Please sign in to comment.