[evolvis-commits] r17586: [#1132] ZIP download does not perform //bugfix

papel at evolvis.org papel at evolvis.org
Mon Oct 10 14:21:58 CEST 2011


Author: papel
Date: 2011-10-10 14:21:58 +0200 (Mon, 10 Oct 2011)
New Revision: 17586

Added:
   trunk/gforge_base/evolvisforge/gforge/common/frs/download.class.php
Removed:
   trunk/gforge_base/evolvisforge/gforge/www/frs/download.class.php
Modified:
   trunk/gforge_base/evolvisforge/gforge/www/frs/index.php
Log:
[#1132] ZIP download does not perform //bugfix

Added: trunk/gforge_base/evolvisforge/gforge/common/frs/download.class.php
===================================================================
--- trunk/gforge_base/evolvisforge/gforge/common/frs/download.class.php	                        (rev 0)
+++ trunk/gforge_base/evolvisforge/gforge/common/frs/download.class.php	2011-10-10 12:21:58 UTC (rev 17586)
@@ -0,0 +1,145 @@
+<?php
+/*-
+ * FusionForge ZIP download for FRS
+ *
+ * Copyright © 2010
+ *	Patrick Apel <p.apel at tarent.de>
+ * All rights reserved.
+ *
+ * This file is part of FusionForge. FusionForge is free software;
+ * you can redistribute it and/or modify it under the terms of the
+ * GNU General Public License as published by the Free Software
+ * Foundation; either version 2 of the Licence, or (at your option)
+ * any later version.
+ *
+ * FusionForge is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with FusionForge; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+require_once $gfcommon.'include/Error.class.php';
+
+class download extends Error {
+	
+	private $uploaddir_, $group_, $package_, $release_;  
+	
+	private $maxTime;//unix timestamp
+
+	public function download($uploaddir=null, $group=null, $package=null, $release=null){
+			$this->uploaddir_ = $uploaddir;
+			$this->group_ = $group;
+			$this->package_ = $package;
+			$this->release_ = $release;
+	}
+	
+	public function getUploadDir(){
+		return $this->uploaddir_;
+	}
+	
+	public function getGroupObject(){
+		return $this->group_;
+	}
+	
+	public function getPackageObject(){
+		return $this->package_;	
+	}
+	
+	public function getReleaseObject(){
+		return $this->release_;	
+	}
+	
+	public function setUploadDir($uploaddir){
+		$this->uploaddir_ = $uploaddir;
+	}
+	
+	public function setGroupObject($group){
+		$this->group_ = $group;
+	}
+	
+	public function setPackageObject($package){
+		$this->package_ = $package;
+	}
+	
+	public function setReleaseObject($release){
+		$this->release_ = $release;
+	}
+	
+	public function setMaxTime($maxTime) {
+		$this->maxTime = $maxTime;
+	}
+	
+	public function getMaxTime() {
+		return $this->maxTime;
+	}
+		
+	public function getNewestReleasePathAsString(){			
+		$uploaddir_ = $this->getUploadDir();
+		$group_ = $this->getGroupObject();
+		$package_ = $this->getPackageObject(); 
+		$release_ = $this->getReleaseObject();
+		
+   	  	return $newestReleasePathAsString = $uploaddir_ .$group_->getUnixName().'/'.$package_->getFileName().'/'.$release_->getFileName();
+	}	
+	
+	public function getPackagePathAsString(){
+		$uploaddir_ = $this->getUploadDir();
+		$group_ = $this->getGroupObject();
+		$package_ = $this->getPackageObject(); 
+
+		return $uploaddir_.$group_->getUnixName().'/'.$package_->getFileName();
+	}
+	
+	public function getNewestReleaseAsStandardFileName() {
+		$package_ = $this->getPackageObject(); 
+
+		return $package_->getFileName()."Release.zip";
+	}
+	
+	public function deleteNewestReleaseFile() {
+		///var/lib/gforge/download/newprojectyyz/newprojectyyza 
+		unlink($this->getPackagePathAsString().'/'.$this->getNewestReleaseAsStandardFileName());
+	}
+	
+	public function createNewestReleaseFilesAsZip(){
+		$uploaddir_ = $this->getUploadDir();
+		$group_ = $this->getGroupObject();
+		$package_ = $this->getPackageObject(); 
+		$release_ = $this->getReleaseObject();
+		
+		$zip = new ZipArchive();
+
+		$filename = $this->getNewestReleaseAsStandardFileName();;
+		$zipFilePlusPath = $this->getPackagePathAsString().'/'.$filename;
+		$filesToZipPath = $this->getNewestReleasePathAsString();
+
+		if ($zip->open($zipFilePlusPath, ZIPARCHIVE::OVERWRITE)!==true) {
+			exit_error(_('Cannot open the file archive.').' '.$zipFilePlusPath.'.');
+		}
+
+		$files_ =& $release_->getFiles(); $intErgCount = count($files_);
+	
+		$firstTimestamp = time();
+
+		for ($i = 0; $i<$intErgCount; $i++) {
+			
+			$thisTimestamp = time();
+
+			$seconds = date("s",$thisTimestamp) - date("s",$firstTimestamp);
+			
+			if($seconds >= 10) {
+				exit_error(_('Packing time espired. There are to many files to pack.'));
+			} 
+			
+			$filePath = $filesToZipPath.'/'.$files_[$i]->getName();
+			$zip->addFile($filePath,$files_[$i]->getName());
+		} 
+
+		$zip->close();
+	}
+}
+?>
\ No newline at end of file

Modified: trunk/gforge_base/evolvisforge/gforge/www/frs/index.php
===================================================================
--- trunk/gforge_base/evolvisforge/gforge/www/frs/index.php	2011-10-07 16:28:46 UTC (rev 17585)
+++ trunk/gforge_base/evolvisforge/gforge/www/frs/index.php	2011-10-10 12:21:58 UTC (rev 17586)
@@ -27,14 +27,18 @@
 require_once('../env.inc.php');
 require_once $gfwww.'include/pre.php';
 require_once $gfwww.'frs/include/frs_utils.php';
+//require_once $gfcommon.'common/include/utils.php';
 require_once $gfcommon.'frs/FRSPackage.class.php';
-require_once $gfwww.'frs/download.class.php';
+require_once $gfcommon.'frs/download.class.php';
 require_once $gfcommon.'include/datepick.php';
 
 $group_id = getIntFromRequest('group_id');
 $release_id = getIntFromRequest('release_id');
 $cur_group =& group_get_object($group_id);
 
+$downloadNewestRelease = getIntFromRequest('downloadNewestRelease', 0);
+$deleteNewestRelease = getIntFromRequest('deleteNewestRelease', 0);
+
 if (!$cur_group) {
 	exit_error(_('No group title'), _('No group'));
 }
@@ -116,22 +120,41 @@
 				html_image('ic/mail16w.png','20','20',array('alt'=>_('Monitor this package')));
 		}
 
-		print '</a></h3></td><td colspan="4">';	
+		print '</a></h3></td><td colspan="4">';
 
 		$frsRelease = new FRSRelease($frsPackage);
 		$newestReleaseId = $frsRelease->getNewestReleaseId($frsPackage->getID());
 		$frsRelease_ = new FRSRelease($frsPackage, $newestReleaseId);
 		
 		$frsDownload = new download($sys_upload_dir, $cur_group, $frsPackage, $frsRelease_);
+		$fileName = '';
+		if($downloadNewestRelease == 1) {	
+			$frsDownload->createNewestReleaseFilesAsZip(); //Creates a zip-archiv
+		} elseif($deleteNewestRelease == 1) {
+			$frsDownload->deleteNewestReleaseFile();
+		}
 		
-//		$frsDownload->createNewestReleaseFilesAsZip(); #Creates a zip-archiv
+		$dlForm = '<form action="'.getStringFromServer('PHP_SELF').'?group_id='.$group_id.'" method="post">';
+		$dlForm .= '<input type="submit" name="dlButton" value="'._('Create archive of the newest release').'"/>';
+		$dlForm .= '<input type="hidden" name="downloadNewestRelease" value="1" />';
+		$dlForm .= '<input type="hidden" name="group_id" value="'.$group_id.'" />';
+		$dlForm .= '</form>';
+		
+		$delForm = '<form action="'.getStringFromServer('PHP_SELF').'?group_id='.$group_id.'" method="post">';
+		$delForm .= '<input type="submit" name="delButton" value="'._('Delete the archive of the newest release').'"/>';
+		$delForm .= '<input type="hidden" name="deleteNewestRelease" value="1" />';
+		$delForm .= '<input type="hidden" name="group_id" value="'.$group_id.'" />';
+		$delForm .= '</form>';
+		
 		$fileName = $frsDownload->getNewestReleaseAsStandardFileName();
 		if(file_exists($frsDownload->getPackagePathAsString().'/'.$fileName)) {
+			$dlForm = '';
 			$link_=util_make_url ('/frs/download.php/'.$fileName.'?group_id='.$cur_group->getID().'&package_id='.$frsPackage->getID().'&file='.$fileName.'&static_link=true&release_zip=true');
 			$link = '<a href="'.$link_.'" title="'._('This link always points to the newest release zip file.').'">'.$fileName.'</a>';
-		} else { $link = _('No version available.'); }
+
+		} else { $delForm = ''; $link = _('No version available.'); }
 		
-//		print '<table><tr '.$cur_style.'><td colspan="3">  <em>'._('Download newest version:').' '.$link.'</em></td></tr></table>';
+		print '<table border="0" cellpadding="0" cellspacing="0"><tr '.$cur_style.'><td>'.$dlForm.'</td><td colspan="3">  '._('Download newest version: ').$link.'  </td><td>'.$delForm.'</td></tr></table>';
 		print '</td></tr>';
 
 		// get the releases of the package
@@ -204,12 +227,10 @@
 						$cell_data=array();
 						
 						$staticLink="";
-							if($package_release['release_id']==$newestReleaseId){ 
-								$staticLink = '<a href="'.util_make_url ('/frs/download.php/'.$file_release['filename'].'?group_id='.$cur_group->getID().'&package_id='.$frsPackage->getID().'&file='.$file_release['filename'].'&static_link=true" title="'._('A static link always points to the newest release file.').'">('._('Static link').')</a>');
-								}
-							
-							
-							
+						if($package_release['release_id']==$newestReleaseId){ 
+							$staticLink = '<a href="'.util_make_url ('/frs/download.php/'.$file_release['filename'].'?group_id='.$cur_group->getID().'&package_id='.$frsPackage->getID().'&file='.$file_release['filename'].'&static_link=true" title="'._('A static link always points to the newest release file.').'">('._('Static link').')</a>');
+						}						
+						
 						$cell_data[] = array( 
 						util_make_link('/frs/download.php/'.$file_release['file_id'].'/'.$file_release['filename'],$file_release['filename']) . '     '.$staticLink,
 						'colspan="3"');



More information about the evolvis-commits mailing list