Closed MaxZhuravlev closed 8 years ago
Unfortunately this work around doesnt really apply to my situation. Even testing on a new blank sheet it returns a 400 error, and it seems to be related to the DefaultServiceRequest.
PHP Fatal error: Uncaught exception 'Google\Spreadsheet\Exception' with message 'Error in Google Request' in /var/www/html/vendor/asimlqt/php-google-spreadsheet-client/src/Google/Spreadsheet/DefaultServiceRequest.php:286
Stack trace:
#0 /var/www/html/vendor/asimlqt/php-google-spreadsheet-client/src/Google/Spreadsheet/DefaultServiceRequest.php(181): Google\Spreadsheet\DefaultServiceRequest->execute(Resource id #94)
#1 /var/www/html/vendor/asimlqt/php-google-spreadsheet-client/src/Google/Spreadsheet/ListFeed.php(89): Google\Spreadsheet\DefaultServiceRequest->post('https://spreads...', '<entry xmlns="h...')
#2 /var/www/html/textLoggerAlpha.php(257): Google\Spreadsheet\ListFeed->insert(Array)
#3 /var/www/html/textLoggerAlpha.php(164): batch(841, 1500)
#4 {main}
thrown in /var/www/html/vendor/asimlqt/php-google-spreadsheet-client/src/Google/Spreadsheet/DefaultServiceRequest.php on line 286
@MaxZhuravlev Thanks for raising this. I can confirm this is definitely a bug and is not to do with this library. It's a bug in the Spreadsheet API which Google need to fix. I have submitted a ticket so we'll just have to wait for their response.
https://code.google.com/a/google.com/p/apps-api-issues/issues/detail?id=4382
As temporary workaround in your situation you can just loop over the entries in reverse order:
foreach (array_reverse($worksheet->getListFeed()->getEntries()) as $entry) {
$values = $entry->getValues();
if ($values["numberordelete"] === "Delete") {
$entry->delete();
}
}
@asimlqt Why use array_reverse?
@DenoBY Have you read the bug report I posted for this issue? There's a link in my previous comment.
Apparently Google don't think this is a bug and are not going to fix it so 'm closing this issue.
@asimlqt Thank
Test: Create such spreadsheet
Run code that should delete rows with "Delete" text:
Result:
First "delete me" row deleted correctly. Second and further deletions/editings are all displaced! Deleting wrong rows!
Also in same situations in long lists, if you try to delete last row, google will return error 400.
Workaround which works for me:
Result of testing this workaround on same spreadsheet: