Total Complexity | 65 |
Total Lines | 715 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Complex classes like SelfServicePortalHelper often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use SelfServicePortalHelper, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
67 | class SelfServicePortalHelper extends Module |
||
68 | { |
||
69 | use DataCleanupHelperTrait; |
||
70 | use LocatorHelperTrait; |
||
71 | |||
72 | /** |
||
73 | * @return void |
||
74 | */ |
||
75 | public function ensureProductShipmentTypeTableIsEmpty(): void |
||
76 | { |
||
77 | $this->createProductShipmentTypeQuery()->deleteAll(); |
||
78 | } |
||
79 | |||
80 | /** |
||
81 | * @param array<string, mixed> $productAbstractTypeOverride |
||
82 | * |
||
83 | * @return \Generated\Shared\Transfer\ProductAbstractTypeTransfer |
||
84 | */ |
||
85 | public function haveProductAbstractType(array $productAbstractTypeOverride = []): ProductAbstractTypeTransfer |
||
86 | { |
||
87 | $productAbstractTypeTransfer = (new ProductAbstractTypeBuilder($productAbstractTypeOverride)) |
||
88 | ->build(); |
||
89 | |||
90 | $productAbstractTypeEntity = $this->getProductAbstractTypeQuery() |
||
91 | ->filterByKey($productAbstractTypeTransfer->getKey()) |
||
92 | ->findOneOrCreate(); |
||
93 | |||
94 | $productAbstractTypeEntity->fromArray($productAbstractTypeTransfer->modifiedToArray()); |
||
95 | if ($productAbstractTypeEntity->isNew() || $productAbstractTypeEntity->isModified()) { |
||
96 | $productAbstractTypeEntity->save(); |
||
97 | } |
||
98 | |||
99 | $productAbstractTypeTransfer->setIdProductAbstractType($productAbstractTypeEntity->getIdProductAbstractType()); |
||
100 | |||
101 | $this->getDataCleanupHelper()->_addCleanup(function () use ($productAbstractTypeTransfer): void { |
||
102 | $this->cleanupProductAbstractType($productAbstractTypeTransfer->getIdProductAbstractType()); |
||
103 | }); |
||
104 | |||
105 | return $productAbstractTypeTransfer; |
||
106 | } |
||
107 | |||
108 | /** |
||
109 | * @param int $idProductAbstract |
||
110 | * @param int $idProductAbstractType |
||
111 | * |
||
112 | * @return void |
||
113 | */ |
||
114 | public function haveProductAbstractToProductAbstractType( |
||
115 | int $idProductAbstract, |
||
116 | int $idProductAbstractType |
||
117 | ): void { |
||
118 | $productAbstractToProductAbstractTypeEntity = $this->getProductAbstractToProductAbstractTypeQuery() |
||
119 | ->filterByFkProductAbstract($idProductAbstract) |
||
120 | ->filterByFkProductAbstractType($idProductAbstractType) |
||
121 | ->findOneOrCreate(); |
||
122 | |||
123 | if ($productAbstractToProductAbstractTypeEntity->isNew() || $productAbstractToProductAbstractTypeEntity->isModified()) { |
||
124 | $productAbstractToProductAbstractTypeEntity->save(); |
||
125 | } |
||
126 | |||
127 | $this->getDataCleanupHelper()->_addCleanup(function () use ($idProductAbstract, $idProductAbstractType): void { |
||
128 | $this->cleanupProductAbstractToProductAbstractType( |
||
129 | $idProductAbstract, |
||
130 | $idProductAbstractType, |
||
131 | ); |
||
132 | }); |
||
133 | } |
||
134 | |||
135 | /** |
||
136 | * @param \Generated\Shared\Transfer\ProductConcreteTransfer $productConcreteTransfer |
||
137 | * @param \Generated\Shared\Transfer\ShipmentTypeTransfer $shipmentTypeTransfer |
||
138 | * |
||
139 | * @return void |
||
140 | */ |
||
141 | public function haveProductConcreteShipmentType( |
||
142 | ProductConcreteTransfer $productConcreteTransfer, |
||
143 | ShipmentTypeTransfer $shipmentTypeTransfer |
||
144 | ): void { |
||
145 | $productShipmentTypeEntity = $this->createProductShipmentTypeQuery() |
||
146 | ->filterByFkProduct($productConcreteTransfer->getIdProductConcreteOrFail()) |
||
147 | ->filterByFkShipmentType($shipmentTypeTransfer->getIdShipmentTypeOrFail()) |
||
148 | ->findOneOrCreate(); |
||
149 | |||
150 | $productShipmentTypeEntity->save(); |
||
151 | |||
152 | $this->getDataCleanupHelper()->_addCleanup(function () use ($productShipmentTypeEntity): void { |
||
153 | $this->deleteProductConcreteShipmentType($productShipmentTypeEntity); |
||
154 | }); |
||
155 | } |
||
156 | |||
157 | /** |
||
158 | * @param array $seedData |
||
159 | * @param int|null $idCompanyBusinessUnit |
||
160 | * |
||
161 | * @return \Generated\Shared\Transfer\CmsBlockGlossaryTransfer |
||
162 | */ |
||
163 | public function haveSalesRepresentativeCmsBlockForBusinessUnit(array $seedData = [], ?int $idCompanyBusinessUnit = 0): CmsBlockGlossaryTransfer |
||
164 | { |
||
165 | $cmsBlockTemplateTransfer = $this->getCmsBlockFacade()->findTemplate('@CmsBlock/template/title_and_content_block.twig'); |
||
166 | |||
167 | $cmsBlockTransfer = (new CmsBlockBuilder($seedData))->build(); |
||
168 | $this->setStoreRelation($cmsBlockTransfer, $seedData); |
||
169 | $blockName = $cmsBlockTransfer->getName() . $idCompanyBusinessUnit; |
||
170 | $cmsBlockTransfer->setName($blockName) |
||
171 | ->setKey($blockName) |
||
172 | ->setIdCmsBlock(null) |
||
173 | ->setFkTemplate($cmsBlockTemplateTransfer->getIdCmsBlockTemplate()) |
||
174 | ->setTemplateName($cmsBlockTemplateTransfer->getTemplateName()); |
||
175 | |||
176 | $cmsBlockTransfer = $this->getCmsBlockFacade()->createCmsBlock($cmsBlockTransfer); |
||
177 | |||
178 | $this->createTranslations($cmsBlockTransfer); |
||
179 | |||
180 | return $this->getCmsBlockFacade()->findGlossary($cmsBlockTransfer->getIdCmsBlockOrFail()); |
||
181 | } |
||
182 | |||
183 | /** |
||
184 | * @param array<string, mixed> $seedData |
||
185 | * |
||
186 | * @throws \InvalidArgumentException |
||
187 | * |
||
188 | * @return \Generated\Shared\Transfer\FileAttachmentTransfer |
||
189 | */ |
||
190 | public function haveFileAttachment(array $seedData): FileAttachmentTransfer |
||
191 | { |
||
192 | $fileAttachmentTransfer = (new FileAttachmentBuilder($seedData))->build(); |
||
193 | |||
194 | $entityName = $fileAttachmentTransfer->getEntityNameOrFail(); |
||
195 | $entityId = $fileAttachmentTransfer->getEntityIdOrFail(); |
||
196 | $idFile = $fileAttachmentTransfer->getFileOrFail()->getIdFileOrFail(); |
||
197 | |||
198 | match ($entityName) { |
||
199 | SelfServicePortalConfig::ENTITY_TYPE_COMPANY => $this->createCompanyFileAttachment($idFile, $entityId), |
||
200 | SelfServicePortalConfig::ENTITY_TYPE_COMPANY_USER => $this->createCompanyUserFileAttachment($idFile, $entityId), |
||
201 | SelfServicePortalConfig::ENTITY_TYPE_COMPANY_BUSINESS_UNIT => $this->createCompanyBusinessUnitFileAttachment($idFile, $entityId), |
||
202 | SelfServicePortalConfig::ENTITY_TYPE_SSP_ASSET => $this->createSspAssetFileAttachment($idFile, $entityId), |
||
203 | default => throw new InvalidArgumentException("Invalid entity type: $entityName"), |
||
204 | }; |
||
205 | |||
206 | return $fileAttachmentTransfer; |
||
207 | } |
||
208 | |||
209 | /** |
||
210 | * @param array<string, mixed> $seedData |
||
211 | * |
||
212 | * @return \Generated\Shared\Transfer\SspInquiryTransfer |
||
213 | */ |
||
214 | public function haveSspInquiry(array $seedData = []): SspInquiryTransfer |
||
215 | { |
||
216 | $sspInquiryTransfer = (new SspInquiryBuilder($seedData))->build(); |
||
217 | |||
218 | if (!$sspInquiryTransfer->getStore()->getIdStore()) { |
||
219 | $sspInquiryTransfer->getStore()->setIdStore( |
||
220 | SpyStoreQuery::create()->findOneByName($sspInquiryTransfer->getStore()->getName())->getIdStore(), |
||
221 | ); |
||
222 | } |
||
223 | $sspInquiryEntity = (new SspInquiryMapper())->mapSspInquiryTransferToSspInquiryEntity($sspInquiryTransfer, new SpySspInquiry()); |
||
224 | |||
225 | if ($sspInquiryTransfer->getStatus()) { |
||
226 | $stateMachineItemState = SpyStateMachineItemStateQuery::create()->findOneByName($sspInquiryTransfer->getStatus()); |
||
227 | if ($stateMachineItemState) { |
||
228 | $sspInquiryEntity->setFkStateMachineItemState($stateMachineItemState->getIdStateMachineItemState()); |
||
229 | } |
||
230 | } |
||
231 | |||
232 | if ($sspInquiryTransfer->getCreatedDate()) { |
||
233 | $sspInquiryEntity->setCreatedAt($sspInquiryTransfer->getCreatedDate()); |
||
234 | } |
||
235 | |||
236 | $sspInquiryEntity->save(); |
||
237 | $sspInquiryTransfer->setIdSspInquiry($sspInquiryEntity->getIdSspInquiry()); |
||
238 | if ($sspInquiryTransfer->getOrder()) { |
||
239 | (new SpySspInquirySalesOrder()) |
||
240 | ->setFkSspInquiry($sspInquiryTransfer->getIdSspInquiry()) |
||
241 | ->setFkSalesOrder($sspInquiryTransfer->getOrder()->getIdSalesOrder()) |
||
242 | ->save(); |
||
243 | } |
||
244 | |||
245 | if ($sspInquiryTransfer->getSspAsset()) { |
||
246 | (new SpySspInquirySspAsset()) |
||
247 | ->setFkSspInquiry($sspInquiryTransfer->getIdSspInquiry()) |
||
248 | ->setFkSspAsset($sspInquiryTransfer->getSspAsset()->getIdSspAsset()); |
||
249 | } |
||
250 | |||
251 | $this->generateAndSaveSspInquiryImages($seedData['fileAmount'] ?? 0, $sspInquiryTransfer); |
||
252 | |||
253 | $this->getDataCleanupHelper()->_addCleanup(function () use ($sspInquiryTransfer): void { |
||
254 | $this->debug(sprintf('Deleting Ssp Inquiry: %s', $sspInquiryTransfer->getIdSspInquiry())); |
||
255 | SpySspInquiryFileQuery::create()->filterByFkSspInquiry($sspInquiryTransfer->getIdSspInquiry())->delete(); |
||
256 | SpySspInquiryQuery::create()->filterByIdSspInquiry($sspInquiryTransfer->getIdSspInquiry())->delete(); |
||
257 | }); |
||
258 | |||
259 | return $sspInquiryTransfer; |
||
260 | } |
||
261 | |||
262 | /** |
||
263 | * @param int $idSalesOrder |
||
264 | * @param int $idSspAsset |
||
265 | * |
||
266 | * @return void |
||
267 | */ |
||
268 | public function haveSalesSspAsset(int $idSalesOrder, int $idSspAsset): void |
||
269 | { |
||
270 | $salesOrderEntity = $this->getSalesOrderQuery() |
||
271 | ->filterByIdSalesOrder($idSalesOrder) |
||
272 | ->findOne(); |
||
273 | |||
274 | $sspAssetEntity = $this->getSspAssetQuery() |
||
275 | ->filterByIdSspAsset($idSspAsset) |
||
276 | ->findOne(); |
||
277 | |||
278 | if ($salesOrderEntity === null || $sspAssetEntity === null) { |
||
279 | return; |
||
280 | } |
||
281 | |||
282 | foreach ($salesOrderEntity->getItems() as $salesOrderItemEntity) { |
||
283 | (new SpySalesOrderItemSspAsset()) |
||
284 | ->setName($sspAssetEntity->getName()) |
||
285 | ->setReference($sspAssetEntity->getReference()) |
||
286 | ->setSerialNumber($sspAssetEntity->getSerialNumber()) |
||
287 | ->setFkSalesOrderItem($salesOrderItemEntity->getIdSalesOrderItem()) |
||
288 | ->save(); |
||
289 | } |
||
290 | |||
291 | $this->getDataCleanupHelper()->_addCleanup(function () use ($idSalesOrder, $idSspAsset): void { |
||
292 | $this->cleanupSalesSspAsset( |
||
293 | $idSalesOrder, |
||
294 | $idSspAsset, |
||
295 | ); |
||
296 | }); |
||
297 | } |
||
298 | |||
299 | /** |
||
300 | * @param array<string, mixed> $seedData |
||
301 | * |
||
302 | * @return \Generated\Shared\Transfer\SspAssetTransfer |
||
303 | */ |
||
304 | public function haveAsset(array $seedData = []): SspAssetTransfer |
||
305 | { |
||
306 | $sspAssetTransfer = (new SspAssetBuilder($seedData))->build(); |
||
307 | |||
308 | $sspAssetEntity = (new SspAssetMapper(new UtilDateTimeService()))->mapSspAssetTransferToSpySspAssetEntity($sspAssetTransfer, new SpySspAsset()); |
||
309 | |||
310 | if (isset($seedData['image'])) { |
||
311 | $this->attachImageToAsset($sspAssetTransfer, $seedData['image']); |
||
312 | } elseif (isset($seedData['generateImage']) && $seedData['generateImage']) { |
||
313 | $this->attachImageToAsset($sspAssetTransfer, $this->generateSmallFile()); |
||
314 | } |
||
315 | |||
316 | if ($sspAssetTransfer->getImage()) { |
||
317 | $sspAssetEntity->setFkImageFile($sspAssetTransfer->getImageOrFail()->getIdFileOrFail()); |
||
318 | } |
||
319 | |||
320 | $sspAssetEntity->save(); |
||
321 | foreach ($sspAssetTransfer->getBusinessUnitAssignments() as $assignment) { |
||
322 | (new SpySspAssetToCompanyBusinessUnit()) |
||
323 | ->setFkSspAsset($sspAssetEntity->getIdSspAsset()) |
||
324 | ->setFkCompanyBusinessUnit($assignment->getCompanyBusinessUnit()->getIdCompanyBusinessUnit()) |
||
325 | ->save(); |
||
326 | } |
||
327 | |||
328 | if (isset($seedData['sspInquiries'])) { |
||
329 | foreach ($seedData['sspInquiries'] as $sspInquiry) { |
||
330 | (new SpySspInquirySspAsset()) |
||
331 | ->setFkSspInquiry($sspInquiry->getIdSspInquiry()) |
||
332 | ->setFkSspAsset($sspAssetEntity->getIdSspAsset()) |
||
333 | ->save(); |
||
334 | } |
||
335 | } |
||
336 | |||
337 | $sspAssetTransfer->setIdSspAsset($sspAssetEntity->getIdSspAsset()); |
||
338 | |||
339 | $this->getDataCleanupHelper()->_addCleanup(function () use ($sspAssetTransfer): void { |
||
340 | $this->debug(sprintf('Deleting Asset: %s', $sspAssetTransfer->getIdSspAsset())); |
||
341 | SpySspAssetToCompanyBusinessUnitQuery::create()->filterByFkSspAsset($sspAssetTransfer->getIdSspAsset())->delete(); |
||
342 | SpySspInquirySspAssetQuery::create()->filterByFkSspAsset($sspAssetTransfer->getIdSspAsset())->delete(); |
||
343 | SpySspAssetQuery::create()->filterByIdSspAsset($sspAssetTransfer->getIdSspAsset())->delete(); |
||
344 | }); |
||
345 | |||
346 | return $sspAssetTransfer; |
||
347 | } |
||
348 | |||
349 | /** |
||
350 | * @param \Generated\Shared\Transfer\SspAssetTransfer $sspAssetTransfer |
||
351 | * @param array<string, mixed> $imageData |
||
352 | * |
||
353 | * @return void |
||
354 | */ |
||
355 | public function attachImageToAsset(SspAssetTransfer $sspAssetTransfer, array $imageData): void |
||
356 | { |
||
357 | $fileManagerDataTransfer = new FileManagerDataTransfer(); |
||
358 | $fileName = sprintf('%s.%s', Uuid::uuid4()->toString(), $imageData['extension']); |
||
359 | |||
360 | $fileManagerDataTransfer->setFileInfo( |
||
361 | (new FileInfoTransfer()) |
||
362 | ->setStorageFileName($fileName) |
||
363 | ->setExtension($imageData['extension']) |
||
364 | ->setSize(strlen($imageData['content'])) |
||
365 | ->setType($imageData['type']), |
||
366 | ); |
||
367 | $fileManagerDataTransfer->setContent($imageData['content']); |
||
368 | $fileManagerDataTransfer->setFile( |
||
369 | (new FileTransfer()) |
||
370 | ->setFileName($fileName) |
||
371 | ->setEncodedContent(base64_encode(gzencode($imageData['content']))) |
||
372 | ->setFileUpload( |
||
373 | (new FileUploadTransfer()) |
||
374 | ->setSize(strlen($imageData['content'])) |
||
375 | ->setMimeTypeName($imageData['type']) |
||
376 | ->setClientOriginalExtension($imageData['extension']), |
||
377 | ), |
||
378 | ); |
||
379 | |||
380 | $fileManagerDataTransfer = (new FileManagerFacade())->saveFile($fileManagerDataTransfer); |
||
381 | |||
382 | $sspAssetTransfer->setImage($fileManagerDataTransfer->getFileOrFail()); |
||
383 | } |
||
384 | |||
385 | /** |
||
386 | * Generates a small image. |
||
387 | * |
||
388 | * @return array<string, string> |
||
389 | */ |
||
390 | public function generateSmallFile(): array |
||
391 | { |
||
392 | $extensions = ['png', 'jpg', 'jpeg', 'heic']; |
||
393 | $extension = $extensions[array_rand($extensions)]; |
||
394 | $size = rand(1, 200 * 1024); // Random size from 1B to 200kB |
||
395 | |||
396 | $imageContent = ''; |
||
397 | $type = ''; |
||
398 | switch ($extension) { |
||
399 | case 'png': |
||
400 | case 'jpg': |
||
401 | case 'jpeg': |
||
402 | $image = imagecreatetruecolor(100, 100); |
||
403 | $backgroundColor = imagecolorallocate($image, 255, 0, 0); |
||
404 | imagefill($image, 0, 0, $backgroundColor); |
||
405 | |||
406 | ob_start(); |
||
407 | if ($extension === 'png') { |
||
408 | imagepng($image); |
||
409 | $type = 'image/png'; |
||
410 | } else { |
||
411 | imagejpeg($image); |
||
412 | $type = 'image/jpeg'; |
||
413 | } |
||
414 | $imageContent = ob_get_clean(); |
||
415 | imagedestroy($image); |
||
416 | |||
417 | break; |
||
418 | case 'heic': |
||
419 | // Simulate a HEIC file with random content |
||
420 | $imageContent = str_repeat('H', $size); |
||
421 | $type = 'image/heic'; |
||
422 | |||
423 | break; |
||
424 | } |
||
425 | |||
426 | if (strlen($imageContent) > $size) { |
||
427 | $imageContent = substr($imageContent, 0, $size); |
||
428 | } else { |
||
429 | $imageContent = str_pad($imageContent, $size, ' '); |
||
430 | } |
||
431 | |||
432 | return ['content' => $imageContent, 'extension' => $extension, 'type' => $type]; |
||
433 | } |
||
434 | |||
435 | /** |
||
436 | * @param int $idSalesOrder |
||
437 | * @param int $idSspAsset |
||
438 | * |
||
439 | * @return void |
||
440 | */ |
||
441 | protected function cleanupSalesSspAsset(int $idSalesOrder, int $idSspAsset): void |
||
442 | { |
||
443 | $salesOrderEntity = $this->getSalesOrderQuery() |
||
444 | ->filterByIdSalesOrder($idSalesOrder) |
||
445 | ->findOne(); |
||
446 | |||
447 | if ($salesOrderEntity === null) { |
||
448 | return; |
||
449 | } |
||
450 | |||
451 | $sspAssetEntity = $this->getSspAssetQuery() |
||
452 | ->filterByIdSspAsset($idSspAsset) |
||
453 | ->findOne(); |
||
454 | |||
455 | if ($sspAssetEntity === null) { |
||
456 | return; |
||
457 | } |
||
458 | |||
459 | $salesOrderItemIds = []; |
||
460 | foreach ($salesOrderEntity->getItems() as $salesOrderItemEntity) { |
||
461 | $salesOrderItemIds[] = $salesOrderItemEntity->getIdSalesOrderItem(); |
||
462 | } |
||
463 | |||
464 | if ($salesOrderItemIds) { |
||
465 | SpySalesOrderItemSspAssetQuery::create() |
||
466 | ->filterByFkSalesOrderItem_In($salesOrderItemIds) |
||
467 | ->filterByReference($sspAssetEntity->getReference()) |
||
468 | ->delete(); |
||
469 | } |
||
470 | } |
||
471 | |||
472 | /** |
||
473 | * Generates and saves small images for the ssp inquiry. |
||
474 | * |
||
475 | * @param int $fileAmount |
||
476 | * @param \Generated\Shared\Transfer\SspInquiryTransfer|int $sspInquiryTransfer |
||
477 | * |
||
478 | * @return void |
||
479 | */ |
||
480 | protected function generateAndSaveSspInquiryImages(int $fileAmount, SspInquiryTransfer $sspInquiryTransfer): void |
||
481 | { |
||
482 | for ($i = 0; $i < $fileAmount; $i++) { |
||
483 | $file = $this->generateSmallFile(); |
||
484 | $fileName = sprintf('%s.%s', Uuid::uuid4()->toString(), $file['extension']); |
||
485 | $fileManagerDataTransfer = new FileManagerDataTransfer(); |
||
486 | $fileManagerDataTransfer->setFileInfo( |
||
487 | (new FileInfoTransfer()) |
||
488 | ->setStorageFileName($fileName) |
||
489 | ->setExtension($file['extension']) |
||
490 | ->setSize(strlen($file['content'])) |
||
491 | ->setType($file['type']), |
||
492 | ); |
||
493 | $fileManagerDataTransfer->setContent($file['content']); |
||
494 | $fileManagerDataTransfer->setFile( |
||
495 | (new FileTransfer())->setFileName($fileName), |
||
496 | ); |
||
497 | |||
498 | $fileManagerDataTransfer = (new FileManagerFacade())->saveFile($fileManagerDataTransfer); |
||
499 | (new SpySspInquiryFile())->setFkSspInquiry($sspInquiryTransfer->getIdSspInquiry()) |
||
500 | ->setFkFile($fileManagerDataTransfer->getFile()->getIdFile()) |
||
501 | ->save(); |
||
502 | $sspInquiryTransfer->addFile( |
||
503 | (new FileTransfer()) |
||
504 | ->setIdFile($fileManagerDataTransfer->getFile()->getIdFile()) |
||
505 | ->setFileName($fileName) |
||
506 | ->setFileInfo(new ArrayObject([$fileManagerDataTransfer->getFileInfo()])), |
||
507 | ); |
||
508 | } |
||
509 | } |
||
510 | |||
511 | /** |
||
512 | * @param \Generated\Shared\Transfer\CmsBlockTransfer $cmsBlockTransfer |
||
513 | * @param array $seedData |
||
514 | * |
||
515 | * @return void |
||
516 | */ |
||
517 | protected function setStoreRelation(CmsBlockTransfer $cmsBlockTransfer, array $seedData = []): void |
||
518 | { |
||
519 | if (!isset($seedData[CmsBlockTransfer::STORE_RELATION])) { |
||
520 | return; |
||
521 | } |
||
522 | |||
523 | $cmsBlockTransfer->setStoreRelation( |
||
524 | (new StoreRelationTransfer()) |
||
525 | ->fromArray($seedData[CmsBlockTransfer::STORE_RELATION]), |
||
526 | ); |
||
527 | } |
||
528 | |||
529 | /** |
||
530 | * @return \Spryker\Zed\CmsBlock\Business\CmsBlockFacadeInterface |
||
531 | */ |
||
532 | protected function getCmsBlockFacade(): CmsBlockFacadeInterface |
||
533 | { |
||
534 | return $this->getLocator()->cmsBlock()->facade(); |
||
535 | } |
||
536 | |||
537 | /** |
||
538 | * @param \Generated\Shared\Transfer\CmsBlockTransfer $cmsBlockTransfer |
||
539 | * |
||
540 | * @return void |
||
541 | */ |
||
542 | protected function createTranslations(CmsBlockTransfer $cmsBlockTransfer): void |
||
543 | { |
||
544 | $cmsBlockGlossaryPlaceholderTranslationTransfer = (new CmsBlockGlossaryPlaceholderTranslationBuilder()) |
||
545 | ->build() |
||
546 | ->setFkLocale($cmsBlockTransfer->getLocale()->getIdLocale()) |
||
547 | ->setLocaleName($cmsBlockTransfer->getLocale()->getLocaleName()); |
||
548 | |||
549 | $contentCmsBlockGlossaryPlaceholderTransfer = (new CmsBlockGlossaryPlaceholderBuilder()) |
||
550 | ->build() |
||
551 | ->setPlaceholder('content') |
||
552 | ->addTranslation($cmsBlockGlossaryPlaceholderTranslationTransfer) |
||
553 | ->setFkCmsBlock($cmsBlockTransfer->getIdCmsBlock()) |
||
554 | ->setTemplateName($cmsBlockTransfer->getTemplateName()); |
||
555 | $descriptionCmsBlockGlossaryPlaceholderTransfer = (new CmsBlockGlossaryPlaceholderBuilder()) |
||
556 | ->build() |
||
557 | ->setPlaceholder('description') |
||
558 | ->addTranslation($cmsBlockGlossaryPlaceholderTranslationTransfer) |
||
559 | ->setFkCmsBlock($cmsBlockTransfer->getIdCmsBlock()) |
||
560 | ->setTemplateName($cmsBlockTransfer->getTemplateName()); |
||
561 | $titleCmsBlockGlossaryPlaceholderTransfer = (new CmsBlockGlossaryPlaceholderBuilder()) |
||
562 | ->build() |
||
563 | ->setPlaceholder('title') |
||
564 | ->addTranslation($cmsBlockGlossaryPlaceholderTranslationTransfer) |
||
565 | ->setFkCmsBlock($cmsBlockTransfer->getIdCmsBlock()) |
||
566 | ->setTemplateName($cmsBlockTransfer->getTemplateName()); |
||
567 | |||
568 | $cmsBlockGlossaryTransfer = (new CmsBlockGlossaryTransfer()) |
||
569 | ->addGlossaryPlaceholder($contentCmsBlockGlossaryPlaceholderTransfer) |
||
570 | ->addGlossaryPlaceholder($descriptionCmsBlockGlossaryPlaceholderTransfer) |
||
571 | ->addGlossaryPlaceholder($titleCmsBlockGlossaryPlaceholderTransfer); |
||
572 | |||
573 | $this->getCmsBlockFacade()->saveGlossary($cmsBlockGlossaryTransfer); |
||
574 | } |
||
575 | |||
576 | /** |
||
577 | * @param int $idProductAbstractType |
||
578 | * |
||
579 | * @return void |
||
580 | */ |
||
581 | protected function cleanupProductAbstractType(int $idProductAbstractType): void |
||
582 | { |
||
583 | $this->getProductAbstractToProductAbstractTypeQuery() |
||
584 | ->filterByFkProductAbstractType($idProductAbstractType) |
||
585 | ->delete(); |
||
586 | |||
587 | $this->getProductAbstractTypeQuery() |
||
588 | ->filterByIdProductAbstractType($idProductAbstractType) |
||
589 | ->delete(); |
||
590 | } |
||
591 | |||
592 | /** |
||
593 | * @param int $idProductAbstract |
||
594 | * @param int $idProductAbstractType |
||
595 | * |
||
596 | * @return void |
||
597 | */ |
||
598 | protected function cleanupProductAbstractToProductAbstractType(int $idProductAbstract, int $idProductAbstractType): void |
||
599 | { |
||
600 | $this->getProductAbstractToProductAbstractTypeQuery() |
||
601 | ->filterByFkProductAbstract($idProductAbstract) |
||
602 | ->filterByFkProductAbstractType($idProductAbstractType) |
||
603 | ->delete(); |
||
604 | } |
||
605 | |||
606 | /** |
||
607 | * @param \Orm\Zed\SelfServicePortal\Persistence\SpyProductShipmentType $productShipmentTypeEntity |
||
608 | * |
||
609 | * @return void |
||
610 | */ |
||
611 | protected function deleteProductConcreteShipmentType(SpyProductShipmentType $productShipmentTypeEntity): void |
||
612 | { |
||
613 | $this->createProductShipmentTypeQuery() |
||
614 | ->filterByIdProductShipmentType($productShipmentTypeEntity->getIdProductShipmentType()) |
||
615 | ->delete(); |
||
616 | } |
||
617 | |||
618 | /** |
||
619 | * @return \Orm\Zed\SelfServicePortal\Persistence\SpyProductShipmentTypeQuery |
||
620 | */ |
||
621 | protected function createProductShipmentTypeQuery(): SpyProductShipmentTypeQuery |
||
622 | { |
||
623 | return SpyProductShipmentTypeQuery::create(); |
||
624 | } |
||
625 | |||
626 | /** |
||
627 | * @return \Orm\Zed\SelfServicePortal\Persistence\SpyProductAbstractTypeQuery |
||
628 | */ |
||
629 | protected function getProductAbstractTypeQuery(): SpyProductAbstractTypeQuery |
||
630 | { |
||
631 | return SpyProductAbstractTypeQuery::create(); |
||
632 | } |
||
633 | |||
634 | /** |
||
635 | * @return \Orm\Zed\SelfServicePortal\Persistence\SpyProductAbstractToProductAbstractTypeQuery |
||
636 | */ |
||
637 | protected function getProductAbstractToProductAbstractTypeQuery(): SpyProductAbstractToProductAbstractTypeQuery |
||
638 | { |
||
639 | return SpyProductAbstractToProductAbstractTypeQuery::create(); |
||
640 | } |
||
641 | |||
642 | /** |
||
643 | * @return void |
||
644 | */ |
||
645 | public function ensureFileAttachmentTablesAreEmpty(): void |
||
646 | { |
||
647 | $this->createCompanyFileQuery()->deleteAll(); |
||
648 | $this->createCompanyUserFileQuery()->deleteAll(); |
||
649 | $this->createCompanyBusinessUnitFileQuery()->deleteAll(); |
||
650 | } |
||
651 | |||
652 | /** |
||
653 | * @param int $idFile |
||
654 | * @param int $idCompany |
||
655 | * |
||
656 | * @return void |
||
657 | */ |
||
658 | protected function createCompanyFileAttachment(int $idFile, int $idCompany): void |
||
659 | { |
||
660 | $companyFileEntity = $this->createCompanyFileQuery() |
||
661 | ->filterByFkFile($idFile) |
||
662 | ->filterByFkCompany($idCompany) |
||
663 | ->findOneOrCreate(); |
||
664 | |||
665 | $companyFileEntity->save(); |
||
666 | |||
667 | $this->getDataCleanupHelper()->addCleanup(function () use ($companyFileEntity): void { |
||
668 | $companyFileEntity->delete(); |
||
669 | }); |
||
670 | } |
||
671 | |||
672 | /** |
||
673 | * @param int $idFile |
||
674 | * @param int $idCompanyUser |
||
675 | * |
||
676 | * @return void |
||
677 | */ |
||
678 | protected function createCompanyUserFileAttachment(int $idFile, int $idCompanyUser): void |
||
679 | { |
||
680 | $companyUserFileEntity = $this->createCompanyUserFileQuery() |
||
681 | ->filterByFkFile($idFile) |
||
682 | ->filterByFkCompanyUser($idCompanyUser) |
||
683 | ->findOneOrCreate(); |
||
684 | |||
685 | $companyUserFileEntity->save(); |
||
686 | |||
687 | $this->getDataCleanupHelper()->addCleanup(function () use ($companyUserFileEntity): void { |
||
688 | $companyUserFileEntity->delete(); |
||
689 | }); |
||
690 | } |
||
691 | |||
692 | /** |
||
693 | * @param int $idFile |
||
694 | * @param int $idCompanyBusinessUnit |
||
695 | * |
||
696 | * @return void |
||
697 | */ |
||
698 | protected function createCompanyBusinessUnitFileAttachment( |
||
699 | int $idFile, |
||
700 | int $idCompanyBusinessUnit |
||
701 | ): void { |
||
702 | $companyBusinessUnitFileEntity = $this->createCompanyBusinessUnitFileQuery() |
||
703 | ->filterByFkFile($idFile) |
||
704 | ->filterByFkCompanyBusinessUnit($idCompanyBusinessUnit) |
||
705 | ->findOneOrCreate(); |
||
706 | |||
707 | $companyBusinessUnitFileEntity->save(); |
||
708 | |||
709 | $this->getDataCleanupHelper()->addCleanup(function () use ($companyBusinessUnitFileEntity): void { |
||
710 | $companyBusinessUnitFileEntity->delete(); |
||
711 | }); |
||
712 | } |
||
713 | |||
714 | /** |
||
715 | * @param int $idFile |
||
716 | * @param int $idSspAsset |
||
717 | * |
||
718 | * @return void |
||
719 | */ |
||
720 | protected function createSspAssetFileAttachment( |
||
733 | }); |
||
734 | } |
||
735 | |||
736 | /** |
||
737 | * @return \Orm\Zed\SelfServicePortal\Persistence\SpyCompanyFileQuery |
||
738 | */ |
||
739 | public function createCompanyFileQuery(): SpyCompanyFileQuery |
||
742 | } |
||
743 | |||
744 | /** |
||
745 | * @return \Orm\Zed\SelfServicePortal\Persistence\SpyCompanyUserFileQuery |
||
746 | */ |
||
747 | public function createCompanyUserFileQuery(): SpyCompanyUserFileQuery |
||
748 | { |
||
749 | return SpyCompanyUserFileQuery::create(); |
||
750 | } |
||
751 | |||
752 | /** |
||
753 | * @return \Orm\Zed\SelfServicePortal\Persistence\SpyCompanyBusinessUnitFileQuery |
||
754 | */ |
||
755 | public function createCompanyBusinessUnitFileQuery(): SpyCompanyBusinessUnitFileQuery |
||
756 | { |
||
757 | return SpyCompanyBusinessUnitFileQuery::create(); |
||
758 | } |
||
759 | |||
760 | /** |
||
761 | * @return \Orm\Zed\SelfServicePortal\Persistence\SpySspAssetFileQuery |
||
762 | */ |
||
763 | public function createSspAssetFileQuery(): SpySspAssetFileQuery |
||
764 | { |
||
765 | return SpySspAssetFileQuery::create(); |
||
766 | } |
||
767 | |||
768 | /** |
||
769 | * @return \Orm\Zed\Sales\Persistence\SpySalesOrderQuery |
||
770 | */ |
||
771 | protected function getSalesOrderQuery(): SpySalesOrderQuery |
||
774 | } |
||
775 | |||
776 | /** |
||
777 | * @return \Orm\Zed\SspAssetManagement\Persistence\SpySspAssetQuery |
||
778 | */ |
||
779 | protected function getSspAssetQuery(): SpySspAssetQuery |
||
780 | { |
||
781 | return SpySspAssetQuery::create(); |
||
782 | } |
||
783 | } |
||
784 |