Skip to content

Commit 2707fc5

Browse files
author
Michael Espeche
committed
Add new command keyword:update to Update from 2.3 to 2.4
1 parent 48f1c02 commit 2707fc5

File tree

3 files changed

+77
-1
lines changed

3 files changed

+77
-1
lines changed

Commands/Update.php

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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+
}

Config/config.xml

+4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626
<form name="keyword.admin.modification" class="Keyword\Form\KeywordModificationForm"/>
2727
</forms>
2828

29+
<commands>
30+
<command class="Keyword\Commands\Update"/>
31+
</commands>
32+
2933
<services>
3034
<service id="keyword.action" class="Keyword\Action\Keyword">
3135
<tag name="kernel.event_subscriber"/>

Config/module.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<descriptive locale="en_US">
88
<title>Keyword</title>
99
</descriptive>
10-
<version>2.4.3</version>
10+
<version>2.4.4</version>
1111
<author>
1212
<name>Michaël Espeche</name>
1313
<email>mespeche@openstudio.fr</email>

0 commit comments

Comments
 (0)