Exponential 5.x Kernel 7.5.40 Exponential New Stack (Symfony-based) Kernel — PHP Class Reference

CoreInstaller.php
Go to the documentation of this file.
1 <?php
2
7 declare(strict_types=1);
8
9 namespace EzSystems\PlatformInstallerBundle\Installer;
10
11 use Doctrine\DBAL\Connection;
12 use Doctrine\DBAL\DBALException;
13 use Doctrine\DBAL\Platforms\AbstractPlatform;
14 use Doctrine\DBAL\Schema\Schema;
15 use EzSystems\DoctrineSchema\API\Builder\SchemaBuilder;
16 use Symfony\Component\Console\Helper\ProgressBar;
17
21 class CoreInstaller extends DbBasedInstaller implements Installer
22 {
24 protected $schemaBuilder;
25
30 public function __construct(Connection $db, SchemaBuilder $schemaBuilder)
31 {
32 parent::__construct($db);
33
34 $this->schemaBuilder = $schemaBuilder;
35 }
36
47 public function importSchema()
48 {
49 // note: schema is built using Schema Builder event-driven API
50 $schema = $this->schemaBuilder->buildSchema();
51 $databasePlatform = $this->db->getDatabasePlatform();
52 $queries = array_merge(
53 $this->getDropSqlStatementsForExistingSchema($schema, $databasePlatform),
54 // generate schema DDL queries
55 $schema->toSql($databasePlatform)
56 );
57
58 $queriesCount = count($queries);
59 $this->output->writeln(
60 sprintf(
61 '<info>Executing %d queries on database <comment>%s</comment> (<comment>%s</comment>)</info>',
62 $queriesCount,
63 $this->db->getDatabase(),
64 $databasePlatform->getName()
65 )
66 );
67 $progressBar = new ProgressBar($this->output);
68 $progressBar->start($queriesCount);
69
70 try {
71 $this->db->beginTransaction();
72 foreach ($queries as $query) {
73 $this->db->exec($query);
74 $progressBar->advance(1);
75 }
76 $this->db->commit();
77 } catch (DBALException $e) {
78 $this->db->rollBack();
79 throw $e;
80 }
81
82 $progressBar->finish();
83 // go to the next line after ProgressBar::finish and add one more extra blank line for readability
84 $this->output->writeln(PHP_EOL);
85 // clear any leftover progress bar parts in the output buffer
86 $progressBar->clear();
87 }
88
93 public function importData()
94 {
95 $this->runQueriesFromFile($this->getKernelSQLFileForDBMS('cleandata.sql'));
96 }
97
104 protected function getDropSqlStatementsForExistingSchema(
105 Schema $newSchema,
106 AbstractPlatform $databasePlatform
107 ): array {
108 $existingSchema = $this->db->getSchemaManager()->createSchema();
109 $statements = [];
110 // reverse table order for clean-up (due to FKs)
111 $tables = array_reverse($newSchema->getTables());
112 // cleanup pre-existing database
113 foreach ($tables as $table) {
114 if ($existingSchema->hasTable($table->getName())) {
115 $statements[] = $databasePlatform->getDropTableSQL($table);
116 }
117 }
118
119 return $statements;
120 }
121
125 public function importBinaries()
126 {
127 }
128
132 public function createConfiguration()
133 {
134 }
135 }
EzSystems\PlatformInstallerBundle\Installer\CoreInstaller
New variant of CleanInstaller, which uses SchemaBuilder.
Definition: CoreInstaller.php:22
EzSystems\PlatformInstallerBundle\Installer\CoreInstaller\importData
importData()
Definition: CoreInstaller.php:93
EzSystems\PlatformInstallerBundle\Installer\CoreInstaller\createConfiguration
createConfiguration()
{Inactive since 6.1, further info: https://jira.ez.no/browse/EZP-25369 }
Definition: CoreInstaller.php:132
EzSystems\PlatformInstallerBundle\Installer\CoreInstaller\importBinaries
importBinaries()
Handle optional import of binary files to var folder.
Definition: CoreInstaller.php:125
EzSystems\PlatformInstallerBundle\Installer\CoreInstaller\__construct
__construct(Connection $db, SchemaBuilder $schemaBuilder)
Definition: CoreInstaller.php:30
EzSystems\PlatformInstallerBundle\Installer\CoreInstaller\importSchema
importSchema()
Import Schema using event-driven Schema Builder API from eZ Systems DoctrineSchema Bundle.
Definition: CoreInstaller.php:47
EzSystems\PlatformInstallerBundle\Installer\CoreInstaller\getDropSqlStatementsForExistingSchema
getDropSqlStatementsForExistingSchema(Schema $newSchema, AbstractPlatform $databasePlatform)
Definition: CoreInstaller.php:104
EzSystems\PlatformInstallerBundle\Installer\CoreInstaller\$schemaBuilder
$schemaBuilder
Definition: CoreInstaller.php:24
EzSystems\PlatformInstallerBundle\Installer\DbBasedInstaller
Definition: DbBasedInstaller.php:14
EzSystems\PlatformInstallerBundle\Installer\DbBasedInstaller\$db
$db
Definition: DbBasedInstaller.php:16
EzSystems\PlatformInstallerBundle\Installer\DbBasedInstaller\getKernelSQLFileForDBMS
getKernelSQLFileForDBMS($relativeFilePath)
Get DBMS-specific SQL data file path.
Definition: DbBasedInstaller.php:87
EzSystems\PlatformInstallerBundle\Installer\DbBasedInstaller\runQueriesFromFile
runQueriesFromFile($file)
Definition: DbBasedInstaller.php:55
EzSystems\PlatformInstallerBundle\Installer\Installer
Interface Installer.
Definition: Installer.php:18
EzSystems\PlatformInstallerBundle\Installer
Definition: CleanInstaller.php:7
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.