Initial xentral_oss_20.3.c9ffacf

This commit is contained in:
Alex
2021-05-21 08:49:41 +02:00
parent 5406e4a551
commit 34e5ac43d9
18884 changed files with 2109867 additions and 0 deletions
@@ -0,0 +1,54 @@
<?php
declare(strict_types=1);
namespace Xentral\Modules\Ticket\Wrapper;
use Xentral\Components\Database\Database;
class AddressWrapper
{
/** @var Database $db */
private $db;
/**
* AddressWrapper constructor.
*
* @param Database $db
*/
public function __construct(Database $db)
{
$this->db = $db;
}
/**
* @param string $emailAddress
*
* @return int|null
*/
public function tryGetAddressIdByEmailAddress(string $emailAddress): ?int
{
$values = ['email_address' => $emailAddress];
$searchByEmail = 'SELECT a.id FROM `adresse` AS `a`
WHERE a.email LIKE :email_address AND a.geloescht = 0
ORDER BY a.id DESC';
$id = $this->db->fetchValue($searchByEmail, $values);
if ($id !== null && $id > 0) {
return $id;
}
$searchByResponsePerson = 'SELECT ap.adresse FROM `ansprechpartner` AS `ap`
WHERE ap.email LIKE :email_address
ORDER BY ap.id DESC';
$id = $this->db->fetchValue($searchByResponsePerson, $values);
if ($id !== null && $id > 0) {
return $id;
}
$searchByContactInfo = 'SELECT ak.adresse FROM `adresse_kontakte` AS `ak`
WHERE ak.kontakt LIKE :email_address ORDER BY ak.id DESC';
$id = $this->db->fetchValue($searchByContactInfo, $values);
return $id;
}
}
@@ -0,0 +1,122 @@
<?php
declare(strict_types=1);
namespace Xentral\Modules\Ticket\Wrapper;
use Xentral\Components\Database\Database;
use Xentral\Modules\Ticket\Exception\InvalidArgumentException;
class EmailBackupWrapper
{
/** @var Database $db */
private $db;
/**
* @param Database $db
*/
public function __construct(Database $db)
{
$this->db = $db;
}
/**
* @param int $emailAccountId
* @param string $subject
* @param string $sender
* @param string $plainTextBody
* @param string $htmlBody
* @param int $timestamp
* @param bool $hasAttachment
*
* @return int
*/
public function createEmailBackup(
int $emailAccountId,
string $subject,
string $sender,
string $plainTextBody,
string $htmlBody,
int $timestamp,
bool $hasAttachment
): int {
$sql = 'INSERT INTO `emailbackup_mails` (
`webmail`, `subject`, `sender`, `action`, `action_html`,
`empfang`, `anhang`, `checksum`
) VALUES (
:mail_account_id, :subject, :sender, :action, :action_html,
:date_received, :has_attachment, :checksum
)';
$date = date('Y-m-d H:i:s', $timestamp);
$checksum = md5($sender . $subject . $timestamp);
$values = [
'mail_account_id' => $emailAccountId,
'subject' => $subject,
'sender' => $sender,
'action' => $plainTextBody,
'action_html' => $htmlBody,
'date_received' => $date,
'has_attachment' => (int)$hasAttachment,
'checksum' => $checksum,
];
$this->db->perform($sql, $values);
return $this->db->lastInsertId();
}
/**
* @param int $emailAccountId
* @param string $sender
* @param string $subject
* @param int $timestamp
*
* @return bool
*/
public function existsEmailBackup(int $emailAccountId, string $sender, string $subject, int $timestamp): bool
{
$date = date('Y-m-d H:i:s', $timestamp);
$checksum = md5($sender . $subject . $timestamp);
$sql = 'SELECT COUNT(eb.id)
FROM `emailbackup_mails` AS `eb`
WHERE eb.checksum = :checksum AND eb.empfang = :date_received AND eb.webmail = :email_account_id';
$values = [
'checksum' => $checksum,
'date_received' => $date,
'email_account_id' => $emailAccountId,
];
$entriesCount = $this->db->fetchValue($sql, $values);
return $entriesCount !== null && $entriesCount > 0;
}
/**
* @param int $emailBackupId
* @param string $message
*
* @throws InvalidArgumentException
*
* @return void
*/
public function addTicketMessageToEmailBackup(int $emailBackupId, string $message): void
{
if (!$this->existsEmailBackupId($emailBackupId)) {
throw new InvalidArgumentException('email backup does not exits');
}
$sql = 'UPDATE `emailbackup_mails` SET `ticketnachricht` = :message WHERE `id` = :id';
$this->db->perform($sql, ['message' => $message, 'id' => $emailBackupId]);
}
/**
* @param int $emailBackupId
*
* @return bool
*/
public function existsEmailBackupId(int $emailBackupId): bool
{
$sql = 'SELECT COUNT(eb.id)
FROM `emailbackup_mails` AS `eb` WHERE eb.id = :id';
$id = $this->db->fetchValue($sql, ['id' => $emailBackupId]);
return $id === $emailBackupId;
}
}