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 diary'; $maxdiaryId = $this->conn->fetchOne($sql); foreach ($memberIds as $id) { for ($i=0; $i<$options['number']; ++$i) { $diaryid = rand(1,$maxdiaryId); $comment = new DiaryComment(); $comment->setDiaryId($diaryid); $comment->setMemberId($id); $comment->setBody('body'); $comment->save(); $comment->free(); $this->logSection('added a diary comment', sprintf('%s - %s', $diaryid, $id)); } } }
protected function executeTransaction($conn, $arguments = array(), $options = array()) { $this->memberIds = array_map(create_function('$m', 'return $m[\'id\'];'), Doctrine::getTable('Member')->findAll(Doctrine::HYDRATE_ARRAY)); $diaries = Doctrine::getTable('Diary')->findAll(Doctrine::HYDRATE_ARRAY); foreach ($diaries as $diary) { for ($i = 0; $i < $options['number']; ++$i) { shuffle($this->memberIds); $comment = new DiaryComment(); $comment->setDiaryId($diary['id']); $comment->setMemberId($this->memberIds[0]); $comment->setBody('body'); $comment->save(); $comment->free(); $this->logSection('added a diary comment', sprintf('%s - %s', $diary['id'], $this->memberIds[0])); } unset($diary); } }