diff --git a/AuthorDepositForm.php b/AuthorDepositForm.php index c1dba0e..3b2b80c 100644 --- a/AuthorDepositForm.php +++ b/AuthorDepositForm.php @@ -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')); } @@ -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(); @@ -104,7 +102,7 @@ public function execute(...$functionArgs) { ); $deposit->cleanup(); } - + $url = ''; $depositPoints = $this->getData('depositPoint'); $depositableDepositPoints = $this->_getDepositableDepositPoints($this->_context); @@ -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) { diff --git a/SwordHandler.php b/SwordHandler.php index 9a7e749..0e5c120 100644 --- a/SwordHandler.php +++ b/SwordHandler.php @@ -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; @@ -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 */ @@ -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); } @@ -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; @@ -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) { @@ -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()); diff --git a/SwordImportExportPlugin.php b/SwordImportExportPlugin.php index 0df6d0f..4672fce 100644 --- a/SwordImportExportPlugin.php +++ b/SwordImportExportPlugin.php @@ -219,7 +219,7 @@ public function display($args, $request) { } catch (\Exception $e) { $errors[] = [ - 'title' => $submission->getLocalizedTitle(), + 'title' => $submission->getCurrentPublication()->getLocalizedTitle(), 'message' => $e->getMessage(), ]; } diff --git a/SwordPlugin.php b/SwordPlugin.php index 32e0dc1..801d1ff 100644 --- a/SwordPlugin.php +++ b/SwordPlugin.php @@ -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() ]) ] @@ -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() ) diff --git a/classes/DepositPointDAO.php b/classes/DepositPointDAO.php index 61ca84f..7b65391 100644 --- a/classes/DepositPointDAO.php +++ b/classes/DepositPointDAO.php @@ -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(); @@ -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 @@ -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; } @@ -111,9 +108,9 @@ public function insertObject($depositPoint) { ] ); $depositPoint->setId($this->getInsertId()); - + $this->updateLocaleFields($depositPoint); - + return $depositPoint->getId(); } @@ -121,7 +118,8 @@ public function insertObject($depositPoint) { * Get a list of fields for which localized data is supported * @return array */ - public function getLocaleFieldNames() { + public function getLocaleFieldNames(): array + { return ['name', 'description']; } @@ -164,7 +162,7 @@ public function updateObject($depositPoint) { $depositPoint->getId() ] ); - + $this->updateLocaleFields($depositPoint); } diff --git a/classes/PKPSwordDeposit.php b/classes/PKPSwordDeposit.php index 236715c..9c1fc59 100644 --- a/classes/PKPSwordDeposit.php +++ b/classes/PKPSwordDeposit.php @@ -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 */ @@ -44,8 +41,8 @@ class PKPSwordDeposit { /** @var Issue */ protected $_issue = null; - /** @var Article */ - protected $_article = null; + /** @var Submission */ + protected $_submission = null; /** * Constructor. @@ -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')); @@ -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(); @@ -111,11 +108,10 @@ 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); } @@ -123,7 +119,7 @@ public function _addFile($submissionFile) { * 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()); } } diff --git a/classes/SwordSchemaMigration.php b/classes/SwordSchemaMigration.php index d585f5c..7a3c278 100644 --- a/classes/SwordSchemaMigration.php +++ b/classes/SwordSchemaMigration.php @@ -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; diff --git a/templates/authorDepositForm.tpl b/templates/authorDepositForm.tpl index 860cb2c..90594a0 100644 --- a/templates/authorDepositForm.tpl +++ b/templates/authorDepositForm.tpl @@ -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()}