Skip to content

Commit 03bc172

Browse files
Aleksander KokoAleksander Koko
authored andcommitted
fixed duplicated emailEntry on SubscriberManager add
1 parent ab31f2c commit 03bc172

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

core/Model/SubscriberModel.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,19 @@ public function getSubscriberById( $id )
115115
return $result->fetch( \PDO::FETCH_ASSOC );
116116
}
117117

118+
public function getSubscriberByEmail( $emailAddress )
119+
{
120+
$result = $this->db->query(
121+
sprintf(
122+
"SELECT * FROM %s
123+
WHERE email = '%s'",
124+
$this->config->getTableName( 'user', true ),
125+
$emailAddress
126+
)
127+
);
128+
return $result->fetch( \PDO::FETCH_ASSOC );
129+
}
130+
118131
/**
119132
* Cleanly delete all records of a subscriber from DB
120133
* @param int $id ID of subscriber to delete

core/SubscriberManager.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,10 @@ public function add( \phpList\Entity\SubscriberEntity $scrEntity )
135135
throw new \Exception( 'Cannot insert subscriber with invalid email address: "' . $scrEntity->emailAddress . '"' );
136136
}
137137

138+
$entity = $this->subscriberModel->getSubscriberByEmail($scrEntity->emailAddress);
139+
if($entity["email"] !== null)
140+
throw new \Exception("Subscriber with that email already exists");
141+
138142
// Save subscriber to db
139143
$newSubscriberId = $this->subscriberModel->save(
140144
$scrEntity->emailAddress

0 commit comments

Comments
 (0)