1: <?php
2: /**
3: * This code is licensed under AGPLv3 license or Afterlogic Software License
4: * if commercial version of the product was purchased.
5: * For full statements of the licenses see LICENSE-AFTERLOGIC and LICENSE-AGPL3 files.
6: */
7:
8: namespace Aurora\Modules\MailScheduledMessages\Storages\Db;
9:
10: /**
11: * @license https://www.gnu.org/licenses/agpl-3.0.html AGPL-3.0
12: * @license https://afterlogic.com/products/common-licensing Afterlogic Software License
13: * @copyright Copyright (c) 2023, Afterlogic Corp.
14: */
15: class Storage extends \Aurora\Modules\MailScheduledMessages\Storages\Storage
16: {
17: /**
18: * @var CDbStorage $oConnection
19: */
20: protected $oConnection;
21:
22: /**
23: * @var CApiMinCommandCreatorMySQL
24: */
25: protected $oCommandCreator;
26:
27: /**
28: *
29: * @param \Aurora\System\Managers\AbstractManager $oManager
30: */
31: public function __construct(\Aurora\System\Managers\AbstractManager &$oManager)
32: {
33: parent::__construct($oManager);
34:
35: $this->oConnection =& $oManager->GetConnection();
36: $this->oCommandCreator = new CommandCreator\MySQL();
37: }
38:
39: /**
40: * @return array|bool
41: */
42: public function getMessagesForSend($iTimestamp)
43: {
44: $mResult = [];
45:
46: if ($this->oConnection->Execute($this->oCommandCreator->getMessagesForSend($iTimestamp))) {
47: $oRow = null;
48: while (false !== ($oRow = $this->oConnection->GetNextRecord())) {
49: $mResult[] = [
50: 'AccountId' => (int) $oRow->account_id,
51: 'FolderFullName' => $oRow->folder_full_name,
52: 'MessageUid' => $oRow->message_uid,
53: 'ScheduleTimestamp' => (int) $oRow->schedule_timestamp
54: ];
55: }
56: $this->oConnection->FreeResult();
57: }
58:
59: return $mResult;
60: }
61:
62: public function getMessage($iAccountID, $sFolderFullName, $sMessageUid)
63: {
64: $mResult = false;
65: if ($this->oConnection->Execute($this->oCommandCreator->getMessage($iAccountID, $sFolderFullName, $sMessageUid))) {
66: $oRow = $this->oConnection->GetNextRecord();
67: if ($oRow !== false) {
68: $mResult = [
69: 'AccountId' => (int) $oRow->account_id,
70: 'FolderFullName' => $oRow->folder_full_name,
71: 'MessageUid' => $oRow->message_uid,
72: 'ScheduleTimestamp' => (int) $oRow->schedule_timestamp
73: ];
74: }
75: $this->oConnection->FreeResult();
76: }
77:
78: return $mResult;
79: }
80:
81: public function addMessage($iAccountID, $sFolderFullName, $sMessageUid, $iTimestamp)
82: {
83: return $this->oConnection->Execute($this->oCommandCreator->addMessage($iAccountID, $sFolderFullName, $sMessageUid, $iTimestamp));
84: }
85:
86: public function updateMessageScheduleTimestamp($iAccountID, $sFolderFullName, $sMessageUid, $iTimestamp)
87: {
88: return $this->oConnection->Execute($this->oCommandCreator->updateMessageScheduleTimestamp($iAccountID, $sFolderFullName, $sMessageUid, $iTimestamp));
89: }
90:
91: public function removeMessage($iAccountID, $sFolderFullName, $sMessageUid)
92: {
93: return $this->oConnection->Execute($this->oCommandCreator->removeMessage($iAccountID, $sFolderFullName, $sMessageUid));
94: }
95: }
96: