Skip to content

Commit

Permalink
pkp#110 add createGally support
Browse files Browse the repository at this point in the history
  • Loading branch information
withanage committed Sep 7, 2022
1 parent 6209c8c commit 8d4cf6b
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 60 deletions.
10 changes: 5 additions & 5 deletions TexturePlugin.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public function callbackLoadHandler($hookName, $args) {
case 'texture/media':
define('HANDLER_CLASS', 'TextureHandler');
define('TEXTURE_PLUGIN_NAME', $this->getName());
$args[2] = $this->getPluginPath() . '/' . 'TextureHandler.inc.php';
$args[2] = $this->getPluginPath() .DIRECTORY_SEPARATOR.'controllers'.DIRECTORY_SEPARATOR. 'TextureHandler.inc.php';
break;
}

Expand Down Expand Up @@ -137,12 +137,12 @@ public function templateFetchCallback($hookName, $params) {
if (strtolower($fileExtension) == 'text/xml') {
import('lib.pkp.classes.linkAction.request.OpenWindowAction');
$this->_editWithTextureAction($row, $dispatcher, $request, $submissionFile, $stageId);
//$this->_createGalleyAction($row, $dispatcher, $request, $submissionFile, $stageId, $fileStage);
//$this->_exportAction($row, $dispatcher, $request, $submissionFile, $stageId, $fileStage);
$this->_createGalleyAction($row, $dispatcher, $request, $submissionFile, $stageId, $fileStage);
#$this->_exportAction($row, $dispatcher, $request, $submissionFile, $stageId, $fileStage);
} elseif (strtolower($fileExtension) == TEXTURE_DAR_FILE_TYPE) {
$this->_extractAction($row, $dispatcher, $request, $submissionFile, $stageId, $fileStage, TEXTURE_DAR_FILE_TYPE);
// $this->_extractAction($row, $dispatcher, $request, $submissionFile, $stageId, $fileStage, TEXTURE_DAR_FILE_TYPE);
} elseif (strtolower($fileExtension) == TEXTURE_ZIP_FILE_TYPE) {
$this->_extractAction($row, $dispatcher, $request, $submissionFile, $stageId, $fileStage, TEXTURE_ZIP_FILE_TYPE);
// $this->_extractAction($row, $dispatcher, $request, $submissionFile, $stageId, $fileStage, TEXTURE_ZIP_FILE_TYPE);
} elseif (strtolower($fileExtension) == TEXTURE_HTML_FILE_TYPE) {
import('lib.pkp.classes.linkAction.request.OpenWindowAction');
$this->_createGalleyAction($row, $dispatcher, $request, $submissionFile, $stageId, $fileStage);
Expand Down
12 changes: 8 additions & 4 deletions TextureHandler.inc.php → controllers/TextureHandler.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public function extract($args, $request) {
$user = $request->getUser();
$zipType = $request->getUserVar("zipType");
$submissionFile = $this->getAuthorizedContextObject(ASSOC_TYPE_SUBMISSION_FILE);
$archivePath = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'texture-' . $zipType . '-archive' . mt_rand();
$archivePath = TextureHandler . inc . 'texture-' . $zipType . '-archive' . mt_rand();
$image_types = array('gif', 'jpg', 'jpeg', 'png', 'jpe');
$html_types = array('html');

Expand All @@ -110,7 +110,7 @@ public function extract($args, $request) {
$genreDAO = DAORegistry::getDAO('GenreDAO');
$genre = $genreDAO->getByKey('SUBMISSION', $submission->getData('contextId'));
$fileStage = $submissionFile->getFileStage();
$sourceFileId = $submissionFile->getData('submissionFileId');
$sourceFileId = $submissionFile->getData('fileId');
if ($zipType == TEXTURE_DAR_FILE_TYPE) {
$manifestFileDom = new DOMDocument();
$darManifestFilePath = $archivePath . DIRECTORY_SEPARATOR . DAR_MANIFEST_FILE;
Expand Down Expand Up @@ -559,7 +559,7 @@ public function json($args, $request) {


} elseif (!empty($resources) && isset($resources[DAR_MANUSCRIPT_FILE]) && is_object($resources[DAR_MANUSCRIPT_FILE])) {
$this->_updateManuscriptFile($request, $resources, $submission, $submissionFile);
$this->updateManuscriptFile($request, $resources, $submission, $submissionFile);
} else {
return new JSONMessage(false);
}
Expand All @@ -579,7 +579,7 @@ public function json($args, $request) {
* @param $submissionFile SubmissionFile
* @return SubmissionFile
*/
protected function _updateManuscriptFile($request, $resources, $submission, $submissionFile) {
protected function updateManuscriptFile($request, $resources, $submission, $submissionFile) {

$modifiedDocument = new DOMDocument('1.0', 'utf-8');
$modifiedData = $resources[DAR_MANUSCRIPT_FILE]->data;
Expand All @@ -593,6 +593,10 @@ protected function _updateManuscriptFile($request, $resources, $submission, $sub
$origDocument = new DOMDocument('1.0', 'utf-8');
$origDocument->loadXML($manuscriptXml);


# add license


$body = $origDocument->documentElement->getElementsByTagName('body')->item(0);
$origDocument->documentElement->removeChild($body);

Expand Down
133 changes: 82 additions & 51 deletions controllers/grid/form/TextureArticleGalleyForm.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@

import('lib.pkp.classes.form.Form');

class TextureArticleGalleyForm extends Form {
class TextureArticleGalleyForm extends Form
{
/** @var the $_submission */
var $_submission = null;

Expand All @@ -31,7 +32,8 @@ class TextureArticleGalleyForm extends Form {
* @param $publication
* @param $submission Submission
*/
function __construct($request, $plugin, $publication, $submission) {
function __construct($request, $plugin, $publication, $submission)
{
$this->_submission = $submission;
$this->_publication = $publication;

Expand All @@ -52,9 +54,7 @@ function __construct($request, $plugin, $publication, $submission) {
'required',
'editor.issues.galleyLocaleRequired'
),
function ($galleyLocale) use ($journal) {
return in_array($galleyLocale, $journal->getSupportedSubmissionLocaleNames());
}

);
}

Expand All @@ -63,7 +63,8 @@ function ($galleyLocale) use ($journal) {
* @param $request
* @return string
*/
function fetch($request, $template = null, $display = false) {
function fetch($request, $template = null, $display = false)
{
$journal = $request->getJournal();
$templateMgr = TemplateManager::getManager($request);

Expand All @@ -83,7 +84,8 @@ function fetch($request, $template = null, $display = false) {
/**
* Assign form data to user-submitted data.
*/
function readInputData() {
function readInputData()
{
$this->readUserVars(
array(
'label',
Expand All @@ -98,69 +100,98 @@ function readInputData() {
* Create article galley and dependent files
* @return ArticleGalley The resulting article galley.
*/
function execute(...$functionArgs) {
function execute(...$functionArgs)
{
$request = Application::get()->getRequest();
$locale = AppLocale::getLocale();

$sourceFile = Services::get('submissionFile')->get($this->getData('submissionFileId'));

$submissionDir = Services::get('submissionFile')->getSubmissionDir($this->getSubmission()->getData('contextId'), $this->getSubmission()->getId());
$files_dir = Config::getVar('files', 'files_dir') . DIRECTORY_SEPARATOR;
$newFileId = Services::get('file')->add(
$files_dir . $sourceFile->getData('path'),
$files_dir . $submissionDir . DIRECTORY_SEPARATOR . uniqid() . '.xml'
);

$submissionFileDao = DAORegistry::getDAO('SubmissionFileDAO');
$newSubmissionFile = $submissionFileDao->newDataObject();

$newSubmissionFile->setAllData(
[
'fileId' => $newFileId,
'assocType' => $sourceFile->getData('assocType'),
'assocId' => $sourceFile->getData('assocId'),
'fileStage' => SUBMISSION_FILE_PROOF,
'mimetype' => $sourceFile->getData('mimetype'),
'locale' => $sourceFile->getData('locale'),
'genreId' => $sourceFile->getData('genreId'),
'name' => $sourceFile->getLocalizedData('name'),
'submissionId' => $this->getSubmission()->getId()
]
);

$context = Application::getRequest()->getJournal();
$submissionId = $this->_submission->getId();

$newSubmissionFile = Services::get('submissionFile')->add($newSubmissionFile, $request);

// Associate XML file into galley
// Create new galley
$articleGalleyDao = DAORegistry::getDAO('ArticleGalleyDAO');
$articleGalley = $articleGalleyDao->newDataObject();
$articleGalley->setData('publicationId', $this->_publication->getId());
$articleGalley->setLabel($this->getData('label'));
$articleGalley->setLocale($this->getData('galleyLocale'));
$newGalleyId = $articleGalleyDao->insertObject($articleGalley);
$articleGalley->setFileId($newSubmissionFile->getData('id'));

$submissionFileDao = DAORegistry::getDAO('SubmissionFileDAO');
$fileStage = $this->getData('fileStage');
$submissionFile = $submissionFileDao->getLatestRevision( $this->getData('submissionFileId'), $fileStage, $submissionId);

// Create galley XML file from the production XML source file
import('lib.pkp.classes.file.SubmissionFileManager');
$submissionFileManager = new SubmissionFileManager($context->getId(), $submissionFile);
$fileId = $submissionFile->getData('submissionFileId');
$revision = $submissionFile->getRevision();
$genreDAO = DAORegistry::getDAO('GenreDAO');
$genre = $genreDAO->getByKey('SUBMISSION', $this->_submission->getData('contextId'));


list($newFileId, $newRevision) = $submissionFileManager->copyFileToFileStage($fileId, $revision, $fileStage, null, true);
$newSubmissionFile = $submissionFileDao->getLatestRevision($newFileId, $fileStage, $submissionId);
$newSubmissionFile->setAssocType(ASSOC_TYPE_REPRESENTATION);
$newSubmissionFile->setAssocId($newGalleyId);
$newSubmissionFile->setGenreId($genre->getId());
$newSubmissionFile->setFileStage(SUBMISSION_FILE_PROOF);
$submissionFileDao->updateObject($newSubmissionFile);
Services::get('galley')->add($articleGalley, $request);

// Associate XML file into galley
if ($articleGalley) {
$articleGalley->setFileId($newSubmissionFile->getFileId());
$articleGalleyDao->updateObject($articleGalley);
}

// Get dependent files of the XML source file
$dependentFiles = $submissionFileDao->getLatestRevisionsByAssocId(
ASSOC_TYPE_SUBMISSION_FILE,
$submissionFile->getData('submissionFileId'),
$submissionFile->getData(),
SUBMISSION_FILE_DEPENDENT
);

// Copy dependent files to the galley XML file
$dependentFiles = Services::get('submissionFile')->getMany([
'assocTypes' => [ASSOC_TYPE_SUBMISSION_FILE],
'assocIds' => [$sourceFile->getData('id')],
'submissionIds' => [$this->getSubmission()->getId()],
'fileStages' => [SUBMISSION_FILE_DEPENDENT],
'includeDependentFiles' => true,
]);


foreach ($dependentFiles as $dependentFile) {
$dependentFileId = $dependentFile->getFileId();
$dependentFileRevision = $dependentFile->getRevision();
$dependentFileStage = $dependentFile->getFileStage();

list($newDependentFileId, $newDependentFileRevision) = $submissionFileManager->copyFileToFileStage($dependentFileId, $dependentFileRevision, $dependentFileStage, null, true);
$newDependentFile = $submissionFileDao->getLatestRevision($newDependentFileId, SUBMISSION_FILE_DEPENDENT, $submissionId);
$newDependentFile->setAssocId($newFileId);
$submissionFileDao->updateObject($newDependentFile);

$newDependentFileId = Services::get('file')->add(
$files_dir . $dependentFile->getData('path'),
$files_dir . $submissionDir . DIRECTORY_SEPARATOR . uniqid() . '.xml'
);

$newDependentFile = $submissionFileDao->newDataObject();

$newDependentFile->setAllData(
[
'fileId' => $newDependentFileId,
'assocType' => $dependentFile->getData('assocType'),
'assocId' => $newSubmissionFile->getData('id'),
'fileStage' => SUBMISSION_FILE_DEPENDENT,
'mimetype' => $dependentFile->getData('mimetype'),
'locale' => $dependentFile->getData('locale'),
'genreId' => $dependentFile->getData('genreId'),
'name' => $dependentFile->getLocalizedData('name'),
'submissionId' => $this->getSubmission()->getId()
]
);

Services::get('submissionFile')->add($newDependentFile, $request);

}

return $articleGalley;
}

function getSubmission()
{
return $this->_submission;
}


}

Expand Down

0 comments on commit 8d4cf6b

Please sign in to comment.