Example #1
0
 /**
  *	@fn download
  *	@short Action method that performs the download of a software artifact.
  *	@details For software artifacts that are locally hosted, a DownloadManager is instantiated and the download
  *	is automatically started. For externally hosted artifacts, the client is redirected to the appropriate URL.
  */
 public function download()
 {
     if (!empty($_REQUEST['id'])) {
         $artifact = new SoftwareArtifact();
         if ($artifact->find_by_id($_REQUEST['id']) === FALSE) {
             HTTP::error(404);
         }
         $artifact->downloads++;
         $artifact->save();
         if (self::SOFTWARE_SAVE_DOWNLOADS) {
             // Logs the download
             $download = new SoftwareDownload();
             $download->artifact_id = $_REQUEST['id'];
             $download->save();
         }
         // Expires the cache of Download Stats
         // Remember: Download Stats are cached by release_id
         $this->expire_cached_page(array('action' => 'download_stats', 'id' => $artifact->release_id));
         if ($artifact->URL) {
             $this->redirect_to($artifact->URL);
         } else {
             $filename = $artifact->local_file();
             if ($filename) {
                 $dl_mgr = new DownloadManager($filename);
                 $dl_mgr->start_download();
             }
         }
     }
     $this->redirect_to(array('action' => 'index'));
 }