Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function getJoinRS() {
- $join = "SELECT * FROM (SELECT m.ID AS MID, m.UserID, m.GroupID, m.Name, m.SName, " .
- "m.Mail, g.ID AS GID, g.Name AS GName, g.IsSystem FROM " .
- "`RS_MailList` AS m JOIN RS_Groups AS g ON m.UserID = g.UserID) as j " .
- "GROUP BY Mail";
- try {
- $result = $this->_rs->query($join)->fetchAll(PDO::FETCH_ASSOC);
- return $result;
- } catch (PDOException $ex) {
- echo "Error function getJoinRS(): " . $ex->getMessage() . "\n";
- return false;
- }
- }
- public function items() {
- $rs = $this->getJoinRS();
- foreach($rs as $mail) {
- $sql = "SELECT * FROM (SELECT m.ID AS MID, m.UserID, m.GroupID, m.Name, m.SName, " .
- "m.Mail, g.ID AS GID, g.Name AS GName, g.IsSystem FROM " .
- "`RS_MailList` AS m JOIN RS_Groups AS g ON m.UserID = g.UserID) as j " .
- "WHERE Mail='" .$mail['Mail'] . "' GROUP BY UserID";
- $rs_result = $this->_rs->query($sql)->fetchAll(PDO::FETCH_ASSOC);
- foreach ($rs_result as $alter) {
- $query = "SELECT id FROM `MailData` WHERE eMail = '" . $mail['Mail'] . "'";
- $rid = $this->_alter->query($query)->fetchAll(PDO::FETCH_ASSOC);
- $id = (int) $rid[0]['id'];
- $i = 0;
- $this->_alter->beginTransaction();
- echo "Transaction for mail address " . $mail['Mail'] . " of UserID " . $alter['UserID'] . " prepare...\n";
- $t = $this->_alter->prepare("INSERT INTO `SubscriberData` (FirstName, LastName) VALUES (:fname, :lname)");
- $t->bindParam(':fname', $alter['Name'], PDO::PARAM_STR);
- $t->bindParam(':lname', $alter['SName'], PDO::PARAM_STR);
- $t->execute();
- $i++;
- $subscriberID = $this->_alter->lastInsertId();
- $item = $this->_alter->prepare("INSERT INTO `ListItem` (UserID, SubscriberID, MailID, ConfirmHash) VALUES (:userID, :subID, :mailID, :hash)");
- $hash = md5($alter['Mail']);
- $item->bindParam(':userID', $alter['UserID'], PDO::PARAM_INT);
- $item->bindParam(':subID', $subscriberID, PDO::PARAM_INT);
- $item->bindParam(':mailID', $id, PDO::PARAM_INT);
- $item->bindParam(':hash', $hash, PDO::PARAM_STR);
- $item->execute();
- $i++;
- $listItemID = $this->_alter->lastInsertID();
- $sql2 = "SELECT * FROM (SELECT m.ID AS MID, m.UserID, m.GroupID, m.Name, m.SName, " .
- "m.Mail, g.ID AS GID, g.Name AS GName, g.IsSystem FROM " .
- "`RS_MailList` AS m JOIN RS_Groups AS g ON m.UserID = g.UserID) as j " .
- "WHERE MID='" . (int) $alter['MID'] . "' GROUP BY UserID, GID";
- $rs_group = $this->_rs->query($sql2)->fetchAll(PDO::FETCH_ASSOC);
- foreach ($rs_group as $g) {
- $group = $this->_alter->prepare("INSERT INTO `Tags` (nameTag, UserID) VALUES (:name, :userID)");
- $group->bindParam(':name', $g['GName'], PDO::PARAM_STR);
- $group->bindParam(':userID', $g['UserID'], PDO::PARAM_INT);
- $group->execute();
- $i++;
- $groupID = $this->_alter->lastInsertId();
- $tags = $this->_alter->prepare("INSERT INTO `TagsListItem` (ItemID, TagID) VALUES (:item, :tag)");
- $tags->bindParam(':item', $listItemID, PDO::PARAM_INT);
- $tags->bindParam(':tag', $groupID, PDO::PARAM_INT);
- $tags->execute();
- $i++;
- }
- try {
- echo "Transaction for mail address ". $mail['Mail'] . " of UserID " . $alter['UserID'] . " start. All queries: " .$i. "\n";
- $this->_alter->commit();
- echo "Transaction complete\n";
- } catch (PDOException $ex) {
- $this->_alter->rollBack();
- echo "Transaction error: " . $ex->getMessage() . "\n";
- }
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment