[Rt-commit] r12010 - in rt/branches/3.8-TESTING: . html/installation

sartak at bestpractical.com sartak at bestpractical.com
Fri May 2 18:21:34 EDT 2008


Author: sartak
Date: Fri May  2 18:21:34 2008
New Revision: 12010

Modified:
   rt/branches/3.8-TESTING/   (props changed)
   rt/branches/3.8-TESTING/html/installation/Basics.html
   rt/branches/3.8-TESTING/html/installation/DatabaseDetails.html
   rt/branches/3.8-TESTING/html/installation/Finish.html
   rt/branches/3.8-TESTING/html/installation/Initialize.html
   rt/branches/3.8-TESTING/html/installation/Sendmail.html
   rt/branches/3.8-TESTING/lib/RT/Config.pm
   rt/branches/3.8-TESTING/lib/RT/Dashboard.pm
   rt/branches/3.8-TESTING/lib/RT/Installer.pm

Log:
 r54799 at Macintosh:  sartak | 2008-05-02 18:20:40 -0400
 Revert a mismerge, this looks like everything


Modified: rt/branches/3.8-TESTING/html/installation/Basics.html
==============================================================================
--- rt/branches/3.8-TESTING/html/installation/Basics.html	(original)
+++ rt/branches/3.8-TESTING/html/installation/Basics.html	Fri May  2 18:21:34 2008
@@ -62,7 +62,6 @@
 
 <%init>
 my @results;
-push @results, 'Connected Database with success!' unless $RT::Installer->{InstallConfig}{DatabaseType} eq 'SQLite';
 
 my @Types = qw/rtname Organization MinimumPasswordLength Timezone/;
 
@@ -82,8 +81,8 @@
         RT::Interface::Web::Redirect(RT->Config->Get('WebURL') .
 'installation/DatabaseDetails.html');
     }
-    if ( $RT::Installer->{InstallConfig}{DatabaseType} eq 'SQLite' ?
-            @results == 0 : @results == 1 ) {
+
+    unless ( @results ) {
         RT::Interface::Web::Redirect(RT->Config->Get('WebURL') .
 'installation/Emails.html');
     }

Modified: rt/branches/3.8-TESTING/html/installation/DatabaseDetails.html
==============================================================================
--- rt/branches/3.8-TESTING/html/installation/DatabaseDetails.html	(original)
+++ rt/branches/3.8-TESTING/html/installation/DatabaseDetails.html	Fri May  2 18:21:34 2008
@@ -54,9 +54,15 @@
     CurrentValue => RT::Installer->CurrentValues(@Types) &>
 <input type="hidden" name="Run" value="1">
 
-<& /Elements/Submit, Label => $RT::Installer->{InstallConfig}{DatabaseType} eq
-'SQLite' ? loc('Next: Customize Basics') : loc('Next: Check Database Connectivity'), Back => 1, BackLabel => loc('Back: Select Database Type'),
+<& /Elements/Submit, Label => loc('Next: Check Database Connectivity'), 
+Back => 1, BackLabel => loc('Back: Select Database Type'),
 &>
+
+% if ( $results[0] eq 'connect succeed!' ) {
+<& /Elements/Submit, Label => loc('Next: Customize Basics'), Name => 'Next' &>
+% }
+
+
 </form>
 </&>
 <%init>
@@ -75,39 +81,78 @@
 
 if ( $Run ) {
 
-    $m->comp('/Widgets/BulkProcess', Types => \@Types, Arguments => \%ARGS, Store
-            => $RT::Installer->{InstallConfig}, Meta =>
-            $RT::Installer->{Meta}, KeepUndef => 1 ); 
+    $m->comp('/Widgets/BulkProcess', Types => \@Types, Arguments => \%ARGS, 
+            Store => $RT::Installer->{InstallConfig}, 
+            Meta => $RT::Installer->{Meta}, KeepUndef => 1 ); 
     if ( $Back ) {
         RT::Interface::Web::Redirect(RT->Config->Get('WebURL') .
 'installation/DatabaseType.html');
     }
-
-    my $handle = DBIx::SearchBuilder::Handle->new();
-    my $db_type = $RT::Installer->{InstallConfig}{DatabaseType};
-    
-    my $dsn;
-    $dsn = "dbi:$db_type:";
-    if ( $db_type eq 'Pg' ) {
-        # with postgres, you want to connect to template1 database
-        $dsn .= 'dbname=template1';
-    }
-    $dsn .= ";host=$ARGS{DatabaseHost}" if $ARGS{DatabaseHost};
-    $dsn .= ";port=$ARGS{DatabasePort}" if $ARGS{DatabasePort};
-    $dsn .= ";requiressl=1" if $ARGS{DatabaseRequireSSL};
     
-    my $dbh = DBI->connect(
-        $dsn, $ARGS{DatabaseUser}, $ARGS{DatabasePassword},
-        { RaiseError => 0, PrintError => 0 },
-    );
-
-    if ( $dbh ) {
+    if ( $ARGS{Next} ) {
         RT::Interface::Web::Redirect(RT->Config->Get('WebURL') .
 'installation/Basics.html');
     }
+
+    my ( $status, $msg ) = RT::Installer->SaveConfig;
+    if ( $status ) {
+        RT->LoadConfig;
+    # dba connect systemdsn
+        my $dbh = DBI->connect(
+            RT::Handle->SystemDSN, $ARGS{DatabaseAdmin}, $ARGS{DatabaseAdminPassword}, { RaiseError => 0, PrintError => 0 },
+        );
+    
+        if ( $dbh ) {
+            push @results, 'connect succeed!';
+            # dba connect dsn, which has table info
+            $dbh = DBI->connect(
+                RT::Handle->DSN, $ARGS{DatabaseAdmin}, $ARGS{DatabaseAdminPassword}, { RaiseError => 0, PrintError => 0 },
+            );
+    
+            if ( $dbh ) {
+                # check if Tickets table exists
+                my $sth = $dbh->table_info('', '', 'Tickets', 'TABLE');
+                # get 'Tickets' if it exists
+                if ( ($sth->fetchrow_array)[2] ) {
+    
+                    $sth = $dbh->prepare('select id from Users where Name=?');
+                    $sth->execute('RT_System'); 
+                    if ( $sth->fetchrow_array ) {
+                        $RT::Installer->{DatabaseAction} = 'none';
+                        push @results, "Database $RT::DatabaseName seems complete,
+    don't need to initialize any more.";
+                    }
+                    else {
+                        $RT::Installer->{DatabaseAction} = 'acl,coredata,insert';
+                        push @results, "Database $RT::DatabaseName already exists 
+    and has RT tables in place, but does not contain RT's metadata. 'Initialize
+    Database' later can use this existing db and tables and insert metadata, if this's ok, click 'Customize Baisc' below to go on customizing RT";
+                    }
+                }
+                else {
+                    $RT::Installer->{DatabaseAction} = 'schema,acl,coredata,insert';
+                    push @results, "Database $RT::DatabaseName already exists, but
+    does not contain RT's tables and metadata. 'Initialize Database' later can use
+    this existing db and insert tables and metadata, if this's ok, click
+    'Customize Baisc' below to go on customizing RT";
+                }
+    
+            }
+            else {
+                $RT::Installer->{DatabaseAction} =
+    'create,schema,acl,coredata,insert';
+            }
+        }
+        else {
+            $RT::Installer->{DatabaseAction} = 'error';
+            push @results, "Failed to connect: $DBI::errstr";
+        }
+    }
     else {
-        push @results, "Failed to connect: $DBI::errstr";
+        push @results, $msg;
     }
+
+
 }
 
 </%init>

Modified: rt/branches/3.8-TESTING/html/installation/Finish.html
==============================================================================
--- rt/branches/3.8-TESTING/html/installation/Finish.html	(original)
+++ rt/branches/3.8-TESTING/html/installation/Finish.html	Fri May  2 18:21:34 2008
@@ -62,4 +62,25 @@
 it as you want.
 </p>
 </div>
+
+<form method="post">
+<input type="hidden" value="1" name="Run" />
+<& /Elements/Submit, Label => 'Start RT Journey!' &>
+</form>
+
 </&>
+<%init>
+if ( $Run ) {
+    RT->InstallMode(0);
+    RT->LoadConfig;
+    RT->ConnectToDatabase();
+    RT->InitSystemObjects();
+    RT->InitClasses();
+    RT->InitPlugins();
+    RT::Interface::Web::Redirect(RT->Config->Get('WebURL'));
+}
+</%init>
+
+<%args>
+$Run => undef
+</%args>

Modified: rt/branches/3.8-TESTING/html/installation/Initialize.html
==============================================================================
--- rt/branches/3.8-TESTING/html/installation/Initialize.html	(original)
+++ rt/branches/3.8-TESTING/html/installation/Initialize.html	Fri May  2 18:21:34 2008
@@ -69,11 +69,61 @@
 'installation/Sendmail.html');
     }
 
-    my $msg = `echo | $^X sbin/rt-setup-database --action init --dba $RT::Installer->{InstallConfig}{DatabaseUser} --dba-password '$RT::Installer->{InstallConfig}{DatabasePassword}' 2>&1`;
-    @results = split /\n/, $msg;
-# XXX $? doesn't work here, so I decided to grep the strings to find if any
-# error happens
-    unless ( grep { /^ERROR:|aborted/ } @results ) {
+    my @actions = split /,/, $RT::Installer->{DatabaseAction};
+
+    my $sysdbh = DBI->connect(
+        RT::Handle->SystemDSN,
+        $RT::Installer->{InstallConfig}{DatabaseAdmin},
+        $RT::Installer->{InstallConfig}{DatabaseAdminPassword}, 
+        { RaiseError => 0, PrintError => 0 },
+    );
+    die $DBI::errstr unless $sysdbh;
+
+    my ( $status, $msg ) = ( 1, '' );
+    if ( shift @actions eq 'create' ) {
+        ($status, $msg) = RT::Handle->CreateDatabase( $sysdbh );
+        unless ( $status ) {
+            push @results, "ERROR: $msg";
+        }
+    }
+
+    if ( $status ) {
+        my $dbh = DBI->connect(
+            RT::Handle->DSN, $RT::Installer->{InstallConfig}{DatabaseAdmin},
+            $RT::Installer->{InstallConfig}{DatabaseAdminPassword}, 
+            { RaiseError => 0, PrintError => 0 },
+        );
+        die $DBI::errstr unless $dbh;
+
+        foreach my $action ( @actions ) {
+            ($status, $msg) = (1, '');
+            if ( $action eq 'schema' ) {
+                ($status, $msg) = RT::Handle->InsertSchema( $dbh );
+            }
+            elsif ( $action eq 'acl' ) {
+                ($status, $msg) = RT::Handle->InsertACL( $dbh );
+            }
+            elsif ( $action eq 'coredata' ) {
+                $RT::Handle = new RT::Handle;
+                $RT::Handle->dbh( undef );
+                RT::ConnectToDatabase();
+                RT::InitLogging();
+                ($status, $msg) = $RT::Handle->InsertInitialData;
+            }
+            elsif ( $action eq 'insert' ) {
+                $RT::Handle = new RT::Handle;
+                RT::Init();
+                my $file = $RT::EtcPath . "/initialdata";
+                ($status, $msg) = $RT::Handle->InsertData( $file );
+            }
+            unless ( $status ) {
+                push @results, "ERROR: $msg";
+                last;
+            }
+        }
+    }
+
+    unless ( @results ) {
         RT::Interface::Web::Redirect(RT->Config->Get('WebURL') .
 'installation/Finish.html');
     }

Modified: rt/branches/3.8-TESTING/html/installation/Sendmail.html
==============================================================================
--- rt/branches/3.8-TESTING/html/installation/Sendmail.html	(original)
+++ rt/branches/3.8-TESTING/html/installation/Sendmail.html	Fri May  2 18:21:34 2008
@@ -58,7 +58,8 @@
     CurrentValue => RT::Installer->CurrentValues(@Types) &>
 
 <input type="hidden" name="Run" value="1">
-<& /Elements/Submit, Label => loc('Next: Initialize Database'), Back => 1,
+<& /Elements/Submit, Label => $RT::Installer->{DatabaseAction} eq 'none' ?
+loc('Next: Finish') : loc('Next: Initialize Database'), Back => 1,
     BackLabel => loc('Back: Customize Emails') &>
 </form>
 </&>
@@ -80,22 +81,22 @@
 
     unless ( @results ) {
 
+        my ( $status, $msg ) = RT::Installer->SaveConfig;
 
-        require File::Spec;
-        my $file = File::Spec->catfile($RT::EtcPath, 'RT_SiteConfig.pm');
+        if ( $status ) {
+            RT->LoadConfig;
 
-        if ( open my $fh, '>', $file  ) {
-            for ( keys %{$RT::Installer->{InstallConfig}} ) {
-                 print $fh "Set( \$$_, '$RT::Installer->{InstallConfig}{$_}' );\n";
-            }
-            print $fh "1;\n";
-            close $fh;
-
-            RT::Interface::Web::Redirect(RT->Config->Get('WebURL') .
+            if ( $RT::Installer->{DatabaseAction} ne 'none' ) {
+                RT::Interface::Web::Redirect(RT->Config->Get('WebURL') .
 'installation/Initialize.html');
+            }
+            else {
+                RT::Interface::Web::Redirect(RT->Config->Get('WebURL') .
+'installation/Finish.html');
+            }
         }
         else {
-            push @results, "Can't open config file $file to write: $!";
+            push @results, $msg;
         }
     }
 }

Modified: rt/branches/3.8-TESTING/lib/RT/Config.pm
==============================================================================
--- rt/branches/3.8-TESTING/lib/RT/Config.pm	(original)
+++ rt/branches/3.8-TESTING/lib/RT/Config.pm	Fri May  2 18:21:34 2008
@@ -167,6 +167,7 @@
     DisableGraphViz => {
         Type            => 'SCALAR',
         PostLoadCheck   => sub {
+            my $self  = shift;
             my $value = shift;
             return if $value;
             return if $INC{'GraphViz'};

Modified: rt/branches/3.8-TESTING/lib/RT/Dashboard.pm
==============================================================================
--- rt/branches/3.8-TESTING/lib/RT/Dashboard.pm	(original)
+++ rt/branches/3.8-TESTING/lib/RT/Dashboard.pm	Fri May  2 18:21:34 2008
@@ -66,27 +66,15 @@
 
 package RT::Dashboard;
 
-use RT::Base;
-use RT::Attribute;
 use RT::SavedSearch;
 
 use strict;
 use warnings;
-use base qw/RT::Base/;
-
-sub new  {
-    my $proto = shift;
-    my $class = ref($proto) || $proto;
-    my $self  = {};
-    $self->{'Id'} = 0;
-    bless ($self, $class);
-    $self->CurrentUser(@_);
-    return $self;
-}
+use base qw/RT::FauxObject/;
 
 my %new_rights = (
-    ModifyDashboard    => 'Create and modify dashboards',
-    SubscribeDashboard => 'Subscribe to email dashboards',
+    ModifyDashboard    => 'Create and modify dashboards', #loc_pair
+    SubscribeDashboard => 'Subscribe to email dashboards', #loc_pair
 );
 
 use RT::System;
@@ -94,183 +82,42 @@
 %RT::ACE::LOWERCASERIGHTNAMES = ( %RT::ACE::LOWERCASERIGHTNAMES,
                                   map { lc($_) => $_ } keys %new_rights);
 
-=head2 Load
+=head2 ObjectName
 
-Takes a privacy specification, an object ID, and a dashboard ID.  Loads
-the given dashboard ID if it belongs to the stated user or group.
-Returns a tuple of status and message, where status is true on
-success.
+An object of this class is called "dashboard"
 
 =cut
 
-sub Load {
-    my $self = shift;
-    my ($privacy, $id) = @_;
-    my $object = $self->_GetObject($privacy);
-
-    if ($object) {
-	$self->{'Attribute'} = $object->Attributes->WithId($id);
-	if ($self->{'Attribute'}->Id) {
-	    $self->{'Id'} = $self->{'Attribute'}->Id;
-	    $self->{'Privacy'} = $privacy;
-	    return (1, $self->loc("Loaded dashboard [_1]", $self->Name));
-	} else {
-	    $RT::Logger->error("Could not load attribute " . $id
-			       . " for object " . $privacy);
-	    return (0, $self->loc("Dashboard attribute load failure"));
-	}
-    } else {
-	$RT::Logger->warning("Could not load object $privacy when loading dashboard");
-	return (0, $self->loc("Could not load object for [_1]", $privacy));
-    }
-
-}
-
-=head2 Save
-
-Takes a privacy, a name, and an arrayref containing an arrayref of saved
-searches and their names. Saves the given parameters to the appropriate user/
-group object, and loads the resulting dashboard. Returns a tuple of status and
-message, where status is true on success. Defaults are:
-  Privacy:  undef
-  Name:     "new dashboard"
-  Searches: (empty array)
-
-=cut
+sub ObjectName { "dashboard" }
 
-sub Save {
-    my $self = shift;
-    my %args = ('Privacy' => 'RT::User-' . $self->CurrentUser->Id,
-		'Name' => 'new dashboard',
-		'Searches' => [],
-		@_);
-    my $privacy = $args{'Privacy'};
-    my $name = $args{'Name'};
-    my @params = @{$args{'Searches'} || []};
-
-    my $object = $self->_GetObject($privacy);
-
-    return (0, $self->loc("Failed to load object for [_1]", $privacy))
-        unless $object;
-
-    if ( $object->isa('RT::System') ) {
-        return (0, $self->loc("No permission to save system-wide dashboards"))
-            unless $self->CurrentUser->HasRight(
-            Object => $RT::System,
-            Right  => 'SuperUser'
-        );
-    }
+sub SaveAttribute {
+    my $self   = shift;
+    my $object = shift;
+    my $args   = shift;
 
-    my ( $att_id, $att_msg ) = $object->AddAttribute(
+    return $object->AddAttribute(
         'Name'        => 'Dashboard',
-        'Description' => $name,
-        'Content'     => {Searches => \@params},
+        'Description' => $args{'Name'},
+        'Content'     => {Searches => $args{'Searches'}},
     );
-    if ($att_id) {
-        $self->{'Attribute'} = $object->Attributes->WithId($att_id);
-        $self->{'Id'}        = $att_id;
-        $self->{'Privacy'}   = $privacy;
-        return ( 1, $self->loc( "Saved dashboard [_1]", $name ) );
-    }
-    else {
-        $RT::Logger->error("Dashboard save failure: $att_msg");
-        return ( 0, $self->loc("Failed to create dashboard attribute") );
-    }
 }
 
-=head2 Update
-
-Updates the parameters of an existing dashboard. Takes the arguments "Name" and
-"Searches"; Searches should be an arrayref of arrayrefs of saved searches. If
-Searches or Name is not specified, then they will not be changed.
-
-=cut
-
-sub Update {
+sub UpdateAttribute {
     my $self = shift;
-    my %args = ('Name' => '',
-		@_);
- 
-    return(0, $self->loc("No dashboard loaded")) unless $self->Id;
-    return(0, $self->loc("Could not load dashboard attribute"))
-        unless $self->{'Attribute'}->Id;
+    my $args = shift;
 
     my ($status, $msg) = (1, undef);
-    if (defined $args{'Searches'}) {
+    if (defined $args->{'Searches'}) {
         ($status, $msg) = $self->{'Attribute'}->SetSubValues(
-            Searches => $args{'Searches'},
+            Searches => $args->{'Searches'},
         );
     }
 
-    if ($status && $args{'Name'}) {
-        ($status, $msg) = $self->{'Attribute'}->SetDescription($args{'Name'});
+    if ($status && $args->{'Name'}) {
+        ($status, $msg) = $self->{'Attribute'}->SetDescription($args->{'Name'});
     }
 
-    return (1, $self->loc("Dashboard update: Nothing changed"))
-        if !defined $msg;
-
-    # prevent useless warnings
-    if ($msg =~ /That is already the current value/) {
-        return (1, $self->loc("Dashboard updated"));
-    }
-
-    return ($status, $self->loc("Dashboard update: [_1]", $msg));
-}
-
-=head2 Delete
-    
-Deletes the existing dashboard.  Returns a tuple of status and message,
-where status is true upon success.
-
-=cut
-
-sub Delete {
-    my $self = shift;
-
-    my ($status, $msg) = $self->{'Attribute'}->Delete;
-    if ($status) {
-	return (1, $self->loc("Deleted dashboard"));
-    } else {
-	return (0, $self->loc("Delete failed: [_1]", $msg));
-    }
-}
-	
-
-### Accessor methods
-
-=head2 Name
-
-Returns the name of the dashboard.
-
-=cut
-
-sub Name {
-    my $self = shift;
-    return unless ref($self->{'Attribute'}) eq 'RT::Attribute';
-    return $self->{'Attribute'}->Description();
-}
-
-=head2 Id
-
-Returns the numerical id of this dashboard.
-
-=cut
-
-sub Id {
-     my $self = shift;
-     return $self->{'Id'};
-}
-
-=head2 Privacy
-
-Returns the principal object to whom this dashboard belongs, in a string
-"<class>-<id>", e.g. "RT::Group-16".
-
-=cut
-
-sub Privacy {
-    my $self = shift;
-    return $self->{'Privacy'};
+    return ($status, $msg);
 }
 
 =head2 Searches

Modified: rt/branches/3.8-TESTING/lib/RT/Installer.pm
==============================================================================
--- rt/branches/3.8-TESTING/lib/RT/Installer.pm	(original)
+++ rt/branches/3.8-TESTING/lib/RT/Installer.pm	Fri May  2 18:21:34 2008
@@ -244,6 +244,24 @@
     return { map { $_ => CurrentValue($_) } @types };
 }
 
+
+sub SaveConfig {
+
+    require File::Spec;
+    my $file = File::Spec->catfile($RT::EtcPath, 'RT_SiteConfig.pm');
+
+    if ( open my $fh, '>', $file  ) {
+        for ( keys %{$RT::Installer->{InstallConfig}} ) {
+             print $fh "Set( \$$_, '$RT::Installer->{InstallConfig}{$_}' );\n";
+        }
+        print $fh "1;\n";
+        close $fh;
+        return ( 1, 'saved config with success' );
+    }
+
+    return ( 0, "can't save config to $file: $!" );
+}
+
 =head1 NAME
 
     RT::Installer - RT's Installer


More information about the Rt-commit mailing list