Skip to content

Commit

Permalink
Bug #6, fix to bin/csv-import & ouop-query commandline PHP [iet:1…
Browse files Browse the repository at this point in the history
…0277221]

* [iet:10277034]
  • Loading branch information
nfreear committed Dec 11, 2017
1 parent 14114d2 commit 85e2b0c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
23 changes: 17 additions & 6 deletions bin/csv-import.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@
define( 'CSV_FILENAME', '/example.csv' );
define( 'CSV_HEADING', true );
define( 'CSV_UNSTRICT', true );
define( 'FANCY_PROGRESS', $argc > 1 && $argv[ $argc - 1 ] === '--fancy' );
define( 'PROGRESS_COLOR', 'magenta' );

use IET_OU\Moodle\Auth\Ouopenid\Db\User as OuUser;
use Dariuszp\CliProgressBar;
// Was: use Dariuszp\CliProgressBar;

cli_heading('OU-OpenID CSV importer');
cli_writeln(date('c') . ' --> Start csv import');

if ($argc > 1 && $argv[ $argc - 1 ] === '--delete') {
$input = cli_input('Do you really want to delete? Type Y to delete or n to exit', 'n', [ 'n', 'Y' ], $case = true);
Expand All @@ -51,18 +53,27 @@
cli_writeln("Filename: $csvfile");
cli_writeln("Records: $lineCount");

$bar = new CliProgressBar( $lineCount );
$bar->{ 'setColorTo' . ucfirst(PROGRESS_COLOR) }(); // E.g. ->setColorToMagenta();
$bar->display();
if (FANCY_PROGRESS) {
$bar = new \Dariuszp\CliProgressBar( $lineCount );
$bar->{ 'setColorTo' . ucfirst(PROGRESS_COLOR) }(); // E.g. ->setColorToMagenta();
$bar->display();
}

$count = OuUser::insertFromCsv($csvfile, CSV_HEADING, CSV_UNSTRICT, function ($idx, $userid) {
$bar->progress(); // Was. cli_write('.');
if (FANCY_PROGRESS) {
$bar->progress();
} else {
cli_write('.');
}
});
$bar->end();
if (FANCY_PROGRESS) {
$bar->end();
}

cli_write(sprintf( "\nWarnings (%d): ", count(OuUser::getWarnings()) ));
cli_writeln(json_encode( OuUser::getWarnings(), JSON_PRETTY_PRINT ));

cli_writeln("\nUsers inserted: $count");
cli_writeln(date('c') . ' --> End csv import');

// End.
7 changes: 4 additions & 3 deletions bin/ouop-query.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,18 @@
$counts = [
'Total users' => OuUser::count(),
'Tranche 1' => OuUser::count([ 'batch' => 0 ]), // Deliberately '0'!
'Tranche 2' => OuUser::count([ 'batch' => 2 ]),
'Tranche 32' => OuUser::count([ 'batch' => 32 ]),
'Tranche 33' => OuUser::count([ 'batch' => 33 ]),
'Keystroke preset' => OuUser::count([ 'teslainstrument' => 'kd' ]),
'Plagiarism preset' => OuUser::count([ 'teslainstrument' => 'tpt' ]),
'Forensic preset' => OuUser::count([ 'teslainstrument' => 'fa' ]),
'Voice recog preset' => OuUser::count([ 'teslainstrument' => 'vr' ]),
'Face recog preset' => OuUser::count([ 'teslainstrument' => 'fa' ]),
'Face recog preset' => OuUser::count([ 'teslainstrument' => 'fr' ]),
'No preset' => OuUser::count([ 'teslainstrument' => null ]), // Should always be '0'!
'Is team' => OuUser::count([ 'is_team' => 1 ]),
];

cli_write('Counts: ');
cli_write(date('c') . ' --> Counts: ');
cli_writeln(json_encode( $counts , JSON_PRETTY_PRINT ));

exit; // Work-in-progress!
Expand Down

0 comments on commit 85e2b0c

Please sign in to comment.