Fix duplicate key messages for MySQL >= 8.0.19

[MAILPOET-2642]
This commit is contained in:
Jan Jakeš
2020-01-23 13:37:46 +01:00
committed by Jack Kitterhing
parent dc7e87a67f
commit 996b58a388
3 changed files with 3 additions and 2 deletions

View File

@ -232,7 +232,7 @@ class Model extends \MailPoetVendor\Sudzy\ValidModel {
} catch (\PDOException $e) {
switch ($e->getCode()) {
case 23000:
preg_match("/for key \'(.*?)\'/i", $e->getMessage(), $matches);
preg_match("/for key '(?:.*\.)*(.*?)'/i", $e->getMessage(), $matches);
if (isset($matches[1])) {
$column = $matches[1];
$this->setError(

View File

@ -79,7 +79,7 @@ class SegmentsTest extends \MailPoetTest {
$response = $this->endpoint->save($duplicateEntry);
expect($response->status)->equals(APIResponse::STATUS_BAD_REQUEST);
expect($response->errors[0]['message'])->regExp('/Another record already exists. Please specify a different ".*name"./');
expect($response->errors[0]['message'])->equals('Another record already exists. Please specify a different "name".');
}
public function testItCanRestoreASegment() {

View File

@ -49,6 +49,7 @@ class SaverTest extends \MailPoetTest {
]);
$this->expectException('\MailPoet\DynamicSegments\Exceptions\ErrorSavingException');
$this->expectExceptionCode(Model::DUPLICATE_RECORD);
$this->expectExceptionMessage('Another record already exists. Please specify a different "PRIMARY".');
$this->saver->save($dynamicSegment2);
}