Problem/Motivation
If you use the Schema::dropTable() method the returned value should be the result of the query, but the returned query value is not verified and even if the query fail the method return TRUE.
mysql implementation:
$this->connection->query('DROP TABLE {' . $table . '}');
return TRUE;
postgre implementation:
$this->connection->query('DROP TABLE {' . $table . '}');
$this->resetTableInformation($table);
return TRUE;
sqlite implementation:
$this->connection->tableDropped = TRUE;
$this->connection->query('DROP TABLE {' . $table . '}');
return TRUE;
Proposed resolution
Its true that you always verify:
if (!$this->tableExists($table)) {
return FALSE;
}
But you can't assume that if the table exist this will be delete with the code:
$this->connection->query('DROP TABLE {' . $table . '}');
So, you need to be sure that the table was dropped.
Remaining tasks
Test the patch.
User interface changes
None.
API changes
None.
Data model changes
None.
Comment | File | Size | Author |
---|---|---|---|
#6 | 2862344-5.patch | 4.9 KB | daffie |
#6 | 2862344-5-tests-only.patch | 2.72 KB | daffie |
Comments
Comment #2
adriancidComment #3
daffie CreditAttribution: daffie commentedLooks good.
For all 3 methods:
Can be rewritten to:
Because of the API addition there needs to be a change record.
Comment #4
adriancidComment #5
adriancidComment #6
daffie CreditAttribution: daffie commentedI removed some spaces and tabs that where out of place.
I also moved some blank lines for better readability.
Made no code changes to the patch from comment #4.
I have added testing.
The part of the patch without the tests is for me RTBC.
There is still a change record necessary. See https://www.drupal.org/list-changes/drupal.
@adriancid: If you think that my tests are good enough you can put the status to RTBC. Do you like to make the change record?
Comment #9
daffie CreditAttribution: daffie commentedAdded the change record.
Comment #12
adriancid@daffie I just read the change record and I see that you says that is for Drupal 8.4 but here the issue says 8.3, this will be committed to the 8.3 or 8.4 branch?
https://www.drupal.org/node/2862512
Comment #13
adriancidComment #14
alexpottIf the query fails why wouldn't an exception be thrown?
Comment #15
alexpottDiscussed with @catch - both of us are in agreement the use-case and how this is actually useful needs to be demonstrated. Basically how are we ever going to trigger the return FALSE? All I can see is that we're going to do an extra query for no reason.
Comment #16
adriancid@alexpott we can do something like this to return TRUE or FALSE:
or like this to throw the exception:
I don't know what do you think
Comment #22
pameeela CreditAttribution: pameeela commented@alexpott can you weigh in on #16?
Comment #26
smustgrave CreditAttribution: smustgrave at Mobomo commented@alexpott good to close?
Comment #27
smustgrave CreditAttribution: smustgrave at Mobomo commentedclosing as outdated.
If still an issue please reopen.