1 | <?php |
||
19 | class ZohoSyncDatabaseCommand extends Command |
||
20 | { |
||
21 | /** |
||
22 | * The list of Zoho DAOs to copy. |
||
23 | * |
||
24 | * @var AbstractZohoDao[] |
||
25 | */ |
||
26 | private $zohoDaos; |
||
27 | |||
28 | /** |
||
29 | * @var ZohoDatabaseModelSync |
||
30 | */ |
||
31 | private $zohoDatabaseModelSync; |
||
32 | |||
33 | /** |
||
34 | * @var ZohoDatabaseCopier |
||
35 | */ |
||
36 | private $zohoDatabaseCopier; |
||
37 | |||
38 | /** |
||
39 | * @var ZohoDatabasePusher |
||
40 | */ |
||
41 | private $zohoDatabaseSync; |
||
42 | |||
43 | /** |
||
44 | * |
||
45 | * @var MultiLogger |
||
46 | */ |
||
47 | private $logger; |
||
48 | |||
49 | /** |
||
50 | * @var Lock |
||
51 | */ |
||
52 | private $lock; |
||
53 | |||
54 | /** |
||
55 | * The Zoho Dao and Beans generator |
||
56 | * @var EntitiesGeneratorService |
||
57 | */ |
||
58 | private $zohoEntitiesGenerator; |
||
59 | |||
60 | /** |
||
61 | * |
||
62 | * @var ZohoClient |
||
63 | */ |
||
64 | private $zohoClient; |
||
65 | |||
66 | private $pathZohoDaos; |
||
67 | |||
68 | private $namespaceZohoDaos; |
||
69 | |||
70 | /** |
||
71 | * |
||
72 | * @var Response |
||
73 | */ |
||
74 | private $usersResponse; |
||
75 | |||
76 | |||
77 | /** |
||
78 | * @param ZohoDatabaseModelSync $zohoDatabaseModelSync |
||
79 | * @param ZohoDatabaseCopier $zohoDatabaseCopier |
||
80 | * @param ZohoDatabasePusher $zohoDatabaseSync |
||
81 | * @param EntitiesGeneratorService $zohoEntitiesGenerator The Zoho Dao and Beans generator |
||
82 | * @param ZohoClient $zohoClient |
||
83 | * @param string $pathZohoDaos Tht path where we need to generate the Daos. |
||
84 | * @param string $namespaceZohoDaos Daos namespace |
||
85 | * @param MultiLogger $logger |
||
86 | * @param Lock $lock A lock that can be used to avoid running the same command (copy) twice at the same time |
||
87 | */ |
||
88 | public function __construct(ZohoDatabaseModelSync $zohoDatabaseModelSync, ZohoDatabaseCopier $zohoDatabaseCopier, ZohoDatabasePusher $zohoDatabaseSync, |
||
103 | |||
104 | protected function configure() |
||
114 | |||
115 | protected function execute(InputInterface $input, OutputInterface $output) |
||
116 | { |
||
117 | try { |
||
118 | if ($this->lock) { |
||
119 | $this->lock->acquireLock(); |
||
120 | } |
||
121 | |||
122 | $this->logger->addLogger(new DateTimeFormatter(new ConsoleLogger($output))); |
||
123 | if ($input->getOption('fetch-only') && $input->getOption('push-only')) { |
||
124 | $output->writeln('<error>Options fetch-only and push-only are mutually exclusive.</error>'); |
||
125 | } |
||
126 | |||
127 | $this->syncUserModel($output); |
||
128 | |||
129 | $this->regenerateZohoDao($output); |
||
130 | |||
131 | $this->syncModel($input, $output); |
||
132 | |||
133 | if (!$input->getOption('push-only')) { |
||
134 | $this->fetchUserDb($input, $output); |
||
135 | $this->fetchDb($input, $output); |
||
136 | |||
137 | } |
||
138 | if (!$input->getOption('fetch-only')) { |
||
139 | $this->pushDb($output); |
||
140 | } |
||
141 | if ($this->lock) { |
||
142 | $this->lock->releaseLock(); |
||
143 | } |
||
144 | } catch (LockException $e) { |
||
145 | $output->writeln('<error>Could not start zoho:copy-db copy command. Another zoho:copy-db copy command is already running.</error>'); |
||
146 | } |
||
147 | } |
||
148 | |||
149 | /** |
||
150 | * Sychronizes the model of the database with Zoho records. |
||
151 | * |
||
152 | * @param OutputInterface $output |
||
153 | */ |
||
154 | private function syncModel(InputInterface $input, OutputInterface $output) |
||
155 | { |
||
156 | $twoWaysSync = !$input->getOption('fetch-only'); |
||
157 | $skipCreateTrigger = $input->getOption('skip-trigger'); |
||
158 | |||
159 | $output->writeln('Starting synchronize Zoho data into Zoho CRM.'); |
||
160 | foreach ($this->zohoDaos as $zohoDao) { |
||
161 | $this->zohoDatabaseModelSync->synchronizeDbModel($zohoDao, $twoWaysSync, $skipCreateTrigger); |
||
162 | } |
||
163 | $output->writeln('Zoho data successfully synchronized.'); |
||
164 | } |
||
165 | |||
166 | |||
167 | |||
168 | /** |
||
169 | * Generate the User Response from Zoho |
||
170 | * @param InputInterface $input |
||
|
|||
171 | * @param OutputInterface $output |
||
172 | */ |
||
173 | private function getUsersReponse(OutputInterface $output) |
||
174 | { |
||
175 | $output->writeln("Start to request users data from zoho."); |
||
176 | $this->usersResponse =$this->zohoClient->getUsers(); |
||
177 | $output->writeln("Finish to requuest users data from zoho."); |
||
178 | } |
||
179 | |||
180 | /** |
||
181 | * Sychronizes the model of the database with Zoho Users records. |
||
182 | * |
||
183 | * @param OutputInterface $output |
||
184 | */ |
||
185 | private function syncUserModel(OutputInterface $output) |
||
192 | |||
193 | |||
194 | /** |
||
195 | * @param AbstractZohoDao $zohoDao |
||
196 | * |
||
197 | * @return array |
||
198 | */ |
||
199 | private function getListFieldName(AbstractZohoDao $zohoDao) |
||
210 | |||
211 | /** |
||
212 | * Regerate Zoho Daos |
||
213 | * @param InputInterface $input |
||
214 | * @param OutputInterface $output |
||
215 | */ |
||
216 | private function regenerateZohoDao(OutputInterface $output) |
||
231 | |||
232 | /** |
||
233 | * Run the fetch User Db command. |
||
234 | * |
||
235 | * @param InputInterface $input |
||
236 | * @param OutputInterface $output |
||
237 | */ |
||
238 | private function fetchUserDb(InputInterface $input, OutputInterface $output) |
||
239 | { |
||
240 | $output->writeln('Starting copying Zoho users data into local database.'); |
||
241 | $this->zohoDatabaseCopier->fetchUserFromZoho($this->usersResponse); |
||
242 | $output->writeln('Zoho users data successfully copied.'); |
||
243 | } |
||
244 | |||
245 | |||
246 | /** |
||
247 | * Run the fetch Db command. |
||
248 | * |
||
249 | * @param InputInterface $input |
||
250 | * @param OutputInterface $output |
||
251 | */ |
||
252 | private function fetchDb(InputInterface $input, OutputInterface $output) |
||
269 | |||
270 | /** |
||
271 | * Run the push Db command. |
||
272 | * |
||
273 | * @param OutputInterface $output |
||
274 | */ |
||
275 | private function pushDb(OutputInterface $output) |
||
284 | } |
||
285 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.