🔖 Version 1.0.0-beta

This commit is contained in:
Marc Koch 2025-03-20 16:01:05 +01:00
parent c93a06972b
commit 460a811554
Signed by: marc.koch
GPG key ID: 12406554CFB028B9
26 changed files with 2480 additions and 771 deletions

View file

@ -1,8 +1,8 @@
<?php
declare(strict_types=1);
namespace Civi\Mailinglistsync;
use Civi\Authx\None;
use CRM_Mailinglistsync_ExtensionUtil as E;
class MailingListSettings {
@ -14,6 +14,9 @@ class MailingListSettings {
E::SHORT_NAME . '_logging' => [
'data_type' => 'boolean',
],
E::SHORT_NAME . '_domain' => [
'data_type' => 'string',
],
E::SHORT_NAME . '_mlmmj_host' => [
'data_type' => 'string',
],
@ -75,7 +78,7 @@ class MailingListSettings {
*/
public static function get($key = NULL): mixed {
if (!is_null($key)) {
return \Civi::settings()->get($key);
return \Civi::settings()->get(E::SHORT_NAME . '_' . $key);
}
else {
$settings = [];
@ -95,30 +98,36 @@ class MailingListSettings {
* @return void
*/
public static function validate(array $values, array &$errors): void {
// Validate domain
if (empty($values[E::SHORT_NAME . '_domain'])) {
$errors[E::SHORT_NAME . '_domain'] = E::ts('Domain is required');
}
// Validate url if synchronization is enabled
$url = $values[E::SHORT_NAME . '_mailinglist_mlmmj_host'];
if (!empty($values[E::SHORT_NAME . '_mailinglist_mlmmj_enable']) && !filter_var($url, FILTER_VALIDATE_URL)) {
$errors[E::SHORT_NAME . '_mailinglist_mlmmj_host'] = E::ts('Invalid URL');
$url = $values[E::SHORT_NAME . '_mlmmj_host'];
if (!empty($values[E::SHORT_NAME . '__mlmmj_enable']) && !filter_var($url, FILTER_VALIDATE_URL)) {
$errors[E::SHORT_NAME . '_mlmmj_host'] = E::ts('Invalid URL');
}
// Validate port if synchronization is enabled and port is set
$port = $values[E::SHORT_NAME . '_mailinglist_mlmmj_port'] ?? NULL;
if (!empty($values[E::SHORT_NAME . '_mailinglist_mlmmj_enable']) && !empty($port)) {
$port = $values[E::SHORT_NAME . '_mlmmj_port'] ?? NULL;
if (!empty($values[E::SHORT_NAME . '_mlmmj_enable']) && !empty($port)) {
if (is_numeric($port)) {
$errors[E::SHORT_NAME . '_mailinglist_mlmmj_port'] = E::ts('Port must be a number');
$errors[E::SHORT_NAME . '_mlmmj_port'] = E::ts('Port must be a number');
}
if ($port < 1 || $port > 65535) {
$errors[E::SHORT_NAME . '_mailinglist_mlmmj_port'] = E::ts('Port must be between 1 and 65535');
$errors[E::SHORT_NAME . '_mlmmj_port'] = E::ts('Port must be between 1 and 65535');
}
}
// Require host and token if mlmmj is enabled
if (!empty($values[E::SHORT_NAME . '_mailinglist_mlmmj_enable'])) {
if (empty($values[E::SHORT_NAME . '_mailinglist_mlmmj_host'])) {
$errors[E::SHORT_NAME . '_mailinglist_mlmmj_host'] = E::ts('Host is required');
if (!empty($values[E::SHORT_NAME . '_mlmmj_enable'])) {
if (empty($values[E::SHORT_NAME . '_mlmmj_host'])) {
$errors[E::SHORT_NAME . '_mlmmj_host'] = E::ts('Host is required');
}
if (empty($values[E::SHORT_NAME . '_mailinglist_mlmmj_token'])) {
$errors[E::SHORT_NAME . '_mailinglist_mlmmj_token'] = E::ts('Token is required');
if (empty($values[E::SHORT_NAME . '_mlmmj_token'])) {
$errors[E::SHORT_NAME . '_mlmmj_token'] = E::ts('Token is required');
}
}
}