1
+ <?php
2
+
3
+ namespace Keyword \Commands ;
4
+
5
+ use Propel \Runtime \Propel ;
6
+ use Symfony \Component \Console \Input \InputInterface ;
7
+ use Symfony \Component \Console \Output \OutputInterface ;
8
+
9
+ use Thelia \Command \ContainerAwareCommand ;
10
+
11
+ class Update extends ContainerAwareCommand
12
+ {
13
+ protected function configure ()
14
+ {
15
+ $ this
16
+ ->setName ("keyword:update " )
17
+ ->setDescription ("Update Keyword module " );
18
+ }
19
+
20
+ protected function execute (InputInterface $ input , OutputInterface $ output )
21
+ {
22
+ $ connection = Propel::getConnection (\Keyword \Model \Map \KeywordTableMap::DATABASE_NAME );
23
+ $ connection = $ connection ->getWrappedConnection ();
24
+
25
+ $ stmt = $ connection ->query ("SELECT keyword_group_id, GROUP_CONCAT(keyword_id) keyword_ids
26
+ FROM `keyword_group_associated_keyword`
27
+ GROUP BY keyword_group_id " );
28
+ $ stmt ->execute ();
29
+
30
+ $ output ->writeln (array (
31
+ '' ,
32
+ '<question>Starting update...</question> '
33
+ ));
34
+
35
+ foreach ($ stmt ->fetchAll () as $ data ) {
36
+ $ msg = 'Insert of value ' . $ data ["keyword_group_id " ] . ' into keyword_group_id field of keywords : ' . $ data ["keyword_ids " ];
37
+
38
+ $ stmt = $ connection ->query ('UPDATE `keyword` SET keyword_group_id = ' . $ data ["keyword_group_id " ] . ' WHERE id IN ( ' . $ data ["keyword_ids " ] . ') ' );
39
+ $ stmt ->execute ();
40
+
41
+ $ output ->writeln (array (
42
+ '' ,
43
+ '<info> ' . $ msg . '</info> '
44
+ ));
45
+ }
46
+
47
+ $ output ->writeln (array (
48
+ '' ,
49
+ '<info>Keyword table are now updated.</info> '
50
+ ));
51
+
52
+ $ output ->writeln (array (
53
+ '' ,
54
+ '<question>Removing obsolete tables...</question> '
55
+ ));
56
+
57
+ $ stmt = $ connection ->query ("DROP TABLE IF EXISTS `keyword_group_associated_keyword` " );
58
+ $ stmt ->execute ();
59
+
60
+ $ output ->writeln (array (
61
+ '' ,
62
+ '<info>Tables of the Keyword module are now updated.</info> '
63
+ ));
64
+
65
+ $ output ->writeln (array (
66
+ '' ,
67
+ '<info>Update completed successfully !</info> '
68
+ ));
69
+
70
+
71
+ }
72
+ }
0 commit comments