|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace NerdsAndCompany\Schematic\Services; |
|
4
|
|
|
|
|
5
|
|
|
use Craft; |
|
6
|
|
|
use NerdsAndCompany\Schematic\Behaviors\SourcesBehavior; |
|
7
|
|
|
use NerdsAndCompany\Schematic\Schematic; |
|
8
|
|
|
use NerdsAndCompany\Schematic\Interfaces\MappingInterface; |
|
9
|
|
|
use yii\base\Component as BaseComponent; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Schematic Element Index Settings Service. |
|
13
|
|
|
* |
|
14
|
|
|
* Sync Craft Setups. |
|
15
|
|
|
* |
|
16
|
|
|
* @author Nerds & Company |
|
17
|
|
|
* @copyright Copyright (c) 2015-2018, Nerds & Company |
|
18
|
|
|
* @license MIT |
|
19
|
|
|
* |
|
20
|
|
|
* @see http://www.nerds.company |
|
21
|
|
|
*/ |
|
22
|
|
|
class ElementIndexSettings extends BaseComponent implements MappingInterface |
|
23
|
1 |
|
{ |
|
24
|
|
|
/** |
|
25
|
1 |
|
* Load sources behaviors. |
|
26
|
|
|
* |
|
27
|
|
|
* @return array |
|
28
|
|
|
*/ |
|
29
|
|
|
public function behaviors() |
|
30
|
|
|
{ |
|
31
|
2 |
|
return [ |
|
32
|
|
|
SourcesBehavior::className(), |
|
|
|
|
|
|
33
|
2 |
|
]; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @return array |
|
38
|
|
|
*/ |
|
39
|
|
|
public function export(array $elementTypes = []): array |
|
40
|
|
|
{ |
|
41
|
|
|
$settingDefinitions = []; |
|
42
|
1 |
|
$elementTypes = Craft::$app->elements->getAllElementTypes(); |
|
43
|
|
|
foreach ($elementTypes as $elementType) { |
|
44
|
1 |
|
$settings = Craft::$app->elementIndexes->getSettings($elementType); |
|
45
|
|
|
if (is_array($settings)) { |
|
46
|
1 |
|
$elementTypeName = str_replace('craft\\elements\\', '', $elementType); |
|
47
|
1 |
|
$settingDefinitions[$elementTypeName] = $this->getMappedSettings($settings, 'id', 'handle'); |
|
48
|
1 |
|
} |
|
49
|
1 |
|
} |
|
50
|
1 |
|
|
|
51
|
1 |
|
return $settingDefinitions; |
|
52
|
|
|
} |
|
53
|
1 |
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @param array $settingDefinitions |
|
56
|
|
|
* |
|
57
|
|
|
* @return Result |
|
58
|
|
|
*/ |
|
59
|
|
|
public function import(array $settingDefinitions, array $elementTypes = []): array |
|
60
|
|
|
{ |
|
61
|
1 |
|
Schematic::warning('Element index import is not yet implemented'); |
|
62
|
|
|
|
|
63
|
1 |
|
foreach ($settingDefinitions as $elementType => $settings) { |
|
64
|
|
|
$mappedSettings = $this->getMappedSettings($settings, 'handle', 'id'); |
|
|
|
|
|
|
65
|
1 |
|
// Import the settings |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
1 |
|
return $elementTypes; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
1 |
|
/** |
|
72
|
|
|
* Get mapped element index settings, converting source ids to handles or back again. |
|
73
|
|
|
* |
|
74
|
1 |
|
* @param array $settings |
|
75
|
|
|
* @param string $fromIndex |
|
76
|
|
|
* @param string $toIndex |
|
77
|
1 |
|
* |
|
78
|
|
|
* @return array |
|
79
|
|
|
*/ |
|
80
|
1 |
|
private function getMappedSettings(array $settings, $fromIndex, $toIndex) |
|
81
|
|
|
{ |
|
82
|
|
|
$mappedSettings = ['sourceOrder' => [], 'sources' => []]; |
|
83
|
1 |
|
|
|
84
|
1 |
|
if (isset($settings['sourceOrder'])) { |
|
85
|
1 |
|
foreach ($settings['sourceOrder'] as $row) { |
|
86
|
1 |
|
if ($row[0] == 'key') { |
|
87
|
|
|
$row[1] = $this->getSource(false, $row[1], $fromIndex, $toIndex); |
|
|
|
|
|
|
88
|
1 |
|
} |
|
89
|
|
|
$mappedSettings['sourceOrder'][] = $row; |
|
90
|
|
|
} |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
if (isset($settings['sources'])) { |
|
94
|
|
|
foreach ($settings['sources'] as $source => $sourceSettings) { |
|
95
|
|
|
$mappedSource = $this->getSource(false, $source, $fromIndex, $toIndex); |
|
|
|
|
|
|
96
|
|
|
$mappedSettings['sources'][$mappedSource] = [ |
|
97
|
|
|
'tableAttributes' => $this->getSources('', $sourceSettings['tableAttributes'], $fromIndex, $toIndex), |
|
|
|
|
|
|
98
|
|
|
]; |
|
99
|
|
|
} |
|
100
|
2 |
|
} |
|
101
|
|
|
|
|
102
|
2 |
|
return $mappedSettings; |
|
103
|
2 |
|
} |
|
104
|
|
|
} |
|
105
|
|
|
|
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.