Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
converter.php
1<?php
3
6
8{
9 public static function onInstallModule()
10 {
11 static::convertBizprocProviders();
12 static::convertOptions();
13 }
14
15 public static function convertBizprocProviders()
16 {
17 if (!Main\Loader::includeModule('bizproc'))
18 return false;
19
20 $providerList = Bizproc\RestProviderTable::getList();
21
22 while ($row = $providerList->fetch())
23 {
24 static::addRestSender(array(
25 'APP_ID' => $row['APP_ID'],
26 'APP_NAME' => $row['APP_NAME'],
27 'CODE' => $row['CODE'],
28 'TYPE' => $row['TYPE'],
29 'HANDLER' => $row['HANDLER'],
30 'NAME' => $row['NAME'],
31 'DESCRIPTION' => $row['DESCRIPTION']
32 ));
33 }
34 return true;
35 }
36
37 public static function convertOptions()
38 {
39 $checkList = array('smsru', 'twilio');
40
41 foreach ($checkList as $senderId)
42 {
43 $optionString = Main\Config\Option::get('crm', 'integration.sms.'.$senderId);
44 if (!$optionString)
45 continue;
46
47 $options = unserialize($optionString, ['allowed_classes' => false]);
48 if (!is_array($options))
49 continue;
50
51 if (isset($options['default_sender']))
52 {
53 $options['default_from'] = $options['default_sender'];
54 unset($options['default_sender']);
55 }
56
57 Main\Config\Option::set('messageservice','sender.sms.'.$senderId, serialize($options));
58 }
59 }
60
61 private static function addRestSender($params)
62 {
63 $iterator = Internal\Entity\RestAppTable::getList(array(
64 'select' => array('ID'),
65 'filter' => array(
66 '=APP_ID' => $params['APP_ID'],
67 '=CODE' => $params['CODE']
68 )
69 ));
70 $result = $iterator->fetch();
71 if ($result)
72 {
73 return true;
74 }
75
76 $senderLang = array(
77 'NAME' => $params['NAME'],
78 'DESCRIPTION' => $params['DESCRIPTION'],
79 'APP_NAME' => $params['APP_NAME']
80 );
81 unset($params['NAME'], $params['DESCRIPTION'], $params['APP_NAME']);
82
83 $params['AUTHOR_ID'] = 0;
84 $result = Internal\Entity\RestAppTable::add($params);
85
86 if ($result->getErrors())
87 {
88 return false;
89 }
90
91 $senderLang['APP_ID'] = $result->getId();
92 static::addRestSenderLang($senderLang);
93
94 return true;
95 }
96
97 private static function addRestSenderLang($langFields)
98 {
99 $langData = array();
100
101 foreach ($langFields['NAME'] as $langId => $langName)
102 {
103 $langCode = mb_strtolower($langId);
104 if ($langCode === '*')
105 $langCode = '**';
106
107 $langData[$langCode] = array(
108 'APP_ID' => $langFields['APP_ID'],
109 'LANGUAGE_ID' => $langCode,
110 'NAME' => $langFields['NAME'][$langId],
111 'DESCRIPTION' => isset($langFields['DESCRIPTION'][$langId])
112 ? (string)$langFields['DESCRIPTION'][$langId] : null,
113 'APP_NAME' => isset($langFields['APP_NAME'][$langId])
114 ? (string)$langFields['APP_NAME'][$langId] : null,
115 );
116
117 if (!isset($langData['**']))
118 {
119 $langData['**'] = $langData[$langCode];
120 $langData['**']['LANGUAGE_ID'] = '**';
121 }
122 }
123
124 foreach ($langData as $toAdd)
125 {
126 Internal\Entity\RestAppLangTable::add($toAdd);
127 }
128 }
129}
static includeModule($moduleName)
Definition loader.php:69