Changeset 37233 for main


Ignore:
Timestamp:
2023-01-31T23:41:56+13:00 (15 months ago)
Author:
davidb
Message:

Adding in action for get-fldv-info

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone2/perllib/cgiactions/metadataaction.pm

    r37215 r37233  
    7575        "get-archives-text" => {
    7676            'compulsory-args' => [ "d" ],
    77             'optional-args'   => [ "dv" ] },
     77            'optional-args'   => [ "dv" ]
    7878            #'compulsory-args' => [ "d" ],
    79             #'optional-args' => [ "section" ] },
     79        #'optional-args' => [ "section" ] },
     80    },
    8081   
    8182    #GET METHODS
    8283    "get-import-metadata" => {
    8384        'compulsory-args' => [ "d", "metaname" ],
    84         'optional-args'   => [ "metapos" ] },
     85            'optional-args'   => [ "metapos" ]
     86    },
    8587
    8688    "get-archives-metadata" => {
    8789        'compulsory-args' => [ "d", "metaname" ],
    88         'optional-args'   => [ "dv", "metapos" ] },
     90            'optional-args'   => [ "dv", "metapos" ]
     91    },
    8992
    9093    "get-archives-assocfile" => {
    9194        'compulsory-args' => [ "d", "assocname" ],
    92         'optional-args'   => [ "dv" ] },
     95            'optional-args'   => [ "dv" ]
     96    },
    9397   
    9498    "get-index-metadata" => {
    9599        'compulsory-args' => [ "d", "metaname" ],
    96         'optional-args'   => [ "metapos" ] },
     100            'optional-args'   => [ "metapos" ]
     101    },
    97102
    98103    "get-metadata" => { # alias for get-index-metadata
    99104        'compulsory-args' => [ "d", "metaname" ],
    100         'optional-args'   => [ "metapos" ] },
     105        'optional-args'   => [ "metapos" ]
     106    },
    101107
    102108    "get-live-metadata" => {
    103109        'compulsory-args' => [ "d", "metaname" ],
    104         'optional-args'   => [ ] },
     110            'optional-args'   => [ ]
     111    },
    105112
    106113    "get-metadata-array" => { # where param can be ONE of: index (default), import, archives, live
     
    108115        'optional-args'   => [ "where" ],
    109116        'help-string' => [
    110         'metadata-server.pl?a=get-metadata-array&c=demo&where=index&json=[{"docid":"HASHc5bce2d6d3e5b04e470ec9","metatable":[{"metaname":"username","metapos":"all"},{"metaname":"usertimestamp","metapos":"all"}, {"metaname":"usercomment","metapos":"all"}]}]'
    111         ]}
     117        'metadata-server.pl?a=get-metadata-array&c=demo&where=index&json=[{"docid":"HASHc5bce2d6d3e5b04e470ec9","metatable":[{"metaname":"username","metapos":"all"},{"metaname":"usertimestamp","metapos":"all"}, {"metaname":"usercomment","metapos":"all"}]}]' ]
     118    },
     119
     120    "get-fldv-info" => {
     121        'compulsory-args' => [ "d", ],
     122        'optional-args'   => [ ],
     123        'help-string' => [
     124            "fldv is short for file-level document-version history.  It refers to the filesystem level approach Greenstone takes to keeping a document version history of the documents formed in the 'archives' directory.  When collection is imported with -keepold, for example, any existing documents in the archives area get 'bundled up' as a subfolder called 'nminus-1' within the newly formed document.  If there is an existing 'nminus-1' subdirectory then this is moved to nminus-2 prior to forming a new 'nminus-1'.  And so on.",
     125        "Calling this action returns in JSON formated the array of 'nminus-<n>' subdirectories that a particular document has." ]
     126    }
    112127};
     128
    113129
    114130# To get the final action_table of all available subroutines in this class,
     
    10581074}
    10591075
     1076
     1077
     1078sub get_fldv_info
     1079{
     1080    my $self = shift @_;
     1081
     1082    my $username  = $self->{'username'};
     1083    my $collect   = $self->{'collect'};
     1084    my $gsdl_cgi  = $self->{'gsdl_cgi'};
     1085    my $infodbtype = $self->{'infodbtype'};
     1086
     1087    # Obtain the collect dir
     1088    my $site = $self->{'site'};
     1089    my $collect_dir = $gsdl_cgi->get_collection_dir($site);
     1090   
     1091    my $archive_dir = &util::filename_cat($collect_dir, $collect, "archives");
     1092
     1093    # look up additional args
     1094    my $docid = $self->{'d'};
     1095   
     1096   
     1097    my $arcinfo_doc_filename = &dbutil::get_infodb_file_path($infodbtype, "archiveinf-doc", $archive_dir);
     1098    my $doc_rec = &dbutil::read_infodb_entry($infodbtype, $arcinfo_doc_filename, $docid);
     1099
     1100    # This now stores the full pathname [is this still true??]
     1101    my $doc_file = $doc_rec->{'doc-file'}->[0];
     1102
     1103    my ($unused_doc_tailname, $doc_dirname) = File::Basename::fileparse($doc_file);
     1104    my $doc_full_dirname = &util::filename_cat($archive_dir,$doc_dirname);
     1105   
     1106    my $fldv_full_dirname = &util::filename_cat($doc_full_dirname,$FLDV_HISTORY_DIR);
     1107
     1108    my $sorted_fldv_filtered_dirs_json = "[]";
     1109    if (-d $fldv_full_dirname) {
     1110        my $fldv_filtered_dirs = &FileUtils::readDirectoryFiltered($fldv_full_dirname,undef,"^nminus-\\d+\$");
     1111
     1112        my @sorted_fldv_filtered_dirs = sort {
     1113        my ($a_num) = ($a =~ m/(\d+)$/);
     1114        my ($b_num) = ($b =~ m/(\d+)$/);
     1115       
     1116        # sort into ascending order
     1117        return $a_num <=> $b_num;
     1118        } @$fldv_filtered_dirs;
     1119       
     1120        $sorted_fldv_filtered_dirs_json = encode_json \@sorted_fldv_filtered_dirs;
     1121    }
     1122   
     1123    $gsdl_cgi->generate_ok_message($sorted_fldv_filtered_dirs_json);
     1124}
     1125
     1126
    10601127sub get_metadata_from_archive_xml
    10611128{
Note: See TracChangeset for help on using the changeset viewer.