public static function deleteByUser($userId) { $result = new DeleteResult(); $entity = static::getEntity(); $userId = intval($userId); if ($userId <= 0) { $result->addError(new Entity\FieldError($entity->getField('USER_ID'), 'UserID must be greater than zero')); return $result; } $event = new Event($entity, "OnBeforeDeleteByUser", array("USER_ID" => $userId)); $event->send(); if ($event->getErrors($result)) { return $result; } $event = new Event($entity, "OnDeleteByUser", array("USER_ID" => $userId)); $event->send(); $tableName = $entity->getDBTableName(); $connection = Application::getConnection(); $sql = "DELETE FROM " . $tableName . " WHERE USER_ID = " . $userId; $connection->queryExecute($sql); $event = new Event($entity, "OnAfterDeleteByUser", array("USER_ID" => $userId)); $event->send(); return $result; }
/** * Event listener, which cleans crumbs after move. * @param Event $event Event. * @return void */ public function onObjectOnAfterMove(Event $event) { $primaryData = $event->getParameter('id'); if ($primaryData) { $this->cleanByObjectId($primaryData['ID']); } }
/** * Constructor. * * @param array $params * * @throws SkipHandlerException */ public function __construct($params) { $this->event = $params[0]; $eventParams = $this->event->getParameters(); $this->id = $eventParams['id']['ID']; $this->fields = HighloadBlockTable::getById($this->id)->fetch(); }
/** * @param Entity\Event $event * @return Entity\EventResult * @throws \Bitrix\Main\ArgumentException */ public static function onDelete(Entity\Event $event) { $result = new Entity\EventResult(); $data = $event->getParameters(); $arId = array(); if (array_key_exists('ID', $data['primary'])) { $arId[] = $data['primary']['ID']; } else { $arFilter = array(); foreach ($data['primary'] as $primKey => $primVal) { $arFilter[$primKey] = $primVal; } $tableDataList = static::getList(array('select' => array('ID'), 'filter' => $arFilter)); while ($tableData = $tableDataList->fetch()) { $arId[] = $tableData['ID']; } } foreach ($arId as $primaryId) { $primary = array('POSTING_ID' => $primaryId); PostingReadTable::delete($primary); PostingClickTable::delete($primary); PostingUnsubTable::delete($primary); PostingRecipientTable::delete($primary); } return $result; }
public static function OnAdd(Entity\Event $event) { $data = $event->getParameter("fields"); if ($data['IS_DEFAULT']) { self::clearDefaultValue(); } }
/** * Если включили бесплатный канал, активируем для всех пользователей подписку. * * @return object */ public static function OnBeforeUpdate(Entity\Event $event) { $result = new Entity\EventResult(); $primary = $event->getParameter("id"); $data = $event->getParameter("fields"); $res = self::getById($primary); $arChannel = $res->fetch(); $price = floatval($arChannel["UF_PRICE_H24"]); if ($data["UF_ACTIVE"] && !$arChannel["UF_ACTIVE"] && $price == 0) { //Найдем пользователей, для кого эта подписка была включена $userIds = array(); $result = SubscribeTable::getList(array('filter' => array("=UF_CHANNEL_ID" => $data["ID"]), 'select' => array("ID", "UF_USER_ID"))); while ($arSub = $result->fetch()) { $userIds[$arSub["UF_USER_ID"]] = $arSub["ID"]; } $CSubscribe = new CSubscribe("CHANNEL"); $dbUsers = \CUser::GetList($by = "EMAIL", $order = "desc", array("ACTIVE" => "Y")); while ($arUser = $dbUsers->Fetch()) { if (!array_key_exists($arUser["ID"], $userIds)) { $CSubscribe->setUserSubscribe($data["ID"], $arUser["ID"]); } else { $sub_id = $userIds[$arUser["ID"]]; $CSubscribe->updateUserSubscribe($sub_id, array("UF_ACTIVE" => 1)); } } } return $result; }
public static function onAfterDelete(Event $event) { $parameters = $event->getParameter("id"); $code = $parameters["CODE"]; Designer\ConfigTable::delete(array("APP_CODE" => $code)); parent::onAfterDelete($event); }
/** * @param Entity\Event $event * @return Entity\EventResult */ public static function onAfterDelete(Entity\Event $event) { $result = new Entity\EventResult(); $data = $event->getParameters(); $primary = array('GROUP_ID' => $data['primary']['ID']); GroupConnectorTable::delete($primary); return $result; }
public static function onBeforeUpdate(Entity\Event $event) { $result = new Entity\EventResult(); $data = $event->getParameter("fields"); if (!isset($data['TIMESTAMP_X'])) { $data['TIMESTAMP_X'] = new DateTime(); $result->modifyFields($data); } }
/** * Delete pic after delete record */ public static function onAfterDelete(Entity\Event $event) { $id = $event->getParameter('id'); $result = self::getList(array('filter' => array("!ID" => $id), 'select' => array("UF_IMG_PATH" => "UF_PROG.UF_IMG.UF_PATH"), 'limit' => 1)); $arRecord = $result->fetch(); if (!empty($arRecord["UF_IMG_PATH"])) { unlink(CFile::getCropedPath($arRecord["UF_IMG_PATH"], array(300, 300), true)); } }
/** * Constructor. * * @param array $params * * @throws SkipHandlerException */ public function __construct($params) { $this->event = $params[0]; $eventParams = $this->event->getParameters(); $this->fields = $eventParams['fields']; $this->id = $eventParams['id']['ID']; if (!$this->fieldsHaveBeenChanged()) { throw new SkipHandlerException(); } }
/** * @param Entity\Event $event * @return Entity\EventResult */ public static function onAfterDelete(Entity\Event $event) { $result = new Entity\EventResult(); $data = $event->getParameters(); $primary = array('MAILING_ID' => $data['primary']['ID']); MailingGroupTable::delete($primary); MailingChainTable::delete($primary); MailingSubscriptionTable::delete($primary); PostingTable::delete($primary); return $result; }
/** * @param Entity\Event $event * @return Entity\EventResult */ public static function onBeforeAdd(Entity\Event $event) { $result = new Entity\EventResult(); $data = $event->getParameter('fields'); if (isset($data['TOKEN_EXPIRES_IN'])) { $dateTime = new Type\DateTime(); $dateTime->add('+ ' . $data['TOKEN_EXPIRES_IN'] . ' sec'); $result->modifyFields(['TOKEN_FINAL_DATE' => $dateTime]); } return $result; }
/** * Change data before adding * * @return object */ public static function onBeforeAdd(Entity\Event $event) { $result = new Entity\EventResult(); $data = $event->getParameter("fields"); if (isset($data['UF_CODE'])) { $arParams = array("replace_space" => "-", "replace_other" => "-"); $code = \CDev::translit(trim($data["UF_CODE"]), "ru", $arParams); $result->modifyFields(array('UF_CODE' => $code)); } return $result; }
public static function onBeforeDelete(Entity\Event $event) { $result = new Entity\EventResult(); $primary = $event->getParameter("primary"); if (intval($primary['ID']) > 0) { $dbRes = \Bitrix\Sale\Internals\ShipmentExtraServiceTable::getList(array('filter' => array('=EXTRA_SERVICE_ID' => $primary['ID']))); if ($row = $dbRes->fetch()) { $result->addError(new Entity\EntityError(str_replace('#ID#', $primary['ID'], Loc::getMessage('DELIVERY_EXTRA_SERVICES_ENTITY_ERROR_DELETE')))); } } return $result; }
/** * @param Entity\Event $event * @return Entity\EventResult */ public static function onDelete(Entity\Event $event) { $result = new Entity\EventResult(); $data = $event->getParameters(); $itemDb = static::getByPrimary($data['primary']); while ($item = $itemDb->fetch()) { if (!is_array($item['ENDPOINT'])) { $item['ENDPOINT'] = null; } static::actualizeHandlers($item['MAILING_CHAIN_ID'], null, $item['ENDPOINT']); } return $result; }
public static function onDelete(Event $event) { $row = static::getRowById($event->getParameter('id')); if (!$row) { return; } global $USER; //todo unshare. Fork invite. Hack //not fork if owner by invite unshare user. if (!$row['IS_DELETED'] && $row['INVITE_USER_ID'] != $row['USER_ID'] && $row['USER_ID'] != $USER->getId()) { $scalarFields = array(); foreach (static::getEntity()->getFields() as $fieldName => $field) { if ($field instanceof Entity\ScalarField) { $scalarFields[$fieldName] = true; } } unset($field); $forkRow = array_intersect_key($row, $scalarFields); unset($forkRow['ID']); $forkRow['CAN_FORWARD'] = (bool) $forkRow['CAN_FORWARD']; $forkRow['CAN_EDIT'] = (bool) $forkRow['CAN_EDIT']; $forkRow['IS_DELETED'] = true; $forkRow['IS_APPROVED'] = false; \Bitrix\Webdav\FolderInviteTable::add($forkRow); } \CWebDavSymlinkHelper::sendNotifyUnshare($row); self::deleteSymlinkSections($row); }
public static function onBeforeAdd(Entity\Event $event) { $result = new Entity\EventResult(); $data = $event->getParameter("fields"); if (isset($data["USER_ID"]) && isset($data['PASSWORD'])) { $salt = md5(\CMain::GetServerUniqID() . uniqid()); $password = $salt . md5($salt . $data['PASSWORD']); $modified = array('PASSWORD' => $password); $user = Main\UserTable::getRowById($data["USER_ID"]); if ($user !== null) { $realm = defined('BX_HTTP_AUTH_REALM') ? BX_HTTP_AUTH_REALM : "Bitrix Site Manager"; $digest = md5($user["LOGIN"] . ':' . $realm . ':' . $data['PASSWORD']); $modified['DIGEST_PASSWORD'] = $digest; } $result->modifyFields($modified); } return $result; }
public static function onAfterDelete(Entity\Event $event) { $primary = $event->getParameter("primary"); $ID = $primary["ID"]; $userInfo = self::$deletedList[$ID]; if ($userInfo) { UserLinkTable::deleteBySocserv($userInfo["USER_ID"], $userInfo["ID"]); if ($userInfo["EXTERNAL_AUTH_ID"] === \CSocServBitrix24Net::ID) { $interface = new \CBitrix24NetOAuthInterface(); $interface->setToken($userInfo["OATOKEN"]); $interface->setAccessTokenExpires($userInfo["OATOKEN_EXPIRES"]); $interface->setRefreshToken($userInfo["REFRESH_TOKEN"]); if ($interface->checkAccessToken() || $interface->getNewAccessToken()) { $interface->RevokeAuth(); } } } }
/** * Handler of before delete event * @param Entity\Event $event * @return Entity\EventResult */ public static function onBeforeDelete(Entity\Event $event) { $result = new Entity\EventResult(); $data = $event->getParameters(); $chainListDb = MailingChainTable::getList(array('select' => array('ID', 'SUBJECT', 'MAILING_ID', 'MAILING_NAME' => 'MAILING.NAME'), 'filter' => array('TEMPLATE_TYPE' => 'USER', 'TEMPLATE_ID' => $data['primary']['ID']), 'order' => array('MAILING_NAME' => 'ASC', 'ID'))); if ($chainListDb->getSelectedRowsCount() > 0) { $template = static::getRowById($data['primary']['ID']); $messageList = array(); while ($chain = $chainListDb->fetch()) { $messageList[$chain['MAILING_NAME']] = '[' . $chain['ID'] . '] ' . htmlspecialcharsbx($chain['SUBJECT']) . "\n"; } $message = Loc::getMessage('SENDER_ENTITY_TEMPLATE_DELETE_ERROR_TEMPLATE', array('#NAME#' => $template['NAME'])) . "\n"; foreach ($messageList as $mailingName => $messageItem) { $message .= Loc::getMessage('SENDER_ENTITY_TEMPLATE_DELETE_ERROR_MAILING', array('#NAME#' => $mailingName)) . "\n" . $messageItem . "\n"; } $result->addError(new Entity\EntityError($message)); } return $result; }
/** * Default onDelete handler. Absolutely necessary. * * @param Main\Entity\Event $event Current data for delete. * @return void */ public static function onDelete(Main\Entity\Event $event) { if (!self::isCheckedCouponsUse()) { return; } $coupon = self::getList(array('select' => array('ID', 'DISCOUNT_ID'), 'filter' => array('=ID' => $event->getParameter('id'))))->fetch(); if (!empty($coupon)) { $coupon['DISCOUNT_ID'] = (int) $coupon['DISCOUNT_ID']; self::$discountCheckList[$coupon['DISCOUNT_ID']] = $coupon['DISCOUNT_ID']; } unset($coupon); }
/** * @param Entity\Event $event * @return Entity\EventResult */ public static function onAfterUpdate(Entity\Event $event) { $result = new Entity\EventResult(); $data = $event->getParameters(); if (array_key_exists('STATUS', $data['fields']) || array_key_exists('AUTO_SEND_TIME', $data['fields'])) { if (array_key_exists('STATUS', $data['fields']) && $data['fields']['STATUS'] == PostingTable::STATUS_NEW) { static::initPosting($data['primary']['ID']); } MailingManager::actualizeAgent(null, $data['primary']['ID']); } return $result; }
public static function OnBeforeIntantMessangerChatAdd(\Bitrix\Main\Entity\Event $event) { $result = new \Bitrix\Main\Entity\EventResult(); $fields = $event->getParameter('fields'); $entityType = isset($fields['ENTITY_TYPE']) ? $fields['ENTITY_TYPE'] : ''; $m = null; if (preg_match('/^CRM_([A-Z]+)$/i', $entityType, $m) === 1) { $entityTypeName = isset($m[1]) ? $m[1] : ''; $ownerTypeID = CCrmOwnerType::ResolveID($entityTypeName); $ownerID = isset($fields['ENTITY_ID']) ? intval($fields['ENTITY_ID']) : 0; $ownerInfo = null; if (CCrmOwnerType::IsDefined($ownerTypeID) && $ownerID > 0 && CCrmOwnerType::TryGetInfo($ownerTypeID, $ownerID, $ownerInfo, false)) { $changedFields['TITLE'] = $ownerInfo['CAPTION']; $changedFields['AVATAR'] = $ownerInfo['IMAGE_ID']; $result->modifyFields($changedFields); } } return $result; }
function __OnAddUpdateHL(Entity\Event $event) { $fields = $event->getParameter("fields"); $user_id = $fields['UF_USER_ID']; __recalcSaleDiscount($user_id); }
public static function onAfterUpdate(Entity\Event $event) { $primary = $event->getParameter('primary'); $fields = $event->getParameter('fields'); if (!empty($fields['CODE'])) { self::cleanIdCodeCached($primary['ID']); } }
/** * Usage: only if you want to update "unnormalized" attributes (symlink object) * @param array $attributes * @param array $filter * @return \Bitrix\Main\Entity\Result * @internal */ public static function updateAttributesByFilter(array $attributes, array $filter) { $entity = static::getEntity(); $result = new Result(); $event = new Event($entity, self::EVENT_ON_BEFORE_UPDATE_ATTR_BY_FILTER, array('fields' => $attributes, 'filter' => $filter)); $event->send(); $event->getErrors($result); $attributes = $event->mergeFields($attributes); //static::checkFields($result, null, $attributes); if (!$result->isSuccess(true)) { return $result; } $event = new Event($entity, self::EVENT_ON_UPDATE_ATTR_BY_FILTER, array('fields' => $attributes, 'filter' => $filter)); $event->send(); $connection = Main\Application::getConnection(); $helper = $connection->getSqlHelper(); $tableName = static::getEntity()->getDBTableName(); $update = $helper->prepareUpdate($tableName, $attributes); $filterAttributes = array(); foreach ($filter as $k => $v) { $filterAttributes[] = $helper->prepareAssignment($tableName, $k, $v); } $where = implode(' AND ', $filterAttributes); $sql = "UPDATE " . $tableName . " SET " . $update[0] . " WHERE " . $where; $connection->queryExecute($sql, $update[1]); $event = new Event($entity, self::EVENT_ON_AFTER_UPDATE_ATTR_BY_FILTER, array('fields' => $attributes, 'filter' => $filter)); $event->send(); return $result; }
/** * @param Entity\Event $event * @return Entity\EventResult */ public static function onDelete(Entity\Event $event) { $result = new Entity\EventResult(); $data = $event->getParameters(); $deleteIdList = array(); if (!empty($data['primary'])) { $itemDb = static::getList(array('select' => array('ID'), 'filter' => $data['primary'])); while ($item = $itemDb->fetch()) { $deleteIdList[] = $item['ID']; } } foreach ($deleteIdList as $chainId) { MailingAttachmentTable::delete(array('CHAIN_ID' => $chainId)); MailingTriggerTable::delete(array('MAILING_CHAIN_ID' => $chainId)); PostingTable::delete(array('MAILING_CHAIN_ID' => $chainId)); } return $result; }
/** * Handler of after add event * * @param Entity\Event $event * @return Entity\EventResult */ public static function onAfterAdd(Entity\Event $event) { $result = new Entity\EventResult(); $data = $event->getParameters(); $data = $data['fields']; // update unsub flag of recipient PostingRecipientTable::update(array('ID' => $data['RECIPIENT_ID']), array('IS_UNSUB' => 'Y')); // update unsub counter of posting $resultDb = static::getList(array('filter' => array('RECIPIENT_ID' => $data['RECIPIENT_ID']))); if ($resultDb->getSelectedRowsCount() == 1) { PostingTable::update(array('ID' => $data['POSTING_ID']), array('COUNT_UNSUB' => new \Bitrix\Main\DB\SqlExpression('?# + 1', 'COUNT_UNSUB'))); } return $result; }
/** * Deletes Yandex.Direct banner. * * @param Entity\Event $event Event data. * * @return void * * @throws Engine\YandexException * @throws Main\ArgumentException */ public static function onDelete(Entity\Event $event) { if(!static::$skipRemoteUpdate) { $primary = $event->getParameter("primary"); $engine = self::getEngine(); $dbRes = static::getList(array( 'filter' => array( '=ID' => $primary, '=ENGINE_ID' => $engine->getId(), ), 'select' => array( 'XML_ID', 'CAMPAIGN_XML_ID' => 'CAMPAIGN.XML_ID', ) )); $banner = $dbRes->fetch(); if($banner) { $engine->deleteBanners($banner['CAMPAIGN_XML_ID'], array($banner['XML_ID'])); } } }
/** * @param Entity\Event $event * @return Entity\EventResult */ public static function onAfterDelete(Entity\Event $event) { $result = new Entity\EventResult(); $data = $event->getParameters(); $primary = array('LIST_ID' => $data['primary']['ID']); ContactListTable::delete($primary); return $result; }