Open sunnysideup opened 9 months ago
I sometimes write hacky code like this:
$tableName = 'Product'; $stage = Versioned::get_stage(); if ($stage === 'Live') { $tableName .= '_Live'; }
The "proper" way to write this would be:
$sng = DataObject::singleton(Product::class); $schema = $sng->getSchema(); $tableName = $schema->tableName(Product::class); $tableName = $sng->stageTable($tableName, Versioned::get_stage());
It would be nice if I could write:
$tableName = Versioned::get_stage_table(Product::class);
This means that we should take stageTable from Versioned and add a static function: https://github.com/silverstripe/silverstripe-versioned/blob/2/src/Versioned.php#L2125-L2131
public function stageTable(?string $table = '', ?string $stage = '') { if(! $tableName) { $schema = $sng->getSchema(); $table = $schema->tableName(get_class($this->getOwner())); } if($this->hasStages()) { if(! $stage) { $stage = self::get_stage(); } if ($this->hasStages() && $stage === static::LIVE) { return "{$table}_{$stage}"; } } return $table; } public static function get_stage_table_from_class_name(string $className, ?string $stage = '') { $obj = Injector::inst()->get($className); $tableName = $obj->getSchema()->tableName($className); return $obj->stageTable($tableName, $stage); }
No response
Description
I sometimes write hacky code like this:
The "proper" way to write this would be:
It would be nice if I could write:
This means that we should take stageTable from Versioned and add a static function: https://github.com/silverstripe/silverstripe-versioned/blob/2/src/Versioned.php#L2125-L2131
Additional context or points of discussion
No response
Validations