| 1 | #!/usr/bin/perl -w | ||||||||||
| 2 | |||||||||||
| 3 | package Sakai::Nakamura::ContentUtil; | ||||||||||
| 4 | |||||||||||
| 5 | 2 | ▶ | use 5.008001; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 2 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 2 | require Exporter; | |||||||||
| 11 | |||||||||||
| 12 | 2 | ▶ | use base qw(Exporter); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | |||||||||||
| 14 | 2 | our @EXPORT_OK = (); | |||||||||
| 15 | |||||||||||
| 16 | 2 | our $VERSION = '0.13'; | |||||||||
| 17 | |||||||||||
| 18 | #{{{sub add_file_metadata_setup | ||||||||||
| 19 | |||||||||||
| 20 | 5 | ▶ | sub add_file_metadata_setup { | ||||||||
|
Subroutine
add_file_metadata_setup: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||
| 21 | 5 | my ( $base_url, $content_path, $content_filename, $content_fileextension ) = | |||||||||
| 22 | @_; | ||||||||||
| 23 | 5 | ▶ | if ( !defined $base_url ) { croak 'No base url defined to add against!'; } | ||||||||
|
Branch: 1 branch
| |||||||||||
| 24 | 4 | ▶ | if ( !defined $content_path ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 25 | 1 | croak 'No content path to add file meta data to!'; | |||||||||
| 26 | } | ||||||||||
| 27 | 3 | ▶ | if ( !defined $content_filename ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 28 | 1 | croak 'No content filename provided when attempting to add meta data!'; | |||||||||
| 29 | } | ||||||||||
| 30 | 2 | ▶ | if ( !defined $content_fileextension ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 31 | 1 | croak | |||||||||
| 32 | 'No content file extension provided when attempting to add meta data!'; | ||||||||||
| 33 | } | ||||||||||
| 34 | 1 | my $post_variables = | |||||||||
| 35 | "\$post_variables = ['requests','[{\"url\":\"$content_path\",\"method\":\"POST\",\"parameters\":{\"sakai:pooled-content-file-name\":\"$content_filename\",\"sakai:description\":\"\",\"sakai:permissions\":\"public\",\"sakai:copyright\":\"creativecommons\",\"sakai:allowcomments\":\"true\",\"sakai:showcomments\":\"true\",\"sakai:fileextension\":\"$content_fileextension\",\"_charset_\":\"utf-8\"},\"_charset_\":\"utf-8\"},{\"url\":\"$content_path.save.json\",\"method\":\"POST\",\"_charset_\":\"utf-8\"}]']"; | ||||||||||
| 36 | 1 | return "post $base_url/system/batch $post_variables"; | |||||||||
| 37 | } | ||||||||||
| 38 | |||||||||||
| 39 | #}}} | ||||||||||
| 40 | |||||||||||
| 41 | #{{{sub add_file_metadata_eval | ||||||||||
| 42 | |||||||||||
| 43 | 1 | ▶ | sub add_file_metadata_eval { | ||||||||
|
Subroutine
add_file_metadata_eval: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 44 | 1 | my ($res) = @_; | |||||||||
| 45 | 1 | return ( ${$res}->code eq '200' ); | |||||||||
| 46 | } | ||||||||||
| 47 | |||||||||||
| 48 | #}}} | ||||||||||
| 49 | |||||||||||
| 50 | #{{{sub add_file_perms_setup | ||||||||||
| 51 | |||||||||||
| 52 | 3 | ▶ | sub add_file_perms_setup { | ||||||||
|
Subroutine
add_file_perms_setup: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||
| 53 | 3 | my ( $base_url, $content_path ) = @_; | |||||||||
| 54 | 3 | ▶ | if ( !defined $base_url ) { croak 'No base url defined to add against!'; } | ||||||||
|
Branch: 1 branch
| |||||||||||
| 55 | 2 | ▶ | if ( !defined $content_path ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 56 | 1 | croak 'No content path to add file perms to!'; | |||||||||
| 57 | } | ||||||||||
| 58 | 1 | my $post_variables = | |||||||||
| 59 | "\$post_variables = ['requests','[{\"url\":\"$content_path.members.html\",\"method\":\"POST\",\"parameters\":{\":viewer\":[\"everyone\",\"anonymous\"]}},{\"url\":\"$content_path.modifyAce.html\",\"method\":\"POST\",\"parameters\":{\"principalId\":[\"everyone\"],\"privilege\@jcr:read\":\"granted\"}},{\"url\":\"$content_path.modifyAce.html\",\"method\":\"POST\",\"parameters\":{\"principalId\":[\"anonymous\"],\"privilege\@jcr:read\":\"granted\"}}]']"; | ||||||||||
| 60 | 1 | return "post $base_url/system/batch $post_variables"; | |||||||||
| 61 | } | ||||||||||
| 62 | |||||||||||
| 63 | #}}} | ||||||||||
| 64 | |||||||||||
| 65 | #{{{sub add_file_perms_eval | ||||||||||
| 66 | |||||||||||
| 67 | 1 | ▶ | sub add_file_perms_eval { | ||||||||
|
Subroutine
add_file_perms_eval: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 68 | 1 | my ($res) = @_; | |||||||||
| 69 | 1 | return ( ${$res}->code eq '200' ); | |||||||||
| 70 | } | ||||||||||
| 71 | |||||||||||
| 72 | #}}} | ||||||||||
| 73 | |||||||||||
| 74 | #{{{sub comment_add_setup | ||||||||||
| 75 | |||||||||||
| 76 | 0 | ▶ | sub comment_add_setup { | ||||||||
|
Subroutine
comment_add_setup: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||
| 77 | 0 | my ( $base_url, $content_path, $comment ) = @_; | |||||||||
| 78 | 0 | ▶ | if ( !defined $base_url ) { croak 'No base url defined to add against!'; } | ||||||||
|
Branch: 1 branch
| |||||||||||
| 79 | 0 | ▶ | if ( !defined $content_path ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 80 | 0 | croak 'No content path to add comments to!'; | |||||||||
| 81 | } | ||||||||||
| 82 | 0 | ▶ | if ( !defined $comment ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 83 | 0 | croak 'No comment provided to add!'; | |||||||||
| 84 | } | ||||||||||
| 85 | 0 | my $post_variables = "\$post_variables = ['comment','$comment']"; | |||||||||
| 86 | 0 | return "post $base_url/$content_path.comments $post_variables"; | |||||||||
| 87 | } | ||||||||||
| 88 | |||||||||||
| 89 | #}}} | ||||||||||
| 90 | |||||||||||
| 91 | #{{{sub comment_add_eval | ||||||||||
| 92 | |||||||||||
| 93 | 0 | ▶ | sub comment_add_eval { | ||||||||
|
Subroutine
comment_add_eval: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 94 | 0 | my ($res) = @_; | |||||||||
| 95 | 0 | return ( ${$res}->code eq '201' ); | |||||||||
| 96 | } | ||||||||||
| 97 | |||||||||||
| 98 | #}}} | ||||||||||
| 99 | |||||||||||
| 100 | 2 | 1; | |||||||||
| 101 | |||||||||||
| 102 | __END__ | ||||||||||