3063 Posts in 864 Topics by 646 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 599 Views |
-
Delete users Avatar before update

10 April 2011 at 5:42am
Ok, I want to minimize the amount of files created by members. I am trying to create an onBeforeWrite that will delete the users current avatar whenever it is updated. I am using a CommunityRole decorator to define the extra fields for my members, so I have the onBeforeWrite function there.
However, despite my attempts, the original avatar is never deleted. This is my current code:
function onBeforeWrite(){
parent::onBeforeWrite();
if (isset($this->Avatar)) {
$member = DataObject::get_one('Member', "ID = ".$this->ID);
$member->Avatar->delete();
}
}How do I correct this?
-
Re: Delete users Avatar before update

10 April 2011 at 6:20am
Ok, I determined that I had forgotten to add the required ->owner layer to the array and the if statement was being ignored; so I have updated my code to:
function onBeforeWrite(){
parent::onBeforeWrite();
if (isset($this->owner->Avatar)) {
$member = DataObject::get_one('Member', "ID = ".$this->owner->ID);
$member->Avatar->delete();
}
}However I can't figure out how to actually get the avatar to delete. The code as it is now spits out the error:
[Sat Apr 09 18:10:24 2011] [error] [client 67.193.94.39] PHP Fatal error: Call to a member function delete() on a non-object in ****/community/code/CommunityRole.php on line 64, referer: http://amateurwriting.org/community/editprofile?dev=1
-
Re: Delete users Avatar before update

10 May 2011 at 7:04pm
hi,
try something like this, if your method is still in the decorator. (it's untested…)function onBeforeWrite() {
if ($this->owner->AvatarID) {
$this->owner->Avatar()->delete();
}
parent::onBeforeWrite();
}
| 599 Views | ||
|
Page:
1
|
Go to Top |


