Ferreteria/v0.6/clade/Sys/Data/Engine/aux/ActionRq/Admin/ListSchemas

From Woozle Writes Code
Jump to navigation Jump to search
clade: Sys\Data\Engine\aux\ActionRq\Admin\ListSchemas
Clade Family
Admin ListSchemas (see DBA)
Clade Aliases
Alias Clade
Base* [ca,i] Sys\Data\Engine\aux\ActionRq\Admin
ClientIface Sys\Data\Engine\endpt\Client
Subpages

Code

interface iListSchemas extends BaseIface {}
abstract class caListSchemas extends BaseClass implements iListSchemas {

    // ++ ACTION ++ //

    // CEMENT/DEFAULT: entry point
    public function Go() {
        #$this->GoSetupUI();
        $oaReq = $this->OASavedInput();
        $qoClient = $oaReq->QOClient();
        if ($qoClient->HasIt()) {
            $this->UseClient($qoClient->GetIt());
        } else {
            #echo $qoClient->ReflectThis()->Report();
            #$oItWent = $qoClient->ItWentLike();
            $oFndStat = $qoClient->OFindStatus();
            $this->HandleBadLoad($oFndStat);
        }

    }

    // ++ ACTION: components ++ //

    // PURPOSE: we have the DB object, so do the thing
    // DEFAULT (It's not entirely right for this to be here instead of app-specific, but it'll do for now.)
    protected function UseClient(ClientIface $oClient) {
        $oList = $oClient->SchemaList();
        $nDBs = $oList->Count();
        if ($nDBs > 0) {
            $sS = ($nDBs===1)?'':'s';
            echo $nDBs." schema$sS found:".CRLF;
            $ar = $oList->GetVals();
            foreach ($ar as $oSchema) {
                $sSchema = $oSchema->SchemaName();
                echo " - $sSchema".CRLF;
            }
        } else {
            echo 'No schemas were found. (This is probably a Ferreteria bug.)'.CRLF;
        }
    }
    protected function HandleBadLoad($oItWent) {
        if ($oItWent->HasError()) {
            switch ($oItWent->GetError()) {
              case $oItWent::N_ERR_DB_DEFN:
                $this->HandleBadSlug();
                break;
              case $oItWent::N_ERR_DB_SLUG:
                $this->HandleNoSlug();
                break;
              default:
                $this->HandleMystery();
            }
        }
    }

    // 2025-10-01 Possibly these behaviors (below) should be app-specific, but this at least gets the ball rolling.

    protected function HandleBadSlug() {
        // DEFAULT: list all configured DBs (so user can hopefully correct their mistake)
        $sSlug = $this->QSDbase()->GetIt();
        $vsSlug = self::Screen()->WarnIt($sSlug);
        echo "Database slug [$vsSlug] not found. Here's what is available:".CRLF;
        echo $this->RenderHostsList();
    }
    protected function HandleNoSlug() {
        echo "No database slug specified; here's what is available:".CRLF;
        echo $this->RenderHostsList();
    }
    protected function HandleMystery() {
        echo $oItWent->RenderMessagesBlock();
                    $this->AmHere();
    }

    // -- ACTION -- //
}