-
Notifications
You must be signed in to change notification settings - Fork 115
/
Copy pathInstaller.php
99 lines (83 loc) · 3.63 KB
/
Installer.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php
/**
* This source file is available under the terms of the
* Pimcore Open Core License (POCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) Pimcore GmbH (https://www.pimcore.com)
* @license Pimcore Open Core License (POCL)
*/
namespace Pimcore\Bundle\DataHubBundle;
use Pimcore\Bundle\DataHubBundle\Controller\ConfigController;
use Pimcore\Bundle\DataHubBundle\Migrations\PimcoreX\Version20230503165847;
use Pimcore\Db;
use Pimcore\Extension\Bundle\Installer\Exception\InstallationException;
use Pimcore\Extension\Bundle\Installer\SettingsStoreAwareInstaller;
use Pimcore\Logger;
use Pimcore\Model\Tool\SettingsStore;
use Pimcore\Model\User\Permission\Definition;
/**
* @internal
*/
final class Installer extends SettingsStoreAwareInstaller
{
const DATAHUB_PERMISSION_CATEGORY = 'Datahub';
const DATAHUB_ADAPTER_PERMISSION = 'plugin_datahub_adapter_graphql';
const DATAHUB_ADMIN_PERMISSION = 'plugin_datahub_admin';
public function needsReloadAfterInstall(): bool
{
return true;
}
public function install(): void
{
try {
// create backend permission
Definition::create(ConfigController::CONFIG_NAME)->setCategory(self::DATAHUB_PERMISSION_CATEGORY)->save();
Definition::create(self::DATAHUB_ADAPTER_PERMISSION)->setCategory(self::DATAHUB_PERMISSION_CATEGORY)->save();
Definition::create(self::DATAHUB_ADMIN_PERMISSION)->setCategory(self::DATAHUB_PERMISSION_CATEGORY)->save();
$types = ['document', 'asset', 'object'];
$db = Db::get();
foreach ($types as $type) {
$db->executeQuery('
CREATE TABLE IF NOT EXISTS `plugin_datahub_workspaces_' . $type . "` (
`cid` INT(11) UNSIGNED NOT NULL DEFAULT '0',
`cpath` VARCHAR(765) NULL DEFAULT NULL COLLATE 'utf8_general_ci',
`configuration` VARCHAR(80) NOT NULL DEFAULT '0',
`create` TINYINT(1) UNSIGNED NULL DEFAULT '0',
`read` TINYINT(1) UNSIGNED NULL DEFAULT '0',
`update` TINYINT(1) UNSIGNED NULL DEFAULT '0',
`delete` TINYINT(1) UNSIGNED NULL DEFAULT '0',
PRIMARY KEY (`cid`, `configuration`)
)
COLLATE='utf8mb4_unicode_520_ci'
ENGINE=InnoDB
;
");
}
} catch (\Exception $e) {
Logger::warn($e);
throw new InstallationException($e->getMessage());
}
parent::install();
}
public function isInstalled(): bool
{
// When switching to SettingsStoreAwareInstaller, we need to explicitly mark this bundle installed, if Settingstore entry doesn't exists and datahub permission is installed
// e.g. updating from 1.0.* to 1.1.*
$installEntry = SettingsStore::get($this->getSettingsStoreInstallationId(), 'pimcore');
if (!$installEntry) {
$db = Db::get();
$check = $db->fetchOne('SELECT `key` FROM users_permission_definitions where `key` = ?', [ConfigController::CONFIG_NAME]);
if ($check) {
SettingsStore::set('BUNDLE_INSTALLED__Pimcore\\Bundle\\DataHubBundle\\PimcoreDataHubBundle', true, 'bool', 'pimcore');
return true;
}
}
return parent::isInstalled();
}
public function getLastMigrationVersionClassName(): ?string
{
return Version20230503165847::class;
}
}