[Fusionforge-commits] FusionForge branch master updated. v6.0.5-1884-gf737f58

Franck Villaume nerville at libremir.placard.fr.eu.org
Mon May 29 20:17:55 CEST 2017


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "FusionForge".

The branch, master has been updated
       via  f737f582ed96ef2d325f2428a93ecbe383b1faaf (commit)
       via  2f857c02e77563b0147f76e38ea73a63f736b05f (commit)
      from  5f09ddc1cba8f62d49a68cf3ceac2cf0e061d982 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
https://scm.fusionforge.org/anonscm/gitweb/?p=fusionforge/fusionforge.git;a=commitdiff;h=f737f582ed96ef2d325f2428a93ecbe383b1faaf

commit f737f582ed96ef2d325f2428a93ecbe383b1faaf
Author: Franck Villaume <franck.villaume at trivialdev.com>
Date:   Mon May 29 20:17:16 2017 +0200

    forge cli: start releaseImport, activate frsImport in groupImport, adjust role accordingly

diff --git a/src/bin/forge b/src/bin/forge
index 6c823ad..8aa8e86 100755
--- a/src/bin/forge
+++ b/src/bin/forge
@@ -601,7 +601,14 @@ class CliActions {
 					if (isset($stream['setup']['data_array']['use_frs'])) {
 						$new_group->setUseFRS($stream['setup']['data_array']['use_frs']);
 						if ($new_group->usesFRS() && isset($stream['frs'])) {
-							//TODO: do the injection :-)
+							$filename = 'frsDump-'.$stream['setup']['data_array']['group_id'].'.'.$format;
+							$this->createSubfile($filename, $stream['frs'], $format);
+							if (!$this->frsImport($filename, $format)) {
+								echo _('Unable to inject FRS')."\n";
+								db_rollback();
+								return false;
+							}
+							@unlink($filename);
 						}
 					} else {
 						$new_group->setUseFRS(false);
@@ -686,11 +693,11 @@ class CliActions {
 									case 'new_pm':
 										$perms[$key][$this->getMappingId($stream['setup']['data_array']['group_id'], 'group')] = current($value);
 										break;
-// 									case 'frs':
-// 										foreach ($value as $frsp_key => $frsp_val) {
-// 											$perms[$key][$this->getMappingId($frsp_key, 'package')] = $frsp_val;
-// 										}
-// 										break;
+									case 'frs':
+										foreach ($value as $frsp_key => $frsp_val) {
+											$perms[$key][$this->getMappingId($frsp_key, 'package')] = $frsp_val;
+										}
+										break;
 // 									case 'forum':
 // 										foreach ($value as $fr_key => $fr_val) {
 // 											$perms[$key][$this->getMappingId($fr_key, 'forum')] = $fr_val;
@@ -1449,6 +1456,7 @@ class CliActions {
 				db_rollback();
 				return false;
 			}
+			$importRefMapping['package'][$stream['data_array']['package_id']] = $frsp->getID();
 			if (isset($stream['package_releases']) && is_array($stream['package_releases'])) {
 				foreach ($stream['package_releases'] as $prelease) {
 					$filename = 'releaseDump-'.$prelease['data_array']['release_id'].'.'.$format;
@@ -1462,6 +1470,8 @@ class CliActions {
 				}
 			}
 			db_commit();
+			echo _('Package injected')."\n";
+			return true;
 		} else {
 			echo _('Unable to get project to inject package')._(': ').$group_id."\n";
 			return false;
@@ -1488,7 +1498,44 @@ class CliActions {
 		if (!$stream) {
 			return false;
 		}
-		return true;
+		$package_id = $this->getMappingId($stream['data_array']['package_id'], 'package');
+		$frsp = frspackage_get_object($package_id);
+		if ($frsp && is_object($frsp) && !$frsp->isError()) {
+			db_begin();
+			$frsr = new FRSRelease($frsp);
+			$importData['nopermcheck'] = 1;
+			if (isset($stream['data_array']['release_date'])) {
+				$importData['time'] = $stream['data_array']['release_date'];
+			}
+			if (isset($stream['data_array']['released_by'])) {
+				$importData['user'] = $this->getMappingId($stream['data_array']['released_by'], 'user');
+			}
+			if (isset($stream['data_array']['preformatted'])) {
+				$preformatted = $stream['data_array']['preformatted'];
+			} else {
+				$preformatted = 0;
+			}
+			if (isset($stream['data_array']['status_id'])) {
+				$status_id = $stream['data_array']['status_id'];
+			} else {
+				$status_id = 1;
+			}
+			if (!$frsr->create($stream['data_array']['name'], $stream['data_array']['notes'], $stream['data_array']['changes'], $preformatted, false, $status_id, $importData)) {
+				echo $frsr->getErrorMessage()."\n";
+				db_rollback();
+				return false;
+			}
+			if (isset($stream['release_files']) && is_array($stream['release_files'])) {
+				foreach ($stream['release_files'] as $rfile) {
+					echo 'TODO: support files'."\n";
+				}
+			}
+			db_commit();
+			echo _('Release injected')."\n";
+			return true;
+		} else {
+			echo _('Unable to get package to inject release')._(': ').$package_id."\n";
+		}
 	}
 
 	function pmDump($projectgroupid, $format = 'json') {
diff --git a/src/common/frs/FRSRelease.class.php b/src/common/frs/FRSRelease.class.php
index 525c8e7..0d8bac3 100644
--- a/src/common/frs/FRSRelease.class.php
+++ b/src/common/frs/FRSRelease.class.php
@@ -133,9 +133,11 @@ class FRSRelease extends FFObject {
 	 * @param	string	$changes	The change log for the release.
 	 * @param	int	$preformatted	Whether the notes/log are preformatted with \n chars (1) true (0) false.
 	 * @param	int	$release_date	The unix date of the release.
+	 * @param	array	$importData	Array of data to change creator, time of creation, bypass permission check and do not send notification like:
+	 *					array('user' => 127, 'time' => 1234556789, 'nopermcheck' => 1, 'nonotice' => 1)
 	 * @return	boolean	success.
 	 */
-	function create($name, $notes, $changes, $preformatted, $release_date = false) {
+	function create($name, $notes, $changes, $preformatted, $release_date = false, $status_id = 1, $importData = array()) {
 		if (strlen($name) < 3) {
 			$this->setError(_('FRSRelease Name Must Be At Least 3 Characters'));
 			return false;
@@ -147,13 +149,25 @@ class FRSRelease extends FFObject {
 			$preformatted = 0;
 		}
 
-		if (!forge_check_perm('frs', $this->FRSPackage->getID(), 'release')) {
-			$this->setPermissionDeniedError();
-			return false;
+		if (isset($importData['user'])) {
+			$userid = $importData['user'];
+		} else {
+			$userid = user_getid();
+		}
+
+		if (!isset($importData['nopermcheck']) || (isset($importData['nopermcheck']) && !$importData['nopermcheck'])) {
+			if (!forge_check_perm_for_user(user_get_object($userid), 'frs', $this->FRSPackage->getID(), 'release')) {
+				$this->setPermissionDeniedError();
+				return false;
+			}
 		}
 
-		if (!$release_date) {
-			$release_date=time();
+		if (!$release_date || !isset($importData['time'])) {
+			$release_date = time();
+		} else {
+			if (isset($importData['time'])) {
+				$release_date = $importData['time'];
+			}
 		}
 		$res = db_query_params('SELECT * FROM frs_release WHERE package_id=$1 AND name=$2',
 					array ($this->FRSPackage->getID(),
@@ -171,8 +185,8 @@ class FRSRelease extends FFObject {
 						$preformatted,
 						htmlspecialchars($name),
 						$release_date,
-						user_getid(),
-						1));
+						$userid,
+						$status_id));
 		if (!$result) {
 			$this->setError(_('Error Adding Release: ').db_error());
 			db_rollback();

https://scm.fusionforge.org/anonscm/gitweb/?p=fusionforge/fusionforge.git;a=commitdiff;h=2f857c02e77563b0147f76e38ea73a63f736b05f

commit 2f857c02e77563b0147f76e38ea73a63f736b05f
Author: Franck Villaume <franck.villaume at trivialdev.com>
Date:   Mon May 29 14:06:40 2017 +0200

    forge cli: implement packageImport

diff --git a/src/bin/forge b/src/bin/forge
index a4e5f46..6c823ad 100755
--- a/src/bin/forge
+++ b/src/bin/forge
@@ -1439,7 +1439,33 @@ class CliActions {
 		if (!$stream) {
 			return false;
 		}
-		return true;
+		$group_id = $this->getMappingId($stream['data_array']['group_id'], 'group');
+		$group = group_get_object($group_id);
+		if ($group && is_object($group) && !$group->isError() && $group->usesFRS()) {
+			db_begin();
+			$frsp = new FRSPackage($group);
+			if (!$frsp->create($stream['data_array']['name'], $stream['data_array']['status_id'])) {
+				echo $frsp->getErrorMessage()."\n";
+				db_rollback();
+				return false;
+			}
+			if (isset($stream['package_releases']) && is_array($stream['package_releases'])) {
+				foreach ($stream['package_releases'] as $prelease) {
+					$filename = 'releaseDump-'.$prelease['data_array']['release_id'].'.'.$format;
+					$this->createSubfile($filename, $prelease, $format);
+					if (!$this->releaseImport($filename, $format)) {
+						echo _('Unable to inject release')."\n";
+						db_rollback();
+						return false;
+					}
+					@unlink($filename);
+				}
+			}
+			db_commit();
+		} else {
+			echo _('Unable to get project to inject package')._(': ').$group_id."\n";
+			return false;
+		}
 	}
 
 	function releaseDump($releaseid, $format = 'json') {
diff --git a/src/common/frs/FRSPackage.class.php b/src/common/frs/FRSPackage.class.php
index ab93f33..e09aa02 100644
--- a/src/common/frs/FRSPackage.class.php
+++ b/src/common/frs/FRSPackage.class.php
@@ -146,10 +146,11 @@ class FRSPackage extends FFError {
 	/**
 	 * create - create a new FRSPackage in the database.
 	 *
-	 * @param	$name
+	 * @param	string 	$name	Name of the package
+	 * @param	int	$status Status ID. Default is 1 => Active
 	 * @return	boolean	success.
 	 */
-	function create($name) {
+	function create($name, $status = 1) {
 		if (strlen($name) < 3) {
 			$this->setError(_('FRSPackage Name Must Be At Least 3 Characters'));
 			return false;
@@ -162,7 +163,7 @@ class FRSPackage extends FFError {
 			return false;
 		}
 
-		$res = db_query_params('SELECT * FROM frs_package WHERE group_id=$1 AND name=$2',
+		$res = db_query_params('SELECT * FROM frs_package WHERE group_id = $1 AND name = $2',
 					array($this->Group->getID(),
 						htmlspecialchars($name)));
 		if (db_numrows($res)) {
@@ -174,7 +175,7 @@ class FRSPackage extends FFError {
 		$result = db_query_params('INSERT INTO frs_package(group_id, name, status_id) VALUES ($1, $2, $3)',
 					array($this->Group->getID(),
 						htmlspecialchars($name),
-						1));
+						$status));
 		if (!$result) {
 			$this->setError(_('Error Adding Package')._(': ').db_error());
 			db_rollback();
@@ -216,7 +217,7 @@ class FRSPackage extends FFError {
 	 * @return	boolean	success.
 	 */
 	function fetchData($package_id) {
-		$res = db_query_params('SELECT * FROM frs_package WHERE package_id=$1 AND group_id=$2',
+		$res = db_query_params('SELECT * FROM frs_package WHERE package_id = $1 AND group_id = $2',
 					array($package_id, $this->Group->getID()));
 		if (!$res || db_numrows($res) < 1) {
 			$this->setError(_('Invalid package_id'));

-----------------------------------------------------------------------

Summary of changes:
 src/bin/forge                       | 89 +++++++++++++++++++++++++++++++++----
 src/common/frs/FRSPackage.class.php | 11 ++---
 src/common/frs/FRSRelease.class.php | 30 +++++++++----
 3 files changed, 109 insertions(+), 21 deletions(-)


hooks/post-receive
-- 
FusionForge



More information about the Fusionforge-commits mailing list