Support Topics Documentation Slack YouTube Blog

PHP SDK Remove methods not working


(david muir) #1

Hi,

I cannot remove a row from my collection using any of the methods provided in the php documentation.
I am able to get my row by object and return it, but calling any delete method throws a server error 500.
I have 3 other functions on the same script involving some more advanced object creation and querying which run fine. Here is some sample code

$object = Backendless::$Data->of(“Events”)->findById($objectID);

//data method
//Backendless::$Data->of("Events")->remove($object);


//presistence method
Backendless::$Persistence->of("Events")->remove($object);


//bulk
$event = new Events();
Backendless::$Persistence->of("Events")->removeBulk( $event, "objectId='".$objectID."'" );

Any thoughts? Thank you.


(Sergey Chupov) #2

Hi David,

Do you receive any error message? Like “Internal server error with ID XXX”. Also your application ID would help to search the logs for errors.


(david muir) #3

00750AD9-8347-789A-FF49-87F556EE0500

Internal Server Error 500


(Sergey Chupov) #4

Can you also please provide some objectId on which the remove request fails?


(david muir) #5

sure,

you can use this objectId for a row in Events
60FD196D-8B17-0C84-FF16-363B1BFD1F00.


(Sergey Chupov) #6

Please verify, can you remove the same object via the built-in REST console?


(david muir) #7

Confirmed,

The object was deleted via built in rest console


(Sergey Chupov) #8

I couldn’t find any logs on your applications with an error. Could you please try to debug your code and find a line of code where it fails or some more detailed error message?


(david muir) #9

Any of those Delete Methods are the break points in my code.
I currently call this one and it breaks:
Backendless::$Data->of(“Events”)->remove($object);

I have the object returning right before this call so I know it is retrieved.


(Sergey Chupov) #10

You can go into the remove method (our SDK source is available on GitHub) and see where exactly it fails.


(david muir) #11

I have looked at this method.

If I change your condition here:

if( $object_id == null || $object_id == “” ) {

        throw new BackendlessException( "Missing objectId for remove data", $code );
        
    }else{
        return $object_id;
    }

I get the object id back. If I take that else out it will go into these lines:

$this->cheackTargetTable( $this->extractObjectType( $data ), METHOD ); // if call method of() check target table and table in data structure

    return RequestBuilder::doRequest( 'data', $this->extractObjectType( $data ) . '/' . $object_id, [], 'DELETE' );

This is where the server will break and return error 500


(Sergey Chupov) #12

I believe the code still goes further. Please put a breakpoint in RequestBuilder’s doRequest function and check if the request is sent to the server. If yes, then you should receive the full text of the error in RequestBuilder’s handleError function. If the error is sent by the server, it will be of the form “Internal Server Error with ID XXXX”, where XXXX is the ID by which we will be able to find it in the logs and investigate why it happens. Otherwise it may be an error somewhere on the client, and you will still receive the full reason in RequestBuilder class or elsewhere the code goes.


(david muir) #13

Unfortunately I don’t have the time to look through the functions and debug where this is going wrong. For now I have a quick fix of curling to the rest console for deleting events.
This will work for me.

Hopefully you and your team will find the time to round out the remaining issues in the php sdk.