Ferreteria/v0.6/clade/Sys/Data/Engine/aux/ActionRq/Admin/ToDbOper: Difference between revisions

From Woozle Writes Code
< Ferreteria‎ | v0.6‎ | clade‎ | Sys‎ | Data‎ | Engine‎ | aux‎ | ActionRq‎ | Admin
Jump to navigation Jump to search
No edit summary
No edit summary
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{fmt/title|{{fmt/error|REMOVED}}}}
{{page/clade/v2
{{page/clade/v2
|fam=
|fam=
Line 10: Line 11:
&rarr; {{l/ver/clade|Sys\Data\Engine\aux\AdminRq\ToDbOper|EngDbUConf}}
&rarr; {{l/ver/clade|Sys\Data\Engine\aux\AdminRq\ToDbOper|EngDbUConf}}


{{!-!}} '''Base'''* [c,i] || {{l/ver/clade/full|p=ferreteria|Sys\Data\Engine\aux\ActionRq|Admin}}
|alia=
{{!-!}} '''DbOper'''* [i] || {{l/ver/clade/full|p=ferreteria|Sys\Data\Engine|Ops}}
{{!-!}} '''Base'''* [c,i] {{!!}} {{l/ver/clade/full|p=ferreteria|Sys\Data\Engine\aux\ActionRq|Admin}}
{{!-!}} '''QStr'''* [i]  || {{l/ver/clade/full|p=ferreteria|Data\Mem\QVar|Str}}
{{!-!}} '''DbOper'''* [i] {{!!}} {{l/ver/clade/full|p=ferreteria|Sys\Data\Engine|Ops}}
{{!-!}} '''QStr'''* [i]  {{!!}} {{l/ver/clade/full|p=ferreteria|Data\Mem\QVar|Str}}


}}
}}
Line 21: Line 23:


* '''Parallel''': {{l/same|ToDbConn}}
* '''Parallel''': {{l/same|ToDbConn}}
* '''Related''': {{l/same|ToSchema}}
==History==
* '''{{fmt/date|2025|03|25}}''' created
* '''{{fmt/date|2025|05|31}}''' renamed <code>ToDbConn</code> -> <Code>ToDbOper</code>
* '''{{fmt/date|2025|09|24}}''' Apparently this is now completely redundant?
* '''{{fmt/date|2025|09|25}}''' Or not. (Did I delete something by mistake?) Rescued mostly from .md, but also reconstructing ODbOper().
* '''{{fmt/date|2025|10|11}}''' moved ListHosts() to [[../|Admin (parent)]] from here so it's also available to {{l/same|ToSchema}} classes
* '''{{fmt/date|2025|10|26}}''' functionality consolidated with {{l/same|ToDbConn}}; clade/file {{fmt/error|removed}}
==Code==
==Code==
''as of 2025-10-05''
''as of 2025-10-05''
Line 136: Line 146:
     // -- OUTPUT -- //
     // -- OUTPUT -- //
}
}
}}
===Removed===
===={{fmt/date|2025|09|26}}====
Commented out yesterday:
{{fmt/php/block|1=
    // ++ SETUP ++ //
    // 2025-09-25 I *think* none of this is necessary anymore. (Update: ODbOper() is needed, but it needs to fetch instead of creating.)
    public static function FromDbOper(DbOperIface $o) : iToDbOper {
        $oThis = new static;
        $oThis->WithDbOper($o);
        return $oThis;
    }
    // ++ SETUP: dynamic ++ //
    protected function WithDbOper(DbOperIface $o) { $this->ODbOper($o); }
    // -- SETUP -- //
}}
===={{fmt/date|2025|09|24}}====
Commented out yesterday (but then reinstated 9/25 because the place I thought I moved them does not exist):
{{fmt/php/block|1=
    // ++++ from iface
   
    static function FromDbOper(DbOperIface $o) : self;
    // ++++ from class
   
    // 2025-09-23 moved to [WFe]Sys\Data\aux\uses\tDbOper
    // ++ SETUP ++ //
    public static function FromDbOper(DbOperIface $o) : iToDbOper {
        $oThis = new static;
        $oThis->WithDbOper($o);
        return $oThis;
    }
    // ++ SETUP: dynamic ++ //
    protected function WithDbOper(DbOperIface $o) { $this->ODbOper($o); }
    // -- SETUP -- //
}}
}}

Latest revision as of 00:58, 27 October 2025

REMOVED
clade: Sys\Data\Engine\aux\ActionRq\Admin\ToDbOper
Clade Family
Admin ToDbOper

EngDbExport
EngDbScList
EngDbSetup
EngDbTest
EngDbUConf

Clade Aliases
Alias Clade
Base* [c,i] Sys\Data\Engine\aux\ActionRq\Admin
DbOper* [i] Sys\Data\Engine\Ops
QStr* [i] Data\Mem\QVar\Str
Subpages

About

The caToDbOper class needs to know how to find a Database Operations object from a db name-slug, but can't know where that slug is specified. The QDbConnSlug() function, which returns the value/status of that parameter, is therefore abstract. The same is true of the Schema name-slug. It is up to descendant classes (generally found within application code) to define where those slugs can be found, and return a value/status string object for each.

History

  • 2025-03-25 created
  • 2025-05-31 renamed ToDbConn -> ToDbOper
  • 2025-09-24 Apparently this is now completely redundant?
  • 2025-09-25 Or not. (Did I delete something by mistake?) Rescued mostly from .md, but also reconstructing ODbOper().
  • 2025-10-11 moved ListHosts() to Admin (parent) from here so it's also available to ToSchema classes
  • 2025-10-26 functionality consolidated with ToDbConn; clade/file removed

Code

as of 2025-10-05

interface iToDbOper extends BaseIface {
    #static function FromDbOper(DbOperIface $o) : self;
    // ERROR CODES
    const N_ERR_DB_DEFN = 1;
    const N_ERR_DB_SLUG = 2;
}
abstract class caToDbOper extends BaseClass implements iToDbOper {

    // ++ REGISTRY ++ //

    protected function DbasesOArray() : ObjListIface { return ConnAdmin::ObjectRoster(); }

    // -- REGISTRY -- //
    // ++ OBJECTS ++ //

    private $oDbOp = NULL;
    protected function QDbOper() : QDbOperIface {
        $qoDbOp = $this->FetchDBOper();
        $oItWent = $this->HowItWent();
        if ($qoDbOp->HasIt()) {
            #echo $qoDbOp->ReflectThis()->Report();
            $oDbOp = $qoDbOp->GetObj();
            $this->oDbOp = $oDbOp;
            $qoDbOp->SetIt($oDbOp);
            $oItWent->SetOkay(TRUE);
        } else {
            // the ops object was not retrieved
            $oItWent->SetOkay(FALSE);

            // get more details
            $qsDbSlug = $this->QDbConnSlug();
            if ($qsDbSlug->HasIt()) {
                #echo $qoDbOp->ReflectThis()->Report();
                $sSlug = $qsDbSlug->GetIt();
                $oItWent->AddMsgString(self::Screen()->ErrorIt("Internal issue while loading the '$sSlug' DB definition."));
                $oItWent->SetError(self::N_ERR_DB_DEFN);
            } else {
                $oItWent->AddMsgString(self::Screen()->ErrorIt('Internal issue accessing the DB slug.'));
                $oItWent->SetError(self::N_ERR_DB_SLUG);
            }
        }
        return $qoDbOp;
    }
    protected function DbOper() : QDbOperIface {
        $oDbOp = $this->oDbOp;
        if (is_null($oDbOp)) {
            $qoDbOp = $this->FetchDBOper();
        }
        return $oDbOp;
    }
    // ACTION: tries to retrieve the slug-requested DB from the db classifest
    protected function FetchDbOper() : QDbOperIface {
        $osDbSlug = $this->QDbConnSlug();
        #$osScSlug = $this->QSchemaSlug();
        #echo $oaData->ReflectThis()->Report();
        $doListFiles = FALSE;   // flip this on if the user needs it
        $qoDB = QDbOperClass::AsNew();
        if ($osDbSlug->HasIt()) {
            // Get DB Connection slug for UI display:
            $sDbSlug = $osDbSlug->GetIt();

            // TODO: Look up the DB object (there IS code for this, somewhere...)
            $oaDBs = $this->DbasesOArray();
            #echo 'oaDBs CLASS: '.get_class($oaDBs).CRLF;
            $qoDbConn = $oaDBs->QryIt($sDbSlug);
            if ($qoDbConn->HasIt()) {
                $oDbConn = $qoDbConn->GetIt();
                #echo $oDbConn->ReflectThis()->Report();
                $oDbOper = $oDbConn->OOper();
                $qoDB->SetIt($oDbOper);
                #$this->SetOkay(TRUE);
            }
        } else {
            #$this->SetOkay(FALSE);
        }
        return $qoDB;
    }
    abstract protected function QDbConnSlug() : QStrIface;
    abstract protected function QSchemaSlug() : QStrIface;

    // -- OBJECTS -- //
    // ++ OUTPUT ++ //

    public function ListHosts() : string {

        $oScrn = self::Screen();

        #$oaDBs = DbConnAdmin::Register();
        $oaDBs = $this->DbasesOArray();

        $nDBs = $oaDBs->Count();
        if ($nDBs > 0) {
            $oTable = $oScrn->NewTable();
            $sS = ($nDBs == 1) ? '' : 's';
            $sOut = $oScrn->InfoIt($nDBs)." available DB connection$sS:".CRLF;
            $oHdr = $oTable->RowFromData(['name','specs']);
            $oHdr->IsHeader(TRUE);
            $oaDBs->RewindMe();
            foreach ($oaDBs as $sKey => $oConn) {
                #echo "[$sKey] DB CLASS: ".get_class($oConn).CRLF;
                $arRow = [$sKey,$oConn->DescribeInline()];
                $oTable->RowFromData($arRow);
            }
            $sOut .= $oTable->Render();
        } else {
            $sOut = 'No database connections are defined yet.'.CRLF;
        }
        return $sOut;
    }

    // -- OUTPUT -- //
}

Removed

2025-09-26

Commented out yesterday:

// ++ SETUP ++ //

    // 2025-09-25 I *think* none of this is necessary anymore. (Update: ODbOper() is needed, but it needs to fetch instead of creating.)
    public static function FromDbOper(DbOperIface $o) : iToDbOper {
        $oThis = new static;
        $oThis->WithDbOper($o);
        return $oThis;
    }

    // ++ SETUP: dynamic ++ //

    protected function WithDbOper(DbOperIface $o) { $this->ODbOper($o); }

    // -- SETUP -- //

2025-09-24

Commented out yesterday (but then reinstated 9/25 because the place I thought I moved them does not exist):

// ++++ from iface
    
    static function FromDbOper(DbOperIface $o) : self;

    // ++++ from class
    
    // 2025-09-23 moved to [WFe]Sys\Data\aux\uses\tDbOper

    // ++ SETUP ++ //

    public static function FromDbOper(DbOperIface $o) : iToDbOper {
        $oThis = new static;
        $oThis->WithDbOper($o);
        return $oThis;
    }

    // ++ SETUP: dynamic ++ //

    protected function WithDbOper(DbOperIface $o) { $this->ODbOper($o); }

    // -- SETUP -- //