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

From Woozle Writes Code
Jump to navigation Jump to search
Removed Code

2026-03-03

On 2026-02-26 I commented out the previous version of ExportToStream() which used an Exporter object, because a separate object for this no longer seemed necessary or a good way to do it:

#
    protected function ExportToStream(RStreamIface $oDest) {
        $this->Open();
        $sSchema = $this->SchemaName();

        $oExp = $this->OEngine()->OClient()->Exporter();
        $oCmd = CmdLineClass::FromVoid();
        $oCmd->QOListener()->SetIt($oDest); // set output file-stream as listener for export command
        $oExp->QOCommand()->SetIt($oCmd);   // pass configured Command to Exporter
        $oAct = $oExp->DoSchema($this);     // run the schema export

        $this->Shut();
        return $oAct;
    }

2026-02-24

All code in function commented out on 2026-01-11, making it into a stub; here's what it was before that:

#
    public function OnCheck() {
      // 2026-01-11 Copied from Process -- but I don't think this is actually what we want.
        $oScrn = self::Screen();
        $ofLogIO = self::LogFile()->InOut();

        $oaPipes = $this->OAPipes();
        $qrDestPipe = $oaPipes->DestStream(); // where we are sending the data
        $qrErrsPipe = $oaPipes->ErrsStream(); // errors from the receiver
        $qrSrcePipe = $oaPipes->SrceStream(); // non-error responses from receiver

        // Check for possible response from receiver:

        $isErr = $qrErrsPipe->PullBytes();
        if (is_string($isErr) && ($isErr !== '')) {
            $sMsg = $ok;  // $ok is received text
            $nlMsg = strlen($sMsg);
            if ($nlMsg > 64) {
                $ftMsg = '"'.substr($sMsg,32).'"'." ($nlMsg chars total)";
            } else {
                $ftMsg = $sMsg;
            }
            echo CRLF.$oScrn->ErrorIt('Received Error Message').': '.$ftMsg.CRLF;
            $ofLogIO->WriteEntry("++++ RECEIVED ERROR ++++");
            $ofLogIO->WriteEntry($ftMsg);
            $ofLogIO->WriteEntry("==== BYTES ERRORED ON:");
            $ofLogIO->WriteEntry($sPiece);
            $ofLogIO->WriteEntry("==== STATS:");
            $ofLogIO->WriteEntry("TRIED = [$nlTried] / SENT = [$nlDone]");
            $ofLogIO->WriteEntry("---- RECEIVED ERROR ----");

            // TODO: this needs to be checked by the sender, somehow, because it's target-specific
            if (str_contains($sMsg,'Unknown command')) {
                $doSendLoop = FALSE;
                echo $oScrn->ErrorIt('Stopping').' due to parsing error on remote.'.CRLF;
            }
        }
        $isReply = $qrDestPipe->PullBytes();
        if (is_string($isReply)) {
            $sMsg = $ok;  // $ok is received text
            echo CRLF.$oScrn->InfoIt('Received Reply Message').': '.$sMsg.CRLF;
            $ofLogIO->WriteEntry("==== REPLY MESSAGE: $sMsg");
        }
    }

...and I'm pretty sure all the commented-out stuff here is debugging or leftover chaff, but it makes me nervous to delete so much stuff in one go -- so here's the function as it is now, just before cleanup, commented stuff left commented:

#
    protected function DoExportActual(RStreamIface $oInBuff) {
        $oCli = $this->OEngine()->OClient();
        $oCli->Open();
        #$oConnDB = $this->OServer();        // DB connection
        #$oConnDB->Open();

        // can we do this?
        #$oEndPt = $oConnDB->OEndpoint();
        #echo $oEndPt->ReflectThis()->Report(); die();
        #$oProc = $oEndPt->OProcess();
        #echo $oEndPt->ReflectThis()->Report(); die();

        #$oSockDB = $oConnDB->OSock();
        #$oConnSh = $oSockDB->OJack();

        #$oOperDB = $oConnDB->OOper();
        #echo $oOperDB->ReflectThis()->Report();

        #$oCred = $this->OEngine()->OServer()->CredsForCmd(); // DB connection string from DB-local shell
        #$sCred = $oCred->AsString();
        $sSchema = $this->SchemaName();

        #$sCmd = "mysqldump $sCred --quick $sSchema"; // "--quick" does line-at-a-time rather than buffering entire table
        // should we also try "--single-transaction"? "To dump large tables, you should combine the --single-transaction option with --quick."

        #echo $oConnSh->OSock()->OJack()->ReflectThis()->Report();
        // Send dump command directly to shell, not to DB engine:
        #$oAct = $oOperDB->NewCommOp();
        #$oCmd = CmdLineClass::FromArray(['mysqldump',$sCred,'--quick',$sSchema]);
        #$oAct = $oConnSh->DoCommand($oCmd,$oInBuff);

        #ConveyClass::OUpdater($this);

        #$oProc = $oConnSh->OProcess();
        #$oProc->CaptureWith($oInBuff);  // 2026-01-18 TO BE WRITTEN
        #$oAct = $oConnSh->DoCommand($oCmd);
        #$oAct = $oConnDB->DoCommand($oCmd);

        $oExp = $oCli->Exporter();
        $oExp->QOListener()->SetIt($oInBuff);
        $oAct = $oExp->DoSchema($this);

        $oCli->Shut();
        return $oAct;
    }

2026-01-08

Commented out from @fx/DoImport() (after $oAct->Assimilate($oActConn);) on 2026-01-04:

#
            // 2026-01-04 This is kind of all messed-up.
            // create buffer for sending commands:
            $oReplyBuff = new BufferClass; // buffer for brief replies (not for file-storage)
            $oAct = $oReplyBuff->Open();

            // ** FIRST: create/replace the database as determined earlier

            $oConnx = $oDbConn->OSock();
            $this->AmHere("SQL: $sqCmd");
            #echo $oDbConn->ReflectThis()->Report(); die();
            $oAct = $oDbConn->DoCommand($sqCmd,$oReplyBuff);
            if ($oAct->GetOkay()) {
                $oDbConn->Send($

                // ** AND THEN: import the data

                echo $oScrn->InfoIt('Importing')." from file [$ftFile]...".CRLF;

                // This version expects the data to be sent separately, and should also work remotely.
                $sCmd = "mysql $sCreds -D$sSchema";

                // Send CLI command, which opens a connection to the remote MyMar process:
                $oProc = $oConnx->OPlug()->RunProcess($sCmd);
                // create buffer for import data
                $oSendBuff = TextStreamClass::FromNode($ofData);
                // open data file for read-buffering:
                // send file's data:

                $oProc->Convey($oSendBuff,$oReplyBuff);
                echo CRLF.'Buffer sent.'.CRLF;
            } else {
                echo $oScrn->ErrorIt('Problem').": command to create the schema '$sSchema' did not succeed.".CRLF.$oAct->GetStatusText().CRLF;
            }

            #echo $oAct->ReflectThis()->Report();
            $oAct = $oDbConn->WrapAction($oAct);  // TODO: This is *coming* from DbConn -- shouldn't it already be properly wrapped?
            #echo $oDbConn->ReflectThis()->Report();
            $oDbOper->MsgsOp()->HandleResults($oAct);
            echo $oAct->RenderMessages(); // Does this duplicate stuff that HandleResults() does?
        } else {
            $this->AmHere('FAILED TO OPEN OUTPUT BUFFER');
            $sMsg = $oScrn->ErrorIt('Error').': Could not open output buffer.'.CRLF.$oAct->GetStatusText().CRLF;
            $oAct->AddMsgString($sMsg);
            $oAct->SetOkay(FALSE);
        }

I'm not actually sure if the code there now actually works... but it looks not-wrong. Possibly nothing actually uses RunProcess() anymore?

2025-04-12

From the middle of DoImport():

#
            // This version will only work locally.
            // This is probably faster than buffering...
            // ...but doesn't allow the possibility of showing progress since there's no middleman to audit the data stream.
            $sCmd = "mysql $sCreds -D$sSchema < $fsData";
            // NOTE: "--quick" can do line-at-a-time rather than buffering entire table
            // NOTE: "-D<arg>" = "--database=<arg>"

2025-01-26

This (commented out earlier, from DoBackup() which is now DoExport()) has probably been moved elsewhere, but I'm being paranoid:

#
        // TODO: include program name/version
        $sDateFmt = 'Y/m/d H:i:s';   // "/" chars get escaped, so "." makes the text a little more readable
        $arMeta['db.slug'] = $this->Engine()->ObjectSlug();
        $arMeta['schema'] = $sSchema;
        $arMeta['fspec'] = $fsData; // TODO: get just the filename
        $arMeta['time.start.int'] = time();
        $arMeta['time.start.str'] = date($sDateFmt);
        $fsMeta = $fsData.'.json';
        $jsMeta = json_encode($arMeta,JSON_PRETTY_PRINT);
        file_put_contents($fsMeta,$jsMeta);

This is from inside if ($oAct->GetOkay()) {:

#
            // TODO: integrate $oActBuff results
            if ($oAct->QResponseErr()->HasIt()) {
                $sMsg = trim($oAct->QResponseErr()->GetIt());
                $oScrn->ErrorIt('Error stream').': $sMsg'.CRLF;
            }

            // 2025-01-25 old message-handling
            $sMsg = trim($oAct->GetMessage());
            echo ' - ' . (($oAct->GetOkay() ? $oScrn->GreenIt('Done.') : ($oScrn->ErrorIt('Error: ').$sMsg))) . CRLF;

...and this is from after the if is closed:

#
        $arMeta['time.finish.int'] = time();
        $arMeta['time.finish.str'] = date($sDateFmt);
        $arMeta['status.cmd'] = $oAct->GetStatusText();
        if (is_object($oActBuff)) {
            $arMeta['status.buff'] = $oActBuff->GetStatusText();  // This may be unnecessary.
        }
        $jsMeta = json_encode($arMeta,JSON_PRETTY_PRINT);
        file_put_contents($fsMeta,$jsMeta); // update the metadata file