Skip to content

Commit

Permalink
Merge pull request #38 from bozana/10653
Browse files Browse the repository at this point in the history
fix deprecated submission functions
  • Loading branch information
bozana authored Dec 19, 2024
2 parents 2782ae5 + b278627 commit 0040487
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 56 deletions.
25 changes: 12 additions & 13 deletions AuthorDepositForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,29 @@

use PKP\form\Form;

use APP\plugins\generic\sword\PKPSwordDeposit;
use APP\plugins\generic\sword\classes\DepositPoint;
use APP\plugins\generic\sword\classes\DepositPointsHelper;
use APP\plugins\generic\sword\classes\PKPSwordDeposit;
use APP\submission\Submission;
use APP\template\TemplateManager;
use PKP\context\Context;
use PKP\db\DAORegistry;

class AuthorDepositForm extends Form {
/** @var $_context Context */
/** @var Context $_context */
protected $_context = null;

/** @var $_plugin SwordPlugin */
/** @var SwordPlugin $_plugin */
protected $_plugin = null;

/** @var $_submission Submission */
/** @var Submission $_submission */
protected $_submission = null;

/**
* Constructor
* @param $plugin SwordPlugin
* @param $context Context
* @param $submission Submission
*/

public function __construct(SwordPlugin $plugin, Context $context, Submission $submission) {
$this->_plugin = $plugin;
$this->_context = $context;
$this->_submission = $submission;
AppLocale::requireComponents(LOCALE_COMPONENT_PKP_USER);
parent::__construct($plugin->getTemplateResource('authorDepositForm.tpl'));
}

Expand Down Expand Up @@ -86,7 +84,7 @@ public function display($request = null, $template = null) {
public function execute(...$functionArgs) {
parent::execute(...$functionArgs);
$request = $functionArgs[0];

$deposit = new PKPSwordDeposit($this->_submission);
$deposit->setMetadata($request);
$deposit->addEditorial();
Expand All @@ -104,7 +102,7 @@ public function execute(...$functionArgs) {
);
$deposit->cleanup();
}

$url = '';
$depositPoints = $this->getData('depositPoint');
$depositableDepositPoints = $this->_getDepositableDepositPoints($this->_context);
Expand Down Expand Up @@ -134,6 +132,7 @@ public function execute(...$functionArgs) {
*/
protected function _getDepositableDepositPoints($context) {
$list = [];
/** @var DepositPointDAO $depositPointDao */
$depositPointDao = DAORegistry::getDAO('DepositPointDAO');
$depositPoints = $depositPointDao->getByContextId($context->getId());
foreach ($depositPoints as $depositPoint) {
Expand Down
19 changes: 12 additions & 7 deletions SwordHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace APP\plugins\generic\sword;

use APP\facades\Repo;
use PKP\security\authorization\ContextAccessPolicy;
use PKP\core\JSONMessage;
use PKP\plugins\PluginRegistry;
Expand All @@ -21,10 +22,12 @@
use PKP\security\Validation;

use APP\handler\Handler;

use APP\notification\Notification;
use APP\notification\NotificationManager;
use APP\plugins\generic\sword\classes\DepositPoint;
use APP\plugins\generic\sword\classes\DepositPointsHelper;
use APP\plugins\generic\sword\DepositPointForm;
use APP\template\TemplateManager;

class SwordHandler extends Handler {
/** @var SwordPlugin Sword plugin */
Expand Down Expand Up @@ -73,13 +76,14 @@ public function getSwordPlugin() {
public function depositPoints($args, $request) {
$context = $request->getContext();
$depositPointId = $request->getUserVar('depositPointId');
/** @var DepositPointDAO $depositPointDao */
$depositPointDao = DAORegistry::getDAO('DepositPointDAO');
$depositPoint = $depositPointDao->getById($depositPointId, $context->getId());
if (!$depositPoint) {
return new JSONMessage(false);
}

$isManager = Validation::isAuthorized(ROLE_ID_MANAGER, $context->getId());
$isManager = Validation::isAuthorized(Role::ROLE_ID_MANAGER, $context->getId());
if (!$isManager && $depositPoint->getType() != SWORD_DEPOSIT_TYPE_OPTIONAL_SELECTION) {
return new JSONMessage(false);
}
Expand Down Expand Up @@ -111,17 +115,17 @@ public function index($args, $request) {
$submissionId = (int) array_shift($args);
$save = array_shift($args) == 'save';

$submissionDao = DAORegistry::getDAO('SubmissionDAO');
$submission = $submissionDao->getById($submissionId);
$submission = Repo::submission()->get($submissionId);

if (!$submission || !$user || !$context ||
($submission->getContextId() != $context->getId())) {
($submission->getData('contextId') != $context->getId())) {
$request->redirect(null, 'index');
}

$userCanDeposit = false;
/** @var StageAssignmentDAO $stageAssignmentDao */
$stageAssignmentDao = DAORegistry::getDAO('StageAssignmentDAO');
$daoResult = $stageAssignmentDao->getBySubmissionAndRoleId($submission->getId(), ROLE_ID_AUTHOR);
$daoResult = $stageAssignmentDao->getBySubmissionAndRoleId($submission->getId(), Role::ROLE_ID_AUTHOR);
while ($record = $daoResult->next()) {
if($user->getId() == $record->getData('userId')) {
$userCanDeposit = true;
Expand All @@ -143,6 +147,7 @@ public function index($args, $request) {
$responses = $authorDepositForm->execute($request);
$templateMgr = TemplateManager::getManager($request);
$results = [];
/** @var DepositPointDAO $depositPointDao */
$depositPointDao = DAORegistry::getDAO('DepositPointDAO');
$depositPoints = iterator_to_array($depositPointDao->getByContextId($context->getId()));
foreach ($responses as $url => $response) {
Expand All @@ -168,7 +173,7 @@ public function index($args, $request) {
$notificationManager = new NotificationManager();
$notificationManager->createTrivialNotification(
$user->getId(),
NOTIFICATION_TYPE_ERROR,
Notification::NOTIFICATION_TYPE_ERROR,
['contents' => __('plugins.importexport.sword.depositFailed') . ': ' . $e->getMessage()]
);
error_log($e->getTraceAsString());
Expand Down
2 changes: 1 addition & 1 deletion SwordImportExportPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ public function display($args, $request) {
}
catch (\Exception $e) {
$errors[] = [
'title' => $submission->getLocalizedTitle(),
'title' => $submission->getCurrentPublication()->getLocalizedTitle(),
'message' => $e->getMessage(),
];
}
Expand Down
4 changes: 2 additions & 2 deletions SwordPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ function performAutomaticDeposits(Submission $submission) {
NOTIFICATION_TYPE_SUCCESS,
[
'contents' => __('plugins.generic.sword.automaticDepositComplete', [
'itemTitle' => $submission->getLocalizedTitle(),
'itemTitle' => $submission->getCurrentPublication()->getLocalizedTitle(),
'repositoryName' => $depositPoint->getLocalizedName()
])
]
Expand Down Expand Up @@ -207,7 +207,7 @@ function performAutomaticDeposits(Submission $submission) {

$mail->assignParams([
'contextName' => htmlspecialchars($context->getLocalizedName()),
'submissionTitle' => htmlspecialchars($submission->getLocalizedTitle()),
'submissionTitle' => htmlspecialchars($submission->getCurrentPublication()->getLocalizedTitle()),
'swordDepositUrl' => $dispatcher->url(
$request, ROUTE_PAGE, null, 'sword', 'index', $submission->getId()
)
Expand Down
20 changes: 9 additions & 11 deletions classes/DepositPointDAO.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@ class DepositPointDAO extends DAO {
/** @var SwordPlugin reference to SWORD plugin */
protected $_plugin = null;

/**
* Constructor
* @param $parentPlugin SwordPlugin
*/

public function __construct(SwordPlugin $parentPlugin) {
$this->_plugin = $parentPlugin;
parent::__construct();
Expand All @@ -48,7 +45,7 @@ public function newDataObject() {
public function getById($depositPointId, $contextId = null) {
$params = [(int) $depositPointId];
if ($contextId) $params[] = (int) $contextId;

$result = $this->retrieve(
'SELECT * FROM deposit_points WHERE deposit_point_id = ? ' . ($contextId?' AND context_id = ?':''),
$params
Expand All @@ -72,14 +69,14 @@ public function _fromRow($row) {
$depositPoint->setSwordUsername($row['sword_username']);
$depositPoint->setSwordPassword($row['sword_password']);
$depositPoint->setSwordApikey($row['sword_apikey']);

$this->getDataObjectSettings(
'deposit_point_settings',
'deposit_point_id',
$row['deposit_point_id'],
$depositPoint
);

return $depositPoint;
}

Expand Down Expand Up @@ -111,17 +108,18 @@ public function insertObject($depositPoint) {
]
);
$depositPoint->setId($this->getInsertId());

$this->updateLocaleFields($depositPoint);

return $depositPoint->getId();
}

/**
* Get a list of fields for which localized data is supported
* @return array
*/
public function getLocaleFieldNames() {
public function getLocaleFieldNames(): array
{
return ['name', 'description'];
}

Expand Down Expand Up @@ -164,7 +162,7 @@ public function updateObject($depositPoint) {
$depositPoint->getId()
]
);

$this->updateLocaleFields($depositPoint);
}

Expand Down
34 changes: 15 additions & 19 deletions classes/PKPSwordDeposit.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,21 @@

namespace APP\plugins\generic\sword\classes;

use PKP\submissionFile\SubmissionFile;
use PKP\file\FileManager;
use PKP\db\DAORegistry;

use APP\facades\Repo;
use APP\core\Application;
use APP\core\Services;

use APP\facades\Repo;
use APP\plugins\generic\sword\classes\PKPPackagerMetsSwap;
use Exception;
use PKP\file\FileManager;
use PKP\submissionFile\SubmissionFile;

require_once dirname(__FILE__) . '/../libs/swordappv2/swordappclient.php';
require_once dirname(__FILE__) . '/../libs/swordappv2/swordappentry.php';

class PKPSwordDeposit {
/** @var SWORD deposit METS package */
/** @var PKPPackagerMetsSwap SWORD deposit METS package */
protected $_package = null;

/** @var Complete path and directory name to use for package creation files */
/** @var string Complete path and directory name to use for package creation files */
protected $_outPath = null;

/** @var Journal */
Expand All @@ -44,8 +41,8 @@ class PKPSwordDeposit {
/** @var Issue */
protected $_issue = null;

/** @var Article */
protected $_article = null;
/** @var Submission */
protected $_submission = null;

/**
* Constructor.
Expand All @@ -72,7 +69,7 @@ public function __construct($submission) {
$application = Application::get();
$publication = $submission->getCurrentPublication();

$this->_context = $application->getContextDao()->getById($submission->getContextId());
$this->_context = $application->getContextDao()->getById($submission->getData('contextId'));

$this->_section = Repo::section()->get($publication->getData('sectionId'));

Expand All @@ -87,11 +84,11 @@ public function __construct($submission) {
* @param $request PKPRequest
*/
public function setMetadata($request) {
$publication = $this->_submission->getCurrentPublication();
$this->_package->setCustodian($this->_context->getContactName());
$this->_package->setTitle(html_entity_decode($this->_submission->getLocalizedTitle(), ENT_QUOTES, 'UTF-8'));
$this->_package->setAbstract(html_entity_decode(strip_tags($this->_submission->getLocalizedAbstract()), ENT_QUOTES, 'UTF-8'));
$this->_package->setTitle(html_entity_decode($publication->getLocalizedTitle(), ENT_QUOTES, 'UTF-8'));
$this->_package->setAbstract(html_entity_decode(strip_tags($publication->getLocalizedData('abstract')), ENT_QUOTES, 'UTF-8'));
$this->_package->setType($this->_section->getLocalizedIdentifyType());
$publication = $this->_submission->getCurrentPublication();
foreach ($publication->getData('authors') as $author) {
$creator = $author->getFullName(true);
$affiliation = $author->getLocalizedAffiliation();
Expand All @@ -111,19 +108,18 @@ public function setMetadata($request) {
* @param $submissionFile SubmissionFile
*/
public function _addFile($submissionFile) {
$fileService = Services::get('file');
$file = $fileService->get($submissionFile->getData('fileId'));
$file = app()->get('file')->get($submissionFile->getData('fileId'));
$targetFilename = preg_replace('/[^A-Za-z0-9_\-\.]/', '_', $submissionFile->getLocalizedData('name'));
$targetFilePath = $this->_outPath . '/files/' . $targetFilename;
file_put_contents($targetFilePath, $fileService->fs->read($file->path));
file_put_contents($targetFilePath, app()->get('file')->fs->read($file->path));
$this->_package->addFile($targetFilename, $file->mimetype);
}

/**
* Add all article galleys to the deposit package.
*/
public function addGalleys() {
foreach ($this->_submission->getGalleys() as $galley) {
foreach ($this->_submission->getCurrentPublication()->getData('galleys') as $galley) {
$this->_addFile($galley->getFile());
}
}
Expand Down
1 change: 0 additions & 1 deletion classes/SwordSchemaMigration.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
namespace APP\plugins\generic\sword\classes;

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Builder;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

Expand Down
4 changes: 2 additions & 2 deletions templates/authorDepositForm.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
{csrf}

{if !empty($depositPoints)}
{translate key="plugins.generic.sword.authorDepositDescription" submissionTitle=$submission->getLocalizedTitle()}
{translate key="plugins.generic.sword.authorDepositDescription" submissionTitle=$submission->getCurrentPublication()->getLocalizedTitle()}
<fieldset id="authorDepositPoints">
<ul class="prefabDepositPoints" style="list-style: none;">
{foreach from=$depositPoints item=depositPoint key=depositPointKey name="depositPoints"}
Expand Down Expand Up @@ -97,7 +97,7 @@
{/if}{* !empty($depositPoints) *}

{if $allowAuthorSpecify}
{translate key="plugins.generic.sword.authorCustomDepositDescription" submissionTitle=$submission->getLocalizedTitle()}
{translate key="plugins.generic.sword.authorCustomDepositDescription" submissionTitle=$submission->getCurrentPublication()->getLocalizedTitle()}
<fieldset class="authorSelfDeposit">
<div class="fields">
<div class="section">
Expand Down

0 comments on commit 0040487

Please sign in to comment.