copy view
This commit is contained in:
144
SetupNewComp.pl
144
SetupNewComp.pl
@@ -200,9 +200,10 @@ sub setCompanyDBTables() {
|
||||
or die getTimeStamp("log") . " - pid $$ >> $DBI::errstr";
|
||||
$sth_db->finish;
|
||||
|
||||
my $sth_tb =
|
||||
$dbh->prepare(
|
||||
"SHOW FULL TABLES IN " . $db_adm . " WHERE Table_Type = 'BASE TABLE';" )
|
||||
my $sth_tb = $dbh->prepare(
|
||||
"SELECT table_name, table_type FROM information_schema.tables WHERE table_schema='"
|
||||
. $db_adm
|
||||
. "' ORDER BY table_type ASC;" )
|
||||
or die getTimeStamp("log") . " - pid $$ >> $DBI::errstr";
|
||||
$sth_tb->execute()
|
||||
or die getTimeStamp("log") . " - pid $$ >> $DBI::errstr";
|
||||
@@ -210,30 +211,12 @@ sub setCompanyDBTables() {
|
||||
my $tables_list = $sth_tb->fetchall_arrayref;
|
||||
|
||||
foreach my $table ( @{$tables_list} ) {
|
||||
my $sth_deft =
|
||||
$dbh->prepare( "CREATE TABLE IF NOT EXISTS "
|
||||
. $company_db_name . "."
|
||||
. $table->[0]
|
||||
. " LIKE "
|
||||
. $db_adm . "."
|
||||
. $table->[0]
|
||||
. ";" )
|
||||
or die getTimeStamp("log")
|
||||
. " - pid $$ "
|
||||
. $table->[0]
|
||||
. " >> $DBI::errstr";
|
||||
$sth_deft->execute()
|
||||
or die getTimeStamp("log")
|
||||
. " - pid $$ "
|
||||
. $table->[0]
|
||||
. " >> $DBI::errstr";
|
||||
$sth_deft->finish;
|
||||
if ( $table->[0] ne 'ELABDATADISP' and $table->[0] ne 'RAWDATACOR' ) {
|
||||
my $sth_cpyt =
|
||||
$dbh->prepare( "INSERT "
|
||||
if ( $table->[1] eq 'BASE TABLE' ) { #table
|
||||
my $sth_deft =
|
||||
$dbh->prepare( "CREATE TABLE IF NOT EXISTS "
|
||||
. $company_db_name . "."
|
||||
. $table->[0]
|
||||
. " SELECT * FROM "
|
||||
. " LIKE "
|
||||
. $db_adm . "."
|
||||
. $table->[0]
|
||||
. ";" )
|
||||
@@ -241,14 +224,112 @@ sub setCompanyDBTables() {
|
||||
. " - pid $$ "
|
||||
. $table->[0]
|
||||
. " >> $DBI::errstr";
|
||||
$sth_cpyt->execute()
|
||||
$sth_deft->execute()
|
||||
or die getTimeStamp("log")
|
||||
. " - pid $$ "
|
||||
. $table->[0]
|
||||
. " >> $DBI::errstr";
|
||||
$sth_cpyt->finish;
|
||||
$sth_deft->finish;
|
||||
if ( $table->[0] ne 'ELABDATADISP'
|
||||
and $table->[0] ne 'RAWDATACOR'
|
||||
and $table->[0] ne 'companies'
|
||||
and $table->[0] ne 'sites' )
|
||||
{
|
||||
my $sth_cpyt =
|
||||
$dbh->prepare( "INSERT "
|
||||
. $company_db_name . "."
|
||||
. $table->[0]
|
||||
. " SELECT * FROM "
|
||||
. $db_adm . "."
|
||||
. $table->[0]
|
||||
. ";" )
|
||||
or die getTimeStamp("log")
|
||||
. " - pid $$ "
|
||||
. $table->[0]
|
||||
. " >> $DBI::errstr";
|
||||
$sth_cpyt->execute()
|
||||
or die getTimeStamp("log")
|
||||
. " - pid $$ "
|
||||
. $table->[0]
|
||||
. " >> $DBI::errstr";
|
||||
$sth_cpyt->finish;
|
||||
}
|
||||
elsif ( $table->[0] eq 'companies' ) {
|
||||
my $sth_cpyt =
|
||||
$dbh->prepare( "INSERT "
|
||||
. $company_db_name . "."
|
||||
. $table->[0]
|
||||
. " SELECT * FROM "
|
||||
. $db_adm . "."
|
||||
. $table->[0]
|
||||
. " WHERE id = "
|
||||
. $company_id
|
||||
. ";" )
|
||||
or die getTimeStamp("log")
|
||||
. " - pid $$ "
|
||||
. $table->[0]
|
||||
. " >> $DBI::errstr";
|
||||
$sth_cpyt->execute()
|
||||
or die getTimeStamp("log")
|
||||
. " - pid $$ "
|
||||
. $table->[0]
|
||||
. " >> $DBI::errstr";
|
||||
$sth_cpyt->finish;
|
||||
}
|
||||
elsif ( $table->[0] eq 'sites' ) {
|
||||
my $sth_cpyt =
|
||||
$dbh->prepare( "INSERT "
|
||||
. $company_db_name . "."
|
||||
. $table->[0]
|
||||
. " SELECT * FROM "
|
||||
. $db_adm . "."
|
||||
. $table->[0]
|
||||
. " WHERE company_id = "
|
||||
. $company_id
|
||||
. ";" )
|
||||
or die getTimeStamp("log")
|
||||
. " - pid $$ "
|
||||
. $table->[0]
|
||||
. " >> $DBI::errstr";
|
||||
$sth_cpyt->execute()
|
||||
or die getTimeStamp("log")
|
||||
. " - pid $$ "
|
||||
. $table->[0]
|
||||
. " >> $DBI::errstr";
|
||||
$sth_cpyt->finish;
|
||||
}
|
||||
}
|
||||
elsif ( $table->[1] eq 'VIEW' ) { #view
|
||||
$dbh->do( "USE " . $company_db_name . ";" );
|
||||
my $sth_views =
|
||||
$dbh->prepare(
|
||||
"SHOW CREATE VIEW " . $db_adm . "." . $table->[0] . ";" )
|
||||
or die getTimeStamp("log")
|
||||
. " - pid $$ "
|
||||
. $table->[0]
|
||||
. " >> $DBI::errstr";
|
||||
$sth_views->execute()
|
||||
or die getTimeStamp("log")
|
||||
. " - pid $$ "
|
||||
. $table->[0]
|
||||
. " >> $DBI::errstr";
|
||||
my $view_def = $sth_views->fetchall_arrayref;
|
||||
$sth_views->finish;
|
||||
|
||||
$view_def->[0]->[1] =~ s/$db_adm/$company_db_name/g;
|
||||
|
||||
my $sth_viewd = $dbh->prepare( $view_def->[0]->[1] )
|
||||
or die getTimeStamp("log")
|
||||
. " - pid $$ "
|
||||
. $table->[0]
|
||||
. " >> $DBI::errstr";
|
||||
$sth_viewd->execute()
|
||||
or die getTimeStamp("log")
|
||||
. " - pid $$ "
|
||||
. $table->[0]
|
||||
. " >> $DBI::errstr";
|
||||
$sth_viewd->finish;
|
||||
}
|
||||
}
|
||||
|
||||
$sth_tb->finish;
|
||||
@@ -274,7 +355,8 @@ sub setCompanyOSSet {
|
||||
. ";" )
|
||||
or die getTimeStamp("log") . " - pid $$ >> $DBI::errstr";
|
||||
|
||||
$sth->execute() or die getTimeStamp("log") . " - pid $$ >> $DBI::errstr";
|
||||
$sth->execute()
|
||||
or die getTimeStamp("log") . " - pid $$ >> $DBI::errstr";
|
||||
$sth->finish;
|
||||
|
||||
if (
|
||||
@@ -291,7 +373,11 @@ sub setCompanyOSSet {
|
||||
|
||||
if ( !-d "/home/" . $company_os_user ) {
|
||||
make_path "/home/" . $company_os_user,
|
||||
{ mode => 0755, owner => $company_os_user, group => $company_os_grp }
|
||||
{
|
||||
mode => 0755,
|
||||
owner => $company_os_user,
|
||||
group => $company_os_grp
|
||||
}
|
||||
or warn getTimeStamp("log")
|
||||
. " >> Failed to create path: /home/"
|
||||
. $company_os_user . "\n";
|
||||
|
||||
Reference in New Issue
Block a user