vendor/pimcore/data-hub/src/Installer.php line 77

Open in your IDE?
  1. <?php
  2. /**
  3.  * Pimcore
  4.  *
  5.  * This source file is available under two different licenses:
  6.  * - GNU General Public License version 3 (GPLv3)
  7.  * - Pimcore Commercial License (PCL)
  8.  * Full copyright and license information is available in
  9.  * LICENSE.md which is distributed with this source code.
  10.  *
  11.  *  @copyright  Copyright (c) Pimcore GmbH (http://www.pimcore.org)
  12.  *  @license    http://www.pimcore.org/license     GPLv3 and PCL
  13.  */
  14. namespace Pimcore\Bundle\DataHubBundle;
  15. use Pimcore\Bundle\DataHubBundle\Controller\ConfigController;
  16. use Pimcore\Bundle\DataHubBundle\Migrations\PimcoreX\Version20230503165847;
  17. use Pimcore\Db;
  18. use Pimcore\Extension\Bundle\Installer\Exception\InstallationException;
  19. use Pimcore\Extension\Bundle\Installer\SettingsStoreAwareInstaller;
  20. use Pimcore\Logger;
  21. use Pimcore\Model\Tool\SettingsStore;
  22. use Pimcore\Model\User\Permission\Definition;
  23. class Installer extends SettingsStoreAwareInstaller
  24. {
  25.     const DATAHUB_PERMISSION_CATEGORY 'Datahub';
  26.     const DATAHUB_ADAPTER_PERMISSION 'plugin_datahub_adapter_graphql';
  27.     const DATAHUB_ADMIN_PERMISSION 'plugin_datahub_admin';
  28.     public function needsReloadAfterInstall(): bool
  29.     {
  30.         return true;
  31.     }
  32.     /**
  33.      * {@inheritdoc}
  34.      */
  35.     public function install(): void
  36.     {
  37.         try {
  38.             // create backend permission
  39.             Definition::create(ConfigController::CONFIG_NAME)->setCategory(self::DATAHUB_PERMISSION_CATEGORY)->save();
  40.             Definition::create(self::DATAHUB_ADAPTER_PERMISSION)->setCategory(self::DATAHUB_PERMISSION_CATEGORY)->save();
  41.             Definition::create(self::DATAHUB_ADMIN_PERMISSION)->setCategory(self::DATAHUB_PERMISSION_CATEGORY)->save();
  42.             $types = ['document''asset''object'];
  43.             $db Db::get();
  44.             foreach ($types as $type) {
  45.                 $db->executeQuery('
  46.                     CREATE TABLE IF NOT EXISTS `plugin_datahub_workspaces_' $type "` (
  47.                         `cid` INT(11) UNSIGNED NOT NULL DEFAULT '0',
  48.                         `cpath` VARCHAR(765) NULL DEFAULT NULL COLLATE 'utf8_general_ci',
  49.                         `configuration` VARCHAR(80) NOT NULL DEFAULT '0',
  50.                         `create` TINYINT(1) UNSIGNED NULL DEFAULT '0',
  51.                         `read` TINYINT(1) UNSIGNED NULL DEFAULT '0',
  52.                         `update` TINYINT(1) UNSIGNED NULL DEFAULT '0',
  53.                         `delete` TINYINT(1) UNSIGNED NULL DEFAULT '0',
  54.                         PRIMARY KEY (`cid`, `configuration`)
  55.                         )
  56.                     COLLATE='utf8mb4_general_ci'
  57.                     ENGINE=InnoDB
  58.                     ;
  59.                 ");
  60.             }
  61.         } catch (\Exception $e) {
  62.             Logger::warn($e);
  63.             throw new InstallationException($e->getMessage());
  64.         }
  65.         parent::install();
  66.     }
  67.     public function isInstalled(): bool
  68.     {
  69.         // When switching to SettingsStoreAwareInstaller, we need to explicitly mark this bundle installed, if Settingstore entry doesn't exists and datahub permission is installed
  70.         // e.g. updating from 1.0.* to 1.1.*
  71.         $installEntry SettingsStore::get($this->getSettingsStoreInstallationId(), 'pimcore');
  72.         if (!$installEntry) {
  73.             $db Db::get();
  74.             $check $db->fetchOne('SELECT `key` FROM users_permission_definitions where `key` = ?', [ConfigController::CONFIG_NAME]);
  75.             if ($check) {
  76.                 SettingsStore::set('BUNDLE_INSTALLED__Pimcore\\Bundle\\DataHubBundle\\PimcoreDataHubBundle'true'bool''pimcore');
  77.                 return true;
  78.             }
  79.         }
  80.         return parent::isInstalled();
  81.     }
  82.     public function getLastMigrationVersionClassName(): ?string
  83.     {
  84.         return Version20230503165847::class;
  85.     }
  86. }