Futilities/v0.6/clade/Sys/dba/InReq/DoImport
Jump to navigation
Jump to search
| ||||||||||||||||||||||
About
- PURPOSE: Action-class for the do.import request
History
- 2024-12-04 started
- 2025-01-07 removed value HasIt() check in Go() because that condition is intercepted earlier
- ...and sent to InChker_ReqValue(), which I'm implementing now.
- 2025-07-31 DbStuff parent is redundant, already parented from parent class; removing it.
- 2025-09-25 see InReq.md
Thinking
- 2025-01-09 For now, I'm going to have the value for
readbe in the format "{dbase}/{schema}"- ...so that it can be retrieved from
Go() - ...because although
read:{dbase}:{schema}would be more consistent, the input parser currently discards everything after the second:. - This should, however, be fixed later. Whatever the format is, it should be handled by the input parser, not by Action code.
- (2025-11-17 This has in fact been fixed; it's now handled by
ParseInputArgs().)
- (2025-11-17 This has in fact been fixed; it's now handled by
- ...so that it can be retrieved from
Code
interface iDoImport extends BaseIface, InReqIface {}
class cDoImport extends BaseClass implements iDoImport {
use InReqTrait;
// ++ CONFIG ++ //
protected function ActorRqClass() : string { return BaseClass::class; }
// -- CONFIG -- //
// ++ INPUT ++ //
// OVERRIDE
protected function ParseInputString(string $s) : void {
// main input for this term is name of dbconn to import to
$this->SaveAsEngConnName($s);
// TODO 2025-10-14: if there's an XML file, read it to get default schema, then set that.
// check for meta file -- if available, we'll use it for default schema-name
$oConn = $this->OAUserInput()->QODbConn();
}
// OVERRIDE
protected function ParseInputArgs(array $arArgs) {
if (count($arArgs) > 0) {
// optional extra input is name of schema
// xTODO 2025-10-09: This should probably be calling OAUserInput()->QSchemaSlug(). [DONE 2025-1014]
#$this->OAUserInput()->SetIt(KioskEnum::VAL_SCHEMA->value,$arArgs[0]);
$this->AmHere("SETTING SCHEMA to [$arArgs[0]]");
$this->OAUserInput()->QSSchema()->SetIt($arArgs[0]);
}
}
// -- INPUT -- //
// ++ ACTION ++ //
public function Go() {
#echo $this->OAUserInput()->ReflectThis()->Report();
$oaReq = $this->OAUserInput();
$qoConn = $oaReq->QODbConn();
if ($qoConn->HasIt()) {
$qoSchm = $oaReq->QOSchema();
if ($qoSchm->HasIt()) {
$oSchm = $qoSchm->GetIt();
#echo $oSchm->ReflectThis()->Report();
$bCanReplace = $oaReq->OkToReplace();
// 2025-10-30 TODO: possibly this code belongs in InRqData:
$of = FilePaths::Me()->ImportFoNode();
$oStat = $of->PairCheck();
if ($oStat->GetOkay()) {
$oaNodes = $of->BySchm();
#echo $oSchm->ReflectThis()->Report();
$sSchm = $oSchm->QSchemaName()->GetIt();
$ofSchmData = $oaNodes->GetIt($sSchm);
$this->AmHere("SCHEMA: [$sSchm]");
echo $ofSchmData->ReflectThis()->Report();
#$oIdent = $ofSchmData->Ident();
#echo $oIdent->ReflectThis()->Report();
#$qsSpec = $oIdent->QSFullSpec();
#$fs = $qsSpec->GetIt();
} else {
$this->AmHere("This should never happen.");
}
$oSchm->DoImport($ofSchmData,$bCanReplace);
} else {
echo 'Quitting because no schema was specified.'.CRLF;
echo $oaReq->Inspect()->Render();
}
} else {
$this->AmHere("QSDBCONN is set? [".$oaReq->QSDbConn()->HasIt().']');
echo 'Quitting because no database was specified.'.CRLF;
echo $oaReq->Inspect()->Render();
}
}
protected function RenderFiles() : string {
$oScrn = self::Screen();
$of = FilePaths::Me()->ImportFoNode();
$fp = $of->Ident()->SpecFull();
#$sRtn = $oScrn->InfoIt('Input needed')." -- here are the available data files:".CRLF;
$oStat = $of->PairCheck();
// TODO: show error, or list if no errors
if ($oStat->GetOkay()) {
$ffp = $oScrn->BlueIt($fp);
$sRtn = "Listing for import folder $ffp:".CRLF;
#echo $of->ReflectThis()->Report();
$oaNodes = $of->BySchm();
$oView = $oaNodes->Inspect();
#echo $oView->ReflectThis()->Report();
#echo $oaNodes->ReflectThis()->Report();
$sRtn .= $oView->RenderAsTable();
} else {
// TODO: get error message(s)
$sRtn = self::CodingPrompt('TO BE WRITTEN 2025-03-09');
}
return $sRtn;
}
// -- ACTION -- //
// ++ OUTPUT ++ //
/**
* NOTE that this describes what is *going to happen*, but doesn't attempt to do it.
* However, what is going to happen *can* depend on kept settings -- so those need to be checked
* IF the current reqlet has no value.
* * Apparently this can be called *before* validating the user's input.
* TODO 2025-02-11 This process needs tidying and normalizing.
*/
public function Describe() : string {
#echo $this->ReflectThis()->Report();
#echo $this->RenderStackDump();
$oScrn = self::Screen();
$oaData = $this->OAUserInput();
#$oaData = static::OAKeptInput();
$this->AmHere();
$osDbSlug = $oaData->QSDbConn();
$osScSlug = $oaData->QSSchema();
#echo $oaData->ReflectThis()->Report();
$doListFiles = FALSE; // flip this on if the user needs it
if ($osDbSlug->HasIt()) {
// Get DB Connection slug for UI display:
$sDbSlug = $osDbSlug->GetIt();
$ftDbSlug = $oScrn->BoldIt($sDbSlug);
// Has the Schema been specified?
if ($osScSlug->HasIt()) {
$sScSlug = $osScSlug->GetIt();
$ftScSlug = $oScrn->BoldIt($sScSlug);
$sRtn = "Import schema '$ftScSlug' into the '$ftDbSlug' database"; // TODO 2025-01-26 I think this will need refinement.
} else {
$sRtn = "Import into the '$ftDbSlug' database: can't complete because no schema specified.";
$doListFiles = TRUE;
}
} else {
$sRtn = 'Import data (need to know which schema).'.CRLF;
$doListFiles = TRUE;
}
if ($doListFiles) {
$sHelp = 'COMMANDS: file:<SQL filename>, schema:<schema name>, conn:<connection name>';
$sRtn .=
$this->RenderFiles() // ...so the user can see what's available
.CRLF
.$sHelp.CRLF // TODO: get these from the XML spec data
;
}
return $sRtn;
}
/**
* PURPOSE: handles when a value is not given, but also isn't required
* INSTAR: default is to show an error and quit
*/
protected function DescribeNonValue() : string {
return 'No source/target specified, so list available database connections. (2025-03-09 IS THIS EVER CALLED?)';
}
// -- OUTPUT -- //
}