[Script] Candidate Info deletion script#10416
Conversation
| foreach ($argv as $arg) { | ||
| if (strpos($arg, '--backupdir=') === 0) { | ||
| $backupDir = substr($arg, strlen('--backupdir=')); | ||
| } elseif (strpos($arg, '--candid=') === 0) { | ||
| $candID = substr($arg, strlen('--candid=')); | ||
| } elseif (strpos($arg, '--pscid=') === 0) { | ||
| $PSCID = substr($arg, strlen('--pscid=')); | ||
| } elseif (strpos($arg, '--visitlabel=') === 0) { | ||
| $visit = substr($arg, strlen('--visitlabel=')); | ||
| } elseif (strpos($arg, '--mode=') === 0) { | ||
| $mode = substr($arg, strlen('--mode=')); | ||
| } elseif (strpos($arg, '--target=') === 0) { | ||
| $target = substr($arg, strlen('--target=')); | ||
| } elseif (strpos($arg, '--verbose') === 0) { | ||
| $verbose = true; | ||
| } else { | ||
| // If an argument is not in the list above show help | ||
| showHelp(); | ||
| } | ||
| } |
There was a problem hiding this comment.
not sure if this is done this way for legacy reasons, but my understanding is that getOpt could be used here instead
There was a problem hiding this comment.
since I started with the old script it was legacy but it changed so much, you are right we should use getOpt
| case 'timepoint': | ||
| deleteTimepoint($candidate, $sessionID, $confirm, $printToSQL, $DB, $output); | ||
| break; | ||
| case 'timepoint': | ||
| deleteInstrument($candidate, $sessionID, $instrumentName, $confirm, $printToSQL, $DB, $output); | ||
| break; |
There was a problem hiding this comment.
case 'timepoint' repeated twice here on purpose?
There was a problem hiding this comment.
accidental, bottom one should be instrument
| use \LORIS\StudyEntities\Candidate\CandID; | ||
|
|
||
| const MIN_NUMBER_OF_ARGS = 4; | ||
| const MAX_NUMBER_OF_ARGS = 6; |
There was a problem hiding this comment.
it seems like the are 7 potential options, are some of them mutually exclusive? is that why the max is 6?
There was a problem hiding this comment.
no, I thinkg it was 6 and I added a 7th without updating this, still very much draft
| if ($target === 'timepoint') { | ||
| $prefix .= "_".$visit; | ||
| } | ||
| $backupCandidateDir = rtrim($baseDir, "/") . "/" . $prefix . "_" . date('Ymd_His'); |
There was a problem hiding this comment.
where is $baseDir defined?
There was a problem hiding this comment.
probably menat backupdir
| } | ||
| $backupCandidateDir = rtrim($baseDir, "/") . "/" . $prefix . "_" . date('Ymd_His'); | ||
| if (!is_dir($backupCandidateDir) && !mkdir($backupCandidateDir, 0770, true)) { | ||
| fwrite(STDERR, "[ERROR] Cannot create backup dir: {$run}\n"); |
There was a problem hiding this comment.
where is $run defined?
| } | ||
|
|
||
| // Create ZIP of the run directory (includes SQL and any other files added) | ||
| if (!empty($backupRunDir)) { |
There was a problem hiding this comment.
where is $backupRunDir defined?
| fwrite(STDOUT, "\tThere are no corresponding sessions for $PSCID\n"); | ||
| } else { | ||
| foreach ($sessionIDs as $sessionID) { | ||
| deleteTimepoint($candID, $PSCID, $sessionID, $confirm, $printToSQL, $DB, $output); |
There was a problem hiding this comment.
mismatch between passed parameters and expected parameters in function defintion
| deleteCandidate($candidate, $confirm, $printToSQL, $DB, $output); | ||
| break; | ||
| case 'timepoint': | ||
| deleteTimepoint($candidate, $sessionID, $confirm, $printToSQL, $DB, $output); |
There was a problem hiding this comment.
$lorisInstance not passed as final param
| $DB->delete("issues", ["CandidateID" => $candidateID]); | ||
|
|
||
| //delete from feedback_bvl_entry | ||
| foreach ($feedback_threads as $feedback) { |
There was a problem hiding this comment.
$feedback_threads has not been defined in this scope
| php delete_candidate_data.php --action=<candidate|timepoint> --CandID=<dccid> --PSCID=<pscid> [--mode=<confirm|tosql>] [--backupdir=/path] | ||
| Example: php delete_candidate_data.php --target=candidate --CandID=965327 --PSCID=dcc0007 --mode=confirm --backupdir=/path/to/backup/dir |
There was a problem hiding this comment.
mode is defined as --mode=<direct|tosql|backuponly> above
| { | ||
| //export file | ||
| $filename = __DIR__ | ||
| . "/../../../project/tables_sql/DELETE_candidate_$candID.sql"; |
There was a problem hiding this comment.
fine to hardcode path here?
There was a problem hiding this comment.
no, should be removed
| $mode = null; | ||
| $printToSQL = false; | ||
| $backupDir = null; | ||
| $confirm = false; |
There was a problem hiding this comment.
$confirm set to false but then never seems to have the option of being set to true.
|
|
||
|
|
||
| // RUN | ||
| switch ($target) { |
There was a problem hiding this comment.
consider structuring this such that there is a single try and catch that wraps all the commands with the inclusion of a db rollback
This PR isa n attempt to replace the LORIS deletion scripts for timepoint and candidate. This script's intent is to