Ejemplo n.º 1
0
 public function executeBackup(sfWebRequest $request)
 {
     $this->redirectUnless($this->getUser()->isAuthenticated() && $this->getUser()->getApiUserId(), '@sf_guard_signin');
     $auth_key = $this->getUser()->getApiAuthKey();
     $subreddit_data = Api::getInstance()->setUser($auth_key)->get('subreddit/' . $request->getParameter('id'), true);
     $subreddit = ApiDoctrine::createObject('Subreddit', $subreddit_data['body']);
     $quick_subreddit = ApiDoctrine::createQuickObject($subreddit_data['body']);
     $this->forward404Unless($subreddit && $subreddit->getId());
     $this->setLayout(false);
     if ($request->getParameter('which') == 'intro') {
         $file_location = rtrim(ProjectConfiguration::getSubredditAudioFileLocalDirectory(), '/') . '/';
         $filename = $subreddit->getEpisodeIntro();
         if (file_exists($file_location . $filename)) {
             ProjectConfiguration::registerAws();
             $response = $subreddit->saveFileToApplicationBucket($file_location, $filename, 'intro');
             if ($response->isOK()) {
                 unlink($file_location . $filename);
             }
         }
     } elseif ($request->getParameter('which') == 'outro') {
         $file_location = rtrim(ProjectConfiguration::getSubredditAudioFileLocalDirectory(), '/') . '/';
         $filename = $subreddit->getEpisodeOutro();
         if (file_exists($file_location . $filename)) {
             ProjectConfiguration::registerAws();
             $response = $subreddit->saveFileToApplicationBucket($file_location, $filename, 'outro');
             if ($response->isOK()) {
                 unlink($file_location . $filename);
             }
         }
     }
 }
Ejemplo n.º 2
0
 public function executeUpload_subreddit_outro(sfWebRequest $request)
 {
     $id = $request->getParameter('id');
     $filename = $request->getParameter('name');
     $this->forward404Unless($id && $filename);
     $valid_episode = $this->validateSubredditForOutroUpload($id, $filename);
     $this->forward404Unless($valid_episode);
     // Settings
     $targetDir = rtrim(ProjectConfiguration::getSubredditAudioFileLocalDirectory(), '/');
     //$targetDir = 'uploads/';
     //$cleanupTargetDir = false; // Remove old files
     //$maxFileAge = 60 * 60; // Temp file age in seconds
     // 5 minutes execution time
     @set_time_limit(5 * 60);
     $fileName = $this->getUser()->getAttribute('valid_subreddit_outro_file_hash', '');
     return $this->handlePlupload($request, $targetDir, $fileName);
 }
Ejemplo n.º 3
0
 public function save(Doctrine_Connection $conn = null)
 {
     if (sfConfig::get('sf_environment') != 'test' && ($this->isNew() || in_array('domain', $this->_modified) && $this->_get('domain'))) {
         if (!$this->getBucketName() || strlen($this->getBucketName()) == 0) {
             $bucket_name = $this->createAmazonBucketName(ProjectConfiguration::getAmazonBucketPrefix() . $this->_get('domain'));
             $this->setBucketName($bucket_name);
         }
         if ($this->getBucketName() && (!$this->getCfDistId() || strlen($this->getCfDistId() == 0))) {
             if (!isset($bucket_name) || !$bucket_name) {
                 $bucket_name = $this->getBucketName();
             }
             $results = $this->createAmazonDistribution($bucket_name);
             if ($results !== false) {
                 $this->setCfDistId($results['dist_id']);
                 $this->setCfDomainName($results['domain_name']);
             }
         }
     }
     if (!$this->isNew() && !$this->getSkipBackup() && in_array('episode_intro', $this->_modified) && $this->_get('episode_intro')) {
         $file_location = rtrim(ProjectConfiguration::getSubredditAudioFileLocalDirectory(), '/') . '/';
         $filename = $this->_get('episode_intro');
         if (file_exists($file_location . $filename)) {
             ProjectConfiguration::registerAws();
             $response = $this->saveFileToApplicationBucket($file_location, $filename, 'intro');
             if ($response->isOK()) {
                 unlink($file_location . $filename);
             }
         }
     }
     if (!$this->isNew() && !$this->getSkipBackup() && in_array('episode_outro', $this->_modified) && $this->_get('episode_outro')) {
         $file_location = rtrim(ProjectConfiguration::getSubredditAudioFileLocalDirectory(), '/') . '/';
         $filename = $this->_get('episode_outro');
         if (file_exists($file_location . $filename)) {
             ProjectConfiguration::registerAws();
             $response = $this->saveFileToApplicationBucket($file_location, $filename, 'outro');
             if ($response->isOK()) {
                 unlink($file_location . $filename);
             }
         }
     }
     parent::save($conn);
 }
Ejemplo n.º 4
0
 /**
  * Allows for the upload of a Subreddit intro sound file.
  * @param   sfWebRequest   $request a request object
  * @return  string
  */
 public function executeUpload_outro(sfWebRequest $request)
 {
     // PUT makes more sense, but I am limited currently by my API to POST.
     $this->forward404Unless($request->isMethod(sfRequest::POST));
     $content = $request->getContent();
     // Restores backward compatibility. Content can be the HTTP request full body, or a form encoded "content" var.
     if (strpos($content, 'content=') === 0 || $request->hasParameter('content')) {
         $content = $request->getParameter('content');
     }
     $request->setRequestFormat('html');
     try {
         $parameters = $request->getParameterHolder()->getAll();
         $params = $this->getApiAuthFieldValues($parameters, $content);
         $this->validateUpload($content, $request);
     } catch (Exception $e) {
         $this->getResponse()->setStatusCode($e->getCode() ? $e->getCode() : 406);
         $serializer = $this->getSerializer();
         $this->getResponse()->setContentType($serializer->getContentType());
         $error = $e->getMessage();
         // event filter to enable customisation of the error message.
         $result = $this->dispatcher->filter(new sfEvent($this, 'sfDoctrineRestGenerator.filter_error_output'), $error)->getReturnValue();
         if ($error === $result) {
             $error = array(array('message' => $error));
             $this->output = $serializer->serialize($error, 'error');
         } else {
             $this->output = $serializer->serialize($result);
         }
         $this->setTemplate('index');
         return sfView::SUCCESS;
     }
     // We move the file from its temporary location to the Episode in question.
     if ($this->_nice_filename && $this->_temporary_file_location) {
         $targetDir = rtrim(ProjectConfiguration::getSubredditAudioFileLocalDirectory(), '/');
         $pattern = '/\\.([^\\.]+)$/';
         preg_match($pattern, $filename, $matches);
         $extension = array_key_exists(1, $matches) ? $matches[1] : 'mp3';
         // We don't need the upload hash because we're not uploading AJAX-like in real time.
         $hash = sha1(microtime() . $this->object->getIncremented());
         $fileName = $hash . '.' . $extension;
         //Move the file.
         rename($this->_temporary_file_location, $targetDir . '/' . $fileName);
         // update and save it
         $this->object->setEpisodeOutro($fileName);
     }
     return $this->doSave($params);
 }