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

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 Doctrine\DBAL\Exception;
  16. use Pimcore\Bundle\DataHubBundle\Controller\ConfigController;
  17. use Pimcore\Bundle\DataHubBundle\Migrations\PimcoreX\Version20210305134111;
  18. use Pimcore\Db;
  19. use Pimcore\Extension\Bundle\Installer\Exception\InstallationException;
  20. use Pimcore\Extension\Bundle\Installer\SettingsStoreAwareInstaller;
  21. use Pimcore\Logger;
  22. use Pimcore\Model\Tool\SettingsStore;
  23. use Pimcore\Model\User\Permission\Definition;
  24. class Installer extends SettingsStoreAwareInstaller
  25. {
  26.     const DATAHUB_PERMISSION_CATEGORY 'Datahub';
  27.     const DATAHUB_ADAPTER_PERMISSION 'plugin_datahub_adapter_graphql';
  28.     const DATAHUB_ADMIN_PERMISSION 'plugin_datahub_admin';
  29.     public function needsReloadAfterInstall(): bool
  30.     {
  31.         return true;
  32.     }
  33.     /**
  34.      * {@inheritdoc}
  35.      */
  36.     public function install()
  37.     {
  38.         try {
  39.             // create backend permission
  40.             Definition::create(ConfigController::CONFIG_NAME)->setCategory(self::DATAHUB_PERMISSION_CATEGORY)->save();
  41.             Definition::create(self::DATAHUB_ADAPTER_PERMISSION)->setCategory(self::DATAHUB_PERMISSION_CATEGORY)->save();
  42.             Definition::create(self::DATAHUB_ADMIN_PERMISSION)->setCategory(self::DATAHUB_PERMISSION_CATEGORY)->save();
  43.             $types = ['document''asset''object'];
  44.             $db Db::get();
  45.             foreach ($types as $type) {
  46.                 $db->executeQuery('
  47.                     CREATE TABLE IF NOT EXISTS `plugin_datahub_workspaces_' $type "` (
  48.                         `cid` INT(11) UNSIGNED NOT NULL DEFAULT '0',
  49.                         `cpath` VARCHAR(765) NULL DEFAULT NULL COLLATE 'utf8_general_ci',
  50.                         `configuration` VARCHAR(80) NOT NULL DEFAULT '0',
  51.                         `create` TINYINT(1) UNSIGNED NULL DEFAULT '0',
  52.                         `read` TINYINT(1) UNSIGNED NULL DEFAULT '0',
  53.                         `update` TINYINT(1) UNSIGNED NULL DEFAULT '0',
  54.                         `delete` TINYINT(1) UNSIGNED NULL DEFAULT '0',
  55.                         PRIMARY KEY (`cid`, `configuration`)
  56.                         )
  57.                     COLLATE='utf8mb4_general_ci'
  58.                     ENGINE=InnoDB
  59.                     ;
  60.                 ");
  61.             }
  62.         } catch (\Exception $e) {
  63.             Logger::warn($e);
  64.             throw new InstallationException($e->getMessage());
  65.         }
  66.         parent::install();
  67.     }
  68.     /**
  69.      * @return bool
  70.      *
  71.      * @throws Exception
  72.      */
  73.     public function isInstalled()
  74.     {
  75.         // When switching to SettingsStoreAwareInstaller, we need to explicitly mark this bundle installed, if Settingstore entry doesn't exists and datahub permission is installed
  76.         // e.g. updating from 1.0.* to 1.1.*
  77.         $installEntry SettingsStore::get($this->getSettingsStoreInstallationId(), 'pimcore');
  78.         if (!$installEntry) {
  79.             $db Db::get();
  80.             $check $db->fetchOne('SELECT `key` FROM users_permission_definitions where `key` = ?', [ConfigController::CONFIG_NAME]);
  81.             if ($check) {
  82.                 SettingsStore::set('BUNDLE_INSTALLED__Pimcore\\Bundle\\DataHubBundle\\PimcoreDataHubBundle'true'bool''pimcore');
  83.                 return true;
  84.             }
  85.         }
  86.         return parent::isInstalled();
  87.     }
  88.     public function getLastMigrationVersionClassName(): ?string
  89.     {
  90.         return Version20210305134111::class;
  91.     }
  92. }