1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* This file is part of dispositif/wikibot application (@github) |
4
|
|
|
* 2019-2023 © Philippe M./Irønie <[email protected]> |
5
|
|
|
* For the full copyright and MIT license information, view the license file. |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
declare(strict_types=1); |
9
|
|
|
|
10
|
|
|
|
11
|
|
|
namespace App\Application\OuvrageComplete\Handlers; |
12
|
|
|
|
13
|
|
|
|
14
|
|
|
use App\Application\InfrastructurePorts\DbAdapterInterface; |
15
|
|
|
use App\Domain\Models\PageOuvrageDTO; |
16
|
|
|
use App\Domain\Models\Wiki\OuvrageTemplate; |
17
|
|
|
use App\Domain\Utils\TemplateParser; |
18
|
|
|
use Psr\Log\LoggerInterface; |
19
|
|
|
use Throwable; |
20
|
|
|
|
21
|
|
|
class ParseTemplateHandler implements CompleteHandlerInterface |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* @var PageOuvrageDTO |
25
|
|
|
*/ |
26
|
|
|
protected $pageOuvrage; |
27
|
|
|
/** |
28
|
|
|
* @var LoggerInterface |
29
|
|
|
*/ |
30
|
|
|
protected $logger; |
31
|
|
|
/** |
32
|
|
|
* @var DbAdapterInterface |
33
|
|
|
*/ |
34
|
|
|
protected $queueAdapter; |
35
|
|
|
|
36
|
|
|
public function __construct(PageOuvrageDTO $pageOuvrage, DbAdapterInterface $queueAdapter, LoggerInterface $logger) |
37
|
|
|
{ |
38
|
|
|
$this->pageOuvrage = $pageOuvrage; |
39
|
|
|
$this->logger = $logger; |
40
|
|
|
$this->queueAdapter = $queueAdapter; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function handle(): ?OuvrageTemplate |
44
|
|
|
{ |
45
|
|
|
try { |
46
|
|
|
$parse = TemplateParser::parseAllTemplateByName('ouvrage', $this->pageOuvrage->getRaw()); |
|
|
|
|
47
|
|
|
$origin = $parse['ouvrage'][0]['model'] ?? null; |
48
|
|
|
} catch (Throwable $e) { |
49
|
|
|
$this->logger->warning(sprintf( |
50
|
|
|
"*** ERREUR 432 impossible de transformer en modèle => skip %s : %s \n", |
51
|
|
|
$this->pageOuvrage->getId(), |
52
|
|
|
$this->pageOuvrage->getRaw() |
53
|
|
|
)); |
54
|
|
|
$this->queueAdapter->skipRow($this->pageOuvrage->getId()); |
55
|
|
|
sleep(10); |
56
|
|
|
|
57
|
|
|
return null; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
if (!$origin instanceof OuvrageTemplate) { |
61
|
|
|
$this->logger->warning( |
62
|
|
|
sprintf( |
63
|
|
|
"*** ERREUR 433 impossible de transformer en modèle => skip %s : %s \n", |
64
|
|
|
$this->pageOuvrage->getId(), |
65
|
|
|
$this->pageOuvrage->getRaw() |
66
|
|
|
) |
67
|
|
|
); |
68
|
|
|
$this->queueAdapter->skipRow($this->pageOuvrage->getId()); |
69
|
|
|
sleep(10); |
70
|
|
|
return null; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
return $origin; |
74
|
|
|
} |
75
|
|
|
} |