Spaces:
No application file
No application file
File size: 1,964 Bytes
d2897cd |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
<?php
namespace Mautic\EmailBundle\Entity;
use Doctrine\ORM\NoResultException;
use Mautic\CoreBundle\Entity\CommonRepository;
/**
* @extends CommonRepository<Copy>
*/
class CopyRepository extends CommonRepository
{
/**
* @param string $hash
* @param string $subject
* @param string $body
* @param string $bodyText
*/
public function saveCopy($hash, $subject, $body, $bodyText)
{
$db = $this->getEntityManager()->getConnection();
try {
$db->insert(
MAUTIC_TABLE_PREFIX.'email_copies',
[
'id' => $hash,
'body' => $body,
'body_text' => $bodyText,
'subject' => $subject,
'date_created' => (new \DateTime())->setTimezone(new \DateTimeZone('UTC'))->format('Y-m-d H:i:s'),
]
);
return true;
} catch (\Exception $e) {
error_log($e);
return false;
}
}
/**
* @param string $string md5 hash or content
*
* @return array
*/
public function findByHash($string, $subject = null)
{
if (null !== $subject) {
// Combine subject with $string and hash together
$string = $subject.$string;
}
// Assume that $string is already a md5 hash if 32 characters
$hash = (32 !== strlen($string)) ? $hash = md5($string) : $string;
$q = $this->createQueryBuilder($this->getTableAlias());
$q->where(
$q->expr()->eq($this->getTableAlias().'.id', ':id')
)
->setParameter('id', $hash);
try {
$result = $q->getQuery()->getSingleResult();
} catch (NoResultException) {
$result = null;
}
return $result;
}
public function getTableAlias(): string
{
return 'ec';
}
}
|