-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathm200929_155818_project_config_support.php
50 lines (42 loc) · 1.31 KB
/
m200929_155818_project_config_support.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
namespace lhs\elasticsearch\migrations;
use Craft;
use craft\db\Migration;
use craft\helpers\ArrayHelper;
use craft\models\EntryType;
/**
* m200929_155818_project_config_support migration.
*/
class m200929_155818_project_config_support extends Migration
{
/**
* @inheritdoc
*/
public function safeUp()
{
$projectConfig = Craft::$app->getProjectConfig();
$ids = $projectConfig->get('plugins.elasticsearch.settings.blacklistedEntryTypes');
$IdToHandleMapping = ArrayHelper::map(
Craft::$app->getEntries()->getAllEntryTypes(),
static function (EntryType $entryType) { return $entryType->id; },
static function (EntryType $entryType) { return $entryType->handle; }
);
$handles = array_map(static function ($id) use ($IdToHandleMapping) {
return $IdToHandleMapping[$id];
}, $ids);
$projectConfig->set(
'plugins.elasticsearch.settings.blacklistedEntryTypes',
$handles,
'Elasticsearch plugin: use handles instead of IDs to identify blacklisted sections.'
);
return true;
}
/**
* @inheritdoc
*/
public function safeDown()
{
echo "m200929_155818_project_config_support cannot be reverted.\n";
return false;
}
}