🎉 initial commit

This commit is contained in:
Marc Koch 2025-03-04 10:36:47 +01:00
commit c93a06972b
Signed by untrusted user who does not match committer: marc.koch
GPG key ID: 12406554CFB028B9
27 changed files with 4189 additions and 0 deletions

View file

@ -0,0 +1,49 @@
<?php
namespace Civi\Mailinglistsync;
use Civi\Api4\LocationType;
use Civi\Mailinglistsync\Exceptions\MailinglistException;
use CRM_Mailinglistsync_ExtensionUtil as E;
/**
* Gets the location type IDs for mailing list email-addresses either from
* the database or from the cache.
*
* @return array
* @throws \Civi\Mailinglistsync\Exceptions\MailinglistException
*/
function getLocationTypes(): array {
// Try to get location types from cache
$locationTypes = \Civi::cache()->get(E::SHORT_NAME . '_location_types');
// Get location types from database if not in cache
if ($locationTypes === NULL) {
$locationTypeNames = [
GroupMailingList::getLocationTypeName(),
ADGroupMailingList::getLocationTypeName(),
EventMailingList::getLocationTypeName(),
];
try {
$result = LocationType::get()
->addSelect('id', 'name')
->addWhere('name', 'IN', $locationTypeNames)
->execute()
->getArrayCopy();
$locationTypes = [];
foreach ($result as $locationType) {
$locationTypes[$locationType['id']] = $locationType['name'];
}
}
catch (\Exception $e) {
throw new MailinglistException(
E::ts('Could not get location types'),
MailinglistException::ERROR_CODE_GET_LOCATION_TYPES_FAILED,
);
}
// Cache location types
\Civi::cache()->set(E::SHORT_NAME . '_location_types', $locationTypes);
}
return $locationTypes;
}