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 CommandCreator extends \Aurora\System\Db\AbstractCommandCreator
16: {
17: /**
18: * @return string
19: */
20: public function getMessagesForSend($iTimestamp)
21: {
22: $sSql = "SELECT * FROM %smail_scheduled_messages WHERE schedule_timestamp < %d ORDER BY schedule_timestamp";
23:
24: return sprintf($sSql, $this->prefix(), $iTimestamp);
25: }
26:
27: /**
28: * @param int $iAccountID
29: * @param string $sFolderFullName
30: * @param string $sMessageUid
31: * @param string $sDeviceId
32: *
33: * @return string
34: */
35: public function addMessage($iAccountID, $sFolderFullName, $sMessageUid, $iScheduledTimestamp)
36: {
37: $sSql = 'INSERT INTO %smail_scheduled_messages ( account_id, folder_full_name, message_uid, schedule_timestamp ) VALUES ( %d, %s, %s, %d )';
38:
39: return sprintf($sSql, $this->prefix(), $iAccountID, $this->escapeString($sFolderFullName), $this->escapeString($sMessageUid), $iScheduledTimestamp);
40: }
41:
42: /**
43: * @param int $iAccountID
44: * @param string $sFolderFullName
45: * @param string $sMessageUid
46: * @param string $sDeviceId
47: *
48: * @return string
49: */
50: public function updateMessageScheduleTimestamp($iAccountID, $sFolderFullName, $sMessageUid, $iScheduledTimestamp)
51: {
52: $sSql = 'UPDATE %smail_scheduled_messages SET schedule_timestamp = %d WHERE account_id = %d AND folder_full_name = %s AND message_uid = %s';
53:
54: return sprintf($sSql, $this->prefix(), $iScheduledTimestamp, $iAccountID, $this->escapeString($sFolderFullName), $this->escapeString($sMessageUid));
55: }
56:
57: public function getMessage($iAccountID, $sFolderFullName, $sMessageUid)
58: {
59: $sSql = 'SELECT * FROM %smail_scheduled_messages WHERE account_id = %d AND folder_full_name = %s AND message_uid = %s';
60:
61: return sprintf($sSql, $this->prefix(), $iAccountID, $this->escapeString($sFolderFullName), $this->escapeString($sMessageUid));
62: }
63:
64: /**
65: * @param string $sDeviceId
66: *
67: * @return string
68: */
69: public function removeMessage($iAccountID, $sFolderFullName, $sMessageUid)
70: {
71: $sSql = 'DELETE FROM %smail_scheduled_messages WHERE account_id = %d AND folder_full_name = %s AND message_uid = %s';
72:
73: return sprintf($sSql, $this->prefix(), $iAccountID, $this->escapeString($sFolderFullName), $this->escapeString($sMessageUid));
74: }
75: }
76: