Skip to content

Commit

Permalink
after review: fix deprecated functions
Browse files Browse the repository at this point in the history
  • Loading branch information
bozana committed Dec 19, 2024
1 parent c15f8a1 commit b278627
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 41 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
17 changes: 11 additions & 6 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->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
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
17 changes: 7 additions & 10 deletions classes/PKPSwordDeposit.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,12 @@

namespace APP\plugins\generic\sword\classes;

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

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';
Expand All @@ -43,7 +41,7 @@ class PKPSwordDeposit {
/** @var Issue */
protected $_issue = null;

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

/**
Expand Down Expand Up @@ -110,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);
}

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

0 comments on commit b278627

Please sign in to comment.