Ejemplo n.º 1
0
 /**
  * Если включили бесплатный канал, активируем для всех пользователей подписку.
  * 
  * @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;
 }
Ejemplo n.º 2
0
 public static function onAfterDelete(Event $event)
 {
     $parameters = $event->getParameter("id");
     $code = $parameters["CODE"];
     Designer\ConfigTable::delete(array("APP_CODE" => $code));
     parent::onAfterDelete($event);
 }
Ejemplo n.º 3
0
 public static function OnAdd(Entity\Event $event)
 {
     $data = $event->getParameter("fields");
     if ($data['IS_DEFAULT']) {
         self::clearDefaultValue();
     }
 }
Ejemplo n.º 4
0
 /**
  * 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']);
     }
 }
Ejemplo n.º 5
0
 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);
     }
 }
Ejemplo n.º 6
0
 /**
  * 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));
     }
 }
Ejemplo n.º 7
0
 /**
  * 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;
 }
Ejemplo n.º 8
0
 /**
  * @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;
 }
Ejemplo n.º 9
0
 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;
 }
Ejemplo n.º 10
0
 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();
             }
         }
     }
 }
Ejemplo n.º 11
0
 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;
 }
Ejemplo n.º 12
0
 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;
 }
Ejemplo n.º 13
0
 /**
  * Default onBeforeUpdate handler. Absolutely necessary.
  *
  * @param Main\Entity\Event $event		Current data for update.
  * @return Main\Entity\EventResult
  */
 public static function onBeforeUpdate(Main\Entity\Event $event)
 {
     $result = new Main\Entity\EventResult();
     $data = $event->getParameter('fields');
     $modifyFieldList = array();
     self::setUserID($modifyFieldList, $data, array('MODIFIED_BY'));
     self::setTimestamp($modifyFieldList, $data, array('TIMESTAMP_X'));
     if (!empty($modifyFieldList)) {
         $result->modifyFields($modifyFieldList);
     }
     unset($modifyFieldList);
     return $result;
 }
Ejemplo n.º 14
0
 public static function onAfterDelete(Entity\Event $event)
 {
     $result = new Entity\EventResult();
     $primary = $event->getParameter("primary");
     $tablesToDelete = array('b_sale_delivery2location', 'b_sale_delivery2paysystem', 'b_sale_delivery_rstr', 'b_sale_delivery_es');
     $con = \Bitrix\Main\Application::getConnection();
     $sqlHelper = $con->getSqlHelper();
     foreach ($tablesToDelete as $table) {
         $con->queryExecute("DELETE FROM " . $table . " WHERE DELIVERY_ID=" . $sqlHelper->forSql($primary["ID"]));
     }
     $dbRes = self::getList(array('filter' => array("PARENT_ID" => $primary["ID"]), 'select' => array("ID")));
     while ($child = $dbRes->fetch()) {
         self::delete($child["ID"]);
     }
     return $result;
 }
Ejemplo n.º 15
0
function __OnAddUpdateHL(Entity\Event $event)
{
	$fields = $event->getParameter("fields");	
	$user_id = $fields['UF_USER_ID'];		
	
	__recalcSaleDiscount($user_id);
}
Ejemplo n.º 16
0
 public static function onAfterAdd(Event $event)
 {
     $fields = $event->getParameter('fields');
     $fields['ID'] = $event->getParameter('id');
     if ($fields['ID'] && empty($fields['REAL_OBJECT_ID'])) {
         static::update($fields['ID'], array('REAL_OBJECT_ID' => $fields['ID']));
     }
     if (!empty($fields['PARENT_ID'])) {
         ObjectPathTable::appendTo($fields['ID'], $fields['PARENT_ID']);
     } else {
         ObjectPathTable::addAsRoot($fields['ID']);
     }
 }
 /**
  * Constructor.
  *
  * @param array $params
  *
  * @throws SkipHandlerException
  */
 public function __construct($params)
 {
     $this->event = $params[0];
     $this->fields = $this->event->getParameter('fields');
 }
Ejemplo n.º 18
0
 public static function onAfterUpdate(Entity\Event $event)
 {
     $primary = $event->getParameter('primary');
     $fields = $event->getParameter('fields');
     if (!empty($fields['CODE'])) {
         self::cleanIdCodeCached($primary['ID']);
     }
 }
Ejemplo n.º 19
0
	/**
	 * 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']));
			}
		}
	}
Ejemplo n.º 20
0
 /**
  * Default onAfterDelete handler. Absolutely necessary.
  *
  * @param Main\Entity\Event $event		Event object.
  * @return void
  */
 public static function onAfterDelete(Main\Entity\Event $event)
 {
     $id = $event->getParameter('id');
     $id = end($id);
     DiscountEntitiesTable::deleteByDiscount($id);
     DiscountModuleTable::deleteByDiscount($id);
     DiscountGroupTable::deleteByDiscount($id);
     if (self::$deleteCoupons !== false) {
         DiscountCouponTable::deleteByDiscount(self::$deleteCoupons);
         self::$deleteCoupons = false;
     }
     unset($id);
 }
Ejemplo n.º 21
0
 /**
  * Deletes all campaign banners.
  *
  * @param Entity\Event $event Event data.
  *
  * @return void
  *
  * @throws Main\ArgumentException
  */
 public static function onAfterDelete(Entity\Event $event)
 {
     $primary = $event->getParameter("primary");
     $engine = self::getEngine();
     $dbRes = YandexBannerTable::getList(array('filter' => array('=CAMPAIGN_ID' => $primary, '=ENGINE_ID' => $engine->getId()), 'select' => array('ID')));
     YandexBannerTable::setSkipRemoteUpdate(true);
     while ($banner = $dbRes->fetch()) {
         YandexBannerTable::delete($banner['ID']);
     }
     YandexBannerTable::setSkipRemoteUpdate(false);
 }
Ejemplo n.º 22
0
 /**
  * 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;
     }
     $id = $event->getParameter('id');
     $couponIterator = self::getList(array('select' => array('ID', 'DISCOUNT_ID'), 'filter' => array('=ID' => $id)));
     if ($coupon = $couponIterator->fetch()) {
         self::$discountCheckList[] = (int) $coupon['DISCOUNT_ID'];
     }
     unset($coupon, $couponIterator);
 }
Ejemplo n.º 23
0
 public static function onBeforeUpdate(Entity\Event $event)
 {
     $result = new Entity\EventResult();
     /** @var array $data */
     $data = $event->getParameter('fields');
     if (isset($data['UPDATE_TIME'])) {
         $result->modifyFields(array('SYNC_UPDATE_TIME' => new DateTime()));
     }
     return $result;
 }
Ejemplo n.º 24
0
 /**
  * Clear recovery codes after delete user
  *
  * @param Entity\Event $event Our event.
  * @return void
  * @throws \Bitrix\Main\ArgumentTypeException
  */
 public static function onAfterDelete(Entity\Event $event)
 {
     $primary = $event->getParameter('primary');
     RecoveryCodesTable::clearByUser($primary['USER_ID']);
 }
Ejemplo n.º 25
0
 /**
  * Deletes information blocks of given type
  * and language messages from TypeLanguageTable
  *
  * @param \Bitrix\Main\Entity\Event $event Contains information about iblock type being deleted.
  *
  * @return \Bitrix\Main\Entity\EventResult
  */
 public static function onDelete(\Bitrix\Main\Entity\Event $event)
 {
     $id = $event->getParameter("id");
     //Delete information blocks
     $iblockList = IblockTable::getList(array("select" => array("ID"), "filter" => array("=IBLOCK_TYPE_ID" => $id["ID"]), "order" => array("ID" => "DESC")));
     while ($iblock = $iblockList->fetch()) {
         $iblockDeleteResult = IblockTable::delete($iblock["ID"]);
         if (!$iblockDeleteResult->isSuccess()) {
             return $iblockDeleteResult;
         }
     }
     //Delete language messages
     $result = TypeLanguageTable::deleteByIblockTypeId($id["ID"]);
     return $result;
 }
Ejemplo n.º 26
0
 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);
 }
Ejemplo n.º 27
0
 /**
  * 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);
 }
 /**
  * Удаление связанных моделей с параметром referenceAutoDelete
  * @param Entity\Event $event
  */
 protected static function deleteReferenceData(Entity\Event $event)
 {
     /** @var array $entityData Все данные сущности (ключи учтены) */
     $entityId = $event->getParameter('primary')['ID'];
     foreach (static::getMap() as $fieldName => $fieldDetails) {
         // Удаляются только связи с флагом referenceAutoDelete
         if (!is_array($fieldDetails) || empty($fieldDetails['reference']) || empty($fieldDetails['referenceAutoDelete'])) {
             continue;
         }
         /** @var string $referenceClass DataManager привязанной сущности */
         $referenceClass = $fieldDetails['data_type'];
         // Поиск данных для текущего поля. Если данные найдены, но в сущность переданы не были, значит удаляем
         $dbReferenceData = static::getList(['select' => ['REFERENCE_' => $fieldName . '.*'], 'filter' => ['=ID' => $entityId]]);
         while ($referenceData = $dbReferenceData->fetch()) {
             if (empty($referenceData['REFERENCE_ID'])) {
                 continue;
             }
             $referenceClass::delete($referenceData['REFERENCE_ID']);
         }
     }
 }