-
Notifications
You must be signed in to change notification settings - Fork 283
N°8891 - feat(DBObject): Add CopyIfNull() helper to copy attribute only if target is null #771
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -742,6 +742,35 @@ public function SetIfNull($sAttCode, $value) | |
| } | ||
| } | ||
|
|
||
| /** | ||
| * Helper to copy a value only if the target is currently undefined | ||
| * | ||
| * Call Copy() only of the internal representation of the target attribute is null. | ||
| * | ||
| * @api | ||
| * @see Copy() | ||
| * @see SetIfNull()) | ||
| * | ||
| * @param string $sDestAttCode | ||
| * @param string $sSourceAttCode | ||
| * | ||
| * @return bool true if copy was successfull or was not performed because target attribute isn't null | ||
| * | ||
| * @throws \CoreException | ||
| * @throws \CoreUnexpectedValue | ||
| * @throws \Exception | ||
| */ | ||
| public function CopyIfNull($sDestAttCode, $sSourceAttCode) | ||
| { | ||
| $oAttDef = MetaModel::GetAttributeDef(get_class($this), $sDestAttCode); | ||
| $oCurrentValue = $this->Get($sDestAttCode); | ||
| if ($oAttDef->IsNull($oCurrentValue)) | ||
| { | ||
| return $this->Copy($sDestAttCode, $sSourceAttCode); | ||
| } | ||
| return true; | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note to Combodo: Set() and Copy() do return true unconditionaly upon completion, but SetIfNul() do not return any value. Seems unconsistant to me.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And should SetIfNull() be updated to return a boolean upon completion ? |
||
| } | ||
|
|
||
| /** | ||
| * Helper to set a value that fits the attribute max size | ||
| * | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.