1 | <?php |
||
7 | class MigrateToDocumentSetsTask extends BuildTask |
||
8 | { |
||
9 | protected $title = 'DMS 2.0 Migration Tool'; |
||
10 | |||
11 | protected $description = 'Migration tool for upgrading from DMS 1.x to 2.x. Add "action=create-default-document-set" to create a default set. "reassign-documents" to reassign legacy document relations. "dryrun=1" to show changes without writing.'; |
||
12 | |||
13 | /** |
||
14 | * The valid actions that this task can perform (and the method that does them as the key) |
||
15 | * @var array |
||
16 | */ |
||
17 | protected $validActions = array( |
||
18 | 'createDefaultSet' => 'create-default-document-set', |
||
19 | 'reassignDocuments' => 'reassign-documents' |
||
20 | ); |
||
21 | |||
22 | /** |
||
23 | * @var SS_HTTPRequest |
||
24 | */ |
||
25 | protected $request; |
||
26 | |||
27 | /** |
||
28 | * Holds number of pages/sets/documents processed for output at the end. Example: |
||
29 | * |
||
30 | * <code> |
||
31 | * array( |
||
32 | * 'total-pages' => 0, |
||
33 | * 'pages-updated' => 0 |
||
34 | * ) |
||
35 | * </code> |
||
36 | * |
||
37 | * The individual action methods will update these metrics as required |
||
38 | * |
||
39 | * @var array |
||
40 | */ |
||
41 | protected $results = array(); |
||
42 | |||
43 | public function run($request) |
||
61 | |||
62 | /** |
||
63 | * Returns whether dryrun mode is enabled ("dryrun=1") |
||
64 | * |
||
65 | * @return bool |
||
66 | */ |
||
67 | public function isDryrun() |
||
71 | |||
72 | /** |
||
73 | * Creates a default document set for any valid page that doesn't have one |
||
74 | * |
||
75 | * @return $this |
||
76 | */ |
||
77 | protected function createDefaultSet() |
||
97 | |||
98 | /** |
||
99 | * Reassign documents to the default document set, where they'd previously have been assigned to pages |
||
100 | * |
||
101 | * @return $this |
||
102 | */ |
||
103 | protected function reassignDocuments() |
||
139 | |||
140 | /** |
||
141 | * Create a "default" document set and add it to the given Page via the ORM relationship added by |
||
142 | * {@link DMSSiteTreeExtension} |
||
143 | * |
||
144 | * @param SiteTree $page |
||
145 | * @return $this |
||
146 | */ |
||
147 | protected function addDefaultDocumentSet(SiteTree $page) |
||
161 | |||
162 | /** |
||
163 | * Add the given document to the given document set |
||
164 | * |
||
165 | * @param DMSDocument $document |
||
166 | * @param DMSDocumentSet $set |
||
167 | * @return $this |
||
168 | */ |
||
169 | protected function addDocumentToSet(DMSDocument $document, DMSDocumentSet $set) |
||
178 | |||
179 | /** |
||
180 | * Output a header info line |
||
181 | * |
||
182 | * @return $this |
||
183 | */ |
||
184 | protected function outputHeader() |
||
192 | |||
193 | /** |
||
194 | * Output a "finished" notice and the results of what was done |
||
195 | * |
||
196 | * @return $this |
||
197 | */ |
||
198 | protected function outputResults() |
||
207 | |||
208 | /** |
||
209 | * Add the $increment to the result key identified by $key |
||
210 | * |
||
211 | * @param string $key |
||
212 | * @param int $increment |
||
213 | * @return $this |
||
214 | */ |
||
215 | protected function addResult($key, $increment = 1) |
||
223 | |||
224 | /** |
||
225 | * Outputs a message formatted either for CLI or browser output |
||
226 | * |
||
227 | * @param string $message |
||
228 | * @return $this |
||
229 | */ |
||
230 | public function output($message = '') |
||
239 | |||
240 | /** |
||
241 | * Returns whether the task is called via CLI or not |
||
242 | * |
||
243 | * @return bool |
||
244 | */ |
||
245 | protected function isCli() |
||
249 | } |
||
250 |
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.
Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.