vendor/pimcore/pimcore/bundles/CoreBundle/Migrations/Version20210323082921.php line 1

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4.  * Pimcore
  5.  *
  6.  * This source file is available under two different licenses:
  7.  * - GNU General Public License version 3 (GPLv3)
  8.  * - Pimcore Commercial License (PCL)
  9.  * Full copyright and license information is available in
  10.  * LICENSE.md which is distributed with this source code.
  11.  *
  12.  *  @copyright  Copyright (c) Pimcore GmbH (http://www.pimcore.org)
  13.  *  @license    http://www.pimcore.org/license     GPLv3 and PCL
  14.  */
  15. namespace Pimcore\Bundle\CoreBundle\Migrations;
  16. use Doctrine\DBAL\Schema\Schema;
  17. use Doctrine\Migrations\AbstractMigration;
  18. use Pimcore\Config;
  19. use Pimcore\Db\PhpArrayFileTable;
  20. /**
  21.  * @internal
  22.  */
  23. final class Version20210323082921 extends AbstractMigration
  24. {
  25.     public function getDescription(): string
  26.     {
  27.         return '';
  28.     }
  29.     public function up(Schema $schema): void
  30.     {
  31.         $db \Pimcore\Db::get();
  32.         $db->executeQuery('DROP TABLE IF EXISTS `website_settings`;');
  33.         $db->executeQuery("CREATE TABLE `website_settings` (
  34.     `id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
  35.     `name` VARCHAR(190) NOT NULL DEFAULT '',
  36.     `type` ENUM('text','document','asset','object','bool') DEFAULT NULL,
  37.     `data` TEXT,
  38.     `language` VARCHAR(15) NOT NULL DEFAULT '',
  39.     `siteId` INT(11) UNSIGNED DEFAULT NULL,
  40.     `creationDate` INT(11) UNSIGNED DEFAULT '0',
  41.     `modificationDate` INT(11) UNSIGNED DEFAULT '0',
  42.     PRIMARY KEY (`id`),
  43.     INDEX `name` (`name`),
  44.     INDEX `siteId` (`siteId`)
  45. ) DEFAULT CHARSET=utf8mb4;");
  46.         // move data from PHP file to database
  47.         $file Config::locateConfigFile('website-settings.php');
  48.         if (is_file($file)) {
  49.             $data PhpArrayFileTable::get($file)->fetchAll();
  50.             foreach ($data as $row) {
  51.                 if (!empty($row['id'])) {
  52.                     if (!isset($row['language'])) {
  53.                         $row['language'] = '';
  54.                         $this->write("Language of setting id {$row['id']}{$row['name']} for siteId {$row['siteId']} was NULL, converted to empty string");
  55.                     }
  56.                     $db->insert('website_settings'$row);
  57.                 }
  58.             }
  59.         }
  60.     }
  61.     public function down(Schema $schema): void
  62.     {
  63.         $this->addSql('DROP TABLE IF EXISTS `website_settings`;');
  64.     }
  65. }