forked from shopware5/SwagImportExport
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SwagImportExport.php
108 lines (90 loc) · 3.15 KB
/
SwagImportExport.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
107
108
<?php
declare(strict_types=1);
/**
* (c) shopware AG <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace SwagImportExport;
use Shopware\Components\Plugin;
use Shopware\Components\Plugin\Context\ActivateContext;
use Shopware\Components\Plugin\Context\DeactivateContext;
use Shopware\Components\Plugin\Context\InstallContext;
use Shopware\Components\Plugin\Context\UninstallContext;
use Shopware\Components\Plugin\Context\UpdateContext;
use SwagImportExport\Resources\Compiler\HookablePass;
use SwagImportExport\Setup\Install\DefaultProfileInstaller;
use SwagImportExport\Setup\Update\DefaultProfileUpdater;
use Symfony\Component\DependencyInjection\ContainerBuilder;
class SwagImportExport extends Plugin
{
/**
* {@inheritdoc}
*/
public function build(ContainerBuilder $container): void
{
$container->setParameter('swag_import_export.plugin_dir', $this->getPath());
$container->addCompilerPass(new HookablePass());
parent::build($container);
}
/**
* {@inheritdoc}
*/
public function install(InstallContext $context): void
{
$cacheManager = $this->container->get('shopware.cache_manager');
$cacheManager->clearProxyCache();
(new DefaultProfileInstaller($this->container->get('dbal_connection')))->install();
$this->createDirectories();
}
/**
* {@inheritdoc}
*/
public function update(UpdateContext $context): void
{
$cacheManager = $this->container->get('shopware.cache_manager');
$cacheManager->clearProxyCache();
(new DefaultProfileUpdater($this->container->get('dbal_connection')))->update();
$context->scheduleClearCache(UpdateContext::CACHE_LIST_ALL);
$this->createDirectories();
}
/**
* {@inheritdoc}
*/
public function uninstall(UninstallContext $context): void
{
$context->scheduleClearCache(UninstallContext::CACHE_LIST_ALL);
}
/**
* {@inheritdoc}
*/
public function activate(ActivateContext $context): void
{
$context->scheduleClearCache(ActivateContext::CACHE_LIST_ALL);
}
/**
* {@inheritdoc}
*/
public function deactivate(DeactivateContext $context): void
{
$context->scheduleClearCache(DeactivateContext::CACHE_LIST_ALL);
}
private function createDirectories(): void
{
$importCronPath = Shopware()->DocPath() . 'files/import_cron/';
if (!\file_exists($importCronPath)) {
\mkdir($importCronPath, 0777, true);
}
if (!\file_exists($importCronPath . '.htaccess')) {
\copy($this->getPath() . '/Setup/SwagImportExport/template', $importCronPath . '/.htaccess');
}
$importExportPath = Shopware()->DocPath() . 'files/import_export/';
if (!\file_exists($importExportPath)) {
\mkdir($importExportPath, 0777, true);
}
if (!\file_exists($importExportPath . '.htaccess')) {
\copy($this->getPath() . '/Setup/SwagImportExport/template', $importExportPath . '/.htaccess');
}
}
}