1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace OroCRM\Bundle\ChannelBundle\Migrations\Schema\v1_6; |
4
|
|
|
|
5
|
|
|
use Doctrine\DBAL\Connection; |
6
|
|
|
use Doctrine\DBAL\Types\Type; |
7
|
|
|
|
8
|
|
|
use Psr\Log\LoggerInterface; |
9
|
|
|
|
10
|
|
|
use Oro\Bundle\MigrationBundle\Migration\ArrayLogger; |
11
|
|
|
use Oro\Bundle\MigrationBundle\Migration\ParametrizedMigrationQuery; |
12
|
|
|
|
13
|
|
|
use OroCRM\Bundle\ChannelBundle\Entity\Channel; |
14
|
|
|
|
15
|
|
|
class UpdateChannelIntegrationsMode extends ParametrizedMigrationQuery |
16
|
|
|
{ |
17
|
|
|
/** @var int */ |
18
|
|
|
protected $mode; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @param int $mode |
22
|
|
|
*/ |
23
|
|
|
public function __construct($mode) |
24
|
|
|
{ |
25
|
|
|
$this->mode = $mode; |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* {@inheritdoc} |
30
|
|
|
*/ |
31
|
|
|
public function getDescription() |
32
|
|
|
{ |
33
|
|
|
$logger = new ArrayLogger(); |
34
|
|
|
$logger->info('Set Channel Integrations mods restricted'); |
35
|
|
|
|
36
|
|
|
$this->updateChannelIntegrationsMode($logger); |
37
|
|
|
|
38
|
|
|
return $logger->getMessages(); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* {@inheritdoc} |
43
|
|
|
*/ |
44
|
|
|
public function execute(LoggerInterface $logger) |
45
|
|
|
{ |
46
|
|
|
$this->updateChannelIntegrationsMode($logger, false); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
protected function updateChannelIntegrationsMode(LoggerInterface $logger, $dryRun = true) |
50
|
|
|
{ |
51
|
|
|
$ids = $this->getChannelIntegrations($logger); |
52
|
|
|
$updateSql = 'UPDATE oro_integration_channel SET edit_mode = :edit_mode WHERE id IN (:ids)'; |
53
|
|
|
$params = ['ids' => $ids, 'edit_mode' => $this->mode]; |
54
|
|
|
$types = ['ids' => Connection::PARAM_INT_ARRAY, 'edit_mode' => Type::INTEGER]; |
55
|
|
|
|
56
|
|
|
$this->logQuery($logger, $updateSql, $params, $types); |
57
|
|
|
|
58
|
|
|
if (!$dryRun) { |
59
|
|
|
$this->connection->executeUpdate($updateSql, $params, $types); |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @param LoggerInterface $logger |
65
|
|
|
* |
66
|
|
|
* @return array |
67
|
|
|
*/ |
68
|
|
|
protected function getChannelIntegrations(LoggerInterface $logger) |
69
|
|
|
{ |
70
|
|
|
$sql = 'SELECT i.id FROM oro_integration_channel i' . |
71
|
|
|
' INNER JOIN orocrm_channel c ON c.data_source_id = i.id ' . |
72
|
|
|
' WHERE c.status = :status'; |
73
|
|
|
|
74
|
|
|
$params = ['status' => Channel::STATUS_ACTIVE]; |
75
|
|
|
$types = ['status' => Type::BOOLEAN]; |
76
|
|
|
|
77
|
|
|
$this->logQuery($logger, $sql, $params, $types); |
78
|
|
|
$integrations = $this->connection->fetchAll($sql, $params, $types); |
79
|
|
|
|
80
|
|
|
return array_reduce( |
81
|
|
|
$integrations, |
82
|
|
|
function ($ids, $integration) { |
83
|
|
|
$ids[] = $integration['id']; |
84
|
|
|
return $ids; |
85
|
|
|
}, |
86
|
|
|
[] |
87
|
|
|
); |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|