Skip to content

Commit a5c43fb

Browse files
committed
ASDFASDFASDFA
1 parent da095dd commit a5c43fb

File tree

6 files changed

+103
-2
lines changed

6 files changed

+103
-2
lines changed

.env.dist

+4
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ MAIL_TO_ERROR_REPORT_NAME='Database Wizards'
4040
4141
MAIL_TO_SUBSCRIPTION_NAME='Secretary of GEWIS'
4242

43+
MAILMAN_API_ENDPOINT=http://localhost:8020/3.1/
44+
MAILMAN_API_USERNAME=restadmin
45+
MAILMAN_API_PASSWORD=restpass
46+
4347
# LDAP settings (fill in to enable LDAP)
4448
LDAP_SERVERS=ldaps.gewis.nl
4549
LDAP_STARTTLS=true

config/autoload/local.development.php.dist

+9
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,15 @@ return [
5757
],
5858
],
5959

60+
/**
61+
* Mailman REST API configuration.
62+
*/
63+
'mailman_api' => [
64+
'endpoint' => getenv('MAILMAN_API_ENDPOINT'),
65+
'username' => getenv('MAILMAN_API_USERNAME'),
66+
'password' => getenv('MAILMAN_API_PASSWORD'),
67+
],
68+
6069
/**
6170
* LDAP settings for login to database frontend
6271
*/

config/autoload/local.production.php.dist

+9
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,15 @@ return [
5757
],
5858
],
5959

60+
/**
61+
* Mailman REST API configuration.
62+
*/
63+
'mailman_api' => [
64+
'endpoint' => getenv('MAILMAN_API_ENDPOINT'),
65+
'username' => getenv('MAILMAN_API_USERNAME'),
66+
'password' => getenv('MAILMAN_API_PASSWORD'),
67+
],
68+
6069
/**
6170
* LDAP settings for login to database frontend
6271
*/

module/Database/src/Model/MailingList.php

+25
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,15 @@ class MailingList
5454
#[Column(type: "boolean")]
5555
protected bool $defaultSub;
5656

57+
/**
58+
* The identifier of the mailing list in Mailman.
59+
*/
60+
#[Column(
61+
type: "string",
62+
unique: true,
63+
)]
64+
protected string $mailmanId;
65+
5766
/**
5867
* Mailing list members.
5968
*/
@@ -192,6 +201,22 @@ public function setDefaultSub(bool $default): void
192201
$this->defaultSub = $default;
193202
}
194203

204+
/**
205+
* Get the identifier of the mailing list in Mailman.
206+
*/
207+
public function getMailmanId(): string
208+
{
209+
return $this->mailmanId;
210+
}
211+
212+
/**
213+
* Set the identifier of the mailing list in Mailman.
214+
*/
215+
public function setMailmanId(string $mailmanId): void
216+
{
217+
$this->mailmanId = $mailmanId;
218+
}
219+
195220
/**
196221
* Get subscribed members.
197222
*

module/Database/src/Service/Factory/MailingListFactory.php

+3
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,14 @@ public function __invoke(
3131
$mailingListForm = $container->get(MailingListForm::class);
3232
/** @var MailingListMapper $mailingListMapper */
3333
$mailingListMapper = $container->get(MailingListMapper::class);
34+
/** @var array $mailmanConfig */
35+
$mailmanConfig = $container->get('config')['mailman_api'];
3436

3537
return new MailingListService(
3638
$deleteListForm,
3739
$mailingListForm,
3840
$mailingListMapper,
41+
$mailmanConfig,
3942
);
4043
}
4144
}

module/Database/src/Service/MailingList.php

+53-2
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,26 @@
44

55
namespace Database\Service;
66

7-
use Database\Form\DeleteList as DeleteListForm;
8-
use Database\Form\MailingList as MailingListForm;
7+
use Database\Form\{
8+
DeleteList as DeleteListForm,
9+
MailingList as MailingListForm,
10+
};
911
use Database\Mapper\MailingList as MailingListMapper;
1012
use Database\Model\MailingList as MailingListModel;
13+
use Laminas\Http\{
14+
Client,
15+
Client\Adapter\Curl,
16+
Request,
17+
Response};
18+
use RuntimeException;
1119

1220
class MailingList
1321
{
1422
public function __construct(
1523
private readonly DeleteListForm $deleteListForm,
1624
private readonly MailingListForm $mailingListForm,
1725
private readonly MailingListMapper $mailingListMapper,
26+
private readonly array $mailmanConfig,
1827
) {
1928
}
2029

@@ -78,6 +87,48 @@ public function delete(
7887
return true;
7988
}
8089

90+
/**
91+
* @param string $uri
92+
* @param string $method - Request::METHOD_GET
93+
*
94+
* @throws RuntimeException
95+
*
96+
* @return Response
97+
*/
98+
private function createMailmanRequest(
99+
string $uri,
100+
string $method = Request::METHOD_GET,
101+
string $encoding = 'application/json',
102+
array $data = [],
103+
): Response {
104+
$client = new Client();
105+
$request = new Request();
106+
107+
$request->setMethod($method)
108+
->setUri($this->mailmanConfig['endpoint'] . $uri);
109+
$client->setAdapter(Curl::class)
110+
->setAuth($this->mailmanConfig['username'], $this->mailmanConfig['password'])
111+
->setEncType($encoding);
112+
113+
switch ($method) {
114+
case Request::METHOD_GET:
115+
$client->setParameterGet($data);
116+
break;
117+
case Request::METHOD_POST:
118+
$client->setParameterPost($data);
119+
break;
120+
}
121+
122+
return $client->send($request);
123+
}
124+
125+
public function getAllListsFromMailman(): array
126+
{
127+
$client = $this->createMailmanRequest('lists');
128+
129+
try
130+
}
131+
81132
/**
82133
* Get the delete list form.
83134
*/

0 commit comments

Comments
 (0)