🔖 Version 1.0.0-beta
This commit is contained in:
parent
c93a06972b
commit
460a811554
26 changed files with 2480 additions and 771 deletions
|
@ -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');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue