Error Deleting Data from Database

29 views
Skip to first unread message

Boris PADONOU

unread,
Nov 23, 2016, 6:42:45 AM11/23/16
to silverst...@googlegroups.com
Consider this:



private static $db = array(
"Show" => "Boolean",
"Delete" => "Boolean"
);


Private static $ summary_fields = array (
   "Delete" => "Delete",

    "Show" => "Show"

);


Each time the administration is reloaded, the data for that model is removed from the database.

This removed more than 300 documents from my database.

This is because SilverStripe calls the Delete () method in $summary_fields

Which in this case is a very very sensitive function.

In some cases, this little trick of SilverStripe can go very fast and save lives.

But destroys data now. And it took me 48 hours and  think that I was attacking, siphoning ...

For example, you can update the Delete method of the DataObject model to:

function delete ($now = false) {
    If ($now) {

     $ this->brokenOnDelete = true;
       $ this->onBeforeDelete();
   }
 }

So to call the Delete method, $now must take true, so that the data is deleted.


cordially






--
Boris PADONOU

COO KhulaTech SA. www.khulatech.com
CEO GPAY SARL.  www.mygpay.com

Patrick Nelson

unread,
Nov 23, 2016, 7:26:22 AM11/23/16
to silverst...@googlegroups.com
Great find! I haven't tested this to confirm your bug but I can see how this might be an issue.  I think a good solution for your code, right now, would instead be to rename the "Delete" field to something different but similar (e.g. "DoDelete" or maybe "Deleted"). Just some variation of the word that is still close to your intent/use for the field. 

Can you please submit this issue on github and include steps to repeat this big (like you did below)? https://github.com/silverstripe/silverstripe-framework/issues

Thanks for reporting. 

Sent from my iPad
--
You received this message because you are subscribed to the Google Groups "SilverStripe Core Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to silverstripe-d...@googlegroups.com.
To post to this group, send email to silverst...@googlegroups.com.
Visit this group at https://groups.google.com/group/silverstripe-dev.
For more options, visit https://groups.google.com/d/optout.

off...@netwerkstatt.at

unread,
Nov 23, 2016, 8:33:22 AM11/23/16
to silverst...@googlegroups.com

Should there be a check if a field is named like a method in DO base class? E.g. checking for reserved words.

 

In some cases i want a getTitle() method and a Title field (which calls $this->dbObject() to get the value from DB), so then we’d need to whitelist this name…

 

Cheers, Werner

Fred Condo

unread,
Nov 23, 2016, 11:43:33 AM11/23/16
to SilverStripe Core Development
Very good catch. For those trying to reproduce, you have to create a model admin for the model to trigger this bug. Then it is 100% reproducible.

Boris PADONOU

unread,
Nov 23, 2016, 12:10:59 PM11/23/16
to silverst...@googlegroups.com
Thanks Patrick.

I had already fixed by renaming my field in $db to DeleteMe.

To unsubscribe from this group and stop receiving emails from it, send an email to silverstripe-dev+unsubscribe@googlegroups.com.
To post to this group, send email to silverstripe-dev@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "SilverStripe Core Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to silverstripe-dev+unsubscribe@googlegroups.com.
To post to this group, send email to silverstripe-dev@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages