public function save(Doctrine_Connection $conn = null) { if (!$this->isNew() && !$this->getSkipBackup() && in_array('graphic_file', $this->_modified) && $this->_get('graphic_file')) { $file_location = rtrim(ProjectConfiguration::getEpisodeGraphicFileLocalDirectory(), '/') . '/'; $filename = $this->_get('graphic_file'); if (file_exists($file_location . $filename)) { ProjectConfiguration::registerAws(); $response = $this->saveFileToApplicationBucket($file_location, $filename, 'upload', AmazonS3::ACL_PUBLIC); if ($response->isOK()) { unlink($file_location . $filename); } } } if (!$this->isNew() && !$this->getSkipBackup() && in_array('audio_file', $this->_modified) && $this->_get('audio_file')) { $file_location = rtrim(ProjectConfiguration::getEpisodeAudioFileLocalDirectory(), '/') . '/'; $filename = $this->_get('audio_file'); if (file_exists($file_location . $filename)) { ProjectConfiguration::registerAws(); $response = $this->saveFileToApplicationBucket($file_location, $filename, 'audio'); } } if (!$this->isNew() && in_array('is_submitted', $this->_modified) && $this->_get('is_submitted')) { /* The episode has been submitted. We need to send an email about * it to the subreddit moderators. */ $types = array('moderator'); $memberships = sfGuardUserSubredditMembershipTable::getInstance()->getAllBySubredditAndMemberships($this->getSubredditId(), $types); $initial_is_submitted = $this->_get('is_submitted'); $initial_submitted_at = $this->_get('submitted_at'); foreach ($memberships as $membership) { $user = $membership->getSfGuardUser(); $parameters = array('user_id' => $membership->getSfGuardUserId(), 'episode_id' => $this->getIncremented()); $prefer_html = $user->getPreferHtml(); $address = $user->getEmailAddress(); $name = $user->getPreferredName() ? $user->getPreferredName() : $user->getFullName(); $email = EmailTable::getInstance()->getFirstByEmailTypeAndLanguage('EpisodeApprovalPending', $user->getPreferredLanguage()); $subject = $email->generateSubject($parameters); $body = $email->generateBodyText($parameters, $prefer_html); $from = sfConfig::get('app_email_address', ProjectConfiguration::getApplicationName() . ' <' . ProjectConfiguration::getApplicationEmailAddress() . '>'); AppMail::sendMail($address, $from, $subject, $body, $prefer_html ? $body : null); $user->addLoginMessage('You have Episodes awaiting your approval.'); } // @todo: The previous foreach loop sets the 'is_submitted' and 'submitted_at' columns to null. I don't know why. $this->_set('is_submitted', $initial_is_submitted); $this->_set('submitted_at', $initial_submitted_at); } return parent::save($conn); }