Commit aa91bc17 authored by Rob Hulswit's avatar Rob Hulswit

Merge branch 'feature/fallback-registerslot' into 'master'

[backport] fallback values for registerslot

See merge request !225
parents 6727941e 38046385
......@@ -33,3 +33,8 @@ INTEGER newsfolder := LookupInWHFSRegister("mysupersite:news");
```
%LookupInWHFSRegister will never return 0, but will throw and explain which slot was not yet configured in its exception. It may, however, return ids of deleted objects..
## Fallback value
The `<registerslot>` can specify a 'fallback' which will be returned if the slot is unset and can't find its initial value. If the fallback value exists and is returned
it will not be 'set' as the value for the slot so the registerslot won't follow the file if it's moved. Fallback values are mostly useful for tests to specify an alternative
testing version of a register slot
......@@ -1668,6 +1668,7 @@
<xs:attribute name="description" />
<xs:attribute name="descriptiontid" type="SimpleTid" />
<xs:attribute name="initialvalue" />
<xs:attribute name="fallback" />
<xs:attribute name="type" use="required">
<xs:annotation>
<xs:documentation>
......
......@@ -579,6 +579,7 @@ PUBLIC RECORD ARRAY FUNCTION GetWHFSRegisterSlots(STRING modulename, OBJECT modd
, title := ParseXMLTidPtr(modulename, "", slot, "title")
, description := ParseXMLTidPtr(modulename, "", slot, "description")
, initialvalue := slot->GetAttribute("initialvalue")
, fallback := slot->GetAttribute("fallback")
, type := slot->GetAttribute("type")
] INTO slots AT END;
}
......
......@@ -84,18 +84,25 @@ INTEGER FUNCTION TryAddWHFSRegister(RECORD slot, INTEGER for_deleted_file)
}
STRING aboutslot := `WHFS register slot '${slot.module}:${slot.name}' ${for_deleted_file != 0 ? ` refers to deleted object #${for_deleted_file}` : `has not been set`}`;
IF(modinfo.initialvalue = "")
{
GetPrimary()->CommitWork(); //don't waste the work so far
THROW NEW Exception(`${aboutslot} and has no initial value`);
}
INTEGER target;
IF(modinfo.initialvalue != "")
target := LookupWHFSObject(0, modinfo.initialvalue);
//Look it up
INTEGER target := LookupWHFSObject(0, modinfo.initialvalue);
IF(target <= 0)//-1 is not found, 0 is root, both are unacceptable destinations
{
GetPrimary()->CommitWork(); //don't waste the work so far
THROW NEW Exception(`${aboutslot} and its initial value '${modinfo.initialvalue}' could not be located`);
GetPrimary()->CommitWork(); //don't waste the work (EnsureSlotFile) so far
IF(modinfo.fallback != "") //if the fallback is available, return but don't record it
{
target := LookupWHFSObject(0, modinfo.fallback);
IF(target > 0)
RETURN target;
}
IF(modinfo.initialvalue = "")
THROW NEW Exception(`${aboutslot} and has no initial value`);
ELSE
THROW NEW Exception(`${aboutslot} and its initial value '${modinfo.initialvalue}' could not be located`);
}
//Store it
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment