Ferreteria/v0.6/clade/Sys/Data/Engine/aux/Schema/MyMar/@fx/DoImport

From Woozle Writes Code
< Ferreteria‎ | v0.6‎ | clade‎ | Sys‎ | Data‎ | Engine‎ | aux‎ | Schema‎ | MyMar
Jump to navigation Jump to search

About

About

  • Action: import SQL data via command-line

Status

Code

#
    public function DoImport(FileIface $ofData, bool $okToReplace) : ActionIface {
        $oScrn = self::Screen();

        $oMode = ModeClass::FromCodes('R+');
        $ofData->InOut()->Mode($oMode);  // must be readable
        $fsData = $ofData->Ident()->SpecFull();
        $ftFile = $oScrn->BlueIt($fsData);

        $oAct = new ActionClass;

        $this->Open();  // open the connection now so it stays open between ops

        // Run the Engine-process and leave it waiting for input
        $oCmd = CommandClass::FromVoid();
        #$this->AmHere();
        $oActCmd = $this->OServer()->DoCommand($oCmd);
        #$this->AmHere();
        // Save a local pointer to the end-Runner:
        #$oSvrEnd = $oCmd->QORunner()->GetIt();
        $this->QORunner()->SetIt($oCmd->QORunner()->GetIt());

        $oActEnsure = $this->EnsureSchema($okToReplace);

        $oAct->SetOkay($oActEnsure->GetOkay());

        if ($oActEnsure->GetOkay()) {
            $oRun = $oActEnsure->QORunner()->GetIt();

            $oActImport = $this->ImportFromFile($ofData,$oRun);
            $this->AmHere('$oActImport:'.$oActImport->VIEW_AsBlock());
            $oAct->Assimilate($oActImport);
            #$this->AmHere('post-assimilate');

            if ($oActImport->GetOkay()) {
                $ftMsg = $oScrn->GreenIt('Ok!').' - Restore complete.'.CRLF;
                $oAct->AddMsgString($ftMsg);
            }
        }

        $this->Shut();  // done using the connection

        return $oAct;
    }