public function delete(Doctrine_Connection $conn = null)
  {
    if (is_null($conn))
    {
      $conn = opDoctrineQuery::chooseConnection(true);
    }
    $conn->beginTransaction();

    try
    {
      $introFriendUnread = Doctrine_Core::getTable('IntroFriendUnread')->findOneByMemberId($this->member_id_to);
      if ($introFriendUnread && $this->getUpdatedAt() >= $introFriendUnread->getReadAt())
      {
        $introFriendUnread->decreaseCount();
        $introFriendUnread->save($conn);
      }
      parent::delete($conn);
      $conn->commit();
    }
    catch (Exception $e)
    {
      $conn->rollback();
      throw $e;
    }

  }
 public function save(Doctrine_Connection $conn = null)
 {
     if (is_null($conn)) {
         $conn = opDoctrineQuery::chooseConnection(true);
     }
     parent::save($conn);
 }
Esempio n. 3
0
 public function executePost(sfWebRequest $request)
 {
     $conn = opDoctrineQuery::getMasterConnection();
     $conn->beginTransaction();
     try {
         $params = $this->getDiaryCommentFormParameter($request, $this->getUser()->getMemberId());
         $diaryComment = new DiaryComment();
         $diaryComment->setMemberId($this->member->getId());
         $diaryComment->setDiaryId($params['diary_id']);
         $diaryComment->setBody($request['body']);
         $diaryComment->save($conn);
         if ($params['image']) {
             $diaryImage = new DiaryCommentImage();
             $diaryImage->setDiaryCommentId($diaryComment->id);
             $diaryImage->setFile($params['image']);
             $diaryImage->save($conn);
             //re-save because file name doesnt have prefix(refs #1643)
             $diaryImage->getFile()->save($conn);
         }
         $conn->commit();
     } catch (opDiaryPluginAPIException $e) {
         $conn->rollback();
         $this->forward400($e->getMessage());
     } catch (Exception $e) {
         $conn->rollback();
         throw $e;
     }
     $this->memberId = $this->getUser()->getMemberId();
     $this->comment = $diaryComment;
 }
 public function save(Doctrine_Connection $conn = null)
 {
     $hasConnection = Doctrine_Manager::getInstance()->hasConnectionForComponent($this->getTable()->getComponentName());
     if (is_null($conn) && !$hasConnection) {
         $conn = opDoctrineQuery::chooseConnection(true);
     }
     parent::save($conn);
 }
 protected function execute($arguments = array(), $options = array())
 {
     $this->logSection('fix-session-db', 'Begin to fix session table structure');
     $this->openDatabaseConnection();
     $this->logSection('fix-session-db', 'Now changing definition of your session table structure');
     $conn = opDoctrineQuery::getMasterConnectionDirect();
     $conn->export->alterTable('session', array('change' => array('id' => array('definition' => array('type' => 'string', 'length' => 128, 'primary' => '1')))));
     $this->logSection('fix-session-db', 'Clear current session data');
     $conn->execute('TRUNCATE session');
     $this->logSection('fix-session-db', 'Finish to fix session table structure');
 }
 protected function executeQueryAndFetchCount(Doctrine_Connection $conn = null)
 {
     if (!$conn) {
         $conn = opDoctrineQuery::getMasterConnectionDirect();
     }
     $p = $this->getQuery();
     $p->specifyConnection($conn);
     $conn->beginTransaction();
     $this->results = $p->setIsFoundRows(true)->execute(array());
     $count = $conn->fetchOne('SELECT FOUND_ROWS()');
     $this->setNbResults($count);
     $conn->commit();
 }
Esempio n. 7
0
 public function executePost(sfWebRequest $request)
 {
     $conn = opDoctrineQuery::getMasterConnection();
     $conn->beginTransaction();
     try {
         $params = $this->getRequestedFormParameter($request);
         $diary = $this->getDiaryObject($this->member->id, $request->getParameter('id'));
         $diary->setTitle($params['title']);
         $diary->setBody($params['body']);
         $diary->setPublicFlag($params['public_flag']);
         if ($diary->is_open && $params['public_flag'] !== 4) {
             $diary->is_open = 0;
         }
         $diary->save($conn);
         $oldDiaryImages = $diary->getDiaryImages();
         foreach ($oldDiaryImages as $oldDiaryImage) {
             if ($request['diary_photo_' . $oldDiaryImage->number . '_photo_delete']) {
                 $oldDiaryImage->delete($conn);
                 unset($oldDiaryImages[$oldDiaryImage->number]);
             }
         }
         if ($params['image']) {
             foreach ($params['image'] as $key => $image) {
                 $number = substr($key, -1);
                 if ($oldDiaryImages[$number]) {
                     throw new opDiaryPluginAPIException('invalid deleteCheck');
                 }
                 $diaryImage = new DiaryImage();
                 $diaryImage->setDiaryId($diary->getId());
                 $diaryImage->setFile($image);
                 $diaryImage->setNumber($number);
                 $diaryImage->save($conn);
                 //re-save because file name doesnt have prefix(refs #1643)
                 $diaryImage->getFile()->save($conn);
                 $diary->updateHasImages();
             }
         }
         $conn->commit();
     } catch (opDiaryPluginAPIException $e) {
         $conn->rollback();
         $this->forward400($e->getMessage());
     } catch (Exception $e) {
         $conn->rollback();
         throw $e;
     }
     $this->diary = $diary;
 }
 public function save()
 {
     if ($this->isOAuthAuthenticate() && array_key_exists(self::IS_GOOGLE_CALENDAR_OAUTH_KEY_REVOKE, $this->values)) {
         $isDelete = (bool) $this->values[self::IS_GOOGLE_CALENDAR_OAUTH_KEY_REVOKE];
         unset($this->values[self::IS_GOOGLE_CALENDAR_OAUTH_KEY_REVOKE]);
         if ($isDelete) {
             $con = opDoctrineQuery::getMasterConnection();
             $con->beginTransaction();
             try {
                 $this->opCalendarOAuth->getClient()->revokeToken();
                 opCalendarPluginToolkit::deleteMemberGoogleCalendar($this->member);
                 $con->commit();
             } catch (Exception $e) {
                 $con->rollback();
                 return false;
             }
         }
     }
     return parent::save();
 }
Esempio n. 9
0
 public static function getSlaveConnection()
 {
     if (!is_null(self::$detectedSlave)) {
         return self::$detectedSlave;
     }
     $prefix = 'slave_';
     $list = array();
     $manager = sfContext::getInstance()->getDatabaseManager();
     foreach ($manager->getNames() as $name) {
         if (substr($name, 0, strlen($prefix)) === $prefix || 'doctrine' === $name || 'master' === $name) {
             $db = $manager->getDatabase($name);
             $list = array_pad($list, count($list) + (int) $db->getParameter('priority', 1), $name);
         }
     }
     shuffle($list);
     $key = array_shift($list);
     try {
         $connection = $manager->getDatabase($key)->getDoctrineConnection();
         self::$detectedSlave = $connection;
     } catch (Doctrine_Connection_Exception $e) {
         self::$detectedSlave = self::getMasterConnection();
     }
     return self::$detectedSlave;
 }
 public function down($direction)
 {
     $conn = opDoctrineQuery::chooseConnection(true);
     $sql = 'DROP TABLE `schedule_resource_lock`';
     $conn->execute($sql);
 }
 protected function detectTargetRecords()
 {
     $conn = opDoctrineQuery::getMasterConnectionDirect();
     $min = $conn->fetchOne('SELECT MIN(c_commu_id) FROM c_commu');
     $max = $conn->fetchOne('SELECT MAX(c_commu_id) FROM c_commu');
     return array($min, $max);
 }
 public function findActivityImageUrlsByActivityIds(array $actvityIds)
 {
     $query = new opDoctrineQuery();
     $query->select('activity_data_id, uri');
     $query->from('ActivityImage');
     $query->andWhereIn('activity_data_id', $actvityIds);
     $searchResult = $query->fetchArray();
     $imageUrls = array();
     foreach ($searchResult as $row) {
         $imageUrls[$row['activity_data_id']] = $row['uri'];
     }
     return $imageUrls;
 }
Esempio n. 13
0
 public function calculateQueryCacheHash()
 {
     self::$lastQueryCacheHash = parent::calculateQueryCacheHash();
     return self::$lastQueryCacheHash;
 }
 public function getCommunityCategoryByCommunityId($id)
 {
     $conn = opDoctrineQuery::getMasterConnectionDirect();
     $result = $conn->fetchOne('SELECT community_category_id FROM community WHERE id = ?', array($id));
     return $result;
 }
Esempio n. 15
0
<?php

$_app = 'pc_frontend';
$_env = 'test';
if (!isset($fixture)) {
    $fixture = 'common';
}
$configuration = ProjectConfiguration::getApplicationConfiguration($_app, $_env, true);
new sfDatabaseManager($configuration);
$conn = opDoctrineQuery::getMasterConnectionDirect();
$conn->exec('SET FOREIGN_KEY_CHECKS = 0');
$task = new sfDoctrineBuildTask($configuration->getEventDispatcher(), new sfFormatter());
$task->setConfiguration($configuration);
$task->run(array(), array('no-confirmation' => true, 'db' => true, 'and-load' => dirname(__FILE__) . '/../fixtures/' . $fixture, 'application' => $_app, 'env' => $_env));
$conn = Doctrine_Manager::getInstance()->getCurrentConnection();
$conn->clear();