2010-02-18 50 views
1

我正在用Doctrine構建Symfony中的任務。我得到所有的地方來批量更新到一個特定的領域。這必須用兩種語言來完成。我正在使用setBaseQuery()使用我想要的語言在查詢上進行JOIN操作。setBaseQuery不適用於Symfony中的任務

如果我在動作中執行以下操作,它沒有任何問題。但是,如果我在一項任務中這樣做;它不能按預期工作。任務完成兩次(一個英文,另一個英文!)。

任何想法,我必須做不同的任務?

的感謝!

$languages = array('es' => 'Spanish', 'en' => 'English'); 
foreach($languages as $lang => $value) { 

    // get all the places 
    $q = Doctrine::getTable('Place') 
    ->createQuery('p') 
    ->leftJoin('p.Translation ptr') 
    ->addWhere('ptr.lang = ?', $lang); 

    $treeObject = Doctrine::getTable('Place')->getTree(); 
    $rootColumnName = $treeObject->getAttribute ('rootColumnName'); 
    $treeObject->setBaseQuery($q); 

    // all the continents 
    foreach ($treeObject->fetchRoots() as $continent) { 
    $this->log(date("Y-m-d H:i:s").' '.$lang.' Continent '.$continent->title); 
    .. 
    } 
} 
+1

什麼是Symfony和學說的版本?只是要清楚。 – develop7 2010-02-18 23:45:29

+0

對不起,我正在使用symfony 1.2.7和doctrine 1.1.6 – fesja 2010-02-19 07:43:31

回答

0

因此該解決方案我已經發現是加入$ model-> Translation [$ lang] - >標題。這很奇怪,因爲標題應該通過setbasequery加載;但似乎沒有。

// all the continents 
foreach ($treeObject->fetchRoots() as $continent) { 
    $this->log(date("Y-m-d H:i:s").' '.$lang.' Continent '.$continent->Translation[$lang]->title); 
    .. 
} 

更新

,我發現了翻譯,但$ continent->保存()沒有保存在西班牙語中的變化(但是它保存它的英文)。我不得不做的學說手冊查詢:

$con = Doctrine_Manager::getInstance()->connection(); 
... 
$con->execute("update model_translation set field='".$field."' where id='".$model->id."' and lang='".$lang."'"); 

現在一切正常......

0

爲了獲得在您的任務數據庫訪問,你需要任何其他數據庫調用來調用你的​​方法如下:

$databaseManager = new sfDatabaseManager($this->configuration); 

http://www.symfony-project.org/book/1_2/16-Application-Management-Tools#chapter_16_sub_custom_tasks_new_in_symfony_1_1

+0

我已經這樣做了,還有 $ connection = $ databaseManager-> getDatabase($ options ['connection']?$ options ['connection']] :null) - > getConnection(); – fesja 2010-02-19 07:42:27

相關問題