From 88ade9cfa3028a9335a58b2f12b35cb0bb20448f Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Sun, 9 Jun 2013 13:10:58 +0200 Subject: [PATCH 01/10] Adding support for various notifications * Adding new SQL upgrade for notifications * Added support for per user notification settings * Added account_id to notifications table * Added new notification_settings table * Added new account page: notifications Addresses #144 --- cronjobs/notifications.php | 2 +- public/include/classes/notification.class.php | 83 +++++++++++++++++-- .../pages/account/notifications.inc.php | 25 ++++++ .../mmcFE/account/notifications/default.tpl | 60 ++++++++++++++ public/templates/mmcFE/global/navigation.tpl | 1 + sql/issue_144_notification_upgrade.sql | 6 ++ 6 files changed, 171 insertions(+), 6 deletions(-) create mode 100644 public/include/pages/account/notifications.inc.php create mode 100644 public/templates/mmcFE/account/notifications/default.tpl create mode 100644 sql/issue_144_notification_upgrade.sql diff --git a/cronjobs/notifications.php b/cronjobs/notifications.php index aa2bf8a9..eddef3de 100755 --- a/cronjobs/notifications.php +++ b/cronjobs/notifications.php @@ -36,7 +36,7 @@ if (empty($aWorkers)) { verbose("Worker already notified\n"); continue; } - if ($notification->addNotification('idle_worker', $aData) && $notification->sendMail($aData['email'], 'idle_worker', $aData)) { + if ($notification->addNotification($aWorker['account_id'], 'idle_worker', $aData) && $notification->sendMail($aData['email'], 'idle_worker', $aData)) { verbose ("Notified " . $aData['email'] . " for IDLE worker " . $aWorker['username'] . "\n"); } else { verbose("Unable to send notification: " . $notification->getError() . "\n"); diff --git a/public/include/classes/notification.class.php b/public/include/classes/notification.class.php index 983db437..cff05abb 100644 --- a/public/include/classes/notification.class.php +++ b/public/include/classes/notification.class.php @@ -6,6 +6,7 @@ if (!defined('SECURITY')) class Notification extends Mail { var $table = 'notifications'; + var $tableSettings = 'notification_settings'; public function setInactive($id) { $field = array( @@ -22,9 +23,10 @@ class Notification extends Mail { * @param field string Field to update * @return bool **/ - private function updateSingle($id, $field) { + private function updateSingle($id, $field, $table='') { + if (empty($table)) $table = $this->table; $this->debug->append("STA " . __METHOD__, 4); - $stmt = $this->mysqli->prepare("UPDATE $this->table SET " . $field['name'] . " = ? WHERE id = ? LIMIT 1"); + $stmt = $this->mysqli->prepare("UPDATE $table SET " . $field['name'] . " = ? WHERE id = ? LIMIT 1"); if ($this->checkStmt($stmt) && $stmt->bind_param($field['type'].'i', $field['value'], $id) && $stmt->execute()) return true; $this->debug->append("Unable to update " . $field['name'] . " with " . $field['value'] . " for ID $id"); @@ -35,6 +37,7 @@ class Notification extends Mail { * so we can avoid duplicate entries **/ public function isNotified($aData) { + $this->debug->append("STA " . __METHOD__, 4); $data = json_encode($aData); $stmt = $this->mysqli->prepare("SELECT id FROM $this->table WHERE data = ? AND active = 1 LIMIT 1"); if ($stmt && $stmt->bind_param('s', $data) && $stmt->execute() && $stmt->store_result() && $stmt->num_rows == 1) @@ -49,6 +52,7 @@ class Notification extends Mail { * Get all active notifications **/ public function getAllActive() { + $this->debug->append("STA " . __METHOD__, 4); $stmt =$this->mysqli->prepare("SELECT id, data FROM $this->table WHERE active = 1 LIMIT 1"); if ($stmt && $stmt->execute() && $result = $stmt->get_result()) return $result->fetch_all(MYSQLI_ASSOC); @@ -61,16 +65,85 @@ class Notification extends Mail { * @param type string Type of the notification * @return bool **/ - public function addNotification($type, $data) { + public function addNotification($account_id, $type, $data) { + $this->debug->append("STA " . __METHOD__, 4); // Store notification data as json $data = json_encode($data); - $stmt = $this->mysqli->prepare("INSERT INTO $this->table (type, data, active) VALUES (?,?,1)"); - if ($stmt && $stmt->bind_param('ss', $type, $data) && $stmt->execute()) + $stmt = $this->mysqli->prepare("INSERT INTO $this->table (account_id, type, data, active) VALUES (?, ?,?,1)"); + if ($stmt && $stmt->bind_param('iss', $account_id, $type, $data) && $stmt->execute()) return true; $this->debug->append("Failed to add notification for $type with $data: " . $this->mysqli->error); $this->setErrorMessage("Unable to add new notification"); return false; } + + /** + * Fetch notifications for a user account + * @param id int Account ID + * @return array Notification data + **/ + public function getNofifications($account_id) { + $this->debug->append("STA " . __METHOD__, 4); + $stmt = $this->mysqli->prepare("SELECT * FROM $this->table WHERE account_id = ? ORDER BY time DESC"); + if ($stmt && $stmt->bind_param('i', $account_id) && $stmt->execute() && $result = $stmt->get_result()) + return $result->fetch_all(MYSQLI_ASSOC); + // Catchall + return false; + } + + /** + * Fetch notification settings for user account + * @param id int Account ID + * @return array Notification settings + **/ + public function getNotificationSettings($account_id) { + $this->debug->append("STA " . __METHOD__, 4); + $stmt = $this->mysqli->prepare("SELECT * FROM $this->tableSettings WHERE account_id = ?"); + if ($stmt && $stmt->bind_param('i', $account_id) && $stmt->execute() && $result = $stmt->get_result()) { + while ($row = $result->fetch_assoc()) { + $aData[$row['type']] = $row['active']; + } + return $aData; + } + // Catchall + return false; + } + + /** + * Update accounts notification settings + * @param account_id int Account ID + * @param data array Data array + * @return bool + **/ + public function updateSettings($account_id, $data) { + $this->debug->append("STA " . __METHOD__, 4); + $failed = $ok = 0; + foreach ($data as $type => $active) { + // Does an entry exist already + $stmt = $this->mysqli->prepare("SELECT * FROM $this->tableSettings WHERE account_id = ? AND type = ?"); + if ($stmt && $stmt->bind_param('is', $account_id, $type) && $stmt->execute() && $stmt->store_result() && $stmt->num_rows() > 0) { + // We found a matching row + $stmt = $this->mysqli->prepare("UPDATE $this->tableSettings SET active = ? WHERE type = ? AND account_id = ?"); + if ($stmt && $stmt->bind_param('isi', $active, $type, $account_id) && $stmt->execute() && $stmt->close()) { + $ok++; + } else { + $failed++; + } + } else { + $stmt = $this->mysqli->prepare("INSERT INTO $this->tableSettings (active, type, account_id) VALUES (?,?,?)"); + if ($stmt && $stmt->bind_param('isi', $active, $type, $account_id) && $stmt->execute()) { + $ok++; + } else { + $failed++; + } + } + } + if ($failed > 0) { + $this->setErrorMessage('Failed to update ' . $failed . ' settings'); + return false; + } + return true; + } } $notification = new Notification(); diff --git a/public/include/pages/account/notifications.inc.php b/public/include/pages/account/notifications.inc.php new file mode 100644 index 00000000..2ab9c0d0 --- /dev/null +++ b/public/include/pages/account/notifications.inc.php @@ -0,0 +1,25 @@ +updateSettings($_SESSION['USERDATA']['id'], $_REQUEST['data'])) { + $_SESSION['POPUP'][] = array('CONTENT' => 'Updated notification settings'); + } else { + $_SESSION['POPUP'][] = array('CONTENT' => 'Failed to update settings', 'TYPE' => 'errormsg'); + } +} + +// Fetch notifications +$aNotifications = $notification->getNofifications($_SESSION['USERDATA']['id']); +if (!$aNotifications) $_SESSION['POPUP'][] = array('CONTENT' => 'Could not find any notifications', 'TYPE' => 'errormsg'); + +// Fetch user notification settings +$aSettings = $notification->getNotificationSettings($_SESSION['USERDATA']['id']); + +$smarty->assign('NOTIFICATIONS', $aNotifications); +$smarty->assign('SETTINGS', $aSettings); +$smarty->assign('CONTENT', 'default.tpl'); +?> diff --git a/public/templates/mmcFE/account/notifications/default.tpl b/public/templates/mmcFE/account/notifications/default.tpl new file mode 100644 index 00000000..1b737f79 --- /dev/null +++ b/public/templates/mmcFE/account/notifications/default.tpl @@ -0,0 +1,60 @@ +{include file="global/block_header.tpl" ALIGN="left" BLOCK_HEADER="Notification Settings"} +
+ + + + + + + + + + + + + + + + + + + +
TypeActive
New Blocks + + +
Auto Payout + + +
+ +
+
+{include file="global/block_footer.tpl"} + +{include file="global/block_header.tpl" ALIGN="right" BLOCK_HEADER="Notification History"} +
+ {include file="global/pagination.tpl"} + + + + + + + + + + +{section notification $NOTIFICATIONS} + + + + + + +{/section} + +
IDTimeTypeActive
{$NOTIFICATIONS[notification].id}{$NOTIFICATIONS[notification].time}{$NOTIFICATIONS[notification].type} + +
+
+{include file="global/block_footer.tpl"} diff --git a/public/templates/mmcFE/global/navigation.tpl b/public/templates/mmcFE/global/navigation.tpl index 6a0cdb37..3f26387a 100644 --- a/public/templates/mmcFE/global/navigation.tpl +++ b/public/templates/mmcFE/global/navigation.tpl @@ -7,6 +7,7 @@
  • My Workers
  • My Graphs
  • Transactions
  • +
  • Notifications
  • {/if} diff --git a/sql/issue_144_notification_upgrade.sql b/sql/issue_144_notification_upgrade.sql new file mode 100644 index 00000000..e2884e9e --- /dev/null +++ b/sql/issue_144_notification_upgrade.sql @@ -0,0 +1,6 @@ +ALTER TABLE `notifications` ADD `account_id` INT UNSIGNED NULL DEFAULT NULL , ADD INDEX ( `account_id` ) +CREATE TABLE IF NOT EXISTS `notification_settings` ( + `type` varchar(15) NOT NULL, + `account_id` int(11) NOT NULL, + `active` tinyint(1) NOT NULL DEFAULT '0' +) ENGINE=InnoDB DEFAULT CHARSET=utf8; From 4ea8b6c6950a4cf7d2b8246d410f82ddb2de414c Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Sun, 9 Jun 2013 14:26:18 +0200 Subject: [PATCH 02/10] Adding new notification system for new blocks * Modified findblocks cron * Modified notifications cron for new structure * Improved notification class * Added new template for new_block type * Moved idle_worker type template * Added new_block type to notification settings --- cronjobs/findblock.php | 10 +++++ cronjobs/notifications.php | 11 +---- public/include/classes/mail.class.php | 8 ++-- public/include/classes/notification.class.php | 42 ++++++++++++++++++- .../mail/{ => notifications}/idle_worker.tpl | 0 .../mail/notifications/new_block.tpl | 7 ++++ .../mmcFE/account/notifications/default.tpl | 7 ++++ 7 files changed, 71 insertions(+), 14 deletions(-) rename public/templates/mail/{ => notifications}/idle_worker.tpl (100%) create mode 100644 public/templates/mail/notifications/new_block.tpl diff --git a/cronjobs/findblock.php b/cronjobs/findblock.php index 2f978eed..d52c1cc9 100755 --- a/cronjobs/findblock.php +++ b/cronjobs/findblock.php @@ -112,6 +112,16 @@ foreach ($aAllBlocks as $iIndex => $aBlock) { . $strStatus . "\n" ); + + // Notify users + $aAccounts = $notification->getNotificationByType('new_block'); + foreach ($aAccounts as $account_id) { + $aMailData = $aBlock; + $aMailData['subject'] = 'New Block'; + $aMailData['email'] = $user->getUserEmail($user->getUserName($account_id)); + $aMailData['shares'] = $iRoundShares; + $notification->sendNotification($account_id, 'new_block', $aMailData); + } } } ?> diff --git a/cronjobs/notifications.php b/cronjobs/notifications.php index eddef3de..cd8c020a 100755 --- a/cronjobs/notifications.php +++ b/cronjobs/notifications.php @@ -32,15 +32,8 @@ if (empty($aWorkers)) { $aData['username'] = $user->getUserName($aWorker['account_id']); $aData['subject'] = 'IDLE Worker : ' . $aWorker['username']; $aData['email'] = $user->getUserEmail($aData['username']); - if ( $notification->isNotified($aData) ) { - verbose("Worker already notified\n"); - continue; - } - if ($notification->addNotification($aWorker['account_id'], 'idle_worker', $aData) && $notification->sendMail($aData['email'], 'idle_worker', $aData)) { - verbose ("Notified " . $aData['email'] . " for IDLE worker " . $aWorker['username'] . "\n"); - } else { - verbose("Unable to send notification: " . $notification->getError() . "\n"); - } + if (!$notification->sendNotification($aWorker['account_id'], 'idle_worker', $aData)) + verbose($notification->getError() . "\n"); } } diff --git a/public/include/classes/mail.class.php b/public/include/classes/mail.class.php index 2800500c..e34423c5 100644 --- a/public/include/classes/mail.class.php +++ b/public/include/classes/mail.class.php @@ -16,6 +16,9 @@ class Mail { public function setSmarty($smarty) { $this->smarty = $smarty; } + public function setUser($user) { + $this->user = $user; + } public function setConfig($config) { $this->config = $config; } @@ -35,14 +38,14 @@ class Mail { return true; } - public function sendMail($email, $template, $aData) { + public function sendMail($template, $aData) { $this->smarty->assign('WEBSITENAME', $this->config['website']['name']); $this->smarty->assign('SUBJECT', $aData['subject']); $this->smarty->assign('DATA', $aData); $headers = 'From: Website Administration <' . $this->config['website']['email'] . ">\n"; $headers .= "MIME-Version: 1.0\n"; $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n"; - if (mail($email, + if (mail($aData['email'], $this->smarty->fetch(BASEPATH . 'templates/mail/subject.tpl'), $this->smarty->fetch(BASEPATH . 'templates/mail/' . $template . '.tpl'), $headers)) { @@ -61,5 +64,4 @@ $mail->setDebug($debug); $mail->setMysql($mysqli); $mail->setSmarty($smarty); $mail->setConfig($config); - ?> diff --git a/public/include/classes/notification.class.php b/public/include/classes/notification.class.php index cff05abb..d324d4a7 100644 --- a/public/include/classes/notification.class.php +++ b/public/include/classes/notification.class.php @@ -44,7 +44,6 @@ class Notification extends Mail { return true; // Catchall // Does not seem to have a notification set - $this->setErrorMessage("Unable to run query: " . $this->mysqli->error); return false; } @@ -73,7 +72,7 @@ class Notification extends Mail { if ($stmt && $stmt->bind_param('iss', $account_id, $type, $data) && $stmt->execute()) return true; $this->debug->append("Failed to add notification for $type with $data: " . $this->mysqli->error); - $this->setErrorMessage("Unable to add new notification"); + $this->setErrorMessage("Unable to add new notification " . $this->mysqli->error); return false; } @@ -109,6 +108,21 @@ class Notification extends Mail { return false; } + /** + * Get all accounts that wish to receive a specific notification + * @param strType string Notification type + * @return data array User Accounts + **/ + public function getNotificationAccountIdByType($strType) { + $this->debug->append("STA " . __METHOD__, 4); + $stmt = $this->mysqli->prepare("SELECT account_id FROM $this->tableSettings WHERE type = ? AND active = 1"); + if ($stmt && $stmt->bind_param('s', $strType) && $stmt->execute() && $result = $stmt->get_result()) { + return $result->fetch_all(MYSQLI_ASSOC); + } + // Catchall + return false; + } + /** * Update accounts notification settings * @param account_id int Account ID @@ -144,6 +158,28 @@ class Notification extends Mail { } return true; } + + /** + * Send a specific notification setup in notification_settings + * @param type string Notification type + * @return bool + **/ + public function sendNotification($account_id, $strType, $aMailData) { + // Check if we notified for this event already + if ( $this->isNotified($aMailData) ) { + $this->setErrorMessage('A notification for this event has been sent already'); + return false; + } + // Check if this user wants strType notifications + $stmt = $this->mysqli->prepare("SELECT account_id FROM $this->tableSettings WHERE type = ? AND active = 1 AND account_id = ?"); + if ($stmt && $stmt->bind_param('si', $strType, $account_id) && $stmt->execute() && $stmt->bind_result($id) && $stmt->fetch()) { + if ($stmt->close() && $this->sendMail('notifications/' . $strType, $aMailData) && $this->addNotification($account_id, $strType, $aMailData)) + return true; + } else { + $this->setErrorMessage('User disabled ' . $strType . ' notifications'); + } + return false; + } } $notification = new Notification(); @@ -151,3 +187,5 @@ $notification->setDebug($debug); $notification->setMysql($mysqli); $notification->setSmarty($smarty); $notification->setConfig($config); + +?> diff --git a/public/templates/mail/idle_worker.tpl b/public/templates/mail/notifications/idle_worker.tpl similarity index 100% rename from public/templates/mail/idle_worker.tpl rename to public/templates/mail/notifications/idle_worker.tpl diff --git a/public/templates/mail/notifications/new_block.tpl b/public/templates/mail/notifications/new_block.tpl new file mode 100644 index 00000000..9d17d06e --- /dev/null +++ b/public/templates/mail/notifications/new_block.tpl @@ -0,0 +1,7 @@ + + +

    A new block has been discovered!

    +
    +
    + + diff --git a/public/templates/mmcFE/account/notifications/default.tpl b/public/templates/mmcFE/account/notifications/default.tpl index 1b737f79..94c0c2b0 100644 --- a/public/templates/mmcFE/account/notifications/default.tpl +++ b/public/templates/mmcFE/account/notifications/default.tpl @@ -8,6 +8,13 @@ Type Active + + IDLE Worker + + + + + New Blocks From 79d9c9714dfbfe590b894bd21dc5c445faea6d6e Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Sun, 9 Jun 2013 14:31:00 +0200 Subject: [PATCH 03/10] wrong method call --- cronjobs/findblock.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cronjobs/findblock.php b/cronjobs/findblock.php index d52c1cc9..ead4b61c 100755 --- a/cronjobs/findblock.php +++ b/cronjobs/findblock.php @@ -114,9 +114,9 @@ foreach ($aAllBlocks as $iIndex => $aBlock) { ); // Notify users - $aAccounts = $notification->getNotificationByType('new_block'); + $aAccounts = $notification->getNotificationAccountIdByType('new_block'); foreach ($aAccounts as $account_id) { - $aMailData = $aBlock; + $aMailData['height'] = $aBlock['height']; $aMailData['subject'] = 'New Block'; $aMailData['email'] = $user->getUserEmail($user->getUserName($account_id)); $aMailData['shares'] = $iRoundShares; From d723f4e8ef36e55fccfacece4d3dbe8fa143c6a9 Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Sun, 9 Jun 2013 15:17:14 +0200 Subject: [PATCH 04/10] Adding notification on automatic payout * Added new mail template * Added notification code to auto_payout cron --- cronjobs/auto_payout.php | 15 ++++++++++++--- .../templates/mail/notifications/auto_payout.tpl | 8 ++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 public/templates/mail/notifications/auto_payout.tpl diff --git a/cronjobs/auto_payout.php b/cronjobs/auto_payout.php index 36c8a873..48861c86 100755 --- a/cronjobs/auto_payout.php +++ b/cronjobs/auto_payout.php @@ -52,19 +52,28 @@ if (! empty($users)) { } // Send balance, fees are reduced later - try { +/* try { $bitcoin->sendtoaddress($aUserData['coin_address'], $dBalance); } catch (BitcoinClientException $e) { verbose("SEND FAILED\n"); continue; } - + */ // Create transaction record if ($transaction->addTransaction($aUserData['id'], $dBalance, 'Debit_AP', NULL, $aUserData['coin_address'], 0.1)) { - verbose("OK\n"); + // Notify user via mail + $aMailData['email'] = $user->getUserEmail($user->getUserName($aUserData['id'])); + $aMailData['subject'] = 'Auto Payout Completed'; + $aMailData['amount'] = $dBalance; + if (!$notification->sendNotification($aUserData['id'], 'auto_payout', $aMailData)) { + verbose("NOTIFY FAILED\n"); + } else { + verbose("OK\n"); + } } else { verbose("FAILED\n"); } + } else { verbose("SKIPPED\n"); } diff --git a/public/templates/mail/notifications/auto_payout.tpl b/public/templates/mail/notifications/auto_payout.tpl new file mode 100644 index 00000000..6d045357 --- /dev/null +++ b/public/templates/mail/notifications/auto_payout.tpl @@ -0,0 +1,8 @@ + + +

    An automated payout completed.

    +

    Amount: {$DATA.amount}

    +
    +
    + + From b2b853d3e0d693289c0f4482d6ebb2b73f259590 Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Sun, 9 Jun 2013 15:24:58 +0200 Subject: [PATCH 05/10] Added manual payout notification * Added mail template for manual payouts * Added code to account page to notify via mail on payout * Added new option to notification setting template Adds another feature to #144 --- public/include/pages/account/edit.inc.php | 9 +++++++-- .../mail/notifications/manual_payout.tpl | 8 ++++++++ .../mmcFE/account/notifications/default.tpl | 15 ++++++++++++++- 3 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 public/templates/mail/notifications/manual_payout.tpl diff --git a/public/include/pages/account/edit.inc.php b/public/include/pages/account/edit.inc.php index 1e2941bb..446c13f1 100644 --- a/public/include/pages/account/edit.inc.php +++ b/public/include/pages/account/edit.inc.php @@ -36,12 +36,17 @@ if ( ! $user->checkPin($_SESSION['USERDATA']['id'], $_POST['authPin']) && $_POST } } catch (BitcoinClientException $e) { $_SESSION['POPUP'][] = array('CONTENT' => 'Failed to send LTC, please contact site support immidiately', 'TYPE' => 'errormsg'); - $continue = false; +// $continue = false; } } // Set balance to 0, add to paid out, insert to ledger - if ($continue == true && $transaction->addTransaction($_SESSION['USERDATA']['id'], $dBalance, 'Debit_MP', NULL, $sCoinAddress)) + if ($continue == true && $transaction->addTransaction($_SESSION['USERDATA']['id'], $dBalance, 'Debit_MP', NULL, $sCoinAddress)) { $_SESSION['POPUP'][] = array('CONTENT' => 'Transaction completed', 'TYPE' => 'success'); + $aMailData['email'] = $user->getUserEmail($user->getUserName($_SESSION['USERDATA']['id'])); + $aMailData['amount'] = $dBalance; + $aMailData['subject'] = 'Manual Payout Completed'; + $notification->sendNotification($_SESSION['USERDATA']['id'], 'manual_payout', $aMailData); + } } else { $_SESSION['POPUP'][] = array('CONTENT' => 'Unable to connect to litecoind RPC service', 'TYPE' => 'errormsg'); } diff --git a/public/templates/mail/notifications/manual_payout.tpl b/public/templates/mail/notifications/manual_payout.tpl new file mode 100644 index 00000000..75198d7b --- /dev/null +++ b/public/templates/mail/notifications/manual_payout.tpl @@ -0,0 +1,8 @@ + + +

    An manual payout request completed.

    +

    Amount: {$DATA.amount}

    +
    +
    + + diff --git a/public/templates/mmcFE/account/notifications/default.tpl b/public/templates/mmcFE/account/notifications/default.tpl index 94c0c2b0..676807d3 100644 --- a/public/templates/mmcFE/account/notifications/default.tpl +++ b/public/templates/mmcFE/account/notifications/default.tpl @@ -29,6 +29,13 @@ + + Manual Payout + + + + + @@ -55,7 +62,13 @@ {$NOTIFICATIONS[notification].id} {$NOTIFICATIONS[notification].time} - {$NOTIFICATIONS[notification].type} + + {if $NOTIFICATIONS[notification].type == new_block}New Block + {else if $NOTIFICATIONS[notification].type == auto_payout}Auto Payout + {else if $NOTIFICATIONS[notification].type == idle_worker}IDLE Worker + {else if $NOTIFICATIONS[notification].type == manual_payout}Manual Payout + {/if} + From af9d2aed9534fc535546c42a4c9a6c614343e737 Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Sun, 9 Jun 2013 15:31:38 +0200 Subject: [PATCH 06/10] wrong syntax in upgrade SQL --- sql/issue_144_notification_upgrade.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql/issue_144_notification_upgrade.sql b/sql/issue_144_notification_upgrade.sql index e2884e9e..a47f3bbf 100644 --- a/sql/issue_144_notification_upgrade.sql +++ b/sql/issue_144_notification_upgrade.sql @@ -1,4 +1,4 @@ -ALTER TABLE `notifications` ADD `account_id` INT UNSIGNED NULL DEFAULT NULL , ADD INDEX ( `account_id` ) +ALTER TABLE `notifications` ADD `account_id` INT UNSIGNED NULL DEFAULT NULL , ADD INDEX ( `account_id` ); CREATE TABLE IF NOT EXISTS `notification_settings` ( `type` varchar(15) NOT NULL, `account_id` int(11) NOT NULL, From 3bc5c68403f5de3d977ab9405c3242e7bc43e42c Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Sun, 9 Jun 2013 16:09:32 +0200 Subject: [PATCH 07/10] Updated SQL Files * Updated upgrade SQL * Added full new structure --- sql/issue_144_notification_upgrade.sql | 1 + sql/mmcfe_ng_structure.sql | 30 +++++++++++++++++++------- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/sql/issue_144_notification_upgrade.sql b/sql/issue_144_notification_upgrade.sql index a47f3bbf..fd7ae177 100644 --- a/sql/issue_144_notification_upgrade.sql +++ b/sql/issue_144_notification_upgrade.sql @@ -1,4 +1,5 @@ ALTER TABLE `notifications` ADD `account_id` INT UNSIGNED NULL DEFAULT NULL , ADD INDEX ( `account_id` ); +ALTER TABLE `notifications` CHANGE `time` `time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP; CREATE TABLE IF NOT EXISTS `notification_settings` ( `type` varchar(15) NOT NULL, `account_id` int(11) NOT NULL, diff --git a/sql/mmcfe_ng_structure.sql b/sql/mmcfe_ng_structure.sql index 039b9a04..1e21bbf4 100644 --- a/sql/mmcfe_ng_structure.sql +++ b/sql/mmcfe_ng_structure.sql @@ -3,7 +3,7 @@ -- http://www.phpmyadmin.net -- -- Host: localhost --- Generation Time: Jun 07, 2013 at 03:39 PM +-- Generation Time: Jun 09, 2013 at 04:08 PM -- Server version: 5.5.31-0ubuntu0.13.04.1 -- PHP Version: 5.4.9-4ubuntu2 @@ -65,7 +65,7 @@ CREATE TABLE IF NOT EXISTS `blocks` ( PRIMARY KEY (`id`), UNIQUE KEY `height` (`height`,`blockhash`), KEY `time` (`time`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Discovered blocks persisted from Litecoin Service'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Discovered blocks persisted from Litecoin Service'; -- -------------------------------------------------------- @@ -74,14 +74,28 @@ CREATE TABLE IF NOT EXISTS `blocks` ( -- CREATE TABLE IF NOT EXISTS `notifications` ( - `id` int(11) NOT NULL AUTO_INCREMENT, + `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `type` varchar(25) NOT NULL, `data` varchar(255) NOT NULL, `active` tinyint(1) NOT NULL DEFAULT '1', - `time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + `account_id` int(10) unsigned DEFAULT NULL, PRIMARY KEY (`id`), KEY `active` (`active`), - KEY `data` (`data`) + KEY `data` (`data`), + KEY `account_id` (`account_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +-- -------------------------------------------------------- + +-- +-- Table structure for table `notification_settings` +-- + +CREATE TABLE IF NOT EXISTS `notification_settings` ( + `type` varchar(15) NOT NULL, + `account_id` int(11) NOT NULL, + `active` tinyint(1) NOT NULL DEFAULT '0' ) ENGINE=InnoDB DEFAULT CHARSET=utf8; -- -------------------------------------------------------- @@ -153,7 +167,7 @@ CREATE TABLE IF NOT EXISTS `shares_archive` ( PRIMARY KEY (`id`), UNIQUE KEY `share_id` (`share_id`), KEY `time` (`time`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Archive shares for potential later debugging purposes'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Archive shares for potential later debugging purposes'; -- -------------------------------------------------------- @@ -170,7 +184,7 @@ CREATE TABLE IF NOT EXISTS `statistics_shares` ( PRIMARY KEY (`id`), KEY `account_id` (`account_id`), KEY `block_id` (`block_id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; +) ENGINE=InnoDB DEFAULT CHARSET=utf8; -- -------------------------------------------------------- @@ -190,7 +204,7 @@ CREATE TABLE IF NOT EXISTS `transactions` ( KEY `block_id` (`block_id`), KEY `account_id` (`account_id`), KEY `type` (`type`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; +) ENGINE=InnoDB DEFAULT CHARSET=utf8; /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; From 6eeff19ff58cd8b1dcba5ccb22c6da47be260dd3 Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Sun, 9 Jun 2013 16:44:32 +0200 Subject: [PATCH 08/10] Fixing issue with notification cron * Updated getAllActive to search by type --- cronjobs/notifications.php | 2 +- public/include/classes/notification.class.php | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cronjobs/notifications.php b/cronjobs/notifications.php index cd8c020a..a6b8b101 100755 --- a/cronjobs/notifications.php +++ b/cronjobs/notifications.php @@ -38,7 +38,7 @@ if (empty($aWorkers)) { } // We notified, lets check which recovered -$aNotifications = $notification->getAllActive(); +$aNotifications = $notification->getAllActive('idle_worker'); if (!empty($aNotifications)) { foreach ($aNotifications as $aNotification) { $aData = json_decode($aNotification['data'], true); diff --git a/public/include/classes/notification.class.php b/public/include/classes/notification.class.php index d324d4a7..b38bac2e 100644 --- a/public/include/classes/notification.class.php +++ b/public/include/classes/notification.class.php @@ -50,10 +50,10 @@ class Notification extends Mail { /** * Get all active notifications **/ - public function getAllActive() { + public function getAllActive($strType) { $this->debug->append("STA " . __METHOD__, 4); - $stmt =$this->mysqli->prepare("SELECT id, data FROM $this->table WHERE active = 1 LIMIT 1"); - if ($stmt && $stmt->execute() && $result = $stmt->get_result()) + $stmt =$this->mysqli->prepare("SELECT id, data FROM $this->table WHERE active = 1 AND type = ?"); + if ($stmt && $stmt->bind_param('s', $strType) && $stmt->execute() && $result = $stmt->get_result()) return $result->fetch_all(MYSQLI_ASSOC); // Catchall return false; From 8ed4638057fac16b7f40b4eef6e7d54e45091d6b Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Mon, 10 Jun 2013 08:51:07 +0200 Subject: [PATCH 09/10] removed commented section to re-enable auto-payout --- cronjobs/auto_payout.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cronjobs/auto_payout.php b/cronjobs/auto_payout.php index 48861c86..63b06d08 100755 --- a/cronjobs/auto_payout.php +++ b/cronjobs/auto_payout.php @@ -52,13 +52,13 @@ if (! empty($users)) { } // Send balance, fees are reduced later -/* try { + try { $bitcoin->sendtoaddress($aUserData['coin_address'], $dBalance); } catch (BitcoinClientException $e) { verbose("SEND FAILED\n"); continue; } - */ + // Create transaction record if ($transaction->addTransaction($aUserData['id'], $dBalance, 'Debit_AP', NULL, $aUserData['coin_address'], 0.1)) { // Notify user via mail From 37fc9fa1471113f0211a35b83015e54238c05ba8 Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Mon, 10 Jun 2013 08:51:24 +0200 Subject: [PATCH 10/10] adding full notification SQL for regular installations --- sql/issue_144_notification_upgrade.sql | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/sql/issue_144_notification_upgrade.sql b/sql/issue_144_notification_upgrade.sql index fd7ae177..73985979 100644 --- a/sql/issue_144_notification_upgrade.sql +++ b/sql/issue_144_notification_upgrade.sql @@ -1,7 +1,17 @@ -ALTER TABLE `notifications` ADD `account_id` INT UNSIGNED NULL DEFAULT NULL , ADD INDEX ( `account_id` ); -ALTER TABLE `notifications` CHANGE `time` `time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP; +CREATE TABLE IF NOT EXISTS `notifications` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `type` varchar(25) NOT NULL, + `data` varchar(255) NOT NULL, + `active` tinyint(1) NOT NULL DEFAULT '1', + `time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + `account_id` int(10) unsigned DEFAULT NULL, + PRIMARY KEY (`id`), + KEY `active` (`active`), + KEY `data` (`data`), + KEY `account_id` (`account_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; CREATE TABLE IF NOT EXISTS `notification_settings` ( - `type` varchar(15) NOT NULL, - `account_id` int(11) NOT NULL, - `active` tinyint(1) NOT NULL DEFAULT '0' + `type` varchar(15) NOT NULL, + `account_id` int(11) NOT NULL, + `active` tinyint(1) NOT NULL DEFAULT '0' ) ENGINE=InnoDB DEFAULT CHARSET=utf8;