Initial commit: CloudOps infrastructure platform
This commit is contained in:
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
|
||||
namespace Mautic\PluginBundle\Model;
|
||||
|
||||
use Mautic\CoreBundle\Model\FormModel;
|
||||
use Mautic\PluginBundle\Entity\IntegrationEntity;
|
||||
use Mautic\PluginBundle\Integration\IntegrationObject;
|
||||
|
||||
/**
|
||||
* @extends FormModel<IntegrationEntity>
|
||||
*/
|
||||
class IntegrationEntityModel extends FormModel
|
||||
{
|
||||
public function getIntegrationEntityRepository()
|
||||
{
|
||||
return $this->em->getRepository(IntegrationEntity::class);
|
||||
}
|
||||
|
||||
public function logDataSync(IntegrationObject $integrationObject): void
|
||||
{
|
||||
}
|
||||
|
||||
public function getSyncedRecords(IntegrationObject $integrationObject, $integrationName, $recordList, $internalEntityId = null)
|
||||
{
|
||||
if (!$formattedRecords = $this->formatListOfContacts($recordList)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$integrationEntityRepo = $this->getIntegrationEntityRepository();
|
||||
|
||||
return $integrationEntityRepo->getIntegrationsEntityId(
|
||||
$integrationName,
|
||||
$integrationObject->getType(),
|
||||
$integrationObject->getInternalType(),
|
||||
$internalEntityId,
|
||||
null,
|
||||
null,
|
||||
false,
|
||||
0,
|
||||
0,
|
||||
$formattedRecords
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<mixed, array<'id', mixed>>
|
||||
*/
|
||||
public function getRecordList($integrationObject): array
|
||||
{
|
||||
$recordList = [];
|
||||
|
||||
foreach ($integrationObject->getRecords() as $record) {
|
||||
$recordList[$record['Id']] = [
|
||||
'id' => $record['Id'],
|
||||
];
|
||||
}
|
||||
|
||||
return $recordList;
|
||||
}
|
||||
|
||||
public function formatListOfContacts($recordList): ?string
|
||||
{
|
||||
if (empty($recordList)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$csList = is_array($recordList) ? implode('", "', array_keys($recordList)) : $recordList;
|
||||
|
||||
return '"'.$csList.'"';
|
||||
}
|
||||
|
||||
public function getMauticContactsById($mauticContactIds, $integrationName, $internalObject)
|
||||
{
|
||||
if (!$formattedRecords = $this->formatListOfContacts($mauticContactIds)) {
|
||||
return [];
|
||||
}
|
||||
$integrationEntityRepo = $this->getIntegrationEntityRepository();
|
||||
|
||||
return $integrationEntityRepo->getIntegrationsEntityId(
|
||||
$integrationName,
|
||||
null,
|
||||
$internalObject,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
false,
|
||||
0,
|
||||
0,
|
||||
$formattedRecords
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
*
|
||||
* @return IntegrationEntity|null
|
||||
*/
|
||||
public function getEntityByIdAndSetSyncDate($id, \DateTime $dateTime)
|
||||
{
|
||||
$entity = $this->getIntegrationEntityRepository()->find($id);
|
||||
if ($entity) {
|
||||
$entity->setLastSyncDate($dateTime);
|
||||
}
|
||||
|
||||
return $entity;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,177 @@
|
||||
<?php
|
||||
|
||||
namespace Mautic\PluginBundle\Model;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\DBAL\Schema\Table;
|
||||
use Doctrine\ORM\EntityManager;
|
||||
use Doctrine\ORM\Mapping\ClassMetadata;
|
||||
use Mautic\CoreBundle\Helper\BundleHelper;
|
||||
use Mautic\CoreBundle\Helper\CoreParametersHelper;
|
||||
use Mautic\CoreBundle\Helper\UserHelper;
|
||||
use Mautic\CoreBundle\Model\FormModel;
|
||||
use Mautic\CoreBundle\Security\Permissions\CorePermissions;
|
||||
use Mautic\CoreBundle\Translation\Translator;
|
||||
use Mautic\LeadBundle\Field\FieldList;
|
||||
use Mautic\LeadBundle\Model\FieldModel;
|
||||
use Mautic\PluginBundle\Entity\Plugin;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
||||
|
||||
/**
|
||||
* @extends FormModel<Plugin>
|
||||
*/
|
||||
class PluginModel extends FormModel
|
||||
{
|
||||
public function __construct(
|
||||
protected FieldModel $leadFieldModel,
|
||||
private FieldList $fieldList,
|
||||
CoreParametersHelper $coreParametersHelper,
|
||||
private BundleHelper $bundleHelper,
|
||||
EntityManager $em,
|
||||
CorePermissions $security,
|
||||
EventDispatcherInterface $dispatcher,
|
||||
UrlGeneratorInterface $router,
|
||||
Translator $translator,
|
||||
UserHelper $userHelper,
|
||||
LoggerInterface $mauticLogger,
|
||||
) {
|
||||
parent::__construct($em, $security, $dispatcher, $router, $translator, $userHelper, $mauticLogger, $coreParametersHelper);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Mautic\PluginBundle\Entity\PluginRepository
|
||||
*/
|
||||
public function getRepository()
|
||||
{
|
||||
return $this->em->getRepository(Plugin::class);
|
||||
}
|
||||
|
||||
public function getIntegrationEntityRepository()
|
||||
{
|
||||
return $this->em->getRepository(\Mautic\PluginBundle\Entity\IntegrationEntity::class);
|
||||
}
|
||||
|
||||
public function getPermissionBase(): string
|
||||
{
|
||||
return 'plugin:plugins';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get lead fields used in selects/matching.
|
||||
*
|
||||
* @return mixed[]
|
||||
*/
|
||||
public function getLeadFields(): array
|
||||
{
|
||||
return $this->fieldList->getFieldList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Company fields.
|
||||
*
|
||||
* @return mixed[]
|
||||
*/
|
||||
public function getCompanyFields(): array
|
||||
{
|
||||
return $this->fieldList->getFieldList(true, true, ['isPublished' => true, 'object' => 'company']);
|
||||
}
|
||||
|
||||
public function saveFeatureSettings($entity): void
|
||||
{
|
||||
$this->em->persist($entity);
|
||||
$this->em->flush();
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads config.php arrays for all plugins.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getAllPluginsConfig()
|
||||
{
|
||||
return $this->bundleHelper->getPluginBundles();
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads all installed Plugin entities from database.
|
||||
*
|
||||
* @return Plugin[]
|
||||
*/
|
||||
public function getInstalledPlugins()
|
||||
{
|
||||
return $this->getEntities(
|
||||
[
|
||||
'index' => 'bundle',
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns metadata for all plugins.
|
||||
*
|
||||
* @return array<string, array<class-string, ClassMetadata>>
|
||||
*/
|
||||
public function getPluginsMetadata(): array
|
||||
{
|
||||
$allMetadata = $this->em->getMetadataFactory()->getAllMetadata();
|
||||
$pluginsMetadata = [];
|
||||
|
||||
foreach ($allMetadata as $meta) {
|
||||
$namespace = $meta->namespace;
|
||||
|
||||
if (str_contains($namespace, 'MauticPlugin')) {
|
||||
$bundleName = preg_replace('/\\\Entity$/', '', $namespace);
|
||||
if (!isset($pluginsMetadata[$bundleName])) {
|
||||
$pluginsMetadata[$bundleName] = [];
|
||||
}
|
||||
$pluginsMetadata[$bundleName][$meta->getName()] = $meta;
|
||||
}
|
||||
}
|
||||
|
||||
return $pluginsMetadata;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all tables of installed plugins.
|
||||
*
|
||||
* @param array<string, array<class-string, ClassMetadata>> $pluginsMetadata
|
||||
*
|
||||
* @return array<string, array<int, Table>>
|
||||
*/
|
||||
public function getInstalledPluginTables(array $pluginsMetadata): array
|
||||
{
|
||||
$currentSchema = $this->em->getConnection()->createSchemaManager()->introspectSchema();
|
||||
$installedPluginsTables = [];
|
||||
|
||||
foreach ($pluginsMetadata as $bundleName => $pluginMetadata) {
|
||||
foreach ($pluginMetadata as $meta) {
|
||||
$table = $meta->getTableName();
|
||||
|
||||
if (!isset($installedPluginsTables[$bundleName])) {
|
||||
$installedPluginsTables[$bundleName] = [];
|
||||
}
|
||||
|
||||
if ($currentSchema->hasTable($table)) {
|
||||
$installedPluginsTables[$bundleName][] = $currentSchema->getTable($table);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $installedPluginsTables;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates new Schema objects for all installed plugins.
|
||||
*/
|
||||
public function createPluginSchemas(array $installedPluginsTables): array
|
||||
{
|
||||
$installedPluginsSchemas = [];
|
||||
foreach ($installedPluginsTables as $bundleName => $tables) {
|
||||
$installedPluginsSchemas[$bundleName] = new Schema($tables);
|
||||
}
|
||||
|
||||
return $installedPluginsSchemas;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user