This appears to work from the member editing side - if you reload the member, the easting and northing is there. However, when I retrieve the published XML for searching (I'm using uComponents for this):
...the easting and northing properties are blank; they remain that way until I save the member a second time in the admin system, presumably because my property changes are not published.
I can't just call Save() after setting the property values because that will go into an infinite loop; is there anything else I can call to publish this that will not fire the AfterSave() event again?
As an addendum, I also can't just click the save button twice; I have to save the postcode change, reload the member from the tree to get the new easting / northing, and then save that.
Actually, I've just very easily solved this by simply using exactly the same code on the BeforeSave event handler rather than AfterSave. No idea why I didn't hink of this before.
As an addendum to the addendum, because this may help someone else, once I had fixed this problem, it became necessary to republish all the existing members to ensure that the easting / northings were updated in the member XML for any affected members, and it's important to note that Content -> right-click -> Republish All does NOT do this.
I solved it by writing a very simple user control to go through all members executing Save() and adding that to the member dashboard.
The important code is very simple (not sure if you even need the error catching as I didn't bother to check what Umbraco does on Save(), but it's there just in case):
List errors = new List();
umbraco.cms.businesslogic.member.Member[] members = umbraco.cms.businesslogic.member.Member.GetAll;
foreach (umbraco.cms.businesslogic.member.Member m in members)
{
try
{
m.Save();
}
catch
{
errors.Add(m.LoginName);
}
}
Whack that on a button click handler and you have a republish button for members. It does take a while though, even for a couple of hundred members, although I do have webservice geocode lookups on every single save, so it may just be my use case that makes it particularly bad.
Auto-update member properties on save
I have a member type with a postcode field.
Using the ApplicationBase, I've set up an AfterSave handler to geocode this and update the member with the easting and northing.
I then try to use this in searches.
The code I am using is this:
This appears to work from the member editing side - if you reload the member, the easting and northing is there. However, when I retrieve the published XML for searching (I'm using uComponents for this):
...the easting and northing properties are blank; they remain that way until I save the member a second time in the admin system, presumably because my property changes are not published.
I can't just call Save() after setting the property values because that will go into an infinite loop; is there anything else I can call to publish this that will not fire the AfterSave() event again?
As an addendum, I also can't just click the save button twice; I have to save the postcode change, reload the member from the tree to get the new easting / northing, and then save that.
Actually, I've just very easily solved this by simply using exactly the same code on the BeforeSave event handler rather than AfterSave. No idea why I didn't hink of this before.
As an addendum to the addendum, because this may help someone else, once I had fixed this problem, it became necessary to republish all the existing members to ensure that the easting / northings were updated in the member XML for any affected members, and it's important to note that Content -> right-click -> Republish All does NOT do this.
I solved it by writing a very simple user control to go through all members executing Save() and adding that to the member dashboard.
The important code is very simple (not sure if you even need the error catching as I didn't bother to check what Umbraco does on Save(), but it's there just in case):
Whack that on a button click handler and you have a republish button for members. It does take a while though, even for a couple of hundred members, although I do have webservice geocode lookups on every single save, so it may just be my use case that makes it particularly bad.
EDIT: Altered loop to use local variable as per http://our.umbraco.org/forum/developers/api-questions/7875-How-to-loop-through-all-members#comment29258
is working on a reply...