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();

        $oAct = new ActionClass;

        $oMode = ModeClass::FromCodes('R+');
        $ofData->InOut()->Mode($oMode);  // must be readable

        $sSchema = $this->QSchemaName()->GetIt();
        $oEngine = $this->OEngine();
        $oClient = $oEngine->OClient();
        $oServer = $oEngine->OServer();

        $fsData = $ofData->Ident()->SpecFull();
        $ftFile = $oScrn->BlueIt($fsData);
        $ftSchema = $oScrn->BlueIt($sSchema);

        // Check to see if schema already exists
        if ($oClient->SchemaExists($sSchema)) {
            echo $oScrn->InfoIt('Found')." schema [$ftSchema]...".CRLF;

            if ($okToReplace) {
                echo $oScrn->InfoIt('Replacing')." schema [$ftSchema]...";
                $oActSub = $oClient->ReplaceSchema($sSchema);
                echo CRLF;
                $oAct->Assimilate($oActSub);  // save action-status info
            } else {
                echo $oScrn->YellowIt('Schema already exists').' -- use "replace" if you want to erase the existing data.'.CRLF;
                $oAct->SetOkay(FALSE);  // can't proceed
            }

        } else {
            echo $oScrn->InfoIt('Creating')." schema [$ftSchema]...";
            $oActSub = $oClient->CreateSchema($sSchema);
            echo $oActSub->VIEW_Inline().CRLF;
            $oAct->Assimilate($oActSub);  // save action-status info
        }

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

    // -- ACTION -- //
}