[Fusionforge-commits] r15910 - in trunk/src/plugins/scmhook: cronjobs library/scmhg/cronjobs library/scmsvn/cronjobs

Franck VILLAUME nerville at fusionforge.org
Sun Jul 1 19:20:11 CEST 2012


Author: nerville
Date: 2012-07-01 19:20:10 +0200 (Sun, 01 Jul 2012)
New Revision: 15910

Modified:
   trunk/src/plugins/scmhook/cronjobs/updateScmRepo.php
   trunk/src/plugins/scmhook/library/scmhg/cronjobs/updateScmRepo.php
   trunk/src/plugins/scmhook/library/scmsvn/cronjobs/updateScmRepo.php
Log:
make it work: use OO where needed

Modified: trunk/src/plugins/scmhook/cronjobs/updateScmRepo.php
===================================================================
--- trunk/src/plugins/scmhook/cronjobs/updateScmRepo.php	2012-06-30 10:31:22 UTC (rev 15909)
+++ trunk/src/plugins/scmhook/cronjobs/updateScmRepo.php	2012-07-01 17:20:10 UTC (rev 15910)
@@ -66,14 +66,15 @@
 	switch ($scmtype) {
 		case 'scmsvn': {
 			cron_debug("INFO start updating hooks for project ".$group->getUnixName());
-			include $gfplugins.'scmhook/library/'.$scmtype.'/cronjobs/updateScmRepo.php';
+			require_once $gfplugins.'scmhook/library/'.$scmtype.'/cronjobs/updateScmRepo.php';
 			global $svndir_prefix;
+			$scmsvncronjob = new ScmSvnUpdateScmRepo();
 			$params = array();
 			$params['group_id'] = $group_id;
 			$params['hooksString'] = $row['hooks'];
 			$params['scm_root'] = forge_get_config('repos_path', 'scmsvn') . '/' . $group->getUnixName();
 
-			if (updateScmRepo($params)) {
+			if ($scmsvncronjob->updateScmRepo($params)) {
 				$res = db_query_params('UPDATE plugin_scmhook set need_update = $1 where id_group = $2', array(0, $group_id));
 				if (!$res) {
 					$returnvalue = false;
@@ -83,12 +84,14 @@
 		}
 		case 'scmhg': {
 			cron_debug("INFO start updating hooks for project ".$group->getUnixName());
-			include $gfplugins.'scmhook/library/'.$scmtype.'/cronjobs/updateScmRepo.php';
+			require_once $gfplugins.'scmhook/library/'.$scmtype.'/cronjobs/updateScmRepo.php';
+			$scmhgcronjob = new ScmHgUpdateScmRepo();
 			$params = array();
 			$params['group_id'] = $group_id;
 			$params['hooksString'] = $row['hooks'];
 			$params['scm_root'] = forge_get_config('repos_path', 'scmhg') . '/' . $group->getUnixName();
-			if (updateScmRepo($params)) {
+			if ($scmhgcronjob->updateScmRepo($params)) {
+				echo 'ici';
 				$res = db_query_params('UPDATE plugin_scmhook set need_update = $1 where id_group = $2', array(0, $group_id));
 				if (!$res) {
 					$returnvalue = false;

Modified: trunk/src/plugins/scmhook/library/scmhg/cronjobs/updateScmRepo.php
===================================================================
--- trunk/src/plugins/scmhook/library/scmhg/cronjobs/updateScmRepo.php	2012-06-30 10:31:22 UTC (rev 15909)
+++ trunk/src/plugins/scmhook/library/scmhg/cronjobs/updateScmRepo.php	2012-07-01 17:20:10 UTC (rev 15910)
@@ -26,58 +26,65 @@
  *	$params['scm_root'] = directory containing the scm repository
  */
 
-/**
- * updateScmRepo - update the scmrepo with the new hooks
- *
- * @params	Array	the complete array description
- * @return	boolean	success or not
- */
-function updateScmRepo($params) {
-	$group_id = $params['group_id'];
-	$hooksString = $params['hooksString'];
-	$scmdir_root = $params['scm_root'];
-	$group = group_get_object($group_id);
-	$scmhookPlugin = new scmhookPlugin;
-	$hooksAvailable = $scmhookPlugin->getAvailableHooks($group_id);
-	$unixname = $group->getUnixName();
-	if (is_dir($scmdir_root)) {
-		$hooksServePushPullBundle = array();
-		foreach ($hooksAvailable as $hook) {
-			switch ($hook->getHookType()) {
-				case "serve-push-pull-bundle": {
-					$hooksServePushPullBundle[] = $hook;
-					break;
+
+class ScmHgUpdateScmRepo {
+	function __construct() {
+		return true;
+	}
+
+	/**
+	* updateScmRepo - update the scmrepo with the new hooks
+	*
+	* @params	Array	the complete array description
+	* @return	boolean	success or not
+	*/
+	function updateScmRepo($params) {
+		$group_id = $params['group_id'];
+		$hooksString = $params['hooksString'];
+		$scmdir_root = $params['scm_root'];
+		$group = group_get_object($group_id);
+		$scmhookPlugin = new scmhookPlugin;
+		$hooksAvailable = $scmhookPlugin->getAvailableHooks($group_id);
+		$unixname = $group->getUnixName();
+		if (is_dir($scmdir_root)) {
+			$hooksServePushPullBundle = array();
+			foreach ($hooksAvailable as $hook) {
+				switch ($hook->getHookType()) {
+					case "serve-push-pull-bundle": {
+						$hooksServePushPullBundle[] = $hook;
+						break;
+					}
+					default: {
+						//byebye hook.... we do not know you...
+						break;
+					}
 				}
-				default: {
-					//byebye hook.... we do not know you...
-					break;
-				}
 			}
-		}
-		//first we disable all hooks
-		foreach($hooksServePushPullBundle as $hookServePushPullBundle) {
-			$hookServePushPullBundle->disable($group);
-		}
-		//now we enable new available hooks
-		$newHooks = explode('|', $hooksString);
-		if (count($newHooks)) {
-			$hooksServePushPullBundle = array();
-			foreach($newHooks as $newHook) {
-				foreach($hooksServePushPullBundle as $hookServePushPullBundle) {
-					if ($hookServePushPullBundle->getClassname() == $newHook) {
-						$newHooksServePushPullBundle[] = $hookServePushPullBundle;
+			//first we disable all hooks
+			foreach($hooksServePushPullBundle as $hookServePushPullBundle) {
+				$hookServePushPullBundle->disable($group);
+			}
+			//now we enable new available hooks
+			$newHooks = explode('|', $hooksString);
+			if (count($newHooks)) {
+				$hooksServePushPullBundle = array();
+				foreach($newHooks as $newHook) {
+					foreach($hooksServePushPullBundle as $hookServePushPullBundle) {
+						if ($hookServePushPullBundle->getClassname() == $newHook) {
+							$newHooksServePushPullBundle[] = $hookServePushPullBundle;
+						}
 					}
 				}
 			}
-		}
-		if (count($newHooksServePushPullBundle)) {
-			foreach($newHooksServePushPullBundle as $newHookServePushPullBundle) {
-				$newHookServePushPullBundle->enable($group);
+			if (count($newHooksServePushPullBundle)) {
+				foreach($newHooksServePushPullBundle as $newHookServePushPullBundle) {
+					$newHookServePushPullBundle->enable($group);
+				}
 			}
+			return true;
 		}
-		return true;
+		return false;
 	}
-	return false;
 }
 
 ?> 

Modified: trunk/src/plugins/scmhook/library/scmsvn/cronjobs/updateScmRepo.php
===================================================================
--- trunk/src/plugins/scmhook/library/scmsvn/cronjobs/updateScmRepo.php	2012-06-30 10:31:22 UTC (rev 15909)
+++ trunk/src/plugins/scmhook/library/scmsvn/cronjobs/updateScmRepo.php	2012-07-01 17:20:10 UTC (rev 15910)
@@ -27,177 +27,183 @@
  *	$params['scm_root'] = directory containing the scm repository
  */
 
-/**
- * updateScmRepo - update the scmrepo with the new hooks
- *
- * @params	Array	the complete array description
- * @return	boolean	success or not
- */
-function updateScmRepo($params) {
-	$group_id = $params['group_id'];
-	$hooksString = $params['hooksString'];
-	$svndir_root = $params['scm_root'];
-	$group = group_get_object($group_id);
-	$scmhookPlugin = new scmhookPlugin;
-	$hooksAvailable = $scmhookPlugin->getAvailableHooks($group_id);
-	$unixname = $group->getUnixName();
+class ScmSvnUpdateScmRepo {
+	function __construct() {
+		return true;
+	}
 
-	if (is_dir($svndir_root)) {
-		@unlink($svndir_root.'/hooks/pre-commit');
-		@unlink($svndir_root.'/hooks/post-commit');
-		$hooksPreCommit = array();
-		$hooksPreRevPropChange = array();
-		$hooksPostCommit = array();
-		foreach ($hooksAvailable as $hook) {
-			switch ($hook->getHookType()) {
-				case "pre-commit": {
-					$hooksPreCommit[] = $hook;
-					break;
+	/**
+	* updateScmRepo - update the scmrepo with the new hooks
+	*
+	* @params	Array	the complete array description
+	* @return	boolean	success or not
+	*/
+	function updateScmRepo($params) {
+		$group_id = $params['group_id'];
+		$hooksString = $params['hooksString'];
+		$svndir_root = $params['scm_root'];
+		$group = group_get_object($group_id);
+		$scmhookPlugin = new scmhookPlugin;
+		$hooksAvailable = $scmhookPlugin->getAvailableHooks($group_id);
+		$unixname = $group->getUnixName();
+
+		if (is_dir($svndir_root)) {
+			@unlink($svndir_root.'/hooks/pre-commit');
+			@unlink($svndir_root.'/hooks/post-commit');
+			$hooksPreCommit = array();
+			$hooksPreRevPropChange = array();
+			$hooksPostCommit = array();
+			foreach ($hooksAvailable as $hook) {
+				switch ($hook->getHookType()) {
+					case "pre-commit": {
+						$hooksPreCommit[] = $hook;
+						break;
+					}
+					case "pre-revprop-change": {
+						$hooksPreRevPropChange[] = $hook;
+						break;
+					}
+					case "post-commit": {
+						$hooksPostCommit[] = $hook;
+						break;
+					}
+					default: {
+						//byebye hook.... we do not validate you...
+						break;
+					}
 				}
-				case "pre-revprop-change": {
-					$hooksPreRevPropChange[] = $hook;
-					break;
-				}
-				case "post-commit": {
-					$hooksPostCommit[] = $hook;
-					break;
-				}
-				default: {
-					//byebye hook.... we do not validate you...
-					break;
-				}
 			}
-		}
 
-		foreach($hooksPreCommit as $hookPreCommit) {
-			if ($hookPreCommit->needCopy()) {
-				foreach($hookPreCommit->getFiles() as $hookPreCommitFile) {
-					@unlink($svndir_root.'/hooks/'.basename($hookPreCommitFile));
+			foreach($hooksPreCommit as $hookPreCommit) {
+				if ($hookPreCommit->needCopy()) {
+					foreach($hookPreCommit->getFiles() as $hookPreCommitFile) {
+						@unlink($svndir_root.'/hooks/'.basename($hookPreCommitFile));
+					}
 				}
 			}
-		}
 
-		foreach($hooksPreRevPropChange as $hook) {
-			if ($hook->needCopy()) {
-				foreach($hook->getFiles() as $file) {
-					@unlink($svndir_root.'/hooks/'.basename($file));
+			foreach($hooksPreRevPropChange as $hook) {
+				if ($hook->needCopy()) {
+					foreach($hook->getFiles() as $file) {
+						@unlink($svndir_root.'/hooks/'.basename($file));
+					}
 				}
 			}
-		}
 
-		foreach($hooksPostCommit as $hookPostCommit) {
-			if ($hookPostCommit->needCopy()) {
-				foreach($hookPostCommit->getFiles() as $hookPostCommitFile) {
-					@unlink($svndir_root.'/hooks/'.basename($hookPostCommitFile));
+			foreach($hooksPostCommit as $hookPostCommit) {
+				if ($hookPostCommit->needCopy()) {
+					foreach($hookPostCommit->getFiles() as $hookPostCommitFile) {
+						@unlink($svndir_root.'/hooks/'.basename($hookPostCommitFile));
+					}
 				}
 			}
-		}
 
-		$newHooks = explode('|', $hooksString);
-		if (count($newHooks)) {
-			$newHooksPreCommit = array();
-			$newHooksPreRevPropChange = array();
-			$newHooksPostCommit = array();
-			foreach($newHooks as $newHook) {
-				foreach($hooksPreCommit as $hookPreCommit) {
-					if ($hookPreCommit->getClassname() == $newHook) {
-						$newHooksPreCommit[] = $hookPreCommit;
+			$newHooks = explode('|', $hooksString);
+			if (count($newHooks)) {
+				$newHooksPreCommit = array();
+				$newHooksPreRevPropChange = array();
+				$newHooksPostCommit = array();
+				foreach($newHooks as $newHook) {
+					foreach($hooksPreCommit as $hookPreCommit) {
+						if ($hookPreCommit->getClassname() == $newHook) {
+							$newHooksPreCommit[] = $hookPreCommit;
+						}
 					}
-				}
-				foreach($hooksPreRevPropChange as $hook) {
-					if ($hook->getClassname() == $newHook) {
-						$newHooksPreRevPropChange[] = $hook;
+					foreach($hooksPreRevPropChange as $hook) {
+						if ($hook->getClassname() == $newHook) {
+							$newHooksPreRevPropChange[] = $hook;
+						}
 					}
-				}
-				foreach($hooksPostCommit as $hookPostCommit) {
-					if ($hookPostCommit->getClassname() == $newHook) {
-						$newHooksPostCommit[] = $hookPostCommit;
+					foreach($hooksPostCommit as $hookPostCommit) {
+						if ($hookPostCommit->getClassname() == $newHook) {
+							$newHooksPostCommit[] = $hookPostCommit;
+						}
 					}
 				}
 			}
-		}
 
-		foreach($newHooksPreCommit as $newHookPreCommit) {
-			if ($newHookPreCommit->needCopy()) {
-				foreach ($newHookPreCommit->getFiles() as $file) {
-					copy($file, $svndir_root.'/hooks/'.basename($file));
-					chmod($svndir_root.'/hooks/'.basename($file), 0755);
+			foreach($newHooksPreCommit as $newHookPreCommit) {
+				if ($newHookPreCommit->needCopy()) {
+					foreach ($newHookPreCommit->getFiles() as $file) {
+						copy($file, $svndir_root.'/hooks/'.basename($file));
+						chmod($svndir_root.'/hooks/'.basename($file), 0755);
+					}
 				}
 			}
-		}
 
-		foreach($hooksPreRevPropChange as $newHook) {
-			if ($newHook->needCopy()) {
-				foreach ($newHook->getFiles() as $file) {
-					copy($file, $svndir_root.'/hooks/'.basename($file));
-					chmod($svndir_root.'/hooks/'.basename($file), 0755);
+			foreach($hooksPreRevPropChange as $newHook) {
+				if ($newHook->needCopy()) {
+					foreach ($newHook->getFiles() as $file) {
+						copy($file, $svndir_root.'/hooks/'.basename($file));
+						chmod($svndir_root.'/hooks/'.basename($file), 0755);
+					}
 				}
 			}
-		}
 
-		foreach($newHooksPostCommit as $newHookPostCommit) {
-			if ($newHookPostCommit->needCopy()) {
-				foreach ($newHookPostCommit->getFiles() as $file) {
-					copy($file, $svndir_root.'/hooks/'.basename($file));
-					chmod($svndir_root.'/hooks/'.basename($file), 0755);
+			foreach($newHooksPostCommit as $newHookPostCommit) {
+				if ($newHookPostCommit->needCopy()) {
+					foreach ($newHookPostCommit->getFiles() as $file) {
+						copy($file, $svndir_root.'/hooks/'.basename($file));
+						chmod($svndir_root.'/hooks/'.basename($file), 0755);
+					}
 				}
 			}
-		}
 
-		if (count($newHooksPreCommit)) {
-			// prepare the pre-commit
-			$file = fopen("/tmp/pre-commit-$unixname.tmp", "w");
-			fwrite($file, file_get_contents(dirname(__FILE__).'/../skel/pre-commit/head'));
-			$string = '';
-			foreach($newHooksPreCommit as $newHookPreCommit) {
-				$string .= $newHookPreCommit->getHookCmd()."\n";
+			if (count($newHooksPreCommit)) {
+				// prepare the pre-commit
+				$file = fopen("/tmp/pre-commit-$unixname.tmp", "w");
+				fwrite($file, file_get_contents(dirname(__FILE__).'/../skel/pre-commit/head'));
+				$string = '';
+				foreach($newHooksPreCommit as $newHookPreCommit) {
+					$string .= $newHookPreCommit->getHookCmd()."\n";
+				}
+				$string .= "\n";
+				fwrite($file, $string);
+				fclose($file);
+				copy('/tmp/pre-commit-'.$unixname.'.tmp', $svndir_root.'/hooks/pre-commit');
+				chmod($svndir_root.'/hooks/pre-commit', 0755);
+				unlink('/tmp/pre-commit-'.$unixname.'.tmp');
+			} else {
+				@unlink($svndir_root.'/hooks/pre-commit');
 			}
-			$string .= "\n";
-			fwrite($file, $string);
-			fclose($file);
-			copy('/tmp/pre-commit-'.$unixname.'.tmp', $svndir_root.'/hooks/pre-commit');
-			chmod($svndir_root.'/hooks/pre-commit', 0755);
-			unlink('/tmp/pre-commit-'.$unixname.'.tmp');
-		} else {
-			@unlink($svndir_root.'/hooks/pre-commit');
-		}
 
-		if (count($newHooksPreRevPropChange)) {
-			// prepare the pre-revprop-change
-			$file = fopen("/tmp/pre-revprop-change-$unixname.tmp", "w");
-			fwrite($file, file_get_contents(dirname(__FILE__).'/../skel/pre-revprop-change/head'));
-			$string = '';
-			foreach($newHooksPreRevPropChange as $hook) {
-				$string .= $hook->getHookCmd()."\n";
+			if (count($newHooksPreRevPropChange)) {
+				// prepare the pre-revprop-change
+				$file = fopen("/tmp/pre-revprop-change-$unixname.tmp", "w");
+				fwrite($file, file_get_contents(dirname(__FILE__).'/../skel/pre-revprop-change/head'));
+				$string = '';
+				foreach($newHooksPreRevPropChange as $hook) {
+					$string .= $hook->getHookCmd()."\n";
+				}
+				$string .= "\n";
+				fwrite($file, $string);
+				fclose($file);
+				copy('/tmp/pre-revprop-change-'.$unixname.'.tmp', $svndir_root.'/hooks/pre-revprop-change');
+				chmod($svndir_root.'/hooks/pre-revprop-change', 0755);
+				unlink('/tmp/pre-revprop-change-'.$unixname.'.tmp');
+			} else {
+				@unlink($svndir_root.'/hooks/pre-revprop-change');
 			}
-			$string .= "\n";
-			fwrite($file, $string);
-			fclose($file);
-			copy('/tmp/pre-revprop-change-'.$unixname.'.tmp', $svndir_root.'/hooks/pre-revprop-change');
-			chmod($svndir_root.'/hooks/pre-revprop-change', 0755);
-			unlink('/tmp/pre-revprop-change-'.$unixname.'.tmp');
-		} else {
-			@unlink($svndir_root.'/hooks/pre-revprop-change');
-		}
 
-		if (count($newHooksPostCommit)) {
-			// prepare the post-commit
-			$file = fopen("/tmp/post-commit-$unixname.tmp", "w");
-			fwrite($file, file_get_contents(dirname(__FILE__).'/../skel/post-commit/head'));
-			$string = '';
-			foreach($newHooksPostCommit as $newHookPostCommit) {
-				$string .= $newHookPostCommit->getHookCmd()."\n";
+			if (count($newHooksPostCommit)) {
+				// prepare the post-commit
+				$file = fopen("/tmp/post-commit-$unixname.tmp", "w");
+				fwrite($file, file_get_contents(dirname(__FILE__).'/../skel/post-commit/head'));
+				$string = '';
+				foreach($newHooksPostCommit as $newHookPostCommit) {
+					$string .= $newHookPostCommit->getHookCmd()."\n";
+				}
+				$string .= "\n";
+				fwrite($file, $string);
+				fclose($file);
+				copy('/tmp/post-commit-'.$unixname.'.tmp', $svndir_root.'/hooks/post-commit');
+				chmod($svndir_root.'/hooks/post-commit', 0755);
+				unlink('/tmp/post-commit-'.$unixname.'.tmp');
 			}
-			$string .= "\n";
-			fwrite($file, $string);
-			fclose($file);
-			copy('/tmp/post-commit-'.$unixname.'.tmp', $svndir_root.'/hooks/post-commit');
-			chmod($svndir_root.'/hooks/post-commit', 0755);
-			unlink('/tmp/post-commit-'.$unixname.'.tmp');
+			return true;
 		}
-		return true;
+		return false;
 	}
-	return false;
 }
 
 ?>




More information about the Fusionforge-commits mailing list