ここの情報は古いです。ご理解頂いた上でお取り扱いください。

Changeset 12229


Ignore:
Timestamp:
Jul 11, 2009, 8:03:16 PM (11 years ago)
Author:
ebihara
Message:

#4036:fixed opDoctrineQuery that uses an instance of the sfContext everytime. it caused errors when doctrine: task is invoked

File:
1 edited

Legend:

Unmodified
Added
Removed
  • OpenPNE3/trunk/lib/util/opDoctrineQuery.class.php

    r12224 r12229  
    8888  }
    8989
     90  static public function getMasterConnectionDirect()
     91  {
     92    $conn = null;
     93
     94    try
     95    {
     96      $conn = Doctrine_Manager::getInstance()->getConnection('master');
     97    }
     98    catch (Doctrine_Manager_Exception $e)
     99    {
     100      // retry getting connection by the old connection name
     101      $conn = Doctrine_Manager::getInstance()->getConnection('doctrine');
     102    }
     103
     104    return $conn;
     105  }
     106
     107  static public function chooseConnection($shouldGoToMaster = true, $queryType = self::SELECT)
     108  {
     109    if (!sfContext::hasInstance())
     110    {
     111      return self::getMasterConnectionDirect();
     112    }
     113
     114    elseif (self::SELECT === $queryType && !$shouldGoToMaster)
     115    {
     116      return self::getSlaveConnection();
     117    }
     118
     119    return self::getMasterConnection();
     120  }
     121
    90122  public function preQuery()
    91123  {
    92     if (self::SELECT === $this->getType() && !$this->shouldGoToMaster)
    93     {
    94       $this->_conn = self::getSlaveConnection();
    95     }
    96     else
    97     {
    98       $this->_conn = self::getMasterConnection();
    99     }
     124    $this->_conn = self::chooseConnection($this->shouldGoToMaster, $this->getType());
    100125  }
    101126}
Note: See TracChangeset for help on using the changeset viewer.