Skip to content

Commit 187289d

Browse files
Aleksander KokoAleksander Koko
authored andcommitted
added exception when a subscriber already exist on a list
1 parent 03bc172 commit 187289d

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

core/Model/ListModel.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@ public function __construct( \phplist\Config $config, \phplist\helper\Database $
2121
*/
2222
public function addSubscriber( $subscriberId, $listId )
2323
{
24+
25+
$lists = $this->getListsForSubscriber((int) $subscriberId);
26+
foreach ($lists as $list){
27+
if((int) $list["id"] === (int) $listId){
28+
throw new \Exception("Subscriber is already subscribed on that list");
29+
}
30+
}
31+
2432
$result = $this->db->query(
2533
sprintf(
2634
'INSERT INTO
@@ -202,7 +210,7 @@ public function getListsForSubscriber( $subscriber_id )
202210
, $subscriber_id
203211
)
204212
);
205-
return $this->makeLists( $result );
213+
return $result->fetchAll( \PDO::FETCH_ASSOC );
206214
}
207215

208216
/**

0 commit comments

Comments
 (0)