forked from jonasraoni/article-importer-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConfiguration.inc.php
219 lines (195 loc) · 5.79 KB
/
Configuration.inc.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
<?php
/**
* @file plugins/importexport/articleImporter/Configuration.inc.php
*
* Copyright (c) 2014-2020 Simon Fraser University
* Copyright (c) 2000-2020 John Willinsky
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @class Configuration
* @ingroup plugins_importexport_articleImporter
*
* @brief Keeps the import options and common shared settings
*/
namespace PKP\Plugins\ImportExport\ArticleImporter;
class Configuration {
/** @var string Default title for sections */
private $_defaultSectionName;
/** @var string[] List of classes that can parse XML articles */
private $_parsers;
/** @var \Context Context */
private $_context;
/** @var \User User instance */
private $_user;
/** @var \User Editor instance */
private $_editor;
/** @var string Default email */
private $_email;
/** @var string Import path */
private $_importPath;
/** @var int Editor's user group ID */
private $_editorGroupId;
/** @var int|null Author's user group ID */
private $_authorGroupId;
/** @var \Genre Submission genre instance */
private $_genre;
/** @var string[] File extensions recognized as images */
private $_imageExt;
/** @var string base filename for issue covers
private $_issueCoverFilename;
/**
* Constructor
* @param string[] $parsers List of parser classes
* @param string $contextPath Path of the context
* @param string $username User to whom imported articles will be assigned
* @param string $editorUsername Editor to whom imported articles should be assigned
* @param string $email Default email when the author email is not provided in the XML
* @param string $importPath Base path where the "volume/issue/article" structure is kept
*/
public function __construct(array $parsers, string $contextPath, string $username, string $editorUsername, string $email, string $importPath, string $defaultSectionName = 'Articles')
{
$this->_defaultSectionName = $defaultSectionName;
$this->_parsers = $parsers;
if (!$this->_context = \Application::getContextDAO()->getByPath($contextPath)) {
throw new \InvalidArgumentException(__('plugins.importexport.articleImporter.unknownJournal', ['journal' => $contextPath]));
}
[$this->_user, $this->_editor] = array_map(function ($username) {
if (!$entity = \DAORegistry::getDAO('UserDAO')->getByUsername($username)) {
throw new \InvalidArgumentException(__('plugins.importexport.articleImporter.unknownUser', ['username' => $username]));
}
return $entity;
}, [$username, $editorUsername]);
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
throw new \InvalidArgumentException(__('plugins.importexport.articleImporter.unknownEmail', ['email' => $email]));
}
$this->_email = $email;
if (!is_dir($importPath)) {
throw new \InvalidArgumentException(__('plugins.importexport.articleImporter.directoryDoesNotExist', ['directory' => $importPath]));
}
$this->_importPath = $importPath;
// Finds the user group ID for the editor
$userGroupDao = \DAORegistry::getDAO('UserGroupDAO');
$userGroupIds = $userGroupDao->getUserGroupIdsByRoleId(\ROLE_ID_MANAGER, $this->_context->getId());
foreach ($userGroupIds as $id) {
if ($userGroupDao->userGroupAssignedToStage($id, \WORKFLOW_STAGE_ID_PRODUCTION)) {
$this->_editorGroupId = $id;
break;
}
}
if (!$this->_editorGroupId) {
throw new \Exception(__('plugins.importexport.articleImporter.missingEditorGroupId'));
}
// Finds the user group ID for the authors
$userGroupDao = \DAORegistry::getDAO('UserGroupDAO');
$userGroupIds = $userGroupDao->getUserGroupIdsByRoleId(\ROLE_ID_AUTHOR, $this->_context->getId());
$this->_authorGroupId = reset($userGroupIds);
// Retrieves the genre for submissions
$this->_genre = \DAORegistry::getDAO('GenreDAO')->getByKey('SUBMISSION', $this->_context->getId());
$this->_imageExt = array('tif', 'tiff', 'png', 'jpg', 'jpeg');
$this->_issueCoverFilename = 'cover';
}
/**
* Retrieves the context instance
* @return \Context
*/
public function getContext(): \Context
{
return $this->_context;
}
/**
* Retrieves the user instance
* @return \User
*/
public function getUser(): \User
{
return $this->_user;
}
/**
* Retrieves the user instance
* @return \User
*/
public function getEditor(): \User
{
return $this->_editor;
}
/**
* Retrieves the default email which will be assigned to authors (when absent)
* @return \Context
*/
public function getEmail(): string
{
return $this->_email;
}
/**
* Retrieves the import base path
* @return string
*/
public function getImportPath(): string
{
return $this->_importPath;
}
/**
* Retrieves the editor user group ID
* @return int
*/
public function getEditorGroupId(): int
{
return $this->_editorGroupId;
}
/**
* Retrieves the author user group ID
* @return ?int
*/
public function getAuthorGroupId(): ?int
{
return $this->_authorGroupId;
}
/**
* Retrieves the submission genre
* @return \Genre
*/
public function getSubmissionGenre(): \Genre
{
return $this->_genre;
}
/**
* Retrieves an article iterator
* @return ArticleIterator
*/
public function getArticleIterator(): ArticleIterator
{
return new ArticleIterator($this->getImportPath());
}
/**
* Retrieves the list of parsers
* @return string[]
*/
public function getParsers(): array
{
return $this->_parsers;
}
/**
* Retrieves the default section name
* @return string
*/
public function getDefaultSectionName(): string
{
return $this->_defaultSectionName;
}
/**
* Retrieves the array of known image extensions
* @return string[]
*/
public function getImageExtensions(): array
{
return $this->_imageExt;
}
/**
* Retrieves the base name for an issue cover file
* @return string
*/
public function getIssueCoverFilename(): string
{
return $this->_issueCoverFilename;
}
}