Commit 0307a929 authored by Robert Lyon's avatar Robert Lyon

Bug 1826284: Allow more info to be displayed

To help with working out where a bulkexport to pdf fails
Also not show the 'acctivation' button on plugins page if not all
required dependencies are met

behatnotneeded

Change-Id: Ia9940d4a981cb9b4e1c46cc0fb8e84d40a5896cf
Signed-off-by: Robert Lyon's avatarRobert Lyon <robertl@catalyst.net.nz>
parent d761c4f5
......@@ -123,7 +123,7 @@ $optionform = pieform(array(
'allowarchives' => array(
'type' => 'switchbox',
'title' => get_string('allowsarchives', 'group'),
'description' => get_string('allowsarchivesdescription', 'group'),
'description' => get_string('allowsarchivesdescription1', 'group'),
'defaultvalue' => $group_data->allowarchives,
'disabled' => !$group_data->submittableto,
),
......
......@@ -330,7 +330,7 @@ $siteoptionform = array(
'exporttoqueue' => array(
'type' => 'switchbox',
'title' => get_string('exporttoqueue', 'admin'),
'description' => get_string('exporttoqueuedescription2', 'admin'),
'description' => get_string('exporttoqueuedescription3', 'admin'),
'defaultvalue' => get_config('exporttoqueue'),
'disabled' => in_array('exporttoqueue', $OVERRIDDEN),
),
......
......@@ -116,14 +116,25 @@ function bulkexport_submit(Pieform $form, $values) {
$usernames = array();
// Read in the usernames explicitly specified
foreach (explode("\n", $values['usernames']) as $username) {
$username = trim($username);
if (!empty($username)) {
$usernames[] = $username;
if (!empty($values['usernames'])) {
foreach (explode("\n", $values['usernames']) as $username) {
$username = trim($username);
if (!empty($username) && record_exists('usr', 'username', $username)) {
$usernames[] = $username;
}
else {
log_debug(get_string('ignoringbulkexportuser', 'admin', $username));
}
}
if (empty($usernames)) {
// All explicit usernames were rejected
require_once(get_config('docroot') . '/lib/htmloutput.php');
print_export_iframe_die(get_string('bulkexportempty', 'admin'), null);
}
}
if (empty($usernames) && !empty($values['authinstance'])) {
if (empty($values['usernames']) && !empty($values['authinstance'])) {
// Export all users from the selected institution
$usernames = get_column_sql("SELECT username FROM {usr} WHERE authinstance = ? AND deleted = 0 AND id != 0", array($values['authinstance']));
}
......@@ -188,8 +199,8 @@ function bulkexport_submit(Pieform $form, $values) {
}
if (!$zipfile = create_zipfile($listing, $files)) {
include_once(get_config('wwwroot') . 'export/download.php');
export_iframe_die(get_string('bulkexportempty', 'admin'));
require_once(get_config('docroot') . '/lib/htmloutput.php');
print_export_iframe_die(get_string('bulkexportempty', 'admin'), null);
}
log_info("Exported $exportcount users to $zipfile");
......
......@@ -126,6 +126,9 @@ class PluginBlocktypeGallery extends MaharaCoreBlocktype {
$firstdone = false;
foreach ($artefactids as $artefactid) {
$artefact = $instance->get_artefact_instance($artefactid);
if ($artefact->get('artefacttype') == 'folder') {
continue;
}
if (!file_exists($artefact->get_path())) {
continue;
}
......
......@@ -439,9 +439,6 @@ class PluginExportHtml extends PluginExport {
array('text' => $view->get('title'), 'path' => 'index.html'),
));
$directory = $this->exportdir . '/' . $this->rootdir . '/views/' . $view->get('id') . '_' . self::text_to_filename($view->get('title'));
if (is_dir($directory)) {
throw new SystemException(get_string('duplicatepagetitle', 'export.html'));
}
if (!check_dir_exists($directory)) {
throw new SystemException("Could not create directory for view $viewid");
}
......@@ -689,15 +686,17 @@ class PluginExportHtml extends PluginExport {
*/
private function get_resume_field_modals(&$idarray, BlockInstance $bi) {
$configdata = $bi->get('configdata');
$field = $bi->get_artefact_instance($configdata['artefactid']);
$attachmentids = array();
if ($attachment = $field->get_attachments()) {
foreach ($attachment as $a) {
array_push($attachmentids, $a->{'id'});
if (isset($configdata['artefactid'])) {
$field = $bi->get_artefact_instance($configdata['artefactid']);
$attachmentids = array();
if ($attachment = $field->get_attachments()) {
foreach ($attachment as $a) {
array_push($attachmentids, $a->{'id'});
}
}
if (!empty($attachmentids)) {
$idarray = array_merge($idarray, $attachmentids);
}
}
if (!empty($attachmentids)) {
$idarray = array_merge($idarray, $attachmentids);
}
}
......
......@@ -534,7 +534,7 @@ function export_add_to_queue($object, $external = null, $submitter = null, $type
else {
$queue->usr = $queue->submitter;
}
$queue->exporttype = 'leap';
$queue->exporttype = 'all';
if (!empty($type)) {
$queue->type = $type;
}
......@@ -647,7 +647,9 @@ function export_process_queue($id = false) {
continue;
}
safe_require('export', $row->exporttype);
if ($row->exporttype != 'all') {
safe_require('export', $row->exporttype);
}
$user = new User();
$user->find_by_id($row->usr);
$class = generate_class_name('export', $row->exporttype);
......@@ -667,7 +669,14 @@ function export_process_queue($id = false) {
log_warn(get_string('unabletoexportportfoliousingoptionsadmin', 'export'));
}
$exporter->includefeedback = false; // currently only doing leap2a exports and they can't handle feedback
if ($row->exporttype == 'leap') {
$exporter->includefeedback = false; // currently only doing leap2a exports and they can't handle feedback
$createarchive = true;
}
else {
$exporter->includefeedback = true;
$createarchive = false;
}
// Get an estimate of how big the unzipped export file would be
// so we can check that we have enough disk space for it
......@@ -678,8 +687,7 @@ function export_process_queue($id = false) {
}
try {
$exporter->export();
$zipfile = $exporter->export_compress();
$zipfile = $exporter->export($createarchive);
}
catch (SystemException $e) {
$errors[] = get_string('exportzipfileerror', 'export', $e->getMessage());
......@@ -779,12 +787,12 @@ function export_process_queue($id = false) {
'message' => false,
'strings' => (object) array(
'subject' => (object) array(
'key' => 'exportdownloademailsubject',
'key' => 'exportdownloademailsubject1',
'section' => 'admin',
'args' => array($filetitle),
),
'message' => (object) array(
'key' => 'exportdownloademailmessage',
'key' => 'exportdownloademailmessage1',
'section' => 'admin',
'args' => array(hsc($arg), $filetitle),
),
......@@ -954,6 +962,7 @@ class PluginExportAll extends PluginExport {
$this->leapexporter = new PluginExportLeap($user, $views, $artefacts, $progresscallback);
$this->pdfactive = get_field('export_installed', 'active', 'name', 'pdf');
if ($this->pdfactive) {
safe_require('export', 'pdf');
$this->pdfexporter = new PluginExportPdf($user, $views, $artefacts, $progresscallback);
}
$this->exportdir = $this->htmlexporter->get('exportdir');
......@@ -977,13 +986,6 @@ class PluginExportAll extends PluginExport {
$this->htmlexporter->includefeedback = $this->includefeedback;
$this->leapexporter->includefeedback = $this->includefeedback;
$this->notify_progress_callback(0, get_string('startinghtmlexport', 'export'));
try {
$html = $this->htmlexporter->export();
}
catch (SystemException $e) {
throw new SystemException('Failed create html export: ' . $e->getMessage());
}
if ($this->pdfactive) {
$this->notify_progress_callback(0, get_string('startingpdfexport', 'export'));
try {
......@@ -993,6 +995,13 @@ class PluginExportAll extends PluginExport {
throw new SystemException('Failed create pdf export: ' . $e->getMessage());
}
}
$this->notify_progress_callback(0, get_string('startinghtmlexport', 'export'));
try {
$html = $this->htmlexporter->export();
}
catch (SystemException $e) {
throw new SystemException('Failed create html export: ' . $e->getMessage());
}
$this->notify_progress_callback(0, get_string('startingleapexport', 'export'));
try {
$leap = $this->leapexporter->export();
......
......@@ -79,6 +79,14 @@ class PluginExportPdf extends PluginExportHtml {
return $combiner;
}
public static function is_usable() {
$dependencies = self::has_plugin_dependencies();
if (!empty($dependencies['requires'])) {
return false;
}
return true;
}
public static function has_plugin_dependencies() {
$needs = get_string('needschromeheadless', 'export.pdf');
// make sure that composer has installed the headlessbrowser hook
......@@ -102,12 +110,10 @@ class PluginExportPdf extends PluginExportHtml {
* Main export routine
* @param $createarchive Boolean specifies whether a zipfile will be created here
* or later on, i.e. in PluginExportAll which creates a zipfile of all export formats.
* Note: If running pdf export and html export together then this should be run first
*/
public function export($createarchive=false) {
// Only call parent if we do not do pdf export after html export
if ($createarchive) {
parent::export($createarchive);
}
parent::export($createarchive);
$this->pdf_view_export_data();
return true;
}
......@@ -125,17 +131,17 @@ class PluginExportPdf extends PluginExportHtml {
$i = 0;
$viewcount = count($this->views);
$browsertype = 'chromium-browser';
system('dpkg -l | grep ' . $browsertype, $error);
if ($error) {
$browsertype = 'chrome';
system('dpkg -l | grep ' . $browsertype, $error2);
if ($error2) {
throw new MaharaException('Need to have a Chrome browser installed to use the headless pdf option');
if (!isset($pdfrun) || $pdfrun == 'first' || $pdfrun == 'all') {
$browsertype = 'chromium-browser';
system('dpkg -l | grep ' . $browsertype, $error);
if ($error) {
$browsertype = 'chrome';
system('dpkg -l | grep ' . $browsertype, $error2);
if ($error2) {
throw new MaharaException('Need to have a Chrome browser installed to use the headless pdf option');
}
}
}
if (!isset($pdfrun) || $pdfrun == 'first' || $pdfrun == 'all') {
$browserFactory = new BrowserFactory($browsertype);
// starts headless chrome
$browser = $browserFactory->createBrowser(['windowSize' => [1280,800],
......@@ -170,13 +176,14 @@ class PluginExportPdf extends PluginExportHtml {
$colpdfs = $viewpdfs = array();
foreach ($viewobjs as $collectionid => $views) {
foreach ($views as $viewid => $view) {
set_time_limit(120);
$this->notify_progress_callback(intval($progressstart + (++$i / $viewcount) * ($progressend - $progressstart)), get_string('exportingviewsprogresspdf', 'export', $i, $viewcount));
if ($this->exportingoneview) {
$directory = $this->exportdir . '/' . $this->rootdir;
}
else {
$directory = $this->exportdir . '/' . $this->rootdir . '/views/' . parent::text_to_filename($view->get('title'));
$directory = $this->exportdir . '/' . $this->rootdir . '/views/' . $view->get('id') . '_' . parent::text_to_filename($view->get('title'));
}
$filename = $directory . "/index.html";
// Adjust the relative links to files to be textual to mention where the file lives within the zip file
......
......@@ -261,7 +261,7 @@ if ($cancreatecontrolled) {
$elements['allowarchives'] = array(
'type' => 'switchbox',
'title' => get_string('allowsarchives', 'group'),
'description' => get_string('allowsarchivesdescription', 'group'),
'description' => get_string('allowsarchivesdescription1', 'group'),
'defaultvalue' => $group_data->allowarchives,
'disabled' => !$group_data->submittableto,
'help' => true,
......
......@@ -927,8 +927,8 @@ $string['exportqueuearchived'] = array(
);
$string['exportdataascsv'] = 'Export all data in CSV format';
$string['nocsvresults'] = 'No results found for CSV file';
$string['exportdownloademailsubject'] = 'Your Leap2A export for "%s" is ready for download';
$string['exportdownloademailmessage'] = '%s, your Leap2A export for "%s" is ready for download. This file will only be available for up to 24 hours after it was generated. Please follow the link below to download the file:';
$string['exportdownloademailsubject1'] = 'Your export for "%s" is ready for download';
$string['exportdownloademailmessage1'] = '%s, your export for "%s" is ready for download. This file will only be available for up to 24 hours after it was generated. Please follow the link below to download the file:';
$string['exportdownloadurl'] = 'Download exported file';
// Add User
......@@ -1179,7 +1179,7 @@ $string['unsuspendinstitutiondescription'] = 'Here you may unsuspend an institut
$string['unsuspendinstitutiondescription_warning'] = '<em>Beware:</em> Unsuspending an institution without resetting or turning off its expiry date may result in a daily re-suspension.';
$string['unsuspendinstitutiondescription_instadmin'] = 'People of suspended institutions cannot log in. Contact the site administrator to unsuspend the institution.';
// Bulk Leap2A User export
// Bulk User export
$string['bulkexport'] = 'Export accounts';
$string['bulkexportempty'] = 'Nothing suitable to export. Please double-check the list of usernames.';
$string['bulkexportinstitution'] = 'The institution from which all members should be exported';
......@@ -1189,6 +1189,7 @@ $string['bulkexportusernames'] = 'Usernames to export';
$string['bulkexportusernamesdescription'] = 'A list of the accounts (one username per line) to be exported along with their data.';
$string['couldnotexportusers'] = 'The following account(s) could not be exported: %s';
$string['exportingusername'] = 'Exporting \'%s\'...';
$string['ignoringbulkexportuser'] = 'Person with username "%s" not found, so ignored';
// Admin User Search
$string['Search'] = 'Search';
......@@ -1332,7 +1333,7 @@ $string['profilecompletenessdesc1'] = 'The profile completion allows people to h
$string['profilecompletenesspreview'] = 'You can preview what the profile completion looks like in the "Profile completion preview" side block.';
$string['exporttoqueue'] = 'Export to queue';
$string['exporttoqueuedescription2'] = 'Let the export queue handle the exporting of portfolios via Leap2A for better server load management.';
$string['exporttoqueuedescription3'] = 'Let the export queue handle the exporting of portfolios for better server load management.';
// Progress meter (ie uploading / downloading data)
$string['validating'] = 'Validating data...';
......
......@@ -396,7 +396,7 @@ $string['allowssubmissionsdescription1'] = "Members can submit pages to the grou
$string['allowssubmissionsdescription'] = 'Members can submit pages to the group.';
$string['allowsarchives'] = 'Allow archiving of submissions';
$string['allowsarchiveserror'] = 'You can only allow archiving if submissions are allowed.';
$string['allowsarchivesdescription'] = 'Pages / collections are archived as zipped Leap2A files during the submission release process.';
$string['allowsarchivesdescription1'] = 'Pages / collections are archived as zipped files during the submission release process.';
// Group reports
$string['report'] = 'Report';
......
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