From e8ab672f09f5f9e58b4a637fdbceeab10c8705e3 Mon Sep 17 00:00:00 2001 From: Shinichi Urabe Date: Tue, 20 Jun 2017 15:56:29 +0900 Subject: [PATCH] (refs #1662) The process of joining members was completed with one SQL. --- lib/model/doctrine/Community.class.php | 37 ++++++++++++++++++++------ 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/lib/model/doctrine/Community.class.php b/lib/model/doctrine/Community.class.php index ce7a7a710..8402c60cd 100644 --- a/lib/model/doctrine/Community.class.php +++ b/lib/model/doctrine/Community.class.php @@ -211,16 +211,37 @@ public function preDelete($event) } } - public function joinAllMembers() + public function joinAllMembers() { - $conn = Doctrine::getTable('Member')->getConnection(); - $query = 'SELECT id FROM '.Doctrine::getTable('Member')->getTableName().' m' - . ' WHERE NOT EXISTS (SELECT * FROM '.Doctrine::getTable('CommunityMember')->getTableName().' cm WHERE m.id = cm.member_id AND cm.community_id = ?)' - . ' AND (m.is_active = 1 OR m.is_active IS NULL)'; - $insertIds = $conn->fetchColumn($query, array($this->getId())); - foreach ($insertIds as $memberId) + $pdo = opDoctrineQuery::getMasterConnection()->getDbh(); + $pdo->beginTransaction(); + + $query = <<join($memberId, $this->getId()); + $stmt = $pdo->prepare($query); + $stmt->execute(array('community_id' => $this->id)); + $total = $stmt->rowCount(); + + $pdo->commit(); } + catch (Exception $e) + { + $pdo->rollback(); + + throw $e; + } + + return $total; } }