コード例 #1
1
  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);

    $this->setContents();
    foreach ($memberIds as $memberid)
    {
      $randomtime = $this->makeRandomTime($options['date'],$options['number']);
      for ($i=0; $i<$options['number']; ++$i)
      {
        $title=$this->makeRandomContents('title',$options['titlecount']);
        $body=$this->makeRandomContents('body',$options['bodycount']);
        $diary = new Diary();
        $diary->setMemberId($memberid);
        $diary->setTitle($title);
        $diary->setBody($body);
        $diary->setPublicFlag(1);
        $diary->setCreatedAt($randomtime[$i]);
        $diary->setUpdatedAt($randomtime[$i]);
        $diary->save();
        $diary->free();
        $this->logSection('posted a diary', sprintf('%s %s', $memberid, $randomtime[$i]));
      }
    }
  }
コード例 #2
0
 public function executePost(sfWebRequest $request)
 {
     $this->forward400If('' === (string) $request['title'], 'title parameter is not specified.');
     $this->forward400If('' === (string) $request['body'], 'body parameter is not specified.');
     $this->forward400If(!isset($request['public_flag']) || '' === (string) $request['public_flag'], 'public flag is not specified');
     if (isset($request['id']) && '' !== $request['id']) {
         $diary = Doctrine::getTable('Diary')->findOneById($request['id']);
         $this->forward400If(false === $diary, 'the specified diary does not exit.');
         $this->forward400If(false === $diary->isAuthor($this->member->getId()), 'this diary is not yours.');
     } else {
         $diary = new Diary();
         $diary->setMemberId($this->member->getId());
     }
     $diary->setTitle($request['title']);
     $diary->setBody($request['body']);
     $diary->setPublicFlag($request['public_flag']);
     $diary->save();
     $this->diary = $diary;
     for ($i = 1; $i <= 3; $i++) {
         $diaryImage = Doctrine::getTable('DiaryImage')->retrieveByDiaryIdAndNumber($diary->getId(), $i);
         $filename = basename($_FILES['diary_photo_' . $i]['name']);
         if (!is_null($filename) && '' !== $filename) {
             try {
                 $validator = new opValidatorImageFile(array('required' => false));
                 $validFile = $validator->clean($_FILES['diary_photo_' . $i]);
             } catch (Exception $e) {
                 $this->forward400($e->getMessage());
             }
             $f = new File();
             $f->setFromValidatedFile($validFile);
             $f->setName(hash('md5', uniqid((string) $i) . $filename));
             if ($stream = fopen($_FILES['diary_photo_' . $i]['tmp_name'], 'r')) {
                 if (!is_null($diaryImage)) {
                     $diaryImage->delete();
                 }
                 $bin = new FileBin();
                 $bin->setBin(stream_get_contents($stream));
                 $f->setFileBin($bin);
                 $f->save();
                 $di = new DiaryImage();
                 $di->setDiaryId($diary->getId());
                 $di->setFileId($f->getId());
                 $di->setNumber($i);
                 $di->save();
                 $diary->updateHasImages();
             } else {
                 $this->forward400(__('Failed to write file to disk.'));
             }
         }
         $deleteCheck = $request['diary_photo_' . $i . '_photo_delete'];
         if ('on' === $deleteCheck && !is_null($diaryImage)) {
             $diaryImage->delete();
         }
     }
 }
コード例 #3
0
 public function insert(SimpleXMLElement $xml)
 {
     $member = Doctrine::getTable('Member')->find($xml->author->id);
     if (!$member) {
         return false;
     }
     $diary = new Diary();
     $diary->setTitle($xml->title);
     $diary->setBody($xml->content);
     $diary->setMember($member);
     $diary->save();
     return $diary;
 }
コード例 #4
0
 protected function executeTransaction($conn, $arguments = array(), $options = array())
 {
     $members = Doctrine::getTable('Member')->findAll(Doctrine::HYDRATE_ARRAY);
     foreach ($members as $member) {
         for ($i = 0; $i < $options['number']; ++$i) {
             $diary = new Diary();
             $diary->setMemberId($member['id']);
             $diary->setTitle('title');
             $diary->setBody('body');
             $diary->setPublicFlag(1);
             $diary->save();
             $diary->free();
             $this->logSection('posted a diary', sprintf('%s', $member['id']));
         }
     }
 }
コード例 #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;
     }
     $mailMessage = $request->getMailMessage();
     $title = $this->getSubject($mailMessage, '(no title)');
     $validator = new opValidatorString(array('rtrim' => true));
     try {
         $body = $validator->clean($mailMessage->getContent());
     } catch (Exception $e) {
         return sfView::ERROR;
     }
     $diary = new Diary();
     $diary->setMember($member);
     $diary->setTitle($title);
     $diary->setBody($body);
     $diary->setPublicFlag($this->getDefaultPublicFlag($member));
     $diaryImages = array();
     if (sfConfig::get('app_diary_is_upload_images', true)) {
         $num = (int) sfConfig::get('app_diary_max_image_file_num', 3);
         $files = $this->getImageFiles($mailMessage, $num);
         $i = 1;
         foreach ($files as $file) {
             $diaryImage = new DiaryImage();
             $diaryImage->setDiary($diary);
             $diaryImage->setFile($file);
             $diaryImage->setNumber($i++);
             $diaryImages[] = $diaryImage;
             $diary->setHasImages(true);
         }
     }
     $diary->save();
     foreach ($diaryImages as $diaryImage) {
         $diaryImage->save();
     }
     return sfView::NONE;
 }