FWS-V2

 view release on metacpan or  search on metacpan

lib/FWS/V2/Database.pm  view on Meta::CPAN

            "<body>\n" .
            "#FWSMenu#" .
            "<div id=\"loc_wrapper\">" .
            "<div id=\"loc\">" .
            "<div id=\"loc_1_wrapper\">" .
            "<div id=\"loc_1\">" .
            "<div id=\"loc_1_1_wrapper\">" .
            "<div id=\"loc_1_1\">#FWSShow-header#</div>" .
            "</div>" .
            "</div>" .
            "</div>" .
            "<div id=\"loc_2_wrapper\">" .
            "<div id=\"loc_2\">" .
            "<div id=\"loc_2_1_wrapper\">" .
            "<div id=\"loc_2_1\">#FWSShow-main#</div>" .
            "</div>" .
            "</div>" .
            "</div>" .
            "<div id=\"loc_3_wrapper\">" .
            "<div id=\"loc_3\">" .
            "<div id=\"loc_3_1_wrapper\">" .
            "<div id=\"loc_3_1\">#FWSShow-footer#</div>" .
            "</div>" .
            "</div>" .
            "</div>" .
            "</div>" .
            "</div>" .
            "<div style=\"clear:both;\"></div>\n" .
            "#FWSJavaLoad#"  . 
            "</body>\n"  . 
            "</html>";
    }


    #
    # create the hash and return it
    #
    my %templateHash;
    $templateHash{guid}           = $paramHash{templateGUID};
    $templateHash{homeGUID}       = $homePageTemplateId;
    $templateHash{title}          = '';
    $templateHash{siteGUID}       = $self->{siteGUID};
    $templateHash{template}       = $template;
    $templateHash{css}            = $css;
    $templateHash{js}             = $js;
    $templateHash{defaultGUID}    = $defaultGUID;

    return %templateHash;
}



=head2 updateDataCache

Update the cache version of the data record.  This is called automatically when saveData is called.

    $fws->updateDataCache(%theDataHash);

=cut

sub updateDataCache {
    my ( $self, %dataHash ) = @_;

    #
    # get the field hash so we don't have to try to add fields that might not be there EVERY time
    #
    my %tableFieldHash = $self->tableFieldHash( 'data_cache' );

    #
    # set the page id of the guid for easy access on search pages
    #
    $dataHash{pageIdOfElement} = $self->_setPageGUID( guid => $dataHash{guid} );
    
    #
    # get the page hash of the page, and update the page description to the data for easy access on search pages
    #
    my %pageHash = $self->dataHash( guid => $dataHash{pageIdOfElement} );
    $dataHash{pageDescription} = $pageHash{pageDescription};

    #
    # get what fields we are aloud to use
    #
    my %dataCacheFields = %{$self->{dataCacheFields}};

    #
    # we will be building these up while we loop
    #
    my $fields;
    my $values;

    #
    # make any fields that "might" be needed
    #
    foreach my $key ( keys %dataHash ) {
        if ( $dataCacheFields{$key} || $key =~ /^(site_guid|guid|name|title|pageIdOfElement|pageDescription)$/ ) {

            #
            # if the type is blank, then this is new
            #
            if ( !$tableFieldHash{$key}{type} ) {
                #
                # alter tha table
                #
                $self->alterTable( table => 'data_cache', field => $key, type => 'text', key => 'FULLTEXT', default => '' );
            }



            #
            # append the new data to the strings we are using to create the insert statement
            #
            $fields .= $self->safeSQL( $key ) . ',';
            $values .= "'" . $self->safeSQL( $dataHash{$key} ) . "',";
        }
    }

    #
    # clean up the commas at the end of values and fields
    #
    $fields =~ s/,$//sg;
    $values =~ s/,$//sg;

lib/FWS/V2/Database.pm  view on Meta::CPAN

    $userGroupHash{guid}          = $guid;

    #
    # get a list of users and add that to the hash
    #
    my @userList = @{$self->runSQL( SQL => "select profile_guid from profile_groups_xref where groups_guid='" . $self->safeSQL( $guid ) . "'" )};
    while (@userList) {
        my $userId = shift @userList;
        $userGroupHash{user}{$userId} = '1';
    }

    return %userGroupHash;
}


=head2 userGroupArray

Return the hash array for all of the user groups;

    my @userGroupArray = $fws->userGroupArray();

=cut

sub userGroupArray {
    my ( $self ) = @_;
    my @userGroupHashArray;

    #
    # get the data from the database and push it into the hash array
    #
    my @userGroupArray = @{$self->runSQL( SQL => "select name,description,guid from groups" )};
    while (@userGroupArray) {

        #
        # fill in the hash
        #
        my %userGroupHash;
        $userGroupHash{name}          = shift @userGroupArray;
        $userGroupHash{description}   = shift @userGroupArray;
        $userGroupHash{guid}          = shift @userGroupArray;

        #
        # push it into the array
        #
        push @userGroupHashArray, {%userGroupHash};
    }
    return @userGroupHashArray;
}


=head2 updateDatabase

Alter the database to match the schema for FWS 2.   The return will print the SQL statements used to adjust the tables.

    print $fws->updateDatabase()."\n";

This method is automatically called when on the web optimized version of FWS when rendering the 'System' screen.  This will also auto trigger a flag to only it allow it to execute once so it doesn't recurse itself.

=cut

sub updateDatabase {
    my ( $self ) = @_;

    #
    # our passback for what we did
    #
    my $dbResponse;
    
    #
    # make sure I didn't do this yet
    #
    if ( !$self->{upadateDatabaseRan} ) { 
        
        #
        # loop though the records and make or update the tables
        #
        for my $table ( keys %{$self->{dataSchema}} ) {

            for my $field ( keys %{$self->{dataSchema}{$table}} ) {
    
                my $type        = $self->{dataSchema}{$table}{$field}{type};
                my $key         = $self->{dataSchema}{$table}{$field}{key};
                my $default     = $self->{dataSchema}{$table}{$field}{default};
    
                #
                # make sure this isn't a bad record.   It at least needs a table name
                #
                if ( $table ) { $dbResponse .= $self->alterTable( table => $table, field => $field, type => $type, key => $key, default => $default ) }
            }
        }
    }
        
    $self->{upadateDatabaseRan} = 1; 
    return $dbResponse;
}


=head2 updateModifiedDate

Update the modified date of the page a dataHash element resides on.

    $fws->updateModifiedDate(%dataHash);

Note: By updating anything that is persistant against multiple pages all pages will have thier date updated as it is considered a site wide change.

=cut

sub updateModifiedDate {
    my ( $self, %paramHash ) = @_;

    #
    # it is default or not
    #
    $paramHash{siteGUID} ||= $self->{siteGUID};

    #
    # set the type to page if the id itself is a page
    #
    my ( $type ) = @{$self->runSQL( SQL => "select element_type from data where guid='" . $self->safeSQL( $paramHash{guid} ) . "' and site_guid='" . $self->safeSQL( $paramHash{siteGUID} ) . "'" )};

    #
    # if its not page loop though till it finds what page its on
    #
    my $isDefault   = 0;
    my $recurCap    = 0;
    while ( $paramHash{guid} && ( $type ne 'page' || $type ne 'home' ) && $recurCap < 100 ) {
        my ( $defaultElement ) = @{$self->runSQL( SQL => "select default_element from data where guid='" . $self->safeSQL( $paramHash{guid} ) . "' and site_guid='" . $self->safeSQL( $paramHash{siteGUID} ) . "'" )};
        ( $paramHash{guid}, $type ) = @{$self->runSQL( SQL => "select parent,data.element_type from guid_xref left join data on data.guid=parent where child='" . $self->safeSQL( $paramHash{guid} ) . "' and guid_xref.site_guid='" . $self->safeSQL( $pa...
        if ( !$isDefault && $defaultElement ) { $isDefault = 1 }
        $recurCap++;
    }

    #
    # if id is blank that means we are updating a home page element
    #
    if ( !$type || $isDefault > 0 || $isDefault < 0) {
        $self->saveExtra( table => 'data', siteGUID => $paramHash{siteGUID}, field => 'dateUpdated', value => time );
    }

    #
    # if is default then update ALL pages
    #
    if ( $isDefault ) {
        $self->saveExtra( table => 'data', siteGUID => $paramHash{siteGUID}, field => 'dateUpdated', value => time );
        my @pageList = @{$self->runSQL( SQL => "select guid from data where data.site_guid='" . $self->safeSQL( $paramHash{siteGUID} ) . "' and (data.element_type='page' or data.element_type='home')" )};
        while ( @pageList ) {
            my $pageId = shift @pageList;
            $self->saveExtra( table => 'data', siteGUID => $paramHash{siteGUID}, guid => $pageId, field => 'dateUpdated', value => time );
        }
    }

    #
    # if the type is page, then just update that page
    #
    if ( $type eq 'page' || $type eq 'home' ) {
        $self->saveExtra( table => 'data', siteGUID => $paramHash{siteGUID}, guid => $paramHash{guid}, field => 'dateUpdated', value => time );
    }
    return;
}


=head2 homeGUID

Return the guid for the home page.  Without any paramanters it will return the home page guid for the current site.

=cut

sub homeGUID {



( run in 0.543 second using v1.01-cache-2.11-cpan-39bf76dae61 )