Example #1
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;
 }
Example #2
0
 public function executePost(sfWebRequest $request)
 {
     $this->forward400If('' === (string) $request['diary_id'], 'diary_id parameter is not specified.');
     $this->forward400If('' === (string) $request['body'], 'body parameter is not specified.');
     $diary = Doctrine::getTable('Diary')->findOneById($request['diary_id']);
     $this->forward400If(false === $diary, 'the specified diary does not exist');
     $diaryComment = new DiaryComment();
     $diaryComment->setMemberId($this->member->getId());
     $diaryComment->setDiaryId($request['diary_id']);
     $diaryComment->setBody($request['body']);
     $diaryComment->save();
     $this->memberId = $this->getUser()->getMemberId();
     $this->comment = $diaryComment;
 }
  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);
     }
 }
Example #5
0
 public function executeCreate(opMailRequest $request)
 {
     if (!Doctrine::getTable('SnsConfig')->get('op_diary_plugin_use_email_post', true)) {
         return sfView::NONE;
     }
     $member = $this->getRoute()->getMember();
     if (!$member) {
         return sfView::NONE;
     }
     $diary = Doctrine::getTable('Diary')->find($request['id']);
     if (!$diary || !$diary->isViewable($member->id)) {
         return sfView::NONE;
     }
     if ($diary->member_id !== $member->id) {
         $relation = Doctrine::getTable('MemberRelationship')->retrieveByFromAndTo($diary->member_id, $member->id);
         if ($relation && $relation->getIsAccessBlock()) {
             return sfView::NONE;
         }
     }
     $mailMessage = $request->getMailMessage();
     $validator = new opValidatorString(array('rtrim' => true));
     try {
         $body = $validator->clean($mailMessage->getContent());
     } catch (Exception $e) {
         return sfView::ERROR;
     }
     $diaryComment = new DiaryComment();
     $diaryComment->setDiary($diary);
     $diaryComment->setMember($member);
     $diaryComment->setBody($body);
     $diaryComment->save();
     if (sfConfig::get('app_diary_comment_is_upload_images', true)) {
         $num = (int) sfConfig::get('app_diary_comment_max_image_file_num', 3);
         $files = $this->getImageFiles($mailMessage, $num);
         foreach ($files as $file) {
             $image = new DiaryCommentImage();
             $image->setDiaryComment($diaryComment);
             $image->setFile($file);
             $image->save();
         }
     }
     return sfView::NONE;
 }
$conn->beginTransaction();
$first->DiaryCommentImages->delete();
$t->is($first->getDiaryCommentImagesJoinFile()->count(), 0, 'count 0');
$conn->rollback();
$t->diag('DiaryComment::isDeletable()');
$first = Doctrine::getTable('DiaryComment')->find(1);
$t->ok(!$first->isDeletable(0), 'int 0');
$t->ok(!$first->isDeletable('0'), 'string zero');
$t->ok(!$first->isDeletable(NULL), 'null');
$t->ok($first->isDeletable(1), 'OK commenter');
$t->ok($first->isDeletable(2), 'OK owner');
$t->ok(!$first->isDeletable(3), 'NG other');
$t->diag('DiaryComment::save()');
$conn = Doctrine::getTable('DiaryComment')->getConnection();
$conn->beginTransaction();
$new = new DiaryComment();
$new->diary_id = 1;
$new->member_id = 1;
$new->save();
$t->is($new->number, 22, 'set next number');
$conn->rollback();
$t->diag('DiaryComment::delete()');
$first = Doctrine::getTable('DiaryComment')->find(1);
$conn = Doctrine::getTable('DiaryComment')->getConnection();
$conn->beginTransaction();
$file_id = $first->DiaryCommentImages[0]->file_id;
$first->delete();
$t->ok(!Doctrine::getTable('DiaryCommentImage')->find(1), 'DiaryImage is deleted');
$t->ok(!Doctrine::getTable('File')->find($file_id), 'File is deleted');
$t->ok(!Doctrine::getTable('FileBin')->find($file_id), 'FileBin is deleted');
$conn->rollback();
<?php

include dirname(__FILE__) . '/../../bootstrap/functional.php';
$t = new opTestFunctional(new sfBrowser());
include dirname(__FILE__) . '/../../bootstrap/database.php';
$mailAddress = '*****@*****.**';
$t->login($mailAddress, 'password');
$t->setCulture('en');
$t->info('should be able to delete a comment');
$comment = Doctrine::getTable('DiaryComment')->findOneByMemberId(1);
$body = 'コメントテスト本文';
$json = $t->post('/diary_comment/delete.json', array('apiKey' => 'dummyApiKey', 'id' => $comment->getId()))->getResponse()->getContent();
$data = json_decode($json, true);
$t->test()->is($data['status'], 'success', 'should return status code "success"');
$t->test()->ok($data['data']['id'], 'should have id');
$t->info('should NOT be able to delete a comment of other\'s on other\'s diary');
$diary = Doctrine::getTable('Diary')->findOneByMemberId(5);
$comment = new DiaryComment();
$comment->setMemberId(5);
$comment->setDiaryId($diary->getId());
$comment->setBody('not to be deleted');
$comment->save();
$json = $t->post('/diary_comment/delete.json', array('apiKey' => 'dummyApiKey', 'id' => $comment->getId()))->with('response')->begin()->isStatusCode(400)->end();
$t->info('存在しないコメントの削除');
$json = $t->post('/diary_comment/delete.json', array('apiKey' => 'dummyApiKey', 'id' => '0'))->with('response')->begin()->isStatusCode('400')->end();