protected function execute($arguments = array(), $options = array()) { $databaseManager = new sfDatabaseManager($this->configuration); $this->conn = $databaseManager->getDatabase('doctrine')->getDoctrineConnection(); $sql = 'SELECT id FROM community'; $where = array(); if ( $options['cmin'] && $options['cmax'] && $options['cmin'] <= $options['cmax']) { $sql .= ' WHERE id BETWEEN ? AND ?'; $where = array(intval($options['cmin']),intval($options['cmax'])); } $commuIds = $this->conn->fetchColumn($sql, $where); foreach ($commuIds as $cid) { for ($i=0; $i < $options['number']; ++$i) { $ct = new CommunityTopic(); $ct->setCommunity(Doctrine::getTable('community')->find($cid)); $ct->setMemberId(self::fetchRandomMemberId($cid)); $ct->setName('name'); $ct->setBody('body'); $ct->save(); $ct->free(); $this->logSection('created a community topic', sprintf("%s", $cid)); } } }
protected function executeTransaction($conn, $arguments = array(), $options = array()) { $communities = Doctrine::getTable('Community')->findAll(Doctrine::HYDRATE_ARRAY); foreach ($communities as $community) { for ($i = 0; $i < $options['number']; ++$i) { $ct = new CommunityTopic(); $ct->setCommunityId($community['id']); $ct->setMemberId(self::fetchRandomMemberId($community['id'])); $ct->setName('name'); $ct->setBody('body'); $ct->save(); $ct->free(); $this->logSection('created a community topic', sprintf("%s", $community['id'])); } } }