42 parent::checkFields($result, $primary, $data);
44 if (isset($data[
'SITE_ID']))
46 $selectResult = \Bitrix\Main\SiteTable::getByPrimary($data[
'SITE_ID']);
47 if (!$selectResult->fetch())
49 $field = static::getEntity()->getField(
'SITE_ID');
52 Localization\
Loc::getMessage(
'MAIN_ENTITY_FIELD_INVALID', array(
'#FIELD_TITLE#' => $field->getTitle())),
53 Entity\FieldError::INVALID_VALUE
58 if (!empty($data[
'ICON']))
60 if (!is_scalar($data[
'ICON']) || !preg_match(
'/[0-9]+/', $data[
'ICON']))
62 $field = static::getEntity()->getField(
'ICON');
65 Localization\
Loc::getMessage(
'MAIN_ENTITY_FIELD_INVALID', array(
'#FIELD_TITLE#' => $field->getTitle())),
66 Entity\FieldError::INVALID_VALUE
93 return new Entity\UpdateResult();
95 $serviceForUpdate = static::getByPrimary(
99 'ID',
'SITE_ID',
'ACTIVE',
'SERVICE_TYPE',
103 if (!$serviceForUpdate)
105 $updateResult =
new Entity\UpdateResult();
108 return $updateResult;
111 if (isset($data[
'ICON']) && is_array($data[
'ICON']))
113 $iconError = $data[
'ICON'][
'name'] ? \CFile::checkImageFile($data[
'ICON']) :
null;
114 if (is_null($iconError))
116 $data[
'ICON'][
'MODULE_ID'] =
'mail';
118 \CFile::saveForDB($data,
'ICON',
'mail/mailservices/icon');
122 $updateResult = parent::update($primary, $data);
124 if ($updateResult->isSuccess())
126 $serviceId = is_array($primary) ? $primary[
'ID'] : $primary;
128 $isSiteChanged = isset($data[
'SITE_ID']) && $data[
'SITE_ID'] != $serviceForUpdate[
'SITE_ID'];
129 $isDeactivated = isset($data[
'ACTIVE']) && $data[
'ACTIVE'] ==
'N' && $serviceForUpdate[
'ACTIVE'] ==
'Y';
130 if (($isSiteChanged || $isDeactivated) && $serviceForUpdate[
'SERVICE_TYPE'] ==
'imap')
132 $emptyService = static::getList(array(
133 'select' => array(
'ID'),
135 '=SITE_ID' => $serviceForUpdate[
'SITE_ID'],
137 '=SERVICE_TYPE' =>
'imap',
147 if ($isSiteChanged || $isDeactivated && $emptyService)
149 $mbData = $emptyService
150 ? array(
'SERVICE_ID' => $emptyService[
'ID'])
151 : array(
'ACTIVE' =>
'N',
'SERVICE_ID' => 0);
156 foreach ($data as $key => $value)
168 $mbData[$key] = $value;
171 $mbData[
'USE_TLS'] = $value;
177 $selectResult = \CMailbox::getList(array(), array(
'SERVICE_ID' => $serviceId));
178 while ($mailbox = $selectResult->fetch())
179 \CMailbox::update($mailbox[
'ID'], $mbData);
182 return $updateResult;
235 $serviceForDelete = static::getByPrimary($primary)->fetch();
236 if (!$serviceForDelete)
238 $deleteResult =
new Entity\DeleteResult();
241 return $deleteResult;
244 $deleteResult = parent::delete($primary);
246 if ($deleteResult->isSuccess())
248 $serviceId = is_array($primary) ? $primary[
'ID'] : $primary;
250 if (in_array($serviceForDelete[
'SERVICE_TYPE'], array(
'controller',
'domain',
'crdomain')))
252 $mbData = array(
'ACTIVE' =>
'N',
'SERVICE_ID' => 0);
256 $emptyService = static::getList(array(
258 '=SITE_ID' => $serviceForDelete[
'SITE_ID'],
268 $mbData = $emptyService
269 ? array(
'SERVICE_ID' => $emptyService[
'ID'],
'NAME' => $emptyService[
'NAME'])
270 : array(
'ACTIVE' =>
'N',
'SERVICE_ID' => 0);
273 $selectResult = \CMailbox::getList(array(), array(
'SERVICE_ID' => $serviceId));
274 while ($mailbox = $selectResult->fetch())
275 \CMailbox::update($mailbox[
'ID'], $mbData);
278 return $deleteResult;