Commit f3ad8981 authored by Robert Lyon's avatar Robert Lyon Committed by Gerrit Code Review
Browse files

Merge "Bug 1937982: Making sure report downloads have unique names" into 21.04_STABLE

parents 2f373cd1 599057ea
......@@ -2287,14 +2287,20 @@ class LiveUser extends User {
* @param $content string file contents
* @param $name string filename to be used when downloading the file
* @param $mimetype string
* @param $suffix boolean datestamp to be added to end of filename
*/
public function set_download_file($content, $name, $mimetype) {
public function set_download_file($content, $name, $mimetype, $suffix=false) {
global $SESSION;
$filename = get_random_key();
$dir = get_config('dataroot') . 'export/' . $this->id . '/';
check_dir_exists($dir);
file_put_contents($dir . $filename, $content);
if ($suffix) {
// Append the current date to the end of the name of the file but before the file extension
// eg "cats.csv" would become "cats_20210101123010.csv"
$name = preg_replace('/\.(.*?)$/', '_' . date('YmdHis', time()) . '.$1', $name);
}
$SESSION->set('downloadfile', array(
'file' => $filename,
......
......@@ -969,7 +969,7 @@ function userdetails_stats_table($limit, $offset, $extra, $institution, $urllink
$data[$i]->lastlogin = format_date(strtotime($data[$i]->lastlogin), 'strftimew3cdatetime');
}
}
$USER->set_download_file(generate_csv($data, $csvfields), $institution . 'userdetailsstatistics.csv', 'text/csv');
$USER->set_download_file(generate_csv($data, $csvfields), $institution . 'userdetailsstatistics.csv', 'text/csv', true);
}
$result['csv'] = true;
$columnkeys = array();
......@@ -1250,7 +1250,7 @@ function useragreement_stats_table($limit, $offset, $extra, $institution, $urlli
'siteprivacy', 'siteprivacyconsentdate', 'siteterms', 'sitetermsconsentdate',
'institutionprivacy', 'institutionprivacyconsentdate', 'institutionterms', 'institutiontermsconsentdate',
'instname');
$USER->set_download_file(generate_csv($data, $csvfields), $institution . 'useragreementsstatistics.csv', 'text/csv');
$USER->set_download_file(generate_csv($data, $csvfields), $institution . 'useragreementsstatistics.csv', 'text/csv', true);
}
$result['csv'] = true;
$columnkeys = array();
......@@ -1614,7 +1614,7 @@ function useractivity_stats_table($limit, $offset, $extra, $institution, $urllin
$csvfields = array('firstname', 'lastname', 'displayname', 'username',
'artefacts', 'pages', 'collections', 'groups', 'logins',
'actions', 'lastlogin', 'lastactivity');
$USER->set_download_file(generate_csv($data, $csvfields), $institution . 'useractivitystatistics.csv', 'text/csv');
$USER->set_download_file(generate_csv($data, $csvfields), $institution . 'useractivitystatistics.csv', 'text/csv', true);
}
$result['csv'] = true;
$columnkeys = array();
......@@ -1909,7 +1909,7 @@ function collaboration_stats_table($limit, $offset, $extra, $institution, $urlli
$csvfields = array('date', 'comments', 'annotations', 'usershare', 'groupshare',
'institutionshare', 'loggedinshare', 'publicshare', 'secretshare',
'friendshare');
$USER->set_download_file(generate_csv($data, $csvfields), $institution . 'collaborationstatistics.csv', 'text/csv');
$USER->set_download_file(generate_csv($data, $csvfields), $institution . 'collaborationstatistics.csv', 'text/csv', true);
}
$result['csv'] = true;
$columnkeys = array();
......@@ -2308,7 +2308,7 @@ function completionverification_stats_table($limit, $offset, $extra, $institutio
$data[$i]->accessrevokedbyauthordate = format_date(strtotime($data[$i]->accessrevokedbyauthordate), 'strftimew3cdatetime');
}
}
$USER->set_download_file(generate_csv($data, $csvfields), $institution . 'userdetailsstatistics.csv', 'text/csv');
$USER->set_download_file(generate_csv($data, $csvfields), $institution . 'completionverificationstatistics.csv', 'text/csv', true);
}
$result['csv'] = true;
......@@ -2510,7 +2510,7 @@ function portfolioswithverifiers_stats_table($limit, $offset, $extra, $instituti
$data[$i]->date = format_date(strtotime($data[$i]->date), 'strftimew3cdatetime');
}
}
$USER->set_download_file(generate_csv($data, $csvfields, $csvheaders), $institution . 'portfolioswithverifiersummarystatistics.csv', 'text/csv');
$USER->set_download_file(generate_csv($data, $csvfields, $csvheaders), $institution . 'portfolioswithverifiersummarystatistics.csv', 'text/csv', true);
}
$smarty = smarty_core();
......@@ -2700,7 +2700,7 @@ function user_stats_table($limit, $offset, $extra) {
}
if (!empty($extra['csvdownload'])) {
$csvfields = array('date', 'loggedin', 'created', 'total');
$USER->set_download_file(generate_csv($data, $csvfields), 'userstatistics.csv', 'text/csv');
$USER->set_download_file(generate_csv($data, $csvfields), 'userstatistics.csv', 'text/csv', true);
}
$result['csv'] = true;
$columnkeys = array();
......@@ -2995,7 +2995,7 @@ function verifiersummary_stats_table($limit, $offset, $extra, $institution, $url
$data[$i]->date = format_date(strtotime($data[$i]->date), 'strftimew3cdatetime');
}
}
$USER->set_download_file(generate_csv($data, $csvfields, $csvheaders), $institution . 'verifiersummarystatistics.csv', 'text/csv');
$USER->set_download_file(generate_csv($data, $csvfields, $csvheaders), $institution . 'verifiersummarystatistics.csv', 'text/csv', true);
}
$result['csv'] = true;
$columnkeys = array();
......@@ -3160,7 +3160,7 @@ function institution_user_stats_table($limit, $offset, &$institutiondata, $extra
}
if (!empty($extra['csvdownload'])) {
$csvfields = array('date', 'loggedin', 'created', 'total');
$USER->set_download_file(generate_csv($data, $csvfields), $institutiondata['name'] . 'userstatistics.csv', 'text/csv');
$USER->set_download_file(generate_csv($data, $csvfields), $institutiondata['name'] . 'userstatistics.csv', 'text/csv', true);
}
$result['csv'] = true;
......@@ -3548,7 +3548,7 @@ function group_stats_table($limit, $offset, $extra) {
'views' => 'pages',
'groupcomments' => 'group_comments',
'sharedcomments' => 'shared_page_comments');
$USER->set_download_file(generate_csv($groupdata, $csvfields, $csvheaders), 'groupstatistics.csv', 'text/csv');
$USER->set_download_file(generate_csv($groupdata, $csvfields, $csvheaders), 'groupstatistics.csv', 'text/csv', true);
}
$result['csv'] = true;
......@@ -3836,7 +3836,7 @@ function view_stats_table($limit, $offset, $extra) {
if (!empty($extra['csvdownload'])) {
$csvfields = array('displaytitle', 'fullurl', 'collectiontitle','ownername', 'ownerurl',
'ctime', 'mtime', 'atime', 'blocks', 'visits', 'comments');
$USER->set_download_file(generate_csv($viewdata, $csvfields), 'viewstatistics.csv', 'text/csv');
$USER->set_download_file(generate_csv($viewdata, $csvfields), 'viewstatistics.csv', 'text/csv', true);
}
$result['csv'] = true;
$columnkeys = array();
......@@ -4098,7 +4098,7 @@ function institution_view_stats_table($limit, $offset, &$institutiondata, $extra
if (!empty($extra['csvdownload'])) {
$csvfields = array('displaytitle', 'fullurl', 'collectiontitle', 'ownername', 'ownerurl',
'ctime', 'mtime', 'atime', 'blocks', 'visits', 'comments');
$USER->set_download_file(generate_csv($viewdata, $csvfields), $institutiondata['name'] . 'viewstatistics.csv', 'text/csv');
$USER->set_download_file(generate_csv($viewdata, $csvfields), $institutiondata['name'] . 'viewstatistics.csv', 'text/csv', true);
}
$result['csv'] = true;
$columnkeys = array();
......@@ -4353,7 +4353,7 @@ function content_stats_table($limit, $offset, $extra) {
if (!empty($extra['csvdownload'])) {
$csvfields = array('field', 'modified', 'value');
$USER->set_download_file(generate_csv($contentdata, $csvfields), 'contentstatistics.csv', 'text/csv');
$USER->set_download_file(generate_csv($contentdata, $csvfields), 'contentstatistics.csv', 'text/csv', true);
}
$result['csv'] = true;
$columnkeys = array();
......@@ -4515,7 +4515,7 @@ function objectionable_stats_table($limit, $offset, $extra, $institution, $urlli
if (!empty($extra['csvdownload'])) {
$csvfields = array('objectname', 'reporter', 'reportedtime', 'report', 'status');
$USER->set_download_file(generate_csv($data, $csvfields), $institution . 'objectionablestatistics.csv', 'text/csv');
$USER->set_download_file(generate_csv($data, $csvfields), $institution . 'objectionablestatistics.csv', 'text/csv', true);
}
$result['csv'] = true;
$columnkeys = array();
......@@ -4653,7 +4653,7 @@ function institution_content_stats_table($limit, $offset, &$institutiondata, $ex
if (!empty($extra['csvdownload'])) {
$csvfields = array('field', 'modified', 'value');
$USER->set_download_file(generate_csv($contentdata, $csvfields), $institutiondata['name'] . 'contentstatistics.csv', 'text/csv');
$USER->set_download_file(generate_csv($contentdata, $csvfields), $institutiondata['name'] . 'contentstatistics.csv', 'text/csv', true);
}
$result['csv'] = true;
......@@ -4809,7 +4809,7 @@ function masquerading_stats_table($limit, $offset, $extra, $institution, $urllin
if (!empty($extra['csvdownload'])) {
$csvfields = array('user', 'reason', 'masquerader', 'masqueraderurl', 'date');
$USER->set_download_file(generate_csv($data, $csvfields), $institution . 'masqueradingstatistics.csv', 'text/csv');
$USER->set_download_file(generate_csv($data, $csvfields), $institution . 'masqueradingstatistics.csv', 'text/csv', true);
}
$result['csv'] = true;
$columnkeys = array();
......@@ -4987,7 +4987,7 @@ function accesslist_stats_table($limit, $offset, $extra, $institution, $urllink)
if (!empty($extra['csvdownload'])) {
$csvfields = array('displayname', 'userurl', 'title', 'views', 'hasaccessrules');
$USER->set_download_file(generate_csv($data, $csvfields), $institution . 'accessstatistics.csv', 'text/csv');
$USER->set_download_file(generate_csv($data, $csvfields), $institution . 'accessstatistics.csv', 'text/csv', true);
}
$result['csv'] = true;
$columnkeys = array();
......@@ -5167,7 +5167,7 @@ function institution_comparison_stats_table($limit, $offset, $extra, $urllink) {
}
if (!empty($extra['csvdownload'])) {
$csvfields = array('name', 'count_members', 'count_views', 'count_blocks', 'count_artefacts', 'count_interaction_forum_post');
$USER->set_download_file(generate_csv($registrationdata, $csvfields), 'institutionstatistics.csv', 'text/csv');
$USER->set_download_file(generate_csv($registrationdata, $csvfields), 'institutionstatistics.csv', 'text/csv', true);
}
$result['csv'] = true;
$columnkeys = array();
......@@ -5368,7 +5368,7 @@ function institution_logins_stats_table($limit, $offset, $extra) {
if (!empty($extra['csvdownload'])) {
$csvfields = array('name', 'displayname', 'count_logins', 'count_active');
$USER->set_download_file(generate_csv($rawdata, $csvfields), 'userloginstatistics.csv', 'text/csv');
$USER->set_download_file(generate_csv($rawdata, $csvfields), 'userloginstatistics.csv', 'text/csv', true);
}
$result['csv'] = true;
$columnkeys = array();
......@@ -6380,7 +6380,7 @@ function assessment_statistics_table($limit, $offset, $extra, $institution, $url
if (!empty($extra['csvdownload'])) {
$csvfields = array('type', 'viewname', 'owner', 'groupname', 'submitted', 'released', 'marker');
$USER->set_download_file(generate_csv($data, $csvfields), $institution . 'assessmentstatistics.csv', 'text/csv');
$USER->set_download_file(generate_csv($data, $csvfields), $institution . 'assessmentstatistics.csv', 'text/csv', true);
}
$result['csv'] = true;
$columnkeys = array();
......
......@@ -164,7 +164,7 @@ These list must take into account the sort option chosen in the block config (Bu
Given I log in as "UserB" with password "Kupuh1pa!"
And I should see "GroupA"
And I choose "Groups" in "Engage" from main menu
And I scroll to the base of id "findgroups"
And I scroll to the center of id "findgroups"
And I follow "GroupA"
And I select "Page UserB_01" from "group_view_submission_form_1_options"
And I press "Submit"
......@@ -203,7 +203,7 @@ These list must take into account the sort option chosen in the block config (Bu
And I should see "Pages and collections | GroupA"
# Check if it is now in the first page of the list of group pages
And I choose "Groups" in "Engage" from main menu
And I scroll to the base of id "findgroups"
And I scroll to the center of id "findgroups"
And I follow "GroupA"
And I should see "Page GroupA_06" in the "Group portfolios" "Groups" property
#And I follow "Next" in the "div#groupviews_pagination" "css_element"
......@@ -211,6 +211,7 @@ These list must take into account the sort option chosen in the block config (Bu
And I should not see "Page GroupA_06" in the "Group portfolios" "Groups" property
# Update the shared page "Page UserA_01"
And I choose "Pages and collections" in "Create" from main menu
And I scroll to the base of id "showmorebtn"
And I click on "Edit" in "Page UserA_01" card menu
And I follow "Settings" in the "Toolbar buttons" "Nav" property
And I set the field "Page description" to "<p>Page 01 (updated)</p>"
......@@ -219,7 +220,7 @@ These list must take into account the sort option chosen in the block config (Bu
And I display the page
# Check if it is now in the first page of the list of shared pages
And I choose "Groups" in "Engage" from main menu
And I scroll to the base of id "findgroups"
And I scroll to the center of id "findgroups"
And I follow "GroupA"
And I should see "Page UserA_01" in the "Pages shared with this group" "Groups" property
#And I follow "2" in the "div#sharedviews_pagination" "css_element"
......@@ -233,7 +234,7 @@ These list must take into account the sort option chosen in the block config (Bu
And I press "Save"
# Check if it is now in the first page of the list of shared collections
And I choose "Groups" in "Engage" from main menu
And I scroll to the base of id "findgroups"
And I scroll to the center of id "findgroups"
And I follow "GroupA"
And I should see "Collection UserA_06" in the "Collections shared with this group" "Groups" property
#And I follow "2" in the "div#sharedcollections_pagination" "css_element"
......@@ -301,7 +302,7 @@ These list must take into account the sort option chosen in the block config (Bu
And I press "Submit"
And I press "Yes"
And I choose "Groups" in "Engage" from main menu
And I scroll to the base of id "findgroups"
And I scroll to the center of id "findgroups"
And I follow "GroupA"
And I select "Page UserC_04" from "group_view_submission_form_1_options"
And I press "Submit"
......@@ -377,7 +378,7 @@ These list must take into account the sort option chosen in the block config (Bu
And I press "Submit"
And I press "Yes"
And I choose "Groups" in "Engage" from main menu
And I scroll to the base of id "findgroups"
And I scroll to the center of id "findgroups"
And I follow "GroupA"
And I select "Page UserC_12" from "group_view_submission_form_1_options"
And I press "Submit"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment