1 | <?php |
||
2 | /** |
||
3 | * FakeJobConfiguration.php |
||
4 | * Copyright (c) 2019 [email protected] |
||
5 | * |
||
6 | * This file is part of Firefly III (https://github.com/firefly-iii). |
||
7 | * |
||
8 | * This program is free software: you can redistribute it and/or modify |
||
9 | * it under the terms of the GNU Affero General Public License as |
||
10 | * published by the Free Software Foundation, either version 3 of the |
||
11 | * License, or (at your option) any later version. |
||
12 | * |
||
13 | * This program is distributed in the hope that it will be useful, |
||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
16 | * GNU Affero General Public License for more details. |
||
17 | * |
||
18 | * You should have received a copy of the GNU Affero General Public License |
||
19 | * along with this program. If not, see <https://www.gnu.org/licenses/>. |
||
20 | */ |
||
21 | |||
22 | declare(strict_types=1); |
||
23 | |||
24 | namespace FireflyIII\Import\JobConfiguration; |
||
25 | |||
26 | use FireflyIII\Models\ImportJob; |
||
27 | use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface; |
||
28 | use Illuminate\Support\MessageBag; |
||
29 | |||
30 | /** |
||
31 | * Class FakeJobConfiguration |
||
32 | * |
||
33 | * @deprecated |
||
34 | * @codeCoverageIgnore |
||
35 | */ |
||
36 | class FakeJobConfiguration implements JobConfigurationInterface |
||
0 ignored issues
–
show
|
|||
37 | { |
||
38 | /** @var ImportJob The import job */ |
||
39 | private $importJob; |
||
40 | |||
41 | /** @var ImportJobRepositoryInterface Import job repository */ |
||
42 | private $repository; |
||
43 | |||
44 | /** |
||
45 | * Returns true when the initial configuration for this job is complete. |
||
46 | * configuration array of job must have two values: |
||
47 | * 'artist' must be 'david bowie', case insensitive |
||
48 | * 'song' must be 'golden years', case insensitive. |
||
49 | * if stage is not "new", then album must be 'station to station' |
||
50 | * |
||
51 | * @return bool |
||
52 | * |
||
53 | */ |
||
54 | public function configurationComplete(): bool |
||
55 | { |
||
56 | $config = $this->importJob->configuration; |
||
57 | if ('new' === $this->importJob->stage) { |
||
58 | return |
||
59 | isset($config['artist'], $config['song'], $config['apply-rules']) |
||
60 | && 'david bowie' === strtolower($config['artist']) |
||
61 | && 'golden years' === strtolower($config['song']); |
||
62 | } |
||
63 | |||
64 | return isset($config['album']) && 'station to station' === strtolower($config['album']); |
||
65 | |||
66 | |||
67 | } |
||
68 | |||
69 | /** |
||
70 | * Store any data from the $data array into the job. |
||
71 | * |
||
72 | * @param array $data |
||
73 | * |
||
74 | * @return MessageBag |
||
75 | * |
||
76 | */ |
||
77 | public function configureJob(array $data): MessageBag |
||
78 | { |
||
79 | $artist = strtolower($data['artist'] ?? ''); |
||
80 | $song = strtolower($data['song'] ?? ''); |
||
81 | $album = strtolower($data['album'] ?? ''); |
||
82 | $applyRules = isset($data['apply_rules']) ? 1 === (int) $data['apply_rules'] : null; |
||
83 | $configuration = $this->importJob->configuration; |
||
84 | if ('david bowie' === $artist) { |
||
85 | // store artist |
||
86 | $configuration['artist'] = $artist; |
||
87 | } |
||
88 | |||
89 | if ('golden years' === $song) { |
||
90 | // store song |
||
91 | $configuration['song'] = $song; |
||
92 | } |
||
93 | |||
94 | if ('station to station' === $album) { |
||
95 | // store album |
||
96 | $configuration['album'] = $album; |
||
97 | } |
||
98 | if (null !== $applyRules) { |
||
99 | $configuration['apply-rules'] = $applyRules; |
||
100 | } |
||
101 | |||
102 | $this->repository->setConfiguration($this->importJob, $configuration); |
||
103 | $messages = new MessageBag(); |
||
104 | |||
105 | if (3 !== count($configuration)) { |
||
106 | $messages->add('some_key', 'Ignore this error: ' . count($configuration)); |
||
107 | } |
||
108 | |||
109 | return $messages; |
||
110 | } |
||
111 | |||
112 | /** |
||
113 | * Return the data required for the next step in the job configuration. |
||
114 | * |
||
115 | * @codeCoverageIgnore |
||
116 | * @return array |
||
117 | */ |
||
118 | public function getNextData(): array |
||
119 | { |
||
120 | return [ |
||
121 | 'rulesOptions' => [ |
||
122 | 1 => (string) trans('firefly.yes'), |
||
123 | 0 => (string) trans('firefly.no'), |
||
124 | ], |
||
125 | ]; |
||
126 | } |
||
127 | |||
128 | /** |
||
129 | * Returns the view of the next step in the job configuration. |
||
130 | * |
||
131 | * @return string |
||
132 | * |
||
133 | */ |
||
134 | public function getNextView(): string |
||
135 | { |
||
136 | // first configure artist: |
||
137 | $config = $this->importJob->configuration; |
||
138 | $artist = $config['artist'] ?? ''; |
||
139 | $song = $config['song'] ?? ''; |
||
140 | $album = $config['album'] ?? ''; |
||
141 | $applyRules = $config['apply-rules'] ?? null; |
||
142 | if (null === $applyRules) { |
||
143 | return 'import.fake.apply-rules'; |
||
144 | } |
||
145 | if ('david bowie' !== strtolower($artist)) { |
||
146 | return 'import.fake.enter-artist'; |
||
147 | } |
||
148 | if ('golden years' !== strtolower($song)) { |
||
149 | return 'import.fake.enter-song'; |
||
150 | } |
||
151 | if ('new' !== $this->importJob->stage && 'station to station' !== strtolower($album)) { |
||
152 | return 'import.fake.enter-album'; |
||
153 | } |
||
154 | |||
155 | return 'impossible-view'; // @codeCoverageIgnore |
||
156 | } |
||
157 | |||
158 | /** |
||
159 | * Set import job. |
||
160 | * |
||
161 | * @param ImportJob $importJob |
||
162 | */ |
||
163 | public function setImportJob(ImportJob $importJob): void |
||
164 | { |
||
165 | $this->importJob = $importJob; |
||
166 | $this->repository = app(ImportJobRepositoryInterface::class); |
||
167 | $this->repository->setUser($importJob->user); |
||
168 | } |
||
169 | } |
||
170 |
This interface has been deprecated. The supplier of the interface has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the interface will be removed and what other interface to use instead.