Skip to content

[Script] Candidate Info deletion script#10416

Draft
ridz1208 wants to merge 1 commit intoaces:mainfrom
ridz1208:new_delete_script
Draft

[Script] Candidate Info deletion script#10416
ridz1208 wants to merge 1 commit intoaces:mainfrom
ridz1208:new_delete_script

Conversation

@ridz1208
Copy link
Copy Markdown
Collaborator

This PR isa n attempt to replace the LORIS deletion scripts for timepoint and candidate. This script's intent is to

  • Add deletion granularity (imaging, biospecimen, consent, ...)
  • Add scope handle all Candidate data including modalities like imaging
  • potentially add support for project overrides without a full script override
  • create a backup before deletion
  • add better flagging
  • add better logging

@github-actions github-actions bot added the Language: PHP PR or issue that update PHP code label Mar 17, 2026
Comment on lines +54 to +73
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();
}
}
Copy link
Copy Markdown
Collaborator

@HenriRabalais HenriRabalais Mar 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure if this is done this way for legacy reasons, but my understanding is that getOpt could be used here instead

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since I started with the old script it was legacy but it changed so much, you are right we should use getOpt

Comment on lines +187 to +192
case 'timepoint':
deleteTimepoint($candidate, $sessionID, $confirm, $printToSQL, $DB, $output);
break;
case 'timepoint':
deleteInstrument($candidate, $sessionID, $instrumentName, $confirm, $printToSQL, $DB, $output);
break;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

case 'timepoint' repeated twice here on purpose?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

accidental, bottom one should be instrument

use \LORIS\StudyEntities\Candidate\CandID;

const MIN_NUMBER_OF_ARGS = 4;
const MAX_NUMBER_OF_ARGS = 6;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it seems like the are 7 potential options, are some of them mutually exclusive? is that why the max is 6?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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');
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where is $baseDir defined?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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");
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where is $run defined?

}

// Create ZIP of the run directory (includes SQL and any other files added)
if (!empty($backupRunDir)) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$lorisInstance not passed as final param

$DB->delete("issues", ["CandidateID" => $candidateID]);

//delete from feedback_bvl_entry
foreach ($feedback_threads as $feedback) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$feedback_threads has not been defined in this scope

Comment on lines +222 to +223
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
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mode is defined as --mode=<direct|tosql|backuponly> above

{
//export file
$filename = __DIR__
. "/../../../project/tables_sql/DELETE_candidate_$candID.sql";
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fine to hardcode path here?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, should be removed

$mode = null;
$printToSQL = false;
$backupDir = null;
$confirm = false;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$confirm set to false but then never seems to have the option of being set to true.



// RUN
switch ($target) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider structuring this such that there is a single try and catch that wraps all the commands with the inclusion of a db rollback

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Language: PHP PR or issue that update PHP code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants