Ferreteria/v0.6/clade/Sys/Data/Engine/aux/ActionRq/Admin/ToDbOper: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
| Line 22: | Line 22: | ||
* '''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 | |||
==Code== | ==Code== | ||
''as of 2025-10-05'' | ''as of 2025-10-05'' | ||
| Line 137: | Line 145: | ||
// -- 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 -- // | |||
}} | }} | ||
Revision as of 14:31, 25 October 2025
| ||||||||||||||||||
About
- Purpose: parent-class for Action Requests that require a Database Operations object
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
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 -- //