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 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; }