Various updates
This commit is contained in:
@ -28,6 +28,20 @@ class Attachment extends Repository
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function install(): void
|
||||
{
|
||||
$query = "
|
||||
CREATE TABLE {$this->getTable()} (
|
||||
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
`message_id` INT UNSIGNED NOT NULL,
|
||||
`filename` VARCHAR(255) NOT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
FOREIGN KEY `fk_messages_{$this->getTable()}` (`message_id`)
|
||||
REFERENCES `messages` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
|
||||
)";
|
||||
$this->getConnection()->query($query);
|
||||
}
|
||||
|
||||
protected function fieldsForInsert(): array
|
||||
{
|
||||
return [
|
||||
@ -115,4 +129,11 @@ class Attachment extends Repository
|
||||
$query = "SELECT * FROM {$this->getTable()} WHERE message_id = ?";
|
||||
return $this->fetchMany($query, [$message_id]);
|
||||
}
|
||||
}
|
||||
public function fetchDownloaded(): array
|
||||
{
|
||||
$query = "SELECT a.*
|
||||
FROM `{$this->getTable()}` a JOIN `attachments_states` `as` ON `as`.attachment_id = a.id
|
||||
WHERE `as`.name = 'downloaded' AND `as`.value = 1";
|
||||
return $this->fetchMany($query);
|
||||
}
|
||||
}
|
||||
|
@ -29,6 +29,21 @@ class Job extends Repository
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function install(): void
|
||||
{
|
||||
$query = "
|
||||
CREATE TABLE {$this->getTable()} (
|
||||
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
`message_id` INT UNSIGNED NOT NULL,
|
||||
`date_time` DATETIME NOT NULL,
|
||||
`executed` INT(1) UNSIGNED DEFAULT 0,
|
||||
PRIMARY KEY (`id`),
|
||||
FOREIGN KEY `fk_messages_{$this->getTable()}` (`message_id`)
|
||||
REFERENCES `messages` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
|
||||
)";
|
||||
$this->getConnection()->query($query);
|
||||
}
|
||||
|
||||
protected function fieldsForUpdate(): array
|
||||
{
|
||||
return $this->fieldsForInsert();
|
||||
@ -105,4 +120,4 @@ class Job extends Repository
|
||||
$query = "SELECT * FROM {$this->getTable()} WHERE `message_id` = ? AND `executed` = 0";
|
||||
return $this->fetchOne($query, [$message_id]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -28,6 +28,18 @@ class Mailbox extends Repository
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function install(): void
|
||||
{
|
||||
$query = "
|
||||
CREATE TABLE {$this->getTable()} (
|
||||
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
`name` VARCHAR(100) NOT NULL,
|
||||
`validity` INT UNSIGNED NOT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
)";
|
||||
$this->getConnection()->query($query);
|
||||
}
|
||||
|
||||
protected function fieldsForUpdate(): array
|
||||
{
|
||||
return $this->fieldsForInsert();
|
||||
@ -86,4 +98,4 @@ class Mailbox extends Repository
|
||||
$query = "SELECT * FROM `{$this->getTable()}` WHERE `name` = ?";
|
||||
return $this->fetchOne($query, [$name]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,34 +3,50 @@ namespace ProVM\Emails\Repository;
|
||||
|
||||
use DateTimeInterface;
|
||||
use PDO;
|
||||
use PDOException;
|
||||
use Exception;
|
||||
use ProVM\Common\Define\Model;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use ProVM\Common\Implement\Repository;
|
||||
use Safe\DateTimeImmutable;
|
||||
use Safe\Exceptions\ErrorfuncException;
|
||||
use ProVM\Common\Define\Model;
|
||||
use ProVM\Common\Implement\Repository;
|
||||
use ProVM\Common\Factory;
|
||||
|
||||
class Message extends Repository
|
||||
{
|
||||
public function __construct(PDO $connection, LoggerInterface $logger, \ProVM\Common\Factory\Model $factory)
|
||||
public function __construct(PDO $connection, LoggerInterface $logger, Factory\Model $factory)
|
||||
{
|
||||
parent::__construct($connection, $logger);
|
||||
$this->setTable('messages')
|
||||
->setFactory($factory);
|
||||
}
|
||||
|
||||
protected \ProVM\Common\Factory\Model $factory;
|
||||
public function getFactory(): \ProVM\Common\Factory\Model
|
||||
protected Factory\Model $factory;
|
||||
public function getFactory(): Factory\Model
|
||||
{
|
||||
return $this->factory;
|
||||
}
|
||||
public function setFactory(\ProVM\Common\Factory\Model $factory): Message
|
||||
public function setFactory(Factory\Model $factory): Message
|
||||
{
|
||||
$this->factory = $factory;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function install(): void
|
||||
{
|
||||
$query = "
|
||||
CREATE TABLE {$this->getTable()} (
|
||||
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
`uid` VARCHAR(255) NOT NULL,
|
||||
`mailbox_id` INT UNSIGNED NOT NULL,
|
||||
`position` INT UNSIGNED NOT NULL,
|
||||
`subject` VARCHAR(255) NOT NULL,
|
||||
`from` VARCHAR(255) NOT NULL,
|
||||
`date_time` DATETIME NOT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
FOREIGN KEY `fk_mailboxes_{$this->getTable()}` (`mailbox_id`)
|
||||
REFERENCES `mailboxes` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
|
||||
)";
|
||||
$this->getConnection()->query($query);
|
||||
}
|
||||
|
||||
protected function fieldsForUpdate(): array
|
||||
{
|
||||
return $this->fieldsForInsert();
|
||||
@ -114,21 +130,23 @@ class Message extends Repository
|
||||
'downloaded_attachments',
|
||||
'scheduled_downloads'
|
||||
];
|
||||
$stateRepository = $this->getFactory()->find(\ProVM\Emails\Model\State\Message::class);
|
||||
foreach ($valid_states as $state_name) {
|
||||
try {
|
||||
$model->getState($state_name);
|
||||
} catch (\Exception $e) {
|
||||
$this->getLogger()->warning($e);
|
||||
$data = [
|
||||
'message_id' => $model->getId(),
|
||||
'name' => $state_name
|
||||
];
|
||||
$state = $this->getFactory()->find(\ProVM\Emails\Model\State\Message::class)->create($data);
|
||||
$state = $stateRepository->create($data);
|
||||
$model->addState($state);
|
||||
}
|
||||
}
|
||||
foreach ($model->getStates() as $state) {
|
||||
$state->setMessage($model);
|
||||
$this->getFactory()->find(\ProVM\Emails\Model\State\Message::class)->save($state);
|
||||
//$state->setMessage($model);
|
||||
$stateRepository->save($state);
|
||||
}
|
||||
}
|
||||
|
||||
@ -161,4 +179,9 @@ class Message extends Repository
|
||||
WHERE `mailbox_id` = ? `subject` = ? AND `from` = ? AND `date_time` = ?";
|
||||
return $this->fetchOne($query, [$mailbox_id, $subject, $from, $dateTime->format('Y-m-d H:i:s')]);
|
||||
}
|
||||
public function fetchAllBySubjectAndDate(string $subject, DateTimeInterface $dateTime): array
|
||||
{
|
||||
$query = "SELECT * FROM `{$this->getTable()}` WHERE `subject` = ? AND `date_time` BETWEEN ? AND ?";
|
||||
return $this->fetchMany($query, [$subject, $dateTime->format('Y-m-d 00:00:00'), $dateTime->format('Y-m-d 23:59:59')]);
|
||||
}
|
||||
}
|
||||
|
@ -26,6 +26,22 @@ class Attachment extends Repository
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function install(): void
|
||||
{
|
||||
$query = "
|
||||
CREATE TABLE {$this->getTable()} (
|
||||
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
`attachment_id` INT UNSIGNED NOT NULL,
|
||||
`name` VARCHAR(100) NOT NULL,
|
||||
`value` INT(1) NOT NULL DEFAULT 0,
|
||||
PRIMARY KEY (`id`),
|
||||
FOREIGN KEY `fk_attachments_{$this->getTable()}` (`attachment_id`)
|
||||
REFERENCES `attachments` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
|
||||
)
|
||||
";
|
||||
$this->getConnection()->query($query);
|
||||
}
|
||||
|
||||
protected function fieldsForInsert(): array
|
||||
{
|
||||
return [
|
||||
@ -90,4 +106,4 @@ class Attachment extends Repository
|
||||
$query = "SELECT * FROM `{$this->getTable()}` WHERE `attachment_id` = ? AND `name` = ?";
|
||||
return $this->fetchOne($query, [$attachment_id, $name]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -28,6 +28,23 @@ class Mailbox extends Repository
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function install(): void
|
||||
{
|
||||
$query = "
|
||||
CREATE TABLE {$this->getTable()} (
|
||||
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
`mailbox_id` INT UNSIGNED NOT NULL,
|
||||
`date_time` DATETIME NOT NULL,
|
||||
`count` INT UNSIGNED NOT NULL,
|
||||
`uids` TEXT NOT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
FOREIGN KEY `fk_mailboxes_{$this->getTable()}` (`mailbox_id`)
|
||||
REFERENCES `mailboxes` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
|
||||
)
|
||||
";
|
||||
$this->getConnection()->query($query);
|
||||
}
|
||||
|
||||
protected function fieldsForUpdate(): array
|
||||
{
|
||||
return $this->fieldsForInsert();
|
||||
@ -99,4 +116,4 @@ class Mailbox extends Repository
|
||||
$query = "SELECT * FROM `{$this->getTable()}` WHERE `mailbox_id` = ? AND `date_time` = ?";
|
||||
return $this->fetchOne($query, [$mailbox_id, $date_time]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -26,6 +26,22 @@ class Message extends Repository
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function install(): void
|
||||
{
|
||||
$query = "
|
||||
CREATE TABLE {$this->getTable()} (
|
||||
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
`message_id` INT UNSIGNED NOT NULL,
|
||||
`name` VARCHAR(100) NOT NULL,
|
||||
`value` INT(1) NOT NULL DEFAULT 0,
|
||||
PRIMARY KEY (`id`),
|
||||
FOREIGN KEY `fk_messages_{$this->getTable()}` (`message_id`)
|
||||
REFERENCES `messages` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
|
||||
)
|
||||
";
|
||||
$this->getConnection()->query($query);
|
||||
}
|
||||
|
||||
protected function fieldsForUpdate(): array
|
||||
{
|
||||
return $this->fieldsForInsert();
|
||||
@ -90,4 +106,4 @@ class Message extends Repository
|
||||
$query = "SELECT * FROM `{$this->getTable()}` WHERE `message_id` = ? AND `name` = ?";
|
||||
return $this->fetchOne($query, [$message_id, $name]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user