Juergen Posted July 10, 2015 Share Posted July 10, 2015 Hello @ all, I am using a hook method to empty some database tables after the save action under certain conditions. It works just fine for "standard fields" with text, but i run into problems by deleting files (images or other files such as pdf). Here is the code that I use: //clean all up if event is cancelled if(($page->template == "events") AND ($page->cancelled == "1")){ $this->message("Folgende Felder wurden geleert: Einleitungssatz, Hauptteil,...); $page->body = ""; $page->introtext = ""; foreach($page->downloadrepeater as $p){ $p->downloadfield = ""; $p->downloadfieldtitle = ""; $p->downloadfiledesc = ""; } } The fields body and introtext will be deleted as expected. The file fields are in a repeater field (downloadrepeater). Therefore I use the foreach loop. The repeaterfield consists of 3 fields: - the file upload field (=downloadfield) - the title field for the file (=downloadfieldtitle) and - the description field (=downloadfiledesc) The values of the title and the description field will be deleted too - so this works. The problem is to delete the file of the file upload field. I know that $p->downloadfield = "" is not the right approach but I have tried it also with delete(). Unfortunately I was not able to figure out the right syntax to delete the file too. Can someone help to get the right api call? Best regards Link to comment Share on other sites More sharing options...
matjazp Posted July 10, 2015 Share Posted July 10, 2015 Not tested, maybe $p->removeAll() or $p->delete($p->filename) 1 Link to comment Share on other sites More sharing options...
Juergen Posted July 10, 2015 Author Share Posted July 10, 2015 I have used $p->delete($p->filename) and it works!! Thanks Link to comment Share on other sites More sharing options...
Juergen Posted July 10, 2015 Author Share Posted July 10, 2015 If the image or file upload field is not in an repeater, you can delete it with this line of code: $page->nameofyourfield->deleteAll(); Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now