Merge the Smartlinks plugin (SmartlinksBundle 0.6.0) into the bundle as the Smart Links domain (0.18.0)
Two domains, one MT3S bundle: Marketing Programs (unchanged) and the
imported Smart Links (smart links + UTM taxonomies), each keeping its
own menu, tables, routes and translations.
- Code moved from MauticPlugin\SmartlinksBundle\ to
MauticPlugin\MT3SMarketingProgramBundle\; template namespace
@Smartlinks/ -> @MT3SMarketingProgram/; smartlinks.js ->
Assets/js/mt3s-mp-smartlinks.js; icon -> Assets/img/smartlinks-icon.svg.
- Incoming migrations renamed Version_0_X_0_SmartLinks.php to avoid
the class-name collision; schema untouched, data intact.
- Permissions folded into MT3SMarketingProgramPermissions:
smart_links + taxonomies under the mt3smarketingprogram: base
(roles that had the old smartlinks: grants must be re-granted).
- config.php: Smart Links routes + menu group, public /l/{slug},
SmartlinksIntegration services, smartlinks_* parameters (legacy
utm_manager_* keys still readable), version 0.18.0. The 0.17.0
placeholder /s/marketing-program-utm-taxonomies is replaced by the
real /s/utm-taxonomies.
- Translations merged (en_US) and added (fr_FR); Tests/ + phpunit moved
in; readme documents both domains and the 0.18.0 merge history.
Verified live: menus, both config tabs, both lists + forms, program
pages, public redirect with taxonomy UTM values, host + unknown-slug
404s, 90/90 unit tests, full php -l, all ini catalogs parse.
This commit is contained in:
1 parent
debce4ba4a
commit
dce849610c
69 files changed
+8225
-43
No files matched your search
@@ -0,0 +1,104 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace MauticPlugin\MT3SMarketingProgramBundle\Entity;
|
||||
|
||||
use Mautic\CoreBundle\Entity\CommonRepository;
|
||||
|
||||
/**
|
||||
* @extends CommonRepository<SmartLink>
|
||||
*/
|
||||
class SmartLinkRepository extends CommonRepository
|
||||
{
|
||||
public function getTableAlias(): string
|
||||
{
|
||||
return 'sl';
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the page and the form with the links, so that the list doesn't query them one by one.
|
||||
*
|
||||
* @param array<string, mixed> $args
|
||||
*/
|
||||
public function getEntities(array $args = [])
|
||||
{
|
||||
$alias = $this->getTableAlias();
|
||||
|
||||
// The hit count of each link as a HIDDEN scalar: not hydrated into the entities, but
|
||||
// available as an order by column ("sl.hitCount") for the Hits column of the list.
|
||||
$hitCount = '(SELECT COUNT(h.id) FROM '.SmartLinkHit::class.' h WHERE h.smartLink = '.$alias.'.id) AS HIDDEN hitCount';
|
||||
|
||||
$args['qb'] = $this->createQueryBuilder($alias)
|
||||
->select($alias, 'pg', 'fm', $hitCount)
|
||||
->leftJoin($alias.'.page', 'pg')
|
||||
->leftJoin($alias.'.form', 'fm');
|
||||
|
||||
return parent::getEntities($args);
|
||||
}
|
||||
|
||||
/**
|
||||
* True when another link already uses this slug. A link being edited never collides with itself.
|
||||
*/
|
||||
public function slugExists(string $slug, ?int $ignoreId = null): bool
|
||||
{
|
||||
if ('' === $slug) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$qb = $this->createQueryBuilder($this->getTableAlias())
|
||||
->select('COUNT('.$this->getTableAlias().'.id)')
|
||||
->where($this->getTableAlias().'.slug = :slug')
|
||||
->setParameter('slug', $slug);
|
||||
|
||||
if (null !== $ignoreId) {
|
||||
$qb->andWhere($this->getTableAlias().'.id != :id')
|
||||
->setParameter('id', $ignoreId);
|
||||
}
|
||||
|
||||
return (int) $qb->getQuery()->getSingleScalarResult() > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* The list's search box matches the slug and the destination URL.
|
||||
*
|
||||
* @return array<int, mixed>
|
||||
*/
|
||||
protected function addCatchAllWhereClause($q, $filter): array
|
||||
{
|
||||
return $this->addStandardCatchAllWhereClause($q, $filter, [
|
||||
$this->getTableAlias().'.slug',
|
||||
$this->getTableAlias().'.destinationUrl',
|
||||
]);
|
||||
}
|
||||
/**
|
||||
* The Hits column of the list sorts by the number of hits of each link: the virtual
|
||||
* "hitCount" order by maps to the HIDDEN hitCount scalar of the list query. Everything
|
||||
* else falls back to core's column handling.
|
||||
*/
|
||||
protected function buildOrderByClause($q, array $args): void
|
||||
{
|
||||
$alias = $this->getTableAlias();
|
||||
$orderBy = (string) ($args['orderBy'] ?? '');
|
||||
$virtual = $alias.'.hitCount' === $orderBy || 'hitCount' === $orderBy;
|
||||
|
||||
if ($virtual && $q instanceof \Doctrine\ORM\QueryBuilder) {
|
||||
$orderByDir = $this->sanitize((string) ($args['orderByDir'] ?? 'ASC'));
|
||||
|
||||
$q->addOrderBy('hitCount', $orderByDir);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
parent::buildOrderByClause($q, $args);
|
||||
}
|
||||
/**
|
||||
* @return array<array{0: string, 1: string}>
|
||||
*/
|
||||
protected function getDefaultOrder(): array
|
||||
{
|
||||
return [
|
||||
[$this->getTableAlias().'.slug', 'ASC'],
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user