protected function executeTransaction($conn, $arguments = array(), $options = array()) { $members = Doctrine::getTable('Member')->findAll(Doctrine::HYDRATE_ARRAY); $memberIds = array_map(create_function('$m', 'return (int)$m[\'id\'];'), $members); foreach ($memberIds as $id) { for ($i = 0; $i < $options['number']; ++$i) { $sendTo = self::fetchRandomMemberId($id, $memberIds); $mes = new SendMessageData(); $mes->setMemberId($id); $mes->setSubject('subject'); $mes->setBody('body'); $mes->setIsSend(true); $mes->setMessageTypeId(1); $mes->save(); $mes->free(); $messageSendList = new MessageSendList(); $messageSendList->setMemberId($sendTo); $messageSendList->setSendMessageData($mes); $messageSendList->save(); $messageSendList->free(); $this->logSection('send message', sprintf("%s - %s", $id, $sendTo)); } } }
protected function execute($arguments = array(), $options = array()) { $databaseManager = new sfDatabaseManager($this->configuration); $this->conn = $databaseManager->getDatabase('doctrine')->getDoctrineConnection(); $sql = 'SELECT id FROM member WHERE is_active != 0'; $where = array(); if ( $options['min'] && $options['max'] && $options['min'] <= $options['max']) { $sql .= ' AND id BETWEEN ? AND ?'; $where = array(intval($options['min']),intval($options['max'])); } $memberIds = $this->conn->fetchColumn($sql, $where); $sql = 'SELECT max(id) FROM member WHERE is_active != 0'; $maxmemberId = $this->conn->fetchOne($sql); foreach ($memberIds as $id) { for ($i=0; $i<$options['number']; ++$i) { // 送り先は、id1~存在する最大のidからランダムに選出 $sendTo = rand(1,$maxmemberId); $mes = new SendMessageData(); $mes->setMemberId($id); $mes->setSubject('subject'); $mes->setBody('body'); // 一定割合で下書き $rate = $options['draftrate']; if ($rate != 0 && rand(1,100) <= $rate ) { $mes->setIsSend(false); } else { $mes->setIsSend(true); } $mes->setMessageTypeId(1); $mes->save(); $messageSendList = new MessageSendList(); $messageSendList->setMemberId($sendTo); $messageSendList->setSendMessageData($mes); $messageSendList->save(); $mesid = $mes->getId(); $messageSendListid = $messageSendList->getId(); $mes->free(); $messageSendList->free(); $this->logSection('send message', sprintf("%s - %s", $id, $sendTo)); // 同時にあしあとをつける if ($options['footprint'] > 0) { $r_date = date('Y-m-d'); for ($j=0 ; $j < $options['footprint'] ; ++$j) { $ashi = new Ashiato(); $ashi->setMemberIdFrom($id); $ashi->setMemberIdTo($sendTo); $ashi->setRDate($r_date); $ashi->save(); } $ashi->free(); } // 一定割合でゴミ箱へ $rate = $options['dustrate']; if ($rate != 0 && rand(1,100) <= $rate ) { // 送信者がゴミ箱 $deleted_message = new DeletedMessage(); $deleted_message->setMemberId($id); $deleted_message->setMessageSendListId($messageSendListid); $deleted_message->save(); // 受信者がゴミ箱 $rec_deleted_message = new DeletedMessage(); $rec_deleted_message->setMemberId($sendTo); $rec_deleted_message->setMessageId($mesid); $rec_deleted_message->save(); $deleted_message->free(); $rec_deleted_message->free(); $this->logSection('delete message', sprintf("%s - %s", $id, $sendTo)); } } } }