[Fusionforge-commits] FusionForge branch master updated. b7d01ebdff022176d0ba63eda684577b103b74a6

Roland Mas lolando at fusionforge.org
Fri Nov 23 14:08:20 CET 2012


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  b7d01ebdff022176d0ba63eda684577b103b74a6 (commit)
       via  e00583f28952220764f66e21f052d664242d9edd (commit)
       via  1b92d059864101b553936ae4aee8dd318df32118 (commit)
      from  3e4511775595d498c3acc58aa2305e1692763d3f (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 -----------------------------------------------------------------
commit b7d01ebdff022176d0ba63eda684577b103b74a6
Author: Roland Mas <lolando at debian.org>
Date:   Fri Nov 23 14:05:59 2012 +0100

    Factor constants for management of extra SCM repositories

diff --git a/src/common/include/constants.php b/src/common/include/constants.php
index 277d3d1..b9606be 100644
--- a/src/common/include/constants.php
+++ b/src/common/include/constants.php
@@ -76,6 +76,10 @@ define('GROUP_IS_TEMPLATE', forge_get_config('template_group'));
 /* Admin */
 define('ADMIN_CRONMAN_ROWS', 30);
 
+/* SCM repositories */
+define('SCM_EXTRA_REPO_ACTION_UPDATE', 0);
+define('SCM_EXTRA_REPO_ACTION_DELETE', 1);
+
 // Local Variables:
 // mode: php
 // c-file-style: "bsd"
diff --git a/src/plugins/scmgit/common/GitPlugin.class.php b/src/plugins/scmgit/common/GitPlugin.class.php
index c5f49d3..95ce8a3 100644
--- a/src/plugins/scmgit/common/GitPlugin.class.php
+++ b/src/plugins/scmgit/common/GitPlugin.class.php
@@ -77,8 +77,9 @@ class GitPlugin extends SCMPlugin {
 
 	function getInstructionsForAnon($project) {
 		$repo_list = array($project->getUnixName());
-		$result = db_query_params ('SELECT repo_name FROM scm_secondary_repos WHERE group_id=$1 AND next_action = 0 AND plugin_id=$2 ORDER BY repo_name',
+		$result = db_query_params ('SELECT repo_name FROM scm_secondary_repos WHERE group_id=$1 AND next_action = $2 AND plugin_id=$3 ORDER BY repo_name',
 					   array ($project->getID(),
+						  SCM_EXTRA_REPO_ACTION_UPDATE,
 						  $this->getID())) ;
 		$rows = db_numrows ($result) ;
 		for ($i=0; $i<$rows; $i++) {
@@ -135,8 +136,9 @@ class GitPlugin extends SCMPlugin {
 	function getInstructionsForRW($project) {
 		$repo_list = array($project->getUnixName());
 		
-		$result = db_query_params ('SELECT repo_name FROM scm_secondary_repos WHERE group_id=$1 AND next_action = 0 AND plugin_id=$2 ORDER BY repo_name',
+		$result = db_query_params ('SELECT repo_name FROM scm_secondary_repos WHERE group_id=$1 AND next_action = $2 AND plugin_id=$3 ORDER BY repo_name',
 					   array ($project->getID(),
+						  SCM_EXTRA_REPO_ACTION_UPDATE,
 						  $this->getID()));
 		$rows = db_numrows ($result) ;
 		for ($i=0; $i<$rows; $i++) {
@@ -411,8 +413,9 @@ class GitPlugin extends SCMPlugin {
 		}
 
 		// Create project-wide secondary repositories
-		$result = db_query_params ('SELECT repo_name, description, clone_url FROM scm_secondary_repos WHERE group_id=$1 AND next_action = 0 AND plugin_id=$2',
+		$result = db_query_params ('SELECT repo_name, description, clone_url FROM scm_secondary_repos WHERE group_id=$1 AND next_action = $2 AND plugin_id=$3',
 					   array ($project->getID(),
+						  SCM_EXTRA_REPO_ACTION_UPDATE,
 						  $this->getID()));
 		$rows = db_numrows ($result) ;
 		for ($i=0; $i<$rows; $i++) {
@@ -453,8 +456,9 @@ class GitPlugin extends SCMPlugin {
 		}
 
 		// Delete project-wide secondary repositories
-		$result = db_query_params ('SELECT repo_name FROM scm_secondary_repos WHERE group_id=$1 AND next_action = 1 AND plugin_id=$2',
+		$result = db_query_params ('SELECT repo_name FROM scm_secondary_repos WHERE group_id=$1 AND next_action = $2 AND plugin_id=$3',
 					   array ($project->getID(),
+						  SCM_EXTRA_REPO_ACTION_DELETE,
 						  $this->getID()));
 		$rows = db_numrows ($result) ;
 		for ($i=0; $i<$rows; $i++) {
@@ -463,9 +467,10 @@ class GitPlugin extends SCMPlugin {
 			if (util_is_valid_repository_name($repo_name)) {
 				system ("rm -rf $repodir");
 			}
-			db_query_params ('DELETE FROM scm_secondary_repos WHERE group_id=$1 AND repo_name=$2 AND next_action = 1 AND plugin_id=$3',
+			db_query_params ('DELETE FROM scm_secondary_repos WHERE group_id=$1 AND repo_name=$2 AND next_action = $3 AND plugin_id=$4',
 					 array ($project->getID(),
 						$repo_name,
+						SCM_EXTRA_REPO_ACTION_DELETE,
 						$this->getID()));
 		}
 
@@ -972,10 +977,11 @@ class GitPlugin extends SCMPlugin {
 			return false;
 		}
 
-		$result = db_query_params ('UPDATE scm_secondary_repos SET next_action = 1 WHERE group_id=$1 AND repo_name=$2 AND plugin_id=$3',
-						array ($params['group_id'],
-						       $params['repo_name'],
-						       $this->getID()));
+		$result = db_query_params ('UPDATE scm_secondary_repos SET next_action = $1 WHERE group_id=$2 AND repo_name=$3 AND plugin_id=$4',
+					   array (SCM_EXTRA_REPO_ACTION_DELETE,
+						  $params['group_id'],
+						  $params['repo_name'],
+						  $this->getID()));
 		if (! $result) {
 			$params['error_msg'] = db_error();
 			return false;
@@ -1017,8 +1023,9 @@ class GitPlugin extends SCMPlugin {
 		$project_name = $project->getUnixName();
 		
 		$select_repo = '<select name="frontpage">' . "\n";
-		$result = db_query_params('SELECT repo_name, description, clone_url FROM scm_secondary_repos WHERE group_id=$1 AND next_action = 0 AND plugin_id=$2 ORDER BY repo_name',
+		$result = db_query_params('SELECT repo_name, description, clone_url FROM scm_secondary_repos WHERE group_id=$1 AND next_action = $2 AND plugin_id=$3 ORDER BY repo_name',
 					  array ($params['group_id'],
+						 SCM_EXTRA_REPO_ACTION_UPDATE,
 						 $this->getID()));
 		if (! $result) {
 			$params['error_msg'] = db_error();

commit e00583f28952220764f66e21f052d664242d9edd
Author: Roland Mas <lolando at debian.org>
Date:   Fri Nov 23 13:53:02 2012 +0100

    Use a shared table for storing extra SCM repositories (secondary+personal)

diff --git a/src/db/20121123-multiple-scm-repositories.sql b/src/db/20121123-multiple-scm-repositories.sql
new file mode 100644
index 0000000..f898053
--- /dev/null
+++ b/src/db/20121123-multiple-scm-repositories.sql
@@ -0,0 +1,19 @@
+CREATE TABLE scm_secondary_repos (
+	group_id int NOT NULL REFERENCES groups ON DELETE CASCADE ON UPDATE CASCADE,
+	plugin_id int NOT NULL REFERENCES plugins ON DELETE CASCADE ON UPDATE CASCADE,
+	repo_name text NOT NULL,
+	clone_url text NOT NULL,
+	description text NOT NULL,
+	next_action int DEFAULT 0 NOT NULL,
+	CONSTRAINT scm_secondary_repos_unique UNIQUE (group_id, plugin_id, repo_name)
+) ;
+CREATE INDEX scm_secondary_repos_gid_idx ON plugin_scmgit_secondary_repos (group_id) ;
+
+CREATE TABLE scm_personal_repos (
+	group_id int NOT NULL REFERENCES groups ON DELETE CASCADE ON UPDATE CASCADE,
+	plugin_id int NOT NULL REFERENCES plugins ON DELETE CASCADE ON UPDATE CASCADE,
+	user_id int NOT NULL REFERENCES users ON DELETE CASCADE ON UPDATE CASCADE,
+	next_action int DEFAULT 0 NOT NULL,
+	CONSTRAINT scm_personal_repos_unique UNIQUE (group_id, plugin_id, user_id)
+) ;
+CREATE INDEX scm_personal_repos_uid_idx ON plugin_scmgit_secondary_repos (group_id) ;
diff --git a/src/plugins/scmgit/common/GitPlugin.class.php b/src/plugins/scmgit/common/GitPlugin.class.php
index e2adade..c5f49d3 100644
--- a/src/plugins/scmgit/common/GitPlugin.class.php
+++ b/src/plugins/scmgit/common/GitPlugin.class.php
@@ -77,8 +77,9 @@ class GitPlugin extends SCMPlugin {
 
 	function getInstructionsForAnon($project) {
 		$repo_list = array($project->getUnixName());
-		$result = db_query_params ('SELECT repo_name FROM plugin_scmgit_secondary_repos WHERE group_id=$1 AND next_action = 0 ORDER BY repo_name',
-					   array ($project->getID())) ;
+		$result = db_query_params ('SELECT repo_name FROM scm_secondary_repos WHERE group_id=$1 AND next_action = 0 AND plugin_id=$2 ORDER BY repo_name',
+					   array ($project->getID(),
+						  $this->getID())) ;
 		$rows = db_numrows ($result) ;
 		for ($i=0; $i<$rows; $i++) {
 			$repo_list[] = db_result($result,$i,'repo_name');
@@ -101,9 +102,10 @@ class GitPlugin extends SCMPlugin {
 			$b .= '</p>';
 		}
 		
-		$result = db_query_params('SELECT u.user_id, u.user_name, u.realname FROM plugin_scmgit_personal_repos p, users u WHERE p.group_id=$1 AND u.user_id=p.user_id AND u.unix_status=$2',
+		$result = db_query_params('SELECT u.user_id, u.user_name, u.realname FROM scm_personal_repos p, users u WHERE p.group_id=$1 AND u.user_id=p.user_id AND u.unix_status=$2 AND plugin_id=$3',
 					   array ($project->getID(),
-						  'A'));
+						  'A',
+						  $this->getID()));
 		$rows = db_numrows($result);
 
 		if ($rows > 0) {
@@ -133,8 +135,9 @@ class GitPlugin extends SCMPlugin {
 	function getInstructionsForRW($project) {
 		$repo_list = array($project->getUnixName());
 		
-		$result = db_query_params ('SELECT repo_name FROM plugin_scmgit_secondary_repos WHERE group_id=$1 AND next_action = 0 ORDER BY repo_name',
-					   array ($project->getID())) ;
+		$result = db_query_params ('SELECT repo_name FROM scm_secondary_repos WHERE group_id=$1 AND next_action = 0 AND plugin_id=$2 ORDER BY repo_name',
+					   array ($project->getID(),
+						  $this->getID()));
 		$rows = db_numrows ($result) ;
 		for ($i=0; $i<$rows; $i++) {
 			$repo_list[] = db_result($result,$i,'repo_name');
@@ -229,9 +232,10 @@ class GitPlugin extends SCMPlugin {
 		if (session_loggedin()) {
                         $u =& user_get_object(user_getid()) ;
 			if ($u->getUnixStatus() == 'A') {
-				$result = db_query_params('SELECT * FROM plugin_scmgit_personal_repos p WHERE p.group_id=$1 AND p.user_id=$2',
+				$result = db_query_params('SELECT * FROM scm_personal_repos p WHERE p.group_id=$1 AND p.user_id=$2 AND plugin_id=$3',
 							  array ($project->getID(),
-								 $u->getID()));
+								 $u->getID(),
+								 $this->getID()));
 				if ($result && db_numrows ($result) > 0) {
 					$b .= '<h2>';
 					$b .= _('Access to your personal repository');
@@ -407,8 +411,9 @@ class GitPlugin extends SCMPlugin {
 		}
 
 		// Create project-wide secondary repositories
-		$result = db_query_params ('SELECT repo_name, description, clone_url FROM plugin_scmgit_secondary_repos WHERE group_id=$1 AND next_action = 0',
-					   array ($project->getID())) ;
+		$result = db_query_params ('SELECT repo_name, description, clone_url FROM scm_secondary_repos WHERE group_id=$1 AND next_action = 0 AND plugin_id=$2',
+					   array ($project->getID(),
+						  $this->getID()));
 		$rows = db_numrows ($result) ;
 		for ($i=0; $i<$rows; $i++) {
 			$repo_name = db_result($result,$i,'repo_name');
@@ -448,8 +453,9 @@ class GitPlugin extends SCMPlugin {
 		}
 
 		// Delete project-wide secondary repositories
-		$result = db_query_params ('SELECT repo_name FROM plugin_scmgit_secondary_repos WHERE group_id=$1 AND next_action = 1',
-					   array ($project->getID())) ;
+		$result = db_query_params ('SELECT repo_name FROM scm_secondary_repos WHERE group_id=$1 AND next_action = 1 AND plugin_id=$2',
+					   array ($project->getID(),
+						  $this->getID()));
 		$rows = db_numrows ($result) ;
 		for ($i=0; $i<$rows; $i++) {
 			$repo_name = db_result($result,$i,'repo_name');
@@ -457,15 +463,17 @@ class GitPlugin extends SCMPlugin {
 			if (util_is_valid_repository_name($repo_name)) {
 				system ("rm -rf $repodir");
 			}
-			db_query_params ('DELETE FROM plugin_scmgit_secondary_repos WHERE group_id=$1 AND repo_name=$2 AND next_action = 1',
+			db_query_params ('DELETE FROM scm_secondary_repos WHERE group_id=$1 AND repo_name=$2 AND next_action = 1 AND plugin_id=$3',
 					 array ($project->getID(),
-						$repo_name)) ;
+						$repo_name,
+						$this->getID()));
 		}
 
 		// Create users' personal repositories
-		$result = db_query_params ('SELECT u.user_name FROM plugin_scmgit_personal_repos p, users u WHERE p.group_id=$1 AND u.user_id=p.user_id AND u.unix_status=$2',
+		$result = db_query_params ('SELECT u.user_name FROM scm_personal_repos p, users u WHERE p.group_id=$1 AND u.user_id=p.user_id AND u.unix_status=$2 AND plugin_id=$3',
 					   array ($project->getID(),
-						  'A')) ;
+						  'A',
+						  $this->getID()));
 		$rows = db_numrows ($result) ;
 		for ($i=0; $i<$rows; $i++) {
 			system ("mkdir -p $root/users") ;
@@ -874,8 +882,10 @@ class GitPlugin extends SCMPlugin {
 			return false;
 		}
 
-		$result = db_query_params('SELECT count(*) AS count FROM plugin_scmgit_secondary_repos WHERE group_id=$1 AND repo_name = $2',
-						array ($params['group_id'], $params['repo_name']));
+		$result = db_query_params('SELECT count(*) AS count FROM scm_secondary_repos WHERE group_id=$1 AND repo_name = $2 AND plugin_id=$3',
+					  array ($params['group_id'],
+						 $params['repo_name'],
+						 $this->getID()));
 		if (! $result) {
 			$params['error_msg'] = db_error();
 			return false;
@@ -897,7 +907,10 @@ class GitPlugin extends SCMPlugin {
 				$clone = $url;
 			} elseif ($url == $project->getUnixName()) {
 				$clone = $url;
-			} elseif (($result = db_query_params('SELECT count(*) AS count FROM plugin_scmgit_secondary_repos WHERE group_id=$1 AND repo_name = $2', array ($project->getID(), $url)))
+			} elseif (($result = db_query_params('SELECT count(*) AS count FROM scm_secondary_repos WHERE group_id=$1 AND repo_name = $2 AND plugin_id=$3',
+							     array ($project->getID(),
+								    $url,
+								    $this->getID())))
 				  && db_result($result, 0, 'count')) {
 				// Local repo: try to clone from an existing repo in same project
 				// Repository found
@@ -918,8 +931,12 @@ class GitPlugin extends SCMPlugin {
 			$description = "Git repository $params[repo_name] for project ".$project->getUnixName();
 		}
 
-		$result = db_query_params ('INSERT INTO plugin_scmgit_secondary_repos (group_id, repo_name, description, clone_url) VALUES ($1, $2, $3, $4)',
-						array ($params['group_id'], $params['repo_name'], $description, $clone));
+		$result = db_query_params ('INSERT INTO scm_secondary_repos (group_id, repo_name, description, clone_url, plugin_id) VALUES ($1, $2, $3, $4, $5)',
+					   array ($params['group_id'],
+						  $params['repo_name'],
+						  $description,
+						  $clone,
+						  $this->getID()));
 		if (! $result) {
 			$params['error_msg'] = db_error();
 			return false;
@@ -942,8 +959,10 @@ class GitPlugin extends SCMPlugin {
 			return false;
 		}
 
-		$result = db_query_params('SELECT count(*) AS count FROM plugin_scmgit_secondary_repos WHERE group_id=$1 AND repo_name = $2',
-						array ($params['group_id'], $params['repo_name']));
+		$result = db_query_params('SELECT count(*) AS count FROM scm_secondary_repos WHERE group_id=$1 AND repo_name = $2 AND plugin_id=$3',
+					  array ($params['group_id'],
+						 $params['repo_name'],
+						 $this->getID()));
 		if (! $result) {
 			$params['error_msg'] = db_error();
 			return false;
@@ -953,8 +972,10 @@ class GitPlugin extends SCMPlugin {
 			return false;
 		}
 
-		$result = db_query_params ('UPDATE plugin_scmgit_secondary_repos SET next_action = 1 WHERE group_id=$1 AND repo_name=$2',
-						array ($params['group_id'], $params['repo_name']));
+		$result = db_query_params ('UPDATE scm_secondary_repos SET next_action = 1 WHERE group_id=$1 AND repo_name=$2 AND plugin_id=$3',
+						array ($params['group_id'],
+						       $params['repo_name'],
+						       $this->getID()));
 		if (! $result) {
 			$params['error_msg'] = db_error();
 			return false;
@@ -996,8 +1017,9 @@ class GitPlugin extends SCMPlugin {
 		$project_name = $project->getUnixName();
 		
 		$select_repo = '<select name="frontpage">' . "\n";
-		$result = db_query_params('SELECT repo_name, description, clone_url FROM plugin_scmgit_secondary_repos WHERE group_id=$1 AND next_action = 0 ORDER BY repo_name',
-						array ($params['group_id']));
+		$result = db_query_params('SELECT repo_name, description, clone_url FROM scm_secondary_repos WHERE group_id=$1 AND next_action = 0 AND plugin_id=$2 ORDER BY repo_name',
+					  array ($params['group_id'],
+						 $this->getID()));
 		if (! $result) {
 			$params['error_msg'] = db_error();
 			return false;
diff --git a/src/plugins/scmgit/db/20121123-use-shared-table.sql b/src/plugins/scmgit/db/20121123-use-shared-table.sql
new file mode 100644
index 0000000..a980387
--- /dev/null
+++ b/src/plugins/scmgit/db/20121123-use-shared-table.sql
@@ -0,0 +1,2 @@
+INSERT INTO scm_secondary_repos (SELECT o.group_id, p.plugin_id, o.repo_name, o.clone_url, o.description, o.next_action FROM plugin_scmgit_secondary_repos o, plugins p WHERE p.plugin_name='scmgit');
+INSERT INTO scm_personal_repos (SELECT o.group_id, p.plugin_id, o.user_id, 0 FROM plugin_scmgit_personal_repos o, plugins p WHERE p.plugin_name='scmgit');

commit 1b92d059864101b553936ae4aee8dd318df32118
Author: Roland Mas <lolando at debian.org>
Date:   Fri Nov 23 13:47:03 2012 +0100

    Added caching getID() method to get a plugin's numeric ID

diff --git a/src/common/include/Plugin.class.php b/src/common/include/Plugin.class.php
index 65b1aba..ecc0ecd 100644
--- a/src/common/include/Plugin.class.php
+++ b/src/common/include/Plugin.class.php
@@ -32,6 +32,7 @@
 class Plugin extends Error {
 	var $name;
 	var $hooks;
+	var $id = NULL;
 
 	/**
 	 * Plugin() - constructor
@@ -116,6 +117,22 @@ class Plugin extends Error {
 	}
 
 	/**
+	 * getID - get the numeric ID of a plugin
+	 *
+	 * @return	int	identifier of the plugin
+	 */
+	function getID() {
+		if ($this->id) {
+			return $this->id;
+		}
+
+		$res = db_query_params('SELECT plugin_id FROM plugins WHERE plugin_name=$1',
+					array($this->name));
+		$this->id = db_result($res,$i,'plugin_id');
+		return $this->id;
+	}
+
+	/**
 	 * getGroups - get a list of all groups using a plugin.
 	 *
 	 * @return	array	array containing group objects.

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

Summary of changes:
 src/common/include/Plugin.class.php                |   17 ++++
 src/common/include/constants.php                   |    4 +
 src/db/20121123-multiple-scm-repositories.sql      |   19 +++++
 src/plugins/scmgit/common/GitPlugin.class.php      |   83 +++++++++++++-------
 .../scmgit/db/20121123-use-shared-table.sql        |    2 +
 5 files changed, 98 insertions(+), 27 deletions(-)
 create mode 100644 src/db/20121123-multiple-scm-repositories.sql
 create mode 100644 src/plugins/scmgit/db/20121123-use-shared-table.sql


hooks/post-receive
-- 
FusionForge



More information about the Fusionforge-commits mailing list