[Fusionforge-commits] r9597 - trunk/plugins/coclico/mailman/bin

Mélanie Le Bail melanelebail at libremir.placard.fr.eu.org
Fri Apr 23 17:18:12 CEST 2010


Author: melanelebail
Date: 2010-04-23 17:18:12 +0200 (Fri, 23 Apr 2010)
New Revision: 9597

Modified:
   trunk/plugins/coclico/mailman/bin/import_members_DB.php
Log:
lighter code for import mailman members


Modified: trunk/plugins/coclico/mailman/bin/import_members_DB.php
===================================================================
--- trunk/plugins/coclico/mailman/bin/import_members_DB.php	2010-04-23 12:52:56 UTC (rev 9596)
+++ trunk/plugins/coclico/mailman/bin/import_members_DB.php	2010-04-23 15:18:12 UTC (rev 9597)
@@ -3,8 +3,7 @@
  * Script to import members of mailman lists in the "plugin_mailman" table
  * must be done before adding extend.py file in /var/lib/mailman/lists
  * but after creating plugin_mailman table in the database
-*/
-
+ */
 require_once 'pre.php';
 require_once 'mailman/include/MailmanListDao.class.php';
 $sql = 'SELECT * from mail_group_list WHERE status=3';
@@ -19,47 +18,37 @@
 	exec('/usr/lib/mailman/bin/dumpdb '.'/var/lib/mailman/lists/'.$listname.'/config.pck', $config, $ret2);
 	if ($ret2==0 ) {
 		$j=0;
-		$foundname=0;
-		$foundpw=0;
 		for ($j=0;$j<count($config);$j++){
-			if ($foundname) {
-				if(preg_match("#([a-zA-Z0-9-_.]*@[a-zA-Z0-9-_.]*).*[u:\s]*\'([a-zA-Z0-9-_.\s]*)\'#",$config[$j],$essai)){
-					$usernames[$essai[1]] = $essai[2];
+			if(preg_match("#\'(usernames|passwords)\'#",$config[$j],$essai)) {
+				$end=false;
+				$i = $j;
+				if (strpos($config[$j],"usernames") !== false)
+				{
+					$username = true;
+					$pwd =false;
 				}
-				if (strpos($config[$j],"}") !==false) {
-					$foundname=0;
+				elseif(strpos($config[$j],"passwords") !== false) {
+					$username = false;
+					$pwd =true;
 				}
-				$essai =null;
-			}
-			if ($foundpw) {
-				if(preg_match("#([a-zA-Z0-9-_.]*@[a-zA-Z0-9-_.]*).*\:[\s]*\'([a-zA-Z0-9-_.]*)\'#",$config[$j],$pwd)){
-					$members[$pwd[1]] = $pwd[2];
-				}
-				if (strpos($config[$j],"}") !==false) {
-					$foundpw=0;
-				}
-				$pwd =null;
-			}
-			if(strpos($config[$j],"usernames") !== false && preg_match("#\{\s*\}#",$config[$j]) == false) {
-				$foundname = 1;
-				if(preg_match("#([a-zA-Z0-9-_.]*@[a-zA-Z0-9-_.]*).*[u:\s]*\'([a-zA-Z0-9-_.\s]*)\'#",$config[$j],$essai)){
-					$usernames[$essai[1]] = $essai[2];
-				}
-				if (strpos($config[$j],"}") !==false) {
-					$foundname=0;
-				}
-				$essai =null;
-			}
+				while ($end==false) {
+					if(preg_match("#([a-zA-Z0-9-_.]*@[a-zA-Z0-9-_.]*).*[u:\s]*\'([a-zA-Z0-9-_.\s]*)\'#",$config[$i],$essai)){
+						if($username) {
+							$usernames[$essai[1]] = $essai[2];
+						}
+						elseif($pwd) {
+							$members[$essai[1]]=$essai[2];
+						}
+					}
 
-			if(strpos($config[$j],"passwords") !== false && strpos($config[$j],"{\s*}") === false) {
-				$foundpw = 1;
-				if(preg_match("#([a-zA-Z0-9-_.]*@[a-zA-Z0-9-_.]*)\'.*\:[\s]*\'([a-zA-Z0-9-_.]*)\'#",$config[$j],$pwd)){
-					$members[$pwd[1]] = $pwd[2];
+					if (strpos($config[$i],"}") ===false) {
+						$i=$i+1;
+					}
+					else {
+						$end=true;
+					}
 				}
-				if (strpos($config[$j],"}") !==false) {
-					$foundpw=0;
-				}
-				$pwd =null;
+
 			}
 		}
 		if (isset($members)) {
@@ -71,23 +60,14 @@
 				else {
 					$row_count = $res->getRow();
 					if ($row_count['count'] == 0){
-						if (isset($usernames)) {
-							$insert =false;
-							foreach ($usernames as $mailu => $name) {
-								if( $mailu == $mail) {
-									echo "Membre trouvé avec mail=".$mail." et nom=".$name." avec pwd=".$pwd."\n";
-									$membersToAdd[$listname] =array($mail,md5($pwd),$name);
-									$insert =true;
-								}
-							}
-							if (!$insert) {
-								echo "Membre trouvé avec mail=".$mail." avec pwd=".$pwd."\n";
-								$membersToAdd[$listname] =array($mail,md5($pwd));
-							}
+						if (isset($usernames) && array_key_exists($mail, $usernames)) {
+							$name = $usernames[$mail];
+							echo "Membre trouvé avec mail=".$mail." et nom=".$name." avec pwd=".$pwd."\n";
+							$dao->newSubscriber($mail,$name,md5($pwd),$listname);
 						}
 						else {
 							echo "Membre trouvé avec mail=".$mail." avec pwd=".$pwd."\n";
-							$membersToAdd[$listname] =array($mail,md5($pwd));
+							$dao->newSubscriber($mail,'',md5($pwd),$listname);
 						}
 					}
 					else {
@@ -105,4 +85,3 @@
 	}
 }
 ?>
-




More information about the Fusionforge-commits mailing list