Skip to content

Add serialization mode for the Native XML import. Needed for issue #9769 #11315

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: stable-3_3_0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions plugins/importexport/native/filter/NativeExportFilter.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@

class NativeExportFilter extends NativeImportExportFilter {

const SERIALIZATION_MODE_RELATIVE_PATH = 'relative';
const SERIALIZATION_MODE_EMBED = 'embed';
const SERIALIZATION_MODE_URL = 'url';

/** @var boolean If set to true no validation (e.g. XML validation) will be done */
var $_noValidation = null;
var $opts = array();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,12 @@ function createSubmissionFileNode($doc, $submissionFile) {
$revisionNode->setAttribute('filesize', filesize($localPath));
$revisionNode->setAttribute('extension', pathinfo($revision->path, PATHINFO_EXTENSION));

if (array_key_exists('no-embed', $this->opts)) {
$hrefNode = $doc->createElementNS($deployment->getNamespace(), 'href');
if (array_key_exists('use-file-urls', $this->opts)) {
if (isset($this->opts['serializationMode'])) {
if ($this->opts['serializationMode'] == NativeExportFilter::SERIALIZATION_MODE_EMBED) {
$embedNode = $doc->createElementNS($deployment->getNamespace(), 'embed', base64_encode(file_get_contents($localPath)));
$embedNode->setAttribute('encoding', 'base64');
$revisionNode->appendChild($embedNode);
} else {
$stageId = Services::get('submissionFile')->getWorkflowStageId($submissionFile);
$dispatcher = Application::get()->getDispatcher();
$request = Application::get()->getRequest();
Expand All @@ -178,17 +181,44 @@ function createSubmissionFileNode($doc, $submissionFile) {
"stageId" => $stageId,
"fileId" => $revision->fileId,
];
$url = $dispatcher->url($request, ROUTE_COMPONENT, $context->getPath(), "api.file.FileApiHandler", "downloadFile", null, $params);
$hrefNode->setAttribute('src', $url);
} else {
$hrefNode->setAttribute('src', $revision->path);

$url = ($this->opts['serializationMode'] == NativeExportFilter::SERIALIZATION_MODE_RELATIVE_PATH)
? $dispatcher->url($request, ROUTE_COMPONENT, $context->getPath(), "api.file.FileApiHandler", "downloadFile", null, $params, null, true)
: $dispatcher->url($request, ROUTE_COMPONENT, $context->getPath(), "api.file.FileApiHandler", "downloadFile", null, $params);

$hrefNode = $doc->createElementNS($deployment->getNamespace(), 'href');
$hrefNode->setAttribute('src', htmlspecialchars($url, ENT_COMPAT, 'UTF-8'));
$hrefNode->setAttribute('mime_type', $revision->mimetype);
$revisionNode->appendChild($hrefNode);
}
$hrefNode->setAttribute('mime_type', $revision->mimetype);
$revisionNode->appendChild($hrefNode);
} else {
$embedNode = $doc->createElementNS($deployment->getNamespace(), 'embed', base64_encode(file_get_contents($localPath)));
$embedNode->setAttribute('encoding', 'base64');
$revisionNode->appendChild($embedNode);
// Make this default behavior if no serialization mode is set
if (!empty($this->opts['use-file-urls'])) {
$stageId = Services::get('submissionFile')->getWorkflowStageId($submissionFile);
$dispatcher = Application::get()->getDispatcher();
$request = Application::get()->getRequest();
$params = [
"submissionFileId" => $submissionFile->getId(),
"submissionId" => $submissionFile->getData('submissionId'),
"stageId" => $stageId,
"fileId" => $revision->fileId,
];

if (!empty($this->opts['use-absolute-urls'])) {
$url = $dispatcher->url($request, ROUTE_COMPONENT, $context->getPath(), "api.file.FileApiHandler", "downloadFile", null, $params);
} else {
$url = $dispatcher->url($request, ROUTE_COMPONENT, $context->getPath(), "api.file.FileApiHandler", "downloadFile", null, $params, null, true);
}

$hrefNode = $doc->createElementNS($deployment->getNamespace(), 'href');
$hrefNode->setAttribute('src', htmlspecialchars($url, ENT_COMPAT, 'UTF-8'));
$hrefNode->setAttribute('mime_type', $revision->mimetype);
$revisionNode->appendChild($hrefNode);
} else if (empty($this->opts['no-embed'])) {
$embedNode = $doc->createElementNS($deployment->getNamespace(), 'embed', base64_encode(file_get_contents($localPath)));
$embedNode->setAttribute('encoding', 'base64');
$revisionNode->appendChild($embedNode);
}
}

$submissionFileNode->appendChild($revisionNode);
Expand Down