Add DatabaseObjectBuilder with TagBuilder implementation#6689
Draft
BurntimeX wants to merge 1 commit into
Draft
Conversation
Introduces an abstract builder for creating, updating and deleting database objects with a fluent setter API, batched transactional deletes and an `INSERT IGNORE`-style helper. `TagBuilder` is the first concrete implementation.
dtdesign
requested changes
Jun 17, 2026
| */ | ||
| final class TagBuilder extends DatabaseObjectBuilder | ||
| { | ||
| public function setTagID(int $tagID): static |
Member
There was a problem hiding this comment.
This must not be available inside the forUpdate() flow. Maybe introduce a generic method DatabaseObjectBuilder::setID() that does that. After all, this is only ever required for (a) sessions and (b) data imports.
| * | ||
| * @return TDatabaseObject | ||
| */ | ||
| public function save(): DatabaseObject |
Member
There was a problem hiding this comment.
This and all other methods declared by DatabaseObjectBuilder should be declared as final to allow us to make adjustments to this crucial component.
| { | ||
| $keys = $values = ''; | ||
| $statementParameters = []; | ||
| foreach (array_merge($this->properties, $this->customProperties) as $key => $value) { |
Member
There was a problem hiding this comment.
Should be \array_merge(), not array_merge().
Comment on lines
+89
to
+97
| if (static::getBaseClass()::getDatabaseTableIndexIsIdentity()) { | ||
| $id = WCF::getDB()->getInsertID(static::getBaseClass()::getDatabaseTableName(), static::getBaseClass()::getDatabaseTableIndexName()); | ||
| } elseif (isset($this->properties[static::getBaseClass()::getDatabaseTableIndexName()])) { | ||
| $id = $this->properties[static::getBaseClass()::getDatabaseTableIndexName()]; | ||
| } else { | ||
| throw new \BadMethodCallException("Missing value for '" . static::getBaseClass()::getDatabaseTableIndexName() . "'"); | ||
| } | ||
|
|
||
| return $id; |
Member
There was a problem hiding this comment.
This can be untangled into two conditional returns and an unconditional exception. The return $id just obfuscates the flow.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Introduces an abstract builder for creating, updating and deleting database objects with a fluent setter API, batched transactional deletes and an
INSERT IGNORE-style helper.TagBuilderis the first concrete implementation.