コード例 #1
0
ファイル: apiv1.php プロジェクト: eric116/BotQueue
 public function api_updateslicejob()
 {
     if (!$this->args('job_id')) {
         throw new Exception("You must provide the 'bot_id' parameter.");
     }
     $sj = new SliceJob($this->args('job_id'));
     if (!$sj->isHydrated()) {
         throw new Exception("Slice job does not exist.");
     }
     if ($sj->get('user_id') != User::$me->id) {
         throw new Exception("This slice job is not yours.");
     }
     //load up our objects
     $job = $sj->getJob();
     //upload our file
     $file = $_FILES['file'];
     $emptyFile = false;
     try {
         $this->ensureGoodFile($file);
     } catch (InvalidUploadedFile $ex) {
         if ($ex->getCode() == UPLOAD_ERR_EMPTY) {
             $emptyFile = true;
         } else {
             throw $ex;
         }
     }
     $data_file = Storage::newFile();
     if (!$emptyFile) {
         //okay, we're good.. do it.
         $data_file->set('user_id', User::$me->id);
         $data_file->upload($file['tmp_name'], StorageInterface::getNiceDir($file['name']));
     }
     //update our status.
     $sj->set('output_log', $this->args('output'));
     $sj->set('error_log', $this->args('errors'));
     if (!$emptyFile) {
         $sj->set('output_id', $data_file->id);
     }
     $sj->save();
     //update our job
     $job->set('slice_complete_time', date("Y-m-d H:i:s"));
     if (!$emptyFile) {
         $job->set('file_id', $data_file->id);
     }
     $job->save();
     //what do do with it now?
     if ($this->args('status') == 'complete') {
         $sj->pass();
     } else {
         if ($this->args('status') == 'failure') {
             $sj->fail();
         } else {
             if ($this->args('status') == 'pending') {
                 $sj->setStatus('pending');
                 $sj->set('finish_date', date("Y-m-d H:i:s"));
                 $sj->save();
             }
         }
     }
     Activity::log($job->getBot()->getLink() . " sliced the " . $job->getLink() . " job via the API.");
     return $job->getBot()->getAPIData();
 }