1 | <?php |
||
12 | class SyncContentsCommand extends AbstractSyncCommand |
||
13 | { |
||
14 | |||
15 | /** |
||
16 | * @var string |
||
17 | */ |
||
18 | protected $signature = 'contentful:contents:sync |
||
19 | {contentTypes?* : The content types, e.g. "article" or "brand". You can specify multiple content types. Omit to synchronize all content types.} |
||
20 | {--batchSize=100 : The number of items to request from Contentful in one batch. Defaults to 100.} |
||
21 | {--ignoreErrors : Whether to ignore errors when synchronizing, useful to get around circular references.} |
||
22 | {--ignoreExisting : Whether to ignore existing entries, i.e. only synchronize new entries.}'; |
||
23 | |||
24 | /** |
||
25 | * @var string |
||
26 | */ |
||
27 | protected $description = 'Synchronizes content from Contentful'; |
||
28 | |||
29 | /** |
||
30 | * @var boolean |
||
31 | */ |
||
32 | protected $ignoreErrors; |
||
33 | |||
34 | /** |
||
35 | * @inheritdoc |
||
36 | */ |
||
37 | protected function getQuery(?string $contentType = null): Query |
||
46 | |||
47 | /** |
||
48 | * @inheritdoc |
||
49 | */ |
||
50 | public function handle() |
||
51 | { |
||
52 | parent::handle(); |
||
53 | |||
54 | // Parse options and arguments |
||
55 | $this->ignoreErrors = (bool)$this->option('ignoreErrors'); |
||
56 | $contentTypes = $this->argument('contentTypes'); |
||
57 | |||
58 | // Synchronize all content types in a particular order unless specific content types were specified |
||
59 | if (!\is_array($contentTypes) || empty($contentTypes)) { |
||
60 | $contentTypes = $this->contentTypes; |
||
61 | } |
||
62 | |||
63 | foreach ($contentTypes as $contentType) { |
||
64 | // Reset counters before each content type |
||
65 | $this->resetCounters(); |
||
66 | |||
67 | $this->synchronizeContentType($contentType); |
||
68 | } |
||
69 | } |
||
70 | |||
71 | /** |
||
72 | * @param string $contentType |
||
73 | * |
||
74 | * @throws \Throwable |
||
75 | */ |
||
76 | protected function synchronizeContentType(string $contentType): void |
||
115 | } |
||
116 |