[Affelio-cvs 1082] CVS update: affelio/lib/Affelio/misc

Back to archive index

Tadashi Okoshi slash****@users*****
2006年 2月 23日 (木) 21:41:38 JST


Index: affelio/lib/Affelio/misc/InitAffelio.pm
diff -u affelio/lib/Affelio/misc/InitAffelio.pm:1.17 affelio/lib/Affelio/misc/InitAffelio.pm:1.18
--- affelio/lib/Affelio/misc/InitAffelio.pm:1.17	Wed Dec 21 17:56:12 2005
+++ affelio/lib/Affelio/misc/InitAffelio.pm	Thu Feb 23 21:41:38 2006
@@ -14,7 +14,7 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 #
-# $Id: InitAffelio.pm,v 1.17 2005/12/21 08:56:12 slash5234 Exp $
+# $Id: InitAffelio.pm,v 1.18 2006/02/23 12:41:38 slash5234 Exp $
 
 package Affelio::misc::InitAffelio;
 {
@@ -198,7 +198,7 @@
 	#profile DB
 	################################
 	my $create_tbl_cmd = <<EOT;
-CREATE TABLE AFuser_CORE_prof(attribute TEXT, value TEXT) 
+CREATE TABLE $af->{site__dbtbl_prefix}_CORE_prof(attribute TEXT, value TEXT) 
 EOT
         if(!$dbh->do($create_tbl_cmd)){
 	    throw  Affelio::exception::DBException("creating prof: $@");
@@ -210,7 +210,7 @@
 	    $af->getPM->save_profile();
 	}catch Error with{
 	    my $e = shift;
-	    throw  Affelio::exception::Exception("Cannot save_profile: $@");
+	    throw  Affelio::exception::Exception("Cannot save_profile: $e");
 	};
 	debug_print("saved profile");
 
@@ -218,7 +218,7 @@
 	#profile attribute DB
 	################################
 	$create_tbl_cmd = <<EOT;
-CREATE TABLE AFuser_CORE_prof_attr(aid INTEGER, name TEXT, type INTEGER)
+CREATE TABLE $af->{site__dbtbl_prefix}_CORE_prof_attr(aid INTEGER, name TEXT, type INTEGER)
 EOT
         if(!$dbh->do($create_tbl_cmd)){
 	    throw  Affelio::exception::DBException("creating attr: $@");
@@ -226,7 +226,7 @@
 	
 	my $sth = "";
 	eval{
-	    $sth = $dbh->prepare(q{insert into AFuser_CORE_prof_attr(aid, name, type) values (?,?,?)});
+	    $sth = $dbh->prepare("insert into $af->{site__dbtbl_prefix}_CORE_prof_attr(aid, name, type) values (?,?,?)");
 	};
 	if($@){
 	    throw  Affelio::exception::DBException("SQL prepare: $@");
@@ -252,7 +252,7 @@
 	#friends DB
 	################################
 	$create_tbl_cmd = <<EOT;
-CREATE TABLE AFuser_CORE_friends(uid INTEGER PRIMARY KEY, af_id CHAR(255), nickname TEXT, timestamp TEXT, password TEXT, intro TEXT, option_pid INTEGER, lastupdated TEXT, f2list TEXT, last_news_in INTEGER DEFAULT 0, last_news_out INTEGER DEFAULT 0,last_access INTEGER DEFAULT 0, count_access INTEGER DEFAULT 0, last_incoming INTEGER DEFAULT 0, count_incoming INTEGER DEFAULT 0, last_outgoing INTEGER DEFAULT 0, count_outgoing INTEGER DEFAULT 0, apps TEXT DEFAULT ' ')
+CREATE TABLE $af->{site__dbtbl_prefix}_CORE_friends(uid INTEGER PRIMARY KEY, af_id CHAR(255), nickname TEXT, timestamp TEXT, password TEXT, intro TEXT, option_pid INTEGER, lastupdated TEXT, f2list TEXT, last_news_in INTEGER DEFAULT 0, last_news_out INTEGER DEFAULT 0,last_access INTEGER DEFAULT 0, count_access INTEGER DEFAULT 0, last_incoming INTEGER DEFAULT 0, count_incoming INTEGER DEFAULT 0, last_outgoing INTEGER DEFAULT 0, count_outgoing INTEGER DEFAULT 0, apps TEXT)
 EOT
         if(!$dbh->do($create_tbl_cmd)){
 	    throw  Affelio::exception::DBException("creating friends tbl: $@");
@@ -262,7 +262,7 @@
 	#erasedfriends DB
 	################################
 	$create_tbl_cmd = <<EOT;
-CREATE TABLE AFuser_CORE_erasedfriends(uid INTEGER PRIMARY KEY, af_id CHAR(255), timestamp TEXT)
+CREATE TABLE $af->{site__dbtbl_prefix}_CORE_erasedfriends(uid INTEGER PRIMARY KEY, af_id CHAR(255), timestamp TEXT)
 EOT
         if(!$dbh->do($create_tbl_cmd)){
 	    throw  Affelio::exception::DBException("creating erased friends tbl: $@");
@@ -272,7 +272,7 @@
 	#friendsfriends DB
 	################################
 	$create_tbl_cmd = <<EOT;
-CREATE TABLE AFuser_CORE_friendsfriends(uid INTEGER PRIMARY KEY, af_id CHAR(255), nickname TEXT, timestamp TEXT, f1list TEXT)
+CREATE TABLE $af->{site__dbtbl_prefix}_CORE_friendsfriends(uid INTEGER PRIMARY KEY, af_id CHAR(255), nickname TEXT, timestamp TEXT, f1list TEXT)
 EOT
         if(!$dbh->do($create_tbl_cmd)){
 	    throw  Affelio::exception::DBException("creating F2 tbl: $@");
@@ -281,7 +281,7 @@
 	################################
 	#group DB
 	################################
-	$create_tbl_cmd = "CREATE TABLE AFuser_CORE_group(gid INTEGER, group_name TEXT, members TEXT, option_pid INTEGER)";
+	$create_tbl_cmd = "CREATE TABLE $af->{site__dbtbl_prefix}_CORE_group(gid INTEGER, group_name TEXT, members TEXT, option_pid INTEGER)";
         if(!$dbh->do($create_tbl_cmd)){
 	    throw  Affelio::exception::DBException("creating grp tbl: $@");
 	}
@@ -289,7 +289,7 @@
 	################################
 	#Permission DB
 	################################
-	$create_tbl_cmd = "CREATE TABLE AFuser_CORE_permission(pid INTEGER, type TEXT, target_id  TEXT, ";
+	$create_tbl_cmd = "CREATE TABLE $af->{site__dbtbl_prefix}_CORE_permission(pid INTEGER, type TEXT, target_id  TEXT, ";
 
         for(my $i=0; $i<=63; $i++){
 	    $create_tbl_cmd .= " attr$i INT,";
@@ -305,7 +305,7 @@
 	#tmp_recvd_hs
         ################################
 	$create_tbl_cmd = <<EOT;
-CREATE TABLE AFuser_SNS_tmp_recvd_hs(sessionid TEXT, timestamp TEXT, af_id CHAR(255), nickname TEXT, DH_key_str TEXT)
+CREATE TABLE $af->{site__dbtbl_prefix}_SNS_tmp_recvd_hs(sessionid TEXT, timestamp TEXT, af_id CHAR(255), nickname TEXT, DH_key_str TEXT)
 EOT
         if(!$dbh->do($create_tbl_cmd)){
 	    throw  Affelio::exception::DBException("creating tmp_recved tbl: $@");
@@ -315,7 +315,7 @@
 	#tmp_sent_hs
 	################################
 	$create_tbl_cmd = <<EOT;
-CREATE TABLE AFuser_SNS_tmp_sent_hs(sessionid TEXT, timestamp TEXT, af_id CHAR(255), nickname TEXT, DH_key_str TEXT)
+CREATE TABLE $af->{site__dbtbl_prefix}_SNS_tmp_sent_hs(sessionid TEXT, timestamp TEXT, af_id CHAR(255), nickname TEXT, DH_key_str TEXT)
 EOT
         if(!$dbh->do($create_tbl_cmd)){
 	    throw  Affelio::exception::DBException("creating tmp_send tbl: $@");
@@ -325,7 +325,7 @@
 	#message
 	################################
 	$create_tbl_cmd = <<EOT;
-CREATE TABLE AFuser_CORE_message(mid INTEGER PRIMARY KEY, timestamp TEXT, msgtitle TEXT, msgtype TEXT, msgfrom TEXT, msgbody TEXT, readflag INTEGER)
+CREATE TABLE $af->{site__dbtbl_prefix}_CORE_message(mid INTEGER PRIMARY KEY, timestamp TEXT, msgtitle TEXT, msgtype TEXT, msgfrom TEXT, msgbody TEXT, readflag INTEGER)
 EOT
         if(!$dbh->do($create_tbl_cmd)){
 	    throw  Affelio::exception::DBException("creating msg tbl: $@");
@@ -335,7 +335,7 @@
 	#apps
 	################################
 	$create_tbl_cmd = <<EOT;
-CREATE TABLE AFuser_CORE_apps(appid INTEGER PRIMARY KEY AUTOINCREMENT, 
+CREATE TABLE $af->{site__dbtbl_prefix}_CORE_apps(appid INTEGER PRIMARY KEY AUTOINCREMENT, 
 			      install_name TEXT, 
 			      install_title TEXT,
 			      app_URI TEXT,
@@ -348,6 +348,10 @@
 			      action_types TEXT,
 			      action_types_desc TEXT)
 EOT
+        if($af->{site__db_type} eq "mysql"){
+	    $create_tbl_cmd =~ s/AUTOINCREMENT/AUTO\_INCREMENT/g;
+	}
+
         if(!$dbh->do($create_tbl_cmd)){
 	    throw  Affelio::exception::DBException("creating apps tbl: $@");
 	} 
@@ -356,7 +360,7 @@
 	#my_news
 	################################
 	$create_tbl_cmd = <<EOT;
-CREATE TABLE AFuser_CORE_my_news(nid INTEGER PRIMARY KEY AUTOINCREMENT, 
+CREATE TABLE $af->{site__dbtbl_prefix}_CORE_my_news(nid INTEGER PRIMARY KEY AUTOINCREMENT, 
 				   datetime INTEGER,
 				   app_install_name TEXT,
 				   title TEXT,
@@ -364,6 +368,9 @@
 				   creator TEXT,
 				   URL TEXT)
 EOT
+        if($af->{site__db_type} eq "mysql"){
+	    $create_tbl_cmd =~ s/AUTOINCREMENT/AUTO\_INCREMENT/g;
+	}
         if(!$dbh->do($create_tbl_cmd)){
 	    throw  Affelio::exception::DBException("creating mynews tbl: $@");
 	} 
@@ -373,7 +380,7 @@
 	#nghr_news
 	################################
 	$create_tbl_cmd = <<EOT;
-CREATE TABLE AFuser_CORE_nghr_news(nid INTEGER PRIMARY KEY AUTOINCREMENT, 
+CREATE TABLE $af->{site__dbtbl_prefix}_CORE_nghr_news(nid INTEGER PRIMARY KEY AUTOINCREMENT, 
 				   datetime INTEGER,
 				   af_id TEXT,
 				   nickname TEXT,
@@ -383,6 +390,9 @@
 				   creator TEXT,
 				   URL TEXT)
 EOT
+        if($af->{site__db_type} eq "mysql"){
+	    $create_tbl_cmd =~ s/AUTOINCREMENT/AUTO\_INCREMENT/g;
+	}
         if(!$dbh->do($create_tbl_cmd)){
 	    throw  Affelio::exception::DBException("creating nghr_news tbl: $@");
 	} 
@@ -600,5 +610,105 @@
 	debug_print("InitAffelio:setup  ****ALL DONE****");
     }
 
+
+    #####################################################################
+    #setup_affelio_AFE2
+    #  all-in-one function to setup affelio
+    #####################################################################
+    sub setup_affelio_AFE2{
+	my $fs_userdata_dir = shift;
+	my $fs_tmpldyn_dir = shift;
+	my $fs_affelio_dir = shift;
+	my $user_afid = shift;
+	#
+	my $locale = shift;
+	my $lh = shift;
+	#
+	my $db_type = shift;
+	my $db_dbname = shift;
+	my $db_username = shift;
+	my $db_password = shift;
+	my $db_hostname = shift;
+	my $db_port = shift;
+	#
+	my $username = shift;
+	my $password = shift;
+	my $nickname =shift;
+	my $email =shift;
+
+	debug_print("InitAffelio:setup start.");
+	#
+	#$dataroot/users/$account/userdata
+	debug_print("\t$fs_userdata_dir ");
+	#
+	#$dataroot/users/$account/templates_dyn
+	debug_print("\t$fs_tmpldyn_dir "); 
+	#
+	#affelio top dir
+	debug_print("\t$fs_affelio_dir"); 
+	#
+        #User's Affelio URL
+	debug_print("\t$user_afid");  
+	#
+	debug_print("\t$locale");
+	debug_print("\t$lh ");
+	debug_print("\t$db_type ");
+	debug_print("\t$db_dbname ");
+	debug_print("\t$db_username ");
+	debug_print("\t$db_password ");
+	debug_print("\t$db_hostname ");
+	debug_print("\t$db_port ");
+	debug_print("\t$username ");
+	debug_print("\t$password "); 
+	debug_print("\t$nickname ");
+	debug_print("\t$email ");
+
+	$ENV{'REDIRECT_AF_USERNAME'} = $username;
+
+	################################
+	#(1)create db.cfg
+	create_db_cfg("$fs_userdata_dir/db.cfg",
+		      $db_type,
+		      $db_dbname,
+		      $db_username,
+		      $db_password,
+		      $db_hostname,
+		      $db_port);
+	debug_print("InitAffelio:setup_AFE2 (1) create db.cfg done");
+
+	################################
+	#(2)create login.cfg
+	my @salts = ( "A".."Z", "a".."z", "0".."9", ".", "/" );
+	my $salt = $salts[int(rand(64))] . $salts[int(rand(64))];
+	my $crypted_password = crypt($password, $salt);
+	create_login_cfg("$fs_userdata_dir/login.cfg",
+			 $username,
+			 $crypted_password);
+	debug_print("InitAffelio:setup_AFE2 (2) create login.cfg [$crypted_password] done.");
+
+	################################
+	#(3)Copy default files
+	copy_def_files($fs_affelio_dir , $fs_userdata_dir, $locale);
+	debug_print("InitAffelio:setup_AFE2 (3) copy default files. done.");
+
+	################################
+	#(4)create resized images
+	create_resized_images($fs_affelio_dir, $fs_userdata_dir);
+
+	################################
+	#(5)initialize DB
+	init_db($fs_affelio_dir , $nickname, $email, $lh);
+	debug_print("InitAffelio:setup_AFE2 (5) Init DB done.");
+
+	################################
+	#(6)Rebuild template
+	my $af;
+	$af = new Affelio(ConfigDir => "$fs_affelio_dir/config/");
+	Affelio::App::Admin::EditTemplates::rebuild($af);
+	debug_print("InitAffelio:setup_AFE2 (6) Rebuild template done.");
+
+	debug_print("InitAffelio:setup_AFE2  ****ALL DONE****");
+    }
+
 }
 1;


Affelio-cvs メーリングリストの案内
Back to archive index