Set file to create galley by plugin

Hi to all members,

I am developing a plugin and would like to create a galley after finishing step ‘3. Enter Metadata’ in the submission process. For this I use the hook ‘Publication::edit’ and have already found a way to store a galley in the database. Here is the code I currently use:

$articleGalleyDAO = DAORegistry::getDAO('ArticleGalleyDAO');
$galley = $articleGalleyDAO->newDataObject();

$galley->setData('submissionFileId', 4); 
$galley->setData('publicationId', $id);
$galley->setData('submission_file_id', 'test');
$galley->setData('urlPath', 'testId' . $testId);

This works fine, but now I want to add an html file that will be displayed in the galley. Is there a function or another way to add a file via the code? So a file should be set e.g. a html which is then displayed in the galley like in the picture below. The file is to be loaded from a path on the PC and set accordingly in the database so that the ‘submission_filde_id’ field in the ‘publications_galleys’ table is filled. I am very glad about any help!

Bildschirmfoto 2021-04-15 um 12.59.52

Hi @tnier01,

Curious what specific version you’re testing your plugin with? If you haven’t checked it out already, our plugin development guide might come in handy as well.

Best regards,

PKP Team

Hi @rcgillis,

I’m testing my plugin currently with OJS in version Yes I have looked at the plugin guide but unfortunately I have not found a solution to the above mentioned issue with it.

Best regards

Hi @tnier01,

OJS 3.4 doesn’t exist yet - the latest version (as of last week) is 3.3.0-5. Can you check your version number again, please?

PKP Team

Hi @rcgillis I just forked the main branch of the ojs repository 23 days ago (GitHub - tnier01/ojs: Open Journal Systems) and am using this as my current OJS version. Here is also a screenshot of my system information:

Bildschirmfoto 2021-04-16 um 13.04.06

Best regards

Hi @tnier01, that’s great! The main branch can go through some unstable periods, and is just about to go through one now, because we’re in the early dev cycle of the next major version. You may find it frustrating to work on the branch but you’re welcome to do so. :+1: (There are stable-3_3_0 and stable-3_3_1 branches that are less volatile at the moment.)

I want to add an html file that will be displayed in the galley

Can you describe in more detail what problems you’re facing? We don’t handle HTML files any differently in the galley settings: a file is uploaded, it gets a submissionFileId, and that ID is attached to a galley. It should be the same as a PDF or any other file.

If you want to upload CSS/JS/image assets along with the HTML file, you’ll want to use the dependent files stage. Our docs have more details about the submission file stages.

On a separate note: what is your use case for this? If you want to quickly import back content, you may want to check out our native import/export tools (see sample issue import) or the QuickSubmit plugin (in the plugin gallery, but only compatible up to 3.3.0-5). If you’re aiming for something more like preprints, where authors upload their only galleys and just get approved by moderators, you may want to use our Open Preprint Server instead of OJS.

Hi @NateWr, first of all thanks for the detailed hints. I would continue to work on the main branch for now, my frustration is not very high yet.

In the meantime I managed to create a submission file. Thanks a lot for the hint with the documentation. I had already tried it as described there before, but when I used SUBMISSION_FILE_SUBMISSION for the fileStage the validation threw errors. Here the errors are shown:
Bildschirmfoto 2021-04-22 um 00.46.52
Since I use the hook Publication::edit and the submission file should be created with the confirmation Save and continue at the end of step 3. Enter Metadata in the submission process, it should be the correct file stage or? whereas others did not work either. Anyway, I was able to solve the problem by using an integer for the fileStage, in my case 2. Is that the right way to do it (then it wouldn’t quite match the documentation)? Is there a documentation where also the corresponding integers for the different fileStages are listed?

Here you can see the corresponding code snippet:

    $request = Application::get()->getRequest();
	$context = $request->getContext();
	$contextId = $context->getId(); 

	$submissionId = $newPublication->_data['id']; 

	$path = Services::get('submissionFile')->getSubmissionDir($contextId, $submissionId);

	$fileId = Services::get('file')->add('/test.html', $path . '/test.html');
	$userId = Application::get()->getRequest()->getUser()->getId(); 

	$primaryLocale = $request->getContext()->getPrimaryLocale();
	$allowedLocales = $request->getContext()->getData('supportedSubmissionLocales');

	$params = [
		'fileStage' => 2,
		'fileId' => $fileId,
		'name' => [
			$primaryLocale => 'my-filename.html',
		'submissionId' => $submissionId,
		'uploaderUserId' => $userId,
        'genreId' => 1
    $errors = Services::get('submissionFile')->validate(VALIDATE_ACTION_ADD, $params, $allowedLocales, $primaryLocale);

	if (empty($errors)) {
		$submissionFile = DAORegistry::getDao('SubmissionFileDAO')->newDataObject();
		$submissionFile = Services::get('submissionFile')->add($submissionFile, $request);

Bildschirmfoto 2021-04-22 um 00.25.32

The general idea behind this is that I would like to create a galley that contains an interactive html-file as additional presentation of the article, which contains values specified by the users during step 3. Enter Metadata in the submission process. Therefore the galley and the corresponding html file should be included/created at the end of this step. The way I have solved it now is to use the hook Publication::edit to read out the required input of the users during step 3. Enter Metadata, to adapt an html-file to this input, to upload it as file and submission file and finally to save and publish it in form of a galley. Does this sound like the right way to go for my idea? Or are there other ways? Ultimately, this galley should always be present when the plugin is activated, if the users want it for the respective article. Whereby the content of the galley depends on the input that the users make during step 3. Enter Metadata.

Thanks in advance for all suggestions.

Hi @tnier01, the SUBMISSION_FILE_SUBMISSION is a PHP constant that is equal to 2. So that’s why it’s working when you use the integer. However, you should use the constant to protect yourself in case the value changes.

If you’re on the main branch, you can use the following:

fileStage' => PKP\submission\SubmissionFile::SUBMISSION_FILE_SUBMISSION,

Does this sound like the right way to go for my idea? Or are there other ways?

It sounds like that will work, however beware that the Publication::edit hook will fire any time the publication is edited, not just in step 3. So you’ll need to be careful about when you are performing the action to make.

An alternate hook that you can use is submissionsubmitstep3form::execute. This will fire whenever the step 3 form is successfully completed.

1 Like