1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* This file is part of EC-CUBE |
4
|
|
|
* |
5
|
|
|
* Copyright(c) 2000-2017 LOCKON CO.,LTD. All Rights Reserved. |
6
|
|
|
* |
7
|
|
|
* http://www.lockon.co.jp/ |
8
|
|
|
* |
9
|
|
|
* This program is free software; you can redistribute it and/or |
10
|
|
|
* modify it under the terms of the GNU General Public License |
11
|
|
|
* as published by the Free Software Foundation; either version 2 |
12
|
|
|
* of the License, or (at your option) any later version. |
13
|
|
|
* |
14
|
|
|
* This program is distributed in the hope that it will be useful, |
15
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
16
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17
|
|
|
* GNU General Public License for more details. |
18
|
|
|
* |
19
|
|
|
* You should have received a copy of the GNU General Public License |
20
|
|
|
* along with this program; if not, write to the Free Software |
21
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
22
|
|
|
*/ |
23
|
|
|
|
24
|
|
|
namespace Eccube\Service; |
25
|
|
|
use Doctrine\Common\Annotations\AnnotationReader; |
26
|
|
|
use Doctrine\ORM\EntityManager; |
27
|
|
|
use Doctrine\ORM\Tools\SchemaTool; |
28
|
|
|
use Eccube\Annotation\Inject; |
29
|
|
|
use Eccube\Annotation\Service; |
30
|
|
|
use Eccube\Doctrine\ORM\Mapping\Driver\ReloadSafeAnnotationDriver; |
31
|
|
|
use Eccube\Util\Str; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @Service |
35
|
|
|
*/ |
36
|
|
|
class SchemaService |
37
|
|
|
{ |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @Inject("orm.em") |
41
|
|
|
* @var EntityManager |
42
|
|
|
*/ |
43
|
|
|
protected $entityManager; |
44
|
|
|
|
45
|
|
|
public function updateSchema($generatedFiles) |
|
|
|
|
46
|
|
|
{ |
47
|
|
|
$outputDir = sys_get_temp_dir() . '/proxy_' . Str::random(12); |
|
|
|
|
48
|
|
|
mkdir($outputDir); |
49
|
|
|
|
50
|
|
|
try { |
51
|
|
|
$chain = $this->entityManager->getConfiguration()->getMetadataDriverImpl(); |
52
|
|
|
$drivers = $chain->getDrivers(); |
53
|
|
|
foreach ($drivers as $namespace => $oldDriver) { |
54
|
|
|
if ('Eccube\Entity' === $namespace) { |
55
|
|
|
$newDriver = new ReloadSafeAnnotationDriver( |
56
|
|
|
new AnnotationReader(), |
57
|
|
|
$oldDriver->getPaths() |
58
|
|
|
); |
59
|
|
|
$newDriver->setFileExtension($oldDriver->getFileExtension()); |
60
|
|
|
$newDriver->addExcludePaths($oldDriver->getExcludePaths()); |
61
|
|
|
$newDriver->setTraitProxiesDirectory(realpath(__DIR__.'/../../../app/proxy/entity')); |
62
|
|
|
$newDriver->setNewProxyFiles($generatedFiles); |
63
|
|
|
$newDriver->setOutputDir($outputDir); |
64
|
|
|
$chain->addDriver($newDriver, $namespace); |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
$tool = new SchemaTool($this->entityManager); |
69
|
|
|
$metaData = $this->entityManager->getMetadataFactory()->getAllMetadata(); |
70
|
|
|
$tool->updateSchema($metaData, true); |
71
|
|
|
|
|
|
|
|
72
|
|
|
} finally { |
73
|
|
|
foreach (glob("${outputDir}/*") as $f) { |
|
|
|
|
74
|
|
|
unlink($f); |
75
|
|
|
} |
76
|
|
|
rmdir($outputDir); |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
} |