forked from shopware/SwagMigrationAssistant
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSwagMigrationAssistant.php
106 lines (91 loc) · 2.95 KB
/
SwagMigrationAssistant.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
100
101
102
103
104
105
106
<?php declare(strict_types=1);
/*
* (c) shopware AG <info@shopware.com>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace SwagMigrationAssistant;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\DBALException;
use Shopware\Core\Defaults;
use Shopware\Core\Framework\Plugin;
use Shopware\Core\Framework\Plugin\Context\InstallContext;
use Shopware\Core\Framework\Plugin\Context\UninstallContext;
use Shopware\Core\Framework\Uuid\Uuid;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
class SwagMigrationAssistant extends Plugin
{
/**
* {@inheritdoc}
*/
public function build(ContainerBuilder $container): void
{
parent::build($container);
$loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/DependencyInjection/'));
$loader->load('entity.xml');
$loader->load('gateway.xml');
$loader->load('migration.xml');
$loader->load('profile.xml');
$loader->load('shopware.xml');
$loader->load('shopware54.xml');
$loader->load('shopware55.xml');
$loader->load('shopware56.xml');
$loader->load('subscriber.xml');
$loader->load('writer.xml');
}
public function rebuildContainer(): bool
{
return false;
}
/**
* {@inheritdoc}
*/
public function getMigrationNamespace(): string
{
return $this->getNamespace() . '\Core\Migration';
}
/**
* {@inheritdoc}
*/
public function postInstall(InstallContext $installContext): void
{
/** @var Connection $connection */
$connection = $this->container->get(Connection::class);
$now = (new \DateTime())->format(Defaults::STORAGE_DATE_TIME_FORMAT);
$connection->beginTransaction();
try {
$connection->insert('swag_migration_general_setting', [
'id' => Uuid::randomBytes(),
'created_at' => $now,
]);
$connection->commit();
} catch (DBALException $e) {
$connection->rollBack();
throw $e;
}
}
/**
* {@inheritdoc}
*/
public function uninstall(UninstallContext $context): void
{
if ($context->keepUserData()) {
parent::uninstall($context);
return;
}
/** @var Connection $connection */
$connection = $this->container->get(Connection::class);
$connection->exec('
DROP TABLE IF EXISTS swag_migration_general_setting;
DROP TABLE IF EXISTS swag_migration_data;
DROP TABLE IF EXISTS swag_migration_mapping;
DROP TABLE IF EXISTS swag_migration_logging;
DROP TABLE IF EXISTS swag_migration_media_file;
DROP TABLE IF EXISTS swag_migration_run;
DROP TABLE IF EXISTS swag_migration_connection;
');
parent::uninstall($context);
}
}