function DeleteCategory($ID) { $iblock_permission = CIBlock::GetPermission(IBLOCK_ID); if ($iblock_permission < "W") { $GLOBALS["USER"]->RequiredHTTPAuthBasic(); return new CSOAPFault('Server Error', 'Unable to authorize user.'); } $ib_section = new CIBlockSection(); if ($ib_section->Delete($ID)) { CIBlockSection::ReSort(); return 1; } return new CSOAPFault('Server Error', 'Error: ' . $ib_section->LAST_ERROR); }
function DeleteDepartment($arFields) { $dpt = intval($arFields['dpt_id']); global $iblockID; $dbRes = CIBlockSection::GetList(array(), array("ID" => $dpt, "IBLOCK_ID" => $iblockID, "CHECK_PERMISSIONS" => "Y"), false, array('ID', 'IBLOCK_ID', 'IBLOCK_SECTION_ID')); if ($arSection = $dbRes->Fetch()) { if ($arSection['IBLOCK_SECTION_ID'] > 0) { $dbRes = CIBlockSection::GetList(array(), array('IBLOCK_ID' => $iblockID, 'SECTION_ID' => $arSection['ID']), false, array('ID', 'IBLOCK_ID')); $obIBlockSection = new CIBlockSection(); $GLOBALS['DB']->StartTransaction(); while ($arRes = $dbRes->Fetch()) { $obIBlockSection->Update($arRes['ID'], array('IBLOCK_SECTION_ID' => $arSection['IBLOCK_SECTION_ID'])); } if ($obIBlockSection->Delete($arSection['ID'])) { $GLOBALS['DB']->Commit(); echo "{id: '" . $arSection['IBLOCK_SECTION_ID'] . "'}"; } else { $GLOBALS['DB']->Rollback(); $res = array('error' => trim(str_replace('<br>', "\n", $ob->LAST_ERROR))); echo "{errors: '" . $res["error"] . "'}"; } } } }
continue; } } switch($_REQUEST['action']) { case "delete": @set_time_limit(0); if($TYPE=="S") { if(CIBlockSectionRights::UserHasRightTo($IBLOCK_ID, $ID, "section_delete")) { $DB->StartTransaction(); $APPLICATION->ResetException(); if(!CIBlockSection::Delete($ID)) { $DB->Rollback(); if($ex = $APPLICATION->GetException()) $lAdmin->AddGroupError(GetMessage("IBLIST_A_SECTION_DELETE_ERROR", array("#ID#" => $ID))." [".$ex->GetString()."]", $TYPE.$ID); else $lAdmin->AddGroupError(GetMessage("IBLIST_A_SECTION_DELETE_ERROR", array("#ID#" => $ID)), $TYPE.$ID); } else { $DB->Commit(); } } else { $lAdmin->AddGroupError(GetMessage("IBLIST_A_SECTION_DELETE_ERROR", array("#ID#" => $ID)), $TYPE.$ID);
$arResultSection = $rsSection->GetNext(); $arResult["URL"] = CComponentEngine::MakePathFromTemplate($arParams["~SECTION_URL"], array("USER_ALIAS" => $arParams["USER_ALIAS"], "SECTION_ID" => $ID)); $arResultFields = array("IBLOCK_ID" => $arParams["IBLOCK_ID"], "DATE" => PhotoDateFormat($arParams["DATE_TIME_FORMAT"], MakeTimeStamp($_REQUEST["UF_DATE"], CSite::GetDateFormat())), "NAME" => $arResultSection["NAME"], "DESCRIPTION" => $arResultSection["DESCRIPTION"], "PASSWORD" => $arResultSection["UF_PASSWORD"], "ID" => $ID, "error" => "", "url" => $arResult["URL"]); } elseif ($bs->LAST_ERROR) { $strWarning .= $bs->LAST_ERROR; $bVarsFromForm = true; } else { $err = $GLOBALS['APPLICATION']->GetException(); if ($err) { $strWarning .= $err->GetString(); } $bVarsFromForm = true; } } elseif ($arParams["ACTION"] == "DROP") { @set_time_limit(1000); if (CIBlockSection::Delete($arResult["SECTION"]["ID"])) { // /Must Be deleted if ($arParams["BEHAVIOUR"] == "USER" && intVal($arResult["SECTION"]["IBLOCK_SECTION_ID"]) == intVal($arResult["GALLERY"]["ID"])) { $arResult["URL"] = CComponentEngine::MakePathFromTemplate($arParams["~GALLERY_URL"], array("USER_ALIAS" => $arParams["USER_ALIAS"])); } elseif (intVal($arResult["SECTION"]["IBLOCK_SECTION_ID"]) > 0) { $arResult["URL"] = CComponentEngine::MakePathFromTemplate($arParams["~SECTION_URL"], array("USER_ALIAS" => $arParams["USER_ALIAS"], "SECTION_ID" => $arResult["SECTION"]["IBLOCK_SECTION_ID"])); } else { $arResult["URL"] = CComponentEngine::MakePathFromTemplate($arParams["~INDEX_URL"], array()); } $arResultFields = array("ID" => $arResult["SECTION"]["ID"], "error" => "", "url" => $arResult["URL"]); } elseif ($e = $APPLICATION->GetException()) { $strWarning .= $e->GetString(); } else { $strWarning .= GetMessage("IBSEC_A_DELERR_REFERERS"); } }
if (IntVal($arParams["USERGROUPS_RESERVE"]) > 0) { $arParams["USERGROUPS_RESERVE"] = array($arParams["USERGROUPS_RESERVE"]); } else { $arParams["USERGROUPS_RESERVE"] = array(); } } $arResult["FatalError"] = ""; if (!CIBlockRights::UserHasRightTo($iblockId, $iblockId, 'element_read')) { $arResult["FatalError"] .= GetMessage("INTS_NO_IBLOCK_PERMS") . "."; } if (StrLen($arResult["FatalError"]) <= 0) { $deleteMeetingId = IntVal($_REQUEST["delete_meeting_id"]); if ($deleteMeetingId > 0 && check_bitrix_sessid() && $GLOBALS["USER"]->IsAuthorized() && ($GLOBALS["USER"]->IsAdmin() || Count(Array_Intersect($GLOBALS["USER"]->GetUserGroupArray(), $arParams["USERGROUPS_MODIFY"])) > 0)) { $dbMeetingsList = CIBlockSection::GetList(array(), array("IBLOCK_ID" => $iblockId, "ID" => $deleteMeetingId)); if ($arMeeting = $dbMeetingsList->Fetch()) { CIBlockSection::Delete($arMeeting["ID"]); } } } $arResult["ALLOWED_FIELDS"] = array("ID" => array("NAME" => GetMessage("INAF_F_ID"), "ORDERABLE" => true, "FILTERABLE" => true, "TYPE" => "int", "IS_FIELD" => true), "NAME" => array("NAME" => GetMessage("INAF_F_NAME"), "ORDERABLE" => true, "FILTERABLE" => true, "TYPE" => "string", "IS_FIELD" => true), "DESCRIPTION" => array("NAME" => GetMessage("INAF_F_DESCRIPTION"), "ORDERABLE" => false, "FILTERABLE" => false, "TYPE" => "text", "IS_FIELD" => true), "UF_FLOOR" => array("NAME" => GetMessage("INAF_F_FLOOR"), "ORDERABLE" => true, "FILTERABLE" => true, "TYPE" => "integer", "IS_FIELD" => false), "UF_PLACE" => array("NAME" => GetMessage("INAF_F_PLACE"), "ORDERABLE" => true, "FILTERABLE" => true, "TYPE" => "integer", "IS_FIELD" => false), "UF_PHONE" => array("NAME" => GetMessage("INAF_F_PHONE"), "ORDERABLE" => false, "FILTERABLE" => false, "TYPE" => "string", "IS_FIELD" => false)); $arUserFields = $GLOBALS["USER_FIELD_MANAGER"]->GetUserFields("IBLOCK_" . $iblockId . "_SECTION", 0, LANGUAGE_ID); $arKeys = Array_Keys($arResult["ALLOWED_FIELDS"]); foreach ($arKeys as $key) { if (!$arResult["ALLOWED_FIELDS"][$key]["IS_FIELD"]) { if (!Array_Key_Exists($key, $arUserFields)) { $arFields = array("ENTITY_ID" => "IBLOCK_" . $iblockId . "_SECTION", "FIELD_NAME" => $key, "USER_TYPE_ID" => $arResult["ALLOWED_FIELDS"][$key]["TYPE"]); $obUserField = new CUserTypeEntity(); $obUserField->Add($arFields); } } }
/** * <p>Функция удаляет информационный блок.</p> * * * * * @param int $ID Код информационного блока. * * * * @return bool <a href="http://dev.1c-bitrix.ru/api_help/iblock/events/onbeforeiblockdelete.php">OnBeforeIBlockDelete</a><a * name="examples"></a> * * * <h4>Example</h4> * <pre> * <?<br>if($USER->IsAdmin())<br>{<br> $DB->StartTransaction();<br> if(!CIBlock::Delete($iblock_id))<br> {<br> $strWarning .= GetMessage("IBLOCK_DELETE_ERROR");<br> $DB->Rollback();<br> }<br> else<br> $DB->Commit();<br>}<br>?><br> * </pre> * * * @static * @link http://dev.1c-bitrix.ru/api_help/iblock/classes/ciblock/delete.php * @author Bitrix */ public static function Delete($ID) { $err_mess = "FILE: " . __FILE__ . "<br>LINE: "; /** @global CDatabase $DB */ global $DB; /** @global CMain $APPLICATION */ global $APPLICATION; /** @global CUserTypeManager $USER_FIELD_MANAGER */ global $USER_FIELD_MANAGER; /** @global CCacheManager $CACHE_MANAGER */ global $CACHE_MANAGER; $ID = IntVal($ID); $APPLICATION->ResetException(); foreach (GetModuleEvents("iblock", "OnBeforeIBlockDelete", true) as $arEvent) { if (ExecuteModuleEventEx($arEvent, array($ID)) === false) { $err = GetMessage("MAIN_BEFORE_DEL_ERR") . ' ' . $arEvent['TO_NAME']; $ex = $APPLICATION->GetException(); if (is_object($ex)) { $err .= ': ' . $ex->GetString(); } $APPLICATION->throwException($err); return false; } } foreach (GetModuleEvents("iblock", "OnIBlockDelete", true) as $arEvent) { ExecuteModuleEventEx($arEvent, array($ID)); } $iblockSections = CIBlockSection::GetList(array(), array("IBLOCK_ID" => $ID, "DEPTH_LEVEL" => 1, "CHECK_PERMISSIONS" => "N"), false, array("ID")); while ($iblockSection = $iblockSections->Fetch()) { if (!CIBlockSection::Delete($iblockSection["ID"], false)) { return false; } } $iblockElements = CIBlockElement::GetList(array(), array("IBLOCK_ID" => $ID, "SHOW_NEW" => "Y", "CHECK_PERMISSIONS" => "N"), false, false, array("IBLOCK_ID", "ID")); while ($iblockElement = $iblockElements->Fetch()) { if (!CIBlockElement::Delete($iblockElement["ID"])) { return false; } } $props = CIBlockProperty::GetList(array(), array("IBLOCK_ID" => $ID, "CHECK_PERMISSIONS" => "N")); while ($property = $props->Fetch()) { if (!CIBlockProperty::Delete($property["ID"])) { return false; } } $seq = new CIBlockSequence($ID); $seq->Drop(true); $obIBlockRights = new CIBlockRights($ID); $obIBlockRights->DeleteAllRights(); CIBlockSectionPropertyLink::DeleteByIBlock($ID); $DB->Query("delete from b_iblock_offers_tmp where PRODUCT_IBLOCK_ID=" . $ID, false, $err_mess . __LINE__); $DB->Query("delete from b_iblock_offers_tmp where OFFERS_IBLOCK_ID=" . $ID, false, $err_mess . __LINE__); if (!$DB->Query("DELETE FROM b_iblock_messages WHERE IBLOCK_ID = " . $ID, false, $err_mess . __LINE__)) { return false; } if (!$DB->Query("DELETE FROM b_iblock_fields WHERE IBLOCK_ID = " . $ID, false, $err_mess . __LINE__)) { return false; } $USER_FIELD_MANAGER->OnEntityDelete("IBLOCK_" . $ID . "_SECTION"); if (!$DB->Query("DELETE FROM b_iblock_group WHERE IBLOCK_ID=" . $ID, false, $err_mess . __LINE__)) { return false; } if (!$DB->Query("DELETE FROM b_iblock_rss WHERE IBLOCK_ID=" . $ID, false, $err_mess . __LINE__)) { return false; } if (!$DB->Query("DELETE FROM b_iblock_site WHERE IBLOCK_ID=" . $ID, false, $err_mess . __LINE__)) { return false; } if (!$DB->Query("DELETE FROM b_iblock WHERE ID=" . $ID, false, $err_mess . __LINE__)) { return false; } $DB->Query("DROP TABLE b_iblock_element_prop_s" . $ID, true, $err_mess . __LINE__); $DB->Query("DROP TABLE b_iblock_element_prop_m" . $ID, true, $err_mess . __LINE__); $DB->Query("DROP SEQUENCE sq_b_iblock_element_prop_m" . $ID, true, $err_mess . __LINE__); CIBlock::CleanCache($ID); if (defined("BX_COMP_MANAGED_CACHE")) { $CACHE_MANAGER->ClearByTag("iblock_id_" . $ID); } $_SESSION["SESS_RECOUNT_DB"] = "Y"; return true; }
if (CWikiSocnet::IsSocNet()) { $arFilter['>LEFT_BORDER'] = CWikiSocnet::$iCatLeftBorder; $arFilter['<RIGHT_BORDER'] = CWikiSocnet::$iCatRightBorder; } if (!empty($sCategoryName)) { $arFilter['NAME'] = $sCategoryName; } $dbList = CIBlockSection::GetList(array('NAME' => 'ASC'), $arFilter, true); $arResult['CATEGORIES'] = array(); $categories = new CWikiCategories(); $catParams = new CWikiCategoryParams(); $catParams->setPathTemplate($arParams['PATH_TO_CATEGORY']); while ($arCat = $dbList->GetNext()) { //fix: http://jabber.bx/view.php?id=26658 if ($arCat['ELEMENT_CNT'] <= 0) { CIBlockSection::Delete($arCat['ID'], false); continue; } $catParams->sName = $arCat['NAME']; $catParams->sTitle = $arCat['NAME']; $catParams->iItemsCount = $arCat['ELEMENT_CNT']; $catParams->bIsRed = 'Y'; $catParams->createLinkFromTemplate(); $categories->addItem($catParams); } //Pages without categories $arElementFilter = array("IBLOCK_ID" => $arParams['IBLOCK_ID'], "SECTION_ID" => CWikiSocnet::IsSocNet() ? CWikiSocnet::$iCatId : false, "INCLUDE_SUBSECTIONS" => "N", "ACTIVE" => "Y"); $noCatCount = CIBlockElement::GetList(array(), $arElementFilter, array(), false, array("ID")); $catParams->sName = GetMessage("WIKI_CATEGORY_NOCAT"); $catParams->sTitle = GetMessage("WIKI_CATEGORY_NOCAT_TITLE"); $catParams->iItemsCount = $noCatCount;
/** * Удаляет запись * @return bool */ public function delete() { $id = $this->getAttribute('id')->getValue(); if ($id > 0 && \CModule::IncludeModule('iblock')) { $res = \CIBlockSection::Delete($id); if ($res) { $this->getAttribute('id')->setValue(0); } return $res; } else { return false; } }
/** * [removeSpecification description] * @param array $arParams * @return bool */ function removeSpecification($arParams) { if (!CModule::IncludeModule('iblock')) { return false; } $arSelect = array("NAME", "ID"); $arFilter = array("IBLOCK_ID" => getIblockSpecifications(), "ACTIVE" => "Y", "SECTION_ID" => intval($arParams["spec"])); $res = CIBlockElement::GetList(array(), $arFilter, false, false, $arSelect); while ($ob = $res->GetNextElement()) { $arItems[] = $ob->GetFields(); } foreach ($arItems as $key => $item) { if (!CIBlockElement::Delete($item["ID"])) { return false; } } if (CIBlockSection::Delete($arParams["spec"])) { return true; } return false; }
function __intr_process_action($action, $arParams, &$res, &$mode, &$arUndo, &$undo_text) { $IBLOCK_ID = $arParams['IBLOCK_ID']; switch ($action) { case 'set_department_head': $dpt = intval($_REQUEST['dpt_id']); $user_id = intval($_REQUEST['user_id']); $ok = false; if ($dpt > 0 && $user_id > 0) { $dbUser = CUser::GetByID($user_id); if ($arUser = $dbUser->Fetch()) { $dbRes = CIBlockSection::GetList(array(), array("ID" => $dpt, "IBLOCK_ID" => $IBLOCK_ID, "CHECK_PERMISSIONS" => "Y"), false, array('NAME', 'UF_HEAD')); if ($arSection = $dbRes->GetNext()) { $ok = true; $ob = new CIBlockSection(); if ($ob->Update($dpt, array('UF_HEAD' => $user_id))) { $arUndo[] = array('action' => 'set_department_head', 'dpt_id' => $dpt, 'user_id' => $arSection['UF_HEAD']); $undo_text = GetMessage('ISV_set_department_head', array("#NAME#" => CUser::FormatName($arParams['NAME_TEMPLATE'], $arUser), "#DEPARTMENT#" => $arSection['NAME'])); $mode = 'reload'; } else { $res = array('error' => trim(str_replace('<br>', "\n", $ob->LAST_ERROR))); } } } } if (!$ok) { $res = array('error' => 'Wrong data'); } // we should change user department too, but have to return error if one exists if (is_array($res)) { break; } case 'change_department': $user_id = intval($_REQUEST['user_id']); $dpt_id = intval($_REQUEST['dpt_id']); $dpt_from = intval($_REQUEST['dpt_from']); $type = intval($_REQUEST['type']); $ok = false; if ($user_id > 0 && $dpt_id > 0) { if (isset($arUser)) { $arRes = $arUser; } else { $dbRes = CUser::GetByID($user_id); $arRes = $dbRes->Fetch(); } if (!isset($arSection)) { $dbRes = CIBlockSection::GetList(array(), array("ID" => $dpt_id, 'IBLOCK_ID' => $IBLOCK_ID, "CHECK_PERMISSIONS" => "Y")); $arSection = $dbRes->GetNext(); } if ($arRes && $arSection) { $ok = true; $arOldDpt = $arDpt = $arRes['UF_DEPARTMENT']; if ($type != 1) { foreach ($arDpt as $key => $dpt) { if ($dpt == $dpt_from) { unset($arDpt[$key]); break; } } } $arDpt[] = $dpt_id; } $obUser = new CUser(); if ($obUser->Update($user_id, array('UF_DEPARTMENT' => array_unique($arDpt)))) { if ($type != 1) { $arUndo[] = array('action' => 'change_department', 'user_id' => $user_id, 'dpt_id' => $dpt_from, 'dpt_from' => $dpt_id); if (!$undo_text) { $undo_text = GetMessage("ISV_change_department", array("#NAME#" => CUser::FormatName($arParams['NAME_TEMPLATE'], $arRes), "#DEPARTMENT#" => $arSection['NAME'])); } } if ($action != 'set_department_head' || $dpt_id != $dpt_from) { $dbRes = CIBlockSection::GetList(array(), array('ID' => $dpt_from, 'IBLOCK_ID' => $IBLOCK_ID, 'UF_HEAD' => $user_id)); if ($arSection = $dbRes->GetNext()) { if ($type != 1) { $arUndo[] = array('action' => 'set_department_head', 'dpt_id' => $dpt_from, 'user_id' => $user_id); } $obIBlockSection = new CIBlockSection(); $obIBlockSection->Update($dpt_from, array('UF_HEAD' => 0)); } } } } if (!$ok) { $res = array('error' => 'Wrong data'); } else { $mode = 'reload'; } break; case 'delete_department': $dpt = intval($_REQUEST['dpt_id']); $dbRes = CIBlockSection::GetList(array(), array("ID" => $dpt, "IBLOCK_ID" => $IBLOCK_ID, "CHECK_PERMISSIONS" => "Y")); if ($arSection = $dbRes->Fetch()) { if ($arSection['IBLOCK_SECTION_ID'] > 0) { $dbRes = CUser::GetList($by, $order, array('UF_DEPARTMENT' => $dpt), array('SELECT' => array('ID'))); if (!$dbRes->Fetch()) { $dbRes = CIBlockSection::GetList(array(), array('IBLOCK_ID' => $IBLOCK_ID, 'SECTION_ID' => $arSection['ID'])); $obIBlockSection = new CIBlockSection(); $GLOBALS['DB']->StartTransaction(); while ($arRes = $dbRes->Fetch()) { $obIBlockSection->Update($arRes['ID'], array('IBLOCK_SECTION_ID' => $arSection['IBLOCK_SECTION_ID'])); } if ($obIBlockSection->Delete($arSection['ID'])) { $GLOBALS['DB']->Commit(); $mode = 'reload'; } else { $GLOBALS['DB']->Rollback(); $res = array('error' => trim(str_replace('<br>', "\n", $ob->LAST_ERROR))); } } else { $res = array('error' => GetMessage('ISV_ERROR_dpt_not_empty')); } } } break; case 'move_department': $dpt = intval($_REQUEST['dpt_id']); $dpt_to = intval($_REQUEST['dpt_to']); $ok = false; if ($dpt > 0 && $dpt_to > 0) { $dbRes = CIBlockSection::GetList(array(), array("ID" => array($dpt, $dpt_to), 'IBLOCK_ID' => $IBLOCK_ID, "CHECK_PERMISSIONS" => "Y")); while ($arRes = $dbRes->GetNext()) { if ($arRes['ID'] == $dpt) { $arSection = $arRes; } else { $arSectionTo = $arRes; } } if ($arSection && $arSectionTo) { $ok = true; $ob = new CIBlockSection(); if ($ob->Update($dpt, array('IBLOCK_SECTION_ID' => $dpt_to))) { $mode = 'reload'; $arUndo[] = array('action' => 'move_department', 'dpt_id' => $dpt, 'dpt_to' => $arSection['IBLOCK_SECTION_ID']); $undo_text = GetMessage('ISV_move_department', array("#DEPARTMENT#" => $arSection["NAME"], "#DEPARTMENT_TO#" => $arSectionTo["NAME"])); } else { $res = array('error' => trim(str_replace('<br>', "\n", $ob->LAST_ERROR))); } } } // we should resort departments in this case if (is_array($res) || !$_REQUEST['dpt_parent']) { break; } case 'sort_department': $dpt_id = intval($_REQUEST['dpt_id']); $dpt_before = intval($_REQUEST['dpt_before']); $dpt_after = intval($_REQUEST['dpt_after']); $dpt_parent = intval($_REQUEST['dpt_parent']); $ok = false; if ($dpt_id > 0 && $dpt_parent > 0 && ($dpt_before > 0 || $dpt_after > 0)) { $arSections = array(); $dbRes = CIBlockSection::GetList(array('left_margin' => asc), array('IBLOCK_ID' => $IBLOCK_ID, 'SECTION_ID' => $dpt_parent)); $arCurrentSection = array(); $arSections = array(); $sortAfter = 0; $sortBefore = 0; while ($arSection = $dbRes->GetNext()) { if ($arSection['ID'] != $dpt_id) { $arSections[] = $arSection; } else { $arCurrentSection = $arSection; } if ($arSection['ID'] == $dpt_after) { $sortAfter = $arSection['SORT']; } elseif ($arSection['ID'] == $dpt_before) { $sortBefore = $arSection['SORT']; } } $GLOBALS['APPLICATION']->RestartBuffer(); $new_sort = -1; if (!$dpt_before && $sortAfter > 0) { $new_sort = $sortAfter + 100; } elseif (!$dpt_after && $sortBefore > 1) { $new_sort = round($sortBefore / 2); } elseif ($dpt_before && $dpt_after && abs($sortBefore - $sortAfter) > 2) { $new_sort = round(abs($sortBefore + $sortAfter) / 2); } $obSection = new CIBlockSection(); if ($new_sort > 0) { // simple variant: update just one section $ok = true; if (!$obSection->Update($dpt_id, array('SORT' => $new_sort))) { $res = array('error' => trim(str_replace('<br>', "\n", $ob->LAST_ERROR))); } } else { if ($dpt_before && $dpt_after) { foreach ($arSections as $key => $arSection) { if ($arSection['ID'] == $dpt_before || $arSection['ID'] == $dpt_after) { $arSections = array_merge(array_slice($arSections, 0, $key + 1), array($arCurrentSection), array_slice($arSections, $key + 1)); break; } } } else { if (!$dpt_after) { array_unshift($arSections, $arCurrentSection); } else { $arSections[] = $arCurrentSection; } } $GLOBALS['DB']->StartTransaction(); $sort = 0; foreach ($arSections as $arSection) { $sort += 100; if (!$obSection->Update($arSection['ID'], array('SORT' => $sort), false)) { $res = array('error' => trim(str_replace('<br>', "\n", $ob->LAST_ERROR))); $GLOBALS['DB']->Rollback(); break; } } if (!is_array($res)) { CIBlockSection::ReSort($IBLOCK_ID); $GLOBALS['DB']->Commit(); $ok = true; } } } if (!is_array($res)) { if (!$ok) { $res = array('error' => 'Wrong data'); } else { $mode = 'reload'; } } break; } }
public static function departmentDelete($params) { if (self::canEdit()) { CModule::IncludeModule('iblock'); $params = array_change_key_case($params, CASE_UPPER); $arDept = self::getDepartment($params['ID']); if (is_array($arDept)) { $ob = new CIBlockSection(); if (!$ob->Delete($arDept['ID'])) { throw new Exception($ob->LAST_ERROR); } return true; } else { throw new Exception('Department not found'); } } else { throw new Exception('Access denied!'); } }
/** * * History update, cron usage only * @global CUser $USER * @return boolean */ public static function orderHistory() { global $USER; if (is_object($USER) == false) { $USER = new RetailUser(); } if (!CModule::IncludeModule("iblock")) { self::eventLog('ICrmOrderActions::orderHistory', 'iblock', 'module not found'); return false; } if (!CModule::IncludeModule("sale")) { self::eventLog('ICrmOrderActions::orderHistory', 'sale', 'module not found'); return false; } if (!CModule::IncludeModule("catalog")) { self::eventLog('ICrmOrderActions::orderHistory', 'catalog', 'module not found'); return false; } $api_host = COption::GetOptionString(self::$MODULE_ID, self::$CRM_API_HOST_OPTION, 0); $api_key = COption::GetOptionString(self::$MODULE_ID, self::$CRM_API_KEY_OPTION, 0); $optionsOrderTypes = array_flip(unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_ORDER_TYPES_ARR, 0))); $optionsDelivTypes = array_flip(unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_DELIVERY_TYPES_ARR, 0))); $optionsPayTypes = array_flip(unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_PAYMENT_TYPES, 0))); $optionsPayStatuses = array_flip(unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_PAYMENT_STATUSES, 0))); // --statuses $optionsPayment = array_flip(unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_PAYMENT, 0))); $optionsOrderProps = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_ORDER_PROPS, 0)); $optionsLegalDetails = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_LEGAL_DETAILS, 0)); $optionsContragentType = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_CONTRAGENT_TYPE, 0)); $optionsSitesList = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_SITES_LIST, 0)); $optionsCustomFields = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_CUSTOM_FIELDS, 0)); foreach ($optionsOrderProps as $code => $value) { if (isset($optionsLegalDetails[$code])) { $optionsOrderProps[$code] = array_merge($optionsOrderProps[$code], $optionsLegalDetails[$code]); } if (isset($optionsCustomFields[$code])) { $optionsOrderProps[$code] = array_merge($optionsOrderProps[$code], $optionsCustomFields[$code]); } $optionsOrderProps[$code]['location'] = 'LOCATION'; if (array_search('CITY', $optionsOrderProps[$code]) == false) { $optionsOrderProps[$code]['city'] = 'CITY'; } if (array_search('ZIP', $optionsOrderProps[$code]) == false) { $optionsOrderProps[$code]['index'] = 'ZIP'; } } $api = new RetailCrm\RestApi($api_host, $api_key); $dateStart = COption::GetOptionString(self::$MODULE_ID, self::$CRM_ORDER_HISTORY_DATE, null); if (is_null($dateStart)) { $dateStart = new \DateTime(); $dateStart = $dateStart->format('Y-m-d H:i:s'); } try { $orderHistory = $api->orderHistory($dateStart); } catch (\RetailCrm\Exception\CurlException $e) { self::eventLog('ICrmOrderActions::orderHistory', 'RetailCrm\\RestApi::orderHistory::CurlException', $e->getCode() . ': ' . $e->getMessage()); return false; } $orderHistory = isset($orderHistory['orders']) ? $orderHistory['orders'] : array(); $log = new Logger(); $log->write($orderHistory, 'history'); $dateFinish = $api->getGeneratedAt(); if (is_null($dateFinish) || $dateFinish == false) { $dateFinish = new \DateTime(); } $defaultOrderType = 1; $dbOrderTypesList = CSalePersonType::GetList(array(), array("ACTIVE" => "Y")); if ($arOrderTypesList = $dbOrderTypesList->Fetch()) { $defaultOrderType = $arOrderTypesList['ID']; } $GLOBALS['INTARO_CRM_FROM_HISTORY'] = true; foreach ($orderHistory as $order) { if (function_exists('intarocrm_order_pre_persist')) { $order = intarocrm_order_pre_persist($order); } if (!isset($order['externalId'])) { // custom orderType function if (function_exists('intarocrm_set_order_type')) { $orderType = intarocrm_set_order_type($order); if ($orderType) { $optionsOrderTypes[$order['orderType']] = $orderType; } else { $optionsOrderTypes[$order['orderType']] = $defaultOrderType; } } // we dont need new orders without any customers (can check only for externalId) if (!isset($order['customer']['externalId'])) { if (!isset($order['customer']['id'])) { continue; } $registerNewUser = true; if (!isset($order['customer']['email']) || $order['customer']['email'] == '') { $login = $order['customer']['email'] = uniqid('user_' . time()) . '@crm.com'; } else { $dbUser = CUser::GetList($by = 'ID', $sort = 'ASC', array('=EMAIL' => $order['email'])); switch ($dbUser->SelectedRowsCount()) { case 0: $login = $order['customer']['email']; break; case 1: $arUser = $dbUser->Fetch(); $registeredUserID = $arUser['ID']; $registerNewUser = false; break; default: $login = uniqid('user_' . time()) . '@crm.com'; break; } } if ($registerNewUser === true) { $userPassword = uniqid(); $newUser = new CUser(); $arFields = array("NAME" => self::fromJSON($order['customer']['firstName']), "LAST_NAME" => self::fromJSON($order['customer']['lastName']), "EMAIL" => $order['customer']['email'], "LOGIN" => $login, "LID" => "ru", "ACTIVE" => "Y", "PASSWORD" => $userPassword, "CONFIRM_PASSWORD" => $userPassword); $registeredUserID = $newUser->Add($arFields); if ($registeredUserID === false) { self::eventLog('ICrmOrderActions::orderHistory', 'CUser::Register', 'Error register user'); continue; } try { $api->customerFixExternalIds(array(array('id' => $order['customer']['id'], 'externalId' => $registeredUserID))); } catch (\RetailCrm\Exception\CurlException $e) { self::eventLog('ICrmOrderActions::orderHistory', 'RetailCrm\\RestApi::customerFixExternalIds::CurlException', $e->getCode() . ': ' . $e->getMessage()); continue; } } $order['customer']['externalId'] = $registeredUserID; } // new order $newOrderFields = array('LID' => CSite::GetDefSite(), 'PERSON_TYPE_ID' => isset($optionsOrderTypes[$order['orderType']]) ? $optionsOrderTypes[$order['orderType']] : $defaultOrderType, 'PAYED' => 'N', 'CANCELED' => 'N', 'STATUS_ID' => 'N', 'PRICE' => 0, 'CURRENCY' => CCurrency::GetBaseCurrency(), 'USER_ID' => $order['customer']['externalId'], 'PAY_SYSTEM_ID' => 0, 'PRICE_DELIVERY' => 0, 'DELIVERY_ID' => 0, 'DISCOUNT_VALUE' => 0, 'USER_DESCRIPTION' => ''); if (count($optionsSitesList) > 1 && ($lid = array_search($order['site'], $optionsSitesList))) { $newOrderFields['LID'] = $lid; } $externalId = CSaleOrder::Add($newOrderFields); if (!isset($order['externalId'])) { try { $api->orderFixExternalIds(array(array('id' => $order['id'], 'externalId' => $externalId))); } catch (\RetailCrm\Exception\CurlException $e) { self::eventLog('ICrmOrderActions::orderHistory', 'RetailCrm\\RestApi::orderFixExternalIds::CurlException', $e->getCode() . ': ' . $e->getMessage()); continue; } } $order['externalId'] = $externalId; } if (isset($order['externalId']) && $order['externalId']) { // custom orderType function if (function_exists('intarocrm_set_order_type')) { $orderType = intarocrm_set_order_type($order); if ($orderType) { $optionsOrderTypes[$order['orderType']] = $orderType; } else { $optionsOrderTypes[$order['orderType']] = $defaultOrderType; } } $arFields = CSaleOrder::GetById($order['externalId']); // incorrect order if ($arFields === false || empty($arFields)) { continue; } $LID = $arFields['LID']; $userId = $arFields['USER_ID']; if (isset($order['customer']['externalId']) && !is_null($order['customer']['externalId'])) { $userId = $order['customer']['externalId']; } $rsOrderProps = CSaleOrderPropsValue::GetList(array(), array('ORDER_ID' => $arFields['ID'])); $arUpdateProps = array(); while ($ar = $rsOrderProps->Fetch()) { $prop = CSaleOrderProps::GetByID($ar['ORDER_PROPS_ID']); $arUpdateProps[$ar['CODE']] = array('ID' => $ar['ID'], 'TYPE' => $prop['TYPE'], 'VALUE' => $ar['VALUE']); } $order['fio'] = trim(implode(' ', array(isset($order['lastName']) ? $order['lastName'] : '', isset($order['firstName']) ? $order['firstName'] : '', isset($order['patronymic']) ? $order['patronymic'] : ''))); if (isset($order['delivery']['address']['city'])) { $order['location'] = $order['delivery']['address']['city']; } if (isset($order['orderType']) && isset($optionsOrderTypes[$order['orderType']])) { if (isset($optionsOrderProps[$arFields['PERSON_TYPE_ID']])) { foreach ($optionsOrderProps[$arFields['PERSON_TYPE_ID']] as $code => $value) { if (in_array($code, array_keys($order)) === false && isset($optionsOrderProps[$optionsOrderTypes[$order['orderType']]][$code])) { $order[$code] = $arUpdateProps[$optionsOrderProps[$arFields['PERSON_TYPE_ID']][$code]]['VALUE']; } } } //update ordertype CSaleOrder::Update($order['externalId'], array('PERSON_TYPE_ID' => $optionsOrderTypes[$order['orderType']])); $arProp = CSaleOrderProps::GetList(array(), array('PERSON_TYPE_ID' => $optionsOrderTypes[$order['orderType']])); $typeParam = array(); while ($ar = $arProp->Fetch()) { $typeParam[$ar['CODE']] = $ar['CODE']; } foreach (array_diff_key($arUpdateProps, $typeParam) as $code => $param) { if (isset($arUpdateProps[$code])) { CSaleOrderPropsValue::Delete($param['ID']); } } $arFields['PERSON_TYPE_ID'] = $optionsOrderTypes[$order['orderType']]; } array_walk_recursive(self::clearArr($order), 'self::recursiveUpdate', array('update' => $arUpdateProps, 'type' => $arFields['PERSON_TYPE_ID'], 'options' => $optionsOrderProps, 'orderId' => $order['externalId'])); foreach ($order['items'] as $item) { if (isset($item['deleted']) && $item['deleted']) { if ($p = CSaleBasket::GetList(array(), array('ORDER_ID' => $order['externalId'], 'PRODUCT_ID' => $item['id']))->Fetch()) { if (!CSaleBasket::Delete($p['ID'])) { self::eventLog('ICrmOrderActions::orderHistory', 'CSaleBasket::Delete', 'Error element delete'); } } else { $prp = CSaleBasket::GetPropsList(array(), array("ORDER_ID" => $order['externalId'], "CODE" => 'ID', "VALUE" => $item['id']))->Fetch(); if (!CSaleBasket::Delete($prp['BASKET_ID'])) { self::eventLog('ICrmOrderActions::orderHistory', 'CSaleBasket::Delete', 'Error castom element delete'); } } continue; } if (isset($item['offer']) === false && isset($item['offer']['externalId']) === false) { continue; } $res = CIBlockElement::GetByID($item['offer']['externalId'])->Fetch(); if ($res) { $p = CSaleBasket::GetList(array(), array('ORDER_ID' => $order['externalId'], 'PRODUCT_ID' => $item['offer']['externalId']))->Fetch(); if ($p == false) { $p = CIBlockElement::GetByID($item['offer']['externalId'])->GetNext(); $iblock = CIBlock::GetByID($p['IBLOCK_ID'])->Fetch(); $p['CATALOG_XML_ID'] = $iblock['XML_ID']; $p['PRODUCT_XML_ID'] = $p['XML_ID']; unset($p['XML_ID']); } elseif ($propResult = CSaleBasket::GetPropsList(array(''), array('BASKET_ID' => $p['ID']))) { while ($r = $propResult->Fetch()) { unset($r['ID']); unset($r['BASKET_ID']); $p['PROPS'][] = $r; } } $arProduct = array(); if (isset($item['created']) && $item['created'] == true) { $productPrice = GetCatalogProductPrice($item['offer']['externalId'], COption::GetOptionString(self::$MODULE_ID, self::$CRM_CATALOG_BASE_PRICE, 0)); $arProduct = array('FUSER_ID' => $userId, 'ORDER_ID' => $order['externalId'], 'QUANTITY' => $item['quantity'], 'CURRENCY' => $productPrice['CURRENCY'], 'LID' => $LID, 'PRODUCT_ID' => $item['offer']['externalId'], 'PRODUCT_PRICE_ID' => $p['PRODUCT_PRICE_ID'], 'WEIGHT' => $p['WEIGHT'], 'DELAY' => $p['DELAY'], 'CAN_BUY' => $p['CAN_BUY'], 'MODULE' => $p['MODULE'], 'NOTES' => $item['comment'] ?: $p['NOTES'], 'PRODUCT_PROVIDER_CLASS' => $p['PRODUCT_PROVIDER_CLASS'], 'DETAIL_PAGE_URL' => $p['DETAIL_PAGE_URL'], 'CATALOG_XML_ID' => $p['CATALOG_XML_ID'], 'PRODUCT_XML_ID' => $p['PRODUCT_XML_ID'], 'CUSTOM_PRICE' => 'Y'); } if (isset($item['isCanceled']) == false) { if (isset($item['initialPrice']) && $item['initialPrice']) { $arProduct['PRICE'] = (double) $item['initialPrice']; } if (isset($item['discount'])) { $arProduct['DISCOUNT_PRICE'] = $item['discount']; } if (isset($item['discountPercent'])) { $arProduct['DISCOUNT_VALUE'] = $item['discountPercent']; $newPrice = round($arProduct['PRICE'] / 100 * (100 - $arProduct['DISCOUNT_VALUE']), 2); $arProduct['DISCOUNT_PRICE'] = $arProduct['DISCOUNT_PRICE'] + $arProduct['PRICE'] - $newPrice; } if (isset($item['discount']) || isset($item['discountPercent'])) { $arProduct['PRICE'] -= $arProduct['DISCOUNT_PRICE']; } if (isset($item['offer']['name']) && $item['offer']['name']) { $arProduct['NAME'] = self::fromJSON($item['offer']['name']); } $arProduct = self::updateCancelProp($arProduct, 0); } elseif (isset($item['isCanceled'])) { $arProduct['PRICE'] = 0; $arProduct = self::updateCancelProp($arProduct, 1); } if (isset($item['created']) && $item['created'] == true) { if (!Add2BasketByProductID($item['offer']['externalId'], $item['quantity'], $arProduct, $p['PROPS'])) { self::eventLog('ICrmOrderActions::orderHistory', 'Add2BasketByProductID', 'Error element add'); } continue; } if (count($p['PROPS']) > 0) { $arProduct['PROPS'] = $p['PROPS']; } if (isset($item['quantity']) && $item['quantity']) { $arProduct['QUANTITY'] = $item['quantity']; } if (isset($item['offer']['name']) && $item['offer']['name']) { $arProduct['NAME'] = self::fromJSON($item['offer']['name']); } if (!CSaleBasket::Update($p['ID'], $arProduct)) { self::eventLog('ICrmOrderActions::orderHistory', 'CSaleBasket::Update', 'Error element update'); } CSaleBasket::DeleteAll($userId); } else { $arProduct = array(); if (isset($item['created']) && $item['created'] == true) { $arProduct = array('FUSER_ID' => $userId, 'ORDER_ID' => $order['externalId'], 'LID' => $LID, 'NOTES' => $item['comment']); } if (isset($item['isCanceled']) == false) { if (isset($item['initialPrice']) && $item['initialPrice']) { $arProduct['PRICE'] = (double) $item['initialPrice']; } if (isset($item['discount'])) { $arProduct['DISCOUNT_PRICE'] = $item['discount']; } if (isset($item['discountPercent'])) { $arProduct['DISCOUNT_VALUE'] = $item['discountPercent']; $newPrice = round($arProduct['PRICE'] / 100 * (100 - $arProduct['DISCOUNT_VALUE']), 2); $arProduct['DISCOUNT_PRICE'] = $arProduct['DISCOUNT_PRICE'] + $arProduct['PRICE'] - $newPrice; } if (isset($item['discount']) || isset($item['discountPercent'])) { $arProduct['PRICE'] -= $arProduct['DISCOUNT_PRICE']; } if (isset($item['offer']['name']) && $item['offer']['name']) { $arProduct['NAME'] = self::fromJSON($item['offer']['name']); } $arProduct = self::updateCancelProp($arProduct, 0); } elseif (isset($item['isCanceled'])) { $arProduct['PRICE'] = 0; $arProduct = self::updateCancelProp($arProduct, 1); } if (isset($item['quantity']) && $item['quantity']) { $arProduct['QUANTITY'] = $item['quantity']; } if (isset($item['offer']['name']) && $item['offer']['name']) { $arProduct['NAME'] = self::fromJSON($item['offer']['name']); } if (isset($item['created']) && $item['created'] == true) { $iBlocks = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_CATALOG_IBLOCKS, 0)); $iBlock = array_shift($iBlocks); $newSection = new CIBlockSection(); $newSectionFields = array("ACTIVE" => 'N', "IBLOCK_ID" => $iBlock, "NAME" => 'RetailCRM', "CODE" => 'RetailCRM'); $resSection = $newSection->Add($newSectionFields); if (!$resSection) { self::eventLog('ICrmOrderActions::orderHistory', 'CIBlockSection::Add', 'Error castom section add'); continue; } $arLoadProductArray = array("IBLOCK_SECTION_ID" => $resSection, "IBLOCK_ID" => $iBlock, "NAME" => $item['offer']['name'] ? $item['offer']['name'] : 'RetailCrmElement', "CODE" => 'RetailCrmElement', "ACTIVE" => 'Y'); $el = new CIBlockElement(); $PRODUCT_ID = $el->Add($arLoadProductArray, false, false, true); if (!$PRODUCT_ID) { self::eventLog('ICrmOrderActions::orderHistory', 'CIBlockElement::Add', 'Error castom element add'); continue; } if (!CCatalogProduct::Add(array("ID" => $PRODUCT_ID))) { self::eventLog('ICrmOrderActions::orderHistory', 'CCatalogProduct::Add', 'Error product add'); continue; } $arFields = array("PRODUCT_ID" => $PRODUCT_ID, "CATALOG_GROUP_ID" => COption::GetOptionString(self::$MODULE_ID, self::$CRM_CATALOG_BASE_PRICE, 0), "PRICE" => $item['initialPrice'] ? $item['initialPrice'] : 1, "CURRENCY" => CCurrency::GetBaseCurrency()); if (!CPrice::Add($arFields)) { self::eventLog('ICrmOrderActions::orderHistory', 'CPrice::Add', 'Error price add'); continue; } $Params = array(array('NAME' => 'id', 'CODE' => 'ID', 'VALUE' => $item['offer']['externalId'])); if (!Add2BasketByProductID($PRODUCT_ID, $item['quantity'], $arProduct, $Params)) { self::eventLog('ICrmOrderActions::orderHistory', 'Add2BasketByProductID', 'Error add to basket'); continue; } if (!CIBlockSection::Delete($resSection)) { self::eventLog('ICrmOrderActions::orderHistory', 'CIBlockSection::Delete', 'Error delete section'); continue; } continue; } $prp = CSaleBasket::GetPropsList(array(), array("ORDER_ID" => $order['externalId'], "CODE" => 'ID', "VALUE" => $item['offer']['externalId']))->Fetch(); CSaleBasket::Update($prp['BASKET_ID'], $arProduct); } } if (isset($order['delivery']) === false || isset($order['delivery']['cost']) === false) { $order['delivery']['cost'] = $arFields['PRICE_DELIVERY']; } if (isset($order['summ']) === false || $order['summ'] <= 0) { $order['summ'] = $arFields['PRICE'] - $arFields['PRICE_DELIVERY']; } $wasCanaceled = $arFields['CANCELED'] == 'Y' ? true : false; if (isset($optionsDelivTypes[$order['delivery']['code']])) { $resultDeliveryTypeId = $optionsDelivTypes[$order['delivery']['code']]; } else { $resultDeliveryTypeId = isset($order['delivery']['service']) && isset($order['delivery']['service']['code']) ? reset(explode(":", $arFields['DELIVERY_ID'], 1)) : $arFields['DELIVERY_ID']; } if (isset($order['delivery']['service']) && isset($order['delivery']['service']['code'])) { $deliveryHandler = reset(CSaleDeliveryHandler::GetBySID($resultDeliveryTypeId)->arResult); if (count($deliveryHandler) > 0 && array_key_exists($order['delivery']['service']['code'], $deliveryHandler['PROFILES'])) { $resultDeliveryTypeId = $resultDeliveryTypeId . ':' . $order['delivery']['service']['code']; } } // orderUpdate $arFields = self::clearArr(array('PRICE_DELIVERY' => $order['delivery']['cost'], 'PRICE' => $order['summ'] + (double) $order['delivery']['cost'], 'DATE_MARKED' => $order['markDatetime'], 'USER_ID' => $userId, 'PAY_SYSTEM_ID' => $optionsPayTypes[$order['paymentType']], 'DELIVERY_ID' => $resultDeliveryTypeId, 'STATUS_ID' => $optionsPayStatuses[$order['status']], 'REASON_CANCELED' => self::fromJSON($order['statusComment']), 'USER_DESCRIPTION' => self::fromJSON($order['customerComment']), 'COMMENTS' => self::fromJSON($order['managerComment']))); if (isset($order['discount'])) { $arFields['DISCOUNT_VALUE'] = $order['discount']; $arFields['PRICE'] -= $order['discount']; } if (!empty($arFields)) { CSaleOrder::Update($order['externalId'], $arFields); } if (isset($order['status']) && $order['status']) { if (isset($optionsPayStatuses[$order['status']]) && $optionsPayStatuses[$order['status']]) { // set STATUS_ID CSaleOrder::StatusOrder($order['externalId'], $optionsPayStatuses[$order['status']]); if ($wasCanaceled && $optionsPayStatuses[$order['status']] != 'YY') { CSaleOrder::CancelOrder($order['externalId'], "N", $order['statusComment']); } elseif ($optionsPayStatuses[$order['status']] == 'YY') { CSaleOrder::CancelOrder($order['externalId'], "Y", $order['statusComment']); } } } // set PAYED if (isset($order['paymentStatus']) && $order['paymentStatus'] && $optionsPayment[$order['paymentStatus']]) { CSaleOrder::PayOrder($order['externalId'], $optionsPayment[$order['paymentStatus']]); } if (function_exists('intarocrm_order_post_persist')) { intarocrm_order_post_persist($order); } } } if (count($orderHistory) > 0) { COption::SetOptionString(self::$MODULE_ID, self::$CRM_ORDER_HISTORY_DATE, $dateFinish->format('Y-m-d H:i:s')); } $GLOBALS['INTARO_CRM_FROM_HISTORY'] = false; return true; }
function InstallService($serviceID, $serviceStage) { $wizard =& $this->GetWizard(); if (CModule::IncludeModule("iblock")) { $type = substr($serviceID, 0, -1); if ($type == "iblockElement") { $dbItem = CIBlockElement::GetList(array(), array("=IBLOCK_CODE" => $serviceStage), false, false, array("ID")); while ($arItem = $dbItem->Fetch()) { CIBlockElement::Delete($arItem["ID"]); } } elseif ($type == "iblockSectionElement") { $dbItem = CIBlockElement::GetList(array(), array("=IBLOCK_CODE" => $serviceStage), false, false, array("ID")); while ($arItem = $dbItem->Fetch()) { CIBlockElement::Delete($arItem["ID"]); } $dbItem = CIBlockSection::GetList(array(), array("=IBLOCK_CODE" => $serviceStage), false, array("ID")); while ($arItem = $dbItem->Fetch()) { CIBlockSection::Delete($arItem["ID"]); } } elseif ($serviceID == "iblockDepartmentsElement") { $dbItem = CIBlockSection::GetList(array(), array("=IBLOCK_CODE" => "departments")); while ($arItem = $dbItem->Fetch()) { if ($arItem["DEPTH_LEVEL"] > 2) { CIBlockSection::Delete($arItem["ID"]); } } } elseif ($serviceID == "tasks") { if (CModule::IncludeModule("tasks")) { $dbItem = CTasks::GetList(array(), array("SITE_ID" => $wizard->GetVar("siteID"))); while ($arItem = $dbItem->Fetch()) { CTasks::Delete($arItem["ID"]); } } } elseif ($serviceID == "calendar") { if (CModule::IncludeModule("calendar")) { $dbItem = CCalendarEvent::GetList(); foreach ($dbItem as $arItem) { CCalendarEvent::Delete(array("id" => $arItem["ID"])); } } } elseif ($serviceID == "meeting") { if (CModule::IncludeModule("meeting")) { $dbItem = CMeeting::GetList(array(), array()); while ($arItem = $dbItem->Fetch()) { if ($arItem["ID"]) { CMeeting::Delete($arItem["ID"]); } } } } elseif ($serviceID == "user") { if ($serviceStage == "user") { $dbUser = CUser::GetList($by = "ID", $order = "DESC", array(">ID" => 1)); while ($arUser = $dbUser->Fetch()) { CUser::Delete($arUser["ID"]); } } } elseif ($serviceID == "crm") { if ($serviceStage == "crm") { if (CModule::IncludeModule('crm')) { $CCrmLead = new CCrmLead(); $resLead = CCrmLead::GetList(array(), array(), array(), false); while ($rowLead = $resLead->Fetch()) { $CCrmLead->Delete($rowLead["ID"]); } $CCrmContact = new CCrmContact(); $resContact = CCrmContact::GetList(array(), array(), array(), false); while ($rowContact = $resContact->Fetch()) { $CCrmContact->Delete($rowContact["ID"]); } $CCrmCompany = new CCrmCompany(); $resCompany = CCrmCompany::GetList(array(), array(), array(), false); while ($rowCompany = $resCompany->Fetch()) { $CCrmCompany->Delete($rowCompany["ID"]); } $CCrmDeal = new CCrmDeal(); $resDeal = CCrmDeal::GetList(array(), array(), array(), false); while ($rowDeal = $resDeal->Fetch()) { $CCrmDeal->Delete($rowDeal["ID"]); } } } } elseif ($serviceID == "cache") { require_once $_SERVER["DOCUMENT_ROOT"] . BX_ROOT . "/modules/main/classes/general/cache_html.php"; if ($serviceStage == "cache1") { BXClearCache(true); } elseif ($serviceStage == "cache2") { $GLOBALS["CACHE_MANAGER"]->CleanAll(); } elseif ($serviceStage == "cache3") { $GLOBALS["stackCacheManager"]->CleanAll(); } elseif ($serviceStage == "cache4") { CHTMLPagesCache::CleanAll(); } COption::SetOptionString("main", "wizard_clear_exec", "Y", false, $wizard->GetVar("siteID")); } } }
if ($rsSection->GetNext()) { $arFields = array("IBLOCK_ID" => $arResult["IBLOCK_ID"], "NAME" => $new_section_name); $obSection->Update($old_section_id, $arFields); } } } if (isset($_POST["form_section_action"]) && $_POST["form_section_action"] == "add" && !$arResult["IS_SOCNET_GROUP_CLOSED"] && ($lists_perm >= CListPermissions::CAN_WRITE || $old_section_id == 0 && CIBlockSectionRights::UserHasRightTo($arIBlock["ID"], $arResult["SECTION_ID"], "section_section_bind"))) { $new_section_name = trim($_POST["new_section_name"], " \n\r\t"); if ($new_section_name) { $arFields = array("IBLOCK_ID" => $arResult["IBLOCK_ID"], "NAME" => $new_section_name, "IBLOCK_SECTION_ID" => $arResult["SECTION_ID"], "CHECK_PERMISSIONS" => "N"); $obSection->Add($arFields); } } elseif ($_POST["action_button_" . $arResult["GRID_ID"]] == "delete" && isset($_POST["ID"]) && is_array($_POST["ID"]) && !$arResult["IS_SOCNET_GROUP_CLOSED"]) { foreach ($_POST["ID"] as $ID) { if ($lists_perm >= CListPermissions::CAN_WRITE || CIBlockSectionRights::UserHasRightTo($arIBlock["ID"], $ID, "section_delete")) { $obSection->Delete($ID, false); } } } elseif ($_POST["action_button_" . $arResult["GRID_ID"]] == "edit" && isset($_POST["FIELDS"]) && is_array($_POST["FIELDS"]) && !$arResult["IS_SOCNET_GROUP_CLOSED"]) { foreach ($_POST["FIELDS"] as $ID => $arField) { if ($lists_perm >= CListPermissions::CAN_WRITE || CIBlockSectionRights::UserHasRightTo($arIBlock["ID"], $ID, "section_edit")) { $arFields = array("NAME" => $arField["NAME"], "CHECK_PERMISSIONS" => "N"); $obSection->Update($ID, $arFields); } } } if (!isset($_POST["AJAX_CALL"])) { LocalRedirect($arResult["LIST_SECTION_URL"]); } } $grid_options = new CGridOptions($arResult["GRID_ID"]);
/** * [delSection description] * @param int $id * @return bool */ protected function delSection($id){ return CIBlockSection::Delete($id); }
protected function workWithUsersSection($iblockId) { $sectionQuery = CIBlockSection::GetList(array(), array("IBLOCK_ID" => $iblockId, "SOCNET_GROUP_ID" => false, "CHECK_PERMISSIONS" => "N", "SECTION_ID" => 0), false, array('IBLOCK_CODE', 'IBLOCK_TYPE_ID', 'ID', 'NAME', 'CREATED_BY')); while ($sectionQuery && ($userSection = $sectionQuery->Fetch())) { $this->abortIfNeeded(); if ($userSection['IBLOCK_CODE'] != 'user_files' || $userSection['IBLOCK_TYPE_ID'] != 'library') { continue; } $droppedQuery = CIBlockSection::GetList(array(), array("IBLOCK_ID" => $iblockId, "SECTION_ID" => $userSection['ID'], "CHECK_PERMISSIONS" => "N", "=NAME" => '.Dropped'), false, array('ID', 'IBLOCK_ID', 'NAME')); if (!$droppedQuery || !($droppedSection = $droppedQuery->Fetch())) { continue; } $this->abortIfNeeded(); $downloadedSectionId = $this->getDownloadedSectionId($iblockId, $userSection['ID'], array('CREATED_BY' => $userSection['CREATED_BY'], 'MODIFIED_BY' => $userSection['CREATED_BY'])); if (!$downloadedSectionId) { continue; } if ($this->workWithDropped($droppedSection, $downloadedSectionId)) { $this->abortIfNeeded(); //0 files in section if (CIBlockSection::Delete($droppedSection['ID'], false)) { static::$countConvertSections++; } } } }
<?php ini_set("display_errors", 1); error_reporting(E_ALL); set_time_limit(0); ini_set('mbstring.func_overload', "2"); ini_set('mbstring.internal_encoding', "UTF-8"); $_SERVER["DOCUMENT_ROOT"] = "/home/bitrix/www"; $DOCUMENT_ROOT = $_SERVER["DOCUMENT_ROOT"]; define("BX_UTF", true); define("NO_KEEP_STATISTIC", true); define("NOT_CHECK_PERMISSIONS", true); define("BX_BUFFER_USED", true); require $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/prolog_before.php"; while (ob_get_level()) { ob_end_flush(); } CModule::IncludeModule("iblock"); $sections_list = CIBlockSection::GetTreeList(array(), array('IBLOCK_ID' => 4), true); while ($arResult = $sections_list->GetNext()) { $nav = CIBlockSection::GetNavChain(4, $arResult["ID"]); $nav->ExtractFields("nav_"); if ($nav_ID == 59 && CIBlockSection::GetSectionElementsCount($arResult["ID"]) == 0) { if (!CIBlockSection::Delete($arResult["ID"])) { echo $arResult["NAME"] . " removed" . "\n"; } } } require $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/epilog_after.php";
function Delete($ID, $arEvIds = false) { global $DB; if (!$this->CheckPermissionForEvent(array(), true)) { return CEventCalendar::ThrowError('EC_ACCESS_DENIED'); } @set_time_limit(0); $DB->StartTransaction(); if (!CIBlockSection::Delete($ID)) { $DB->Rollback(); return false; } $DB->Commit(); return true; }
public static function Delete($ID) { if (!CModule::IncludeModule('iblock')) { return false; } $section = new CIBlockSection(); $dbResult = $section->GetList(array(), array('ID' => $ID, 'GLOBAL_ACTIVE' => 'Y', 'CHECK_PERMISSIONS' => 'N'), false, array('IBLOCK_ID'), false); $currentFields = $dbResult ? $dbResult->Fetch() : null; if (!(is_array($currentFields) && CCrmCatalog::Exists(intval($currentFields['IBLOCK_ID'])))) { self::$LAST_ERROR_CODE = self::ERR_SECTION_NOT_FOUND; self::$LAST_ERROR = GetMessage('CRM_PRODUCT_SECTION_ERR_NOT_FOUND'); return false; } if (self::isIncludesUsedProducts($currentFields['IBLOCK_ID'], $ID)) { // Section includes used products self::$LAST_ERROR_CODE = self::ERR_SECTION_INCLUDES_USED_PRODUCTS; self::$LAST_ERROR = GetMessage('CRM_PRODUCT_SECTION_ERR_SECTION_INCLUDES_USED_PRODUCTS'); return false; } $result = $section->Delete($ID, false); if ($result === false) { self::$LAST_ERROR_CODE = self::ERR_IBLOCK_SECTION_DELETE; self::$LAST_ERROR = $section->LAST_ERROR; } return $result !== false; }
$arResult["USER"]["SHOW_NAME"] = trim($arResult["USER"]["NAME"] . " " . $arResult["USER"]["LAST_NAME"]); if (empty($arResult["USER"]["SHOW_NAME"])) { $arResult["USER"]["SHOW_NAME"] = $arResult["USER"]["LOGIN"]; } } else { $arResult["USER"] = array("SHOW_NAME" => GetMessage("P_USER_UNKNOWN")); } $arResult["USER"]["~SHOW_NAME"] = $arResult["USER"]["SHOW_NAME"]; $arResult["USER"]["SHOW_NAME"] = htmlspecialcharsEx($arResult["USER"]["~SHOW_NAME"]); } /******************************************************************** Actions ********************************************************************/ if ($arParams["ACTION"] == "DROP" && check_bitrix_sessid()) { @set_time_limit(1000); if (!CIBlockSection::Delete($arResult["GALLERY"]["ID"])) { $strWarning = GetMessage("IBSEC_A_DELERR_REFERERS"); if ($e = $APPLICATION->GetException()) { $strWarning = $e->GetString(); } $arError = array("code" => "NOT_DROPED", "title" => $strWarning); } else { PClearComponentCacheEx($arParams["IBLOCK_ID"], array($arResult['GALLERY']['ID']), array($arResult["GALLERY"]["CODE"]), array($arParams["USER_ID"] > 0 ? $arParams["USER_ID"] : 0)); $url = CComponentEngine::MakePathFromTemplate($arParams["~INDEX_URL"], array()); if (count($arResult["GALLERIES"]) > 1) { $url = CComponentEngine::MakePathFromTemplate($arParams["~GALLERIES_URL"], array("USER_ID" => $arResult["GALLERY"]["CREATED_BY"])); } LocalRedirect($url); } } elseif (!empty($_REQUEST["save"])) { $arError = array();
$errorMessage = GetMessage("INTL_NO_FOLDER_PERMS") . "."; } if (StrLen($errorMessage) <= 0) { $folderID = IntVal($_GET["id"]); if ($folderID <= 0) { $errorMessage .= GetMessage("INTL_NO_FOLDER_ID") . ". "; } } if (StrLen($errorMessage) <= 0) { $dbSectionsChain = CIBlockSection::GetNavChain($iblockId, $folderID); $arSect = $dbSectionsChain->GetNext(); if (!$arSect) { $errorMessage .= GetMessage("INTL_FOLDER_NOT_FOUND") . ". "; } else { if ($taskType == 'group' && $arSect["XML_ID"] != $ownerId) { $errorMessage .= GetMessage("INTL_TASK_INTERNAL_ERROR") . " GTK001" . ". "; } elseif ($taskType != 'group' && $arSect["XML_ID"] != "users_tasks") { $errorMessage .= GetMessage("INTL_TASK_INTERNAL_ERROR") . " GTK002" . ". "; } } } if (StrLen($errorMessage) <= 0) { if (!CIBlockSection::Delete($folderID)) { $errorMessage .= GetMessage("INTL_FOLDER_DELETE_ERROR") . " "; } } if (StrLen($errorMessage) > 0) { __TaskReturnError($errorMessage); } } }
function Delete($ID, $bCheckPermissions = true) { $err_mess = "FILE: " . __FILE__ . "<br>LINE: "; global $DB, $APPLICATION, $USER; $ID = IntVal($ID); $APPLICATION->ResetException(); $db_events = GetModuleEvents("iblock", "OnBeforeIBlockSectionDelete"); while ($arEvent = $db_events->Fetch()) { if (ExecuteModuleEventEx($arEvent, array($ID)) === false) { $err = GetMessage("MAIN_BEFORE_DEL_ERR") . ' ' . $arEvent['TO_NAME']; if ($ex = $APPLICATION->GetException()) { $err .= ': ' . $ex->GetString(); } $APPLICATION->throwException($err); return false; } } $s = CIBlockSection::GetList(array(), array("ID" => $ID, "CHECK_PERMISSIONS" => $bCheckPermissions ? "Y" : "N")); if ($s = $s->Fetch()) { CIBlock::_transaction_lock($s["IBLOCK_ID"]); $iblockelements = CIBlockElement::GetList(array(), array("SECTION_ID" => $ID, "SHOW_HISTORY" => "Y", "IBLOCK_ID" => $s["IBLOCK_ID"]), false, false, array("ID", "IBLOCK_ID", "WF_PARENT_ELEMENT_ID")); while ($iblockelement = $iblockelements->Fetch()) { $strSql = "\n\t\t\t\t\tSELECT IBLOCK_SECTION_ID\n\t\t\t\t\tFROM b_iblock_section_element\n\t\t\t\t\tWHERE\n\t\t\t\t\t\tIBLOCK_ELEMENT_ID = " . $iblockelement["ID"] . "\n\t\t\t\t\t\tAND IBLOCK_SECTION_ID<>" . $ID . "\n\t\t\t\t\t\tAND ADDITIONAL_PROPERTY_ID IS NULL\n\t\t\t\t\tORDER BY\n\t\t\t\t\t\tIBLOCK_SECTION_ID\n\t\t\t\t"; $db_section_element = $DB->Query($strSql); if ($ar_section_element = $db_section_element->Fetch()) { $DB->Query("\n\t\t\t\t\t\tUPDATE b_iblock_element\n\t\t\t\t\t\tSET IBLOCK_SECTION_ID=" . $ar_section_element["IBLOCK_SECTION_ID"] . "\n\t\t\t\t\t\tWHERE ID=" . IntVal($iblockelement["ID"]) . "\n\t\t\t\t\t", false, $err_mess . __LINE__); } elseif (IntVal($iblockelement["WF_PARENT_ELEMENT_ID"]) <= 0) { if (!CIBlockElement::Delete($iblockelement["ID"])) { return false; } } else { $DB->Query("\n\t\t\t\t\t\tUPDATE b_iblock_element\n\t\t\t\t\t\tSET IBLOCK_SECTION_ID=NULL, IN_SECTIONS='N'\n\t\t\t\t\t\tWHERE ID=" . IntVal($iblockelement["ID"]) . "\n\t\t\t\t\t", false, $err_mess . __LINE__); } } $iblocksections = CIBlockSection::GetList(array(), array("SECTION_ID" => $ID, "CHECK_PERMISSIONS" => $bCheckPermissions ? "Y" : "N"), false, array("ID")); while ($iblocksection = $iblocksections->Fetch()) { if (!CIBlockSection::Delete($iblocksection["ID"], $bCheckPermissions)) { return false; } } CFile::Delete($s["PICTURE"]); CFile::Delete($s["DETAIL_PICTURE"]); static $arDelCache; if (!is_array($arDelCache)) { $arDelCache = array(); } if (!is_set($arDelCache, $s["IBLOCK_ID"])) { $arDelCache[$s["IBLOCK_ID"]] = false; $db_ps = $DB->Query("SELECT ID,IBLOCK_ID,VERSION,MULTIPLE FROM b_iblock_property WHERE PROPERTY_TYPE='G' AND (LINK_IBLOCK_ID=" . $s["IBLOCK_ID"] . " OR LINK_IBLOCK_ID=0 OR LINK_IBLOCK_ID IS NULL)", false, $err_mess . __LINE__); while ($ar_ps = $db_ps->Fetch()) { if ($ar_ps["VERSION"] == 2) { if ($ar_ps["MULTIPLE"] == "Y") { $strTable = "b_iblock_element_prop_m" . $ar_ps["IBLOCK_ID"]; } else { $strTable = "b_iblock_element_prop_s" . $ar_ps["IBLOCK_ID"]; } } else { $strTable = "b_iblock_element_property"; } $arDelCache[$s["IBLOCK_ID"]][$strTable][] = $ar_ps["ID"]; } } if ($arDelCache[$s["IBLOCK_ID"]]) { foreach ($arDelCache[$s["IBLOCK_ID"]] as $strTable => $arProps) { if (strncmp("b_iblock_element_prop_s", $strTable, 23) == 0) { foreach ($arProps as $prop_id) { $strSql = "UPDATE " . $strTable . " SET PROPERTY_" . $prop_id . "=null,DESCRIPTION_" . $prop_id . "=null WHERE PROPERTY_" . $prop_id . "=" . $s["ID"]; if (!$DB->Query($strSql, false, $err_mess . __LINE__)) { return false; } } } elseif (strncmp("b_iblock_element_prop_m", $strTable, 23) == 0) { $strSql = "SELECT IBLOCK_PROPERTY_ID, IBLOCK_ELEMENT_ID FROM " . $strTable . " WHERE IBLOCK_PROPERTY_ID IN (" . implode(", ", $arProps) . ") AND VALUE_NUM=" . $s["ID"]; $rs = $DB->Query($strSql, false, $err_mess . __LINE__); while ($ar = $rs->Fetch()) { $strSql = "\n\t\t\t\t\t\t\t\tUPDATE " . str_replace("prop_m", "prop_s", $strTable) . "\n\t\t\t\t\t\t\t\tSET\tPROPERTY_" . $ar["IBLOCK_PROPERTY_ID"] . "=null,\n\t\t\t\t\t\t\t\t\tDESCRIPTION_" . $ar["IBLOCK_PROPERTY_ID"] . "=null\n\t\t\t\t\t\t\t\tWHERE IBLOCK_ELEMENT_ID = " . $ar["IBLOCK_ELEMENT_ID"] . "\n\t\t\t\t\t\t\t"; if (!$DB->Query($strSql, false, $err_mess . __LINE__)) { return false; } } $strSql = "DELETE FROM " . $strTable . " WHERE IBLOCK_PROPERTY_ID IN (" . implode(", ", $arProps) . ") AND VALUE_NUM=" . $s["ID"]; if (!$DB->Query($strSql, false, $err_mess . __LINE__)) { return false; } } else { $strSql = "DELETE FROM " . $strTable . " WHERE IBLOCK_PROPERTY_ID IN (" . implode(", ", $arProps) . ") AND VALUE_NUM=" . $s["ID"]; if (!$DB->Query($strSql, false, $err_mess . __LINE__)) { return false; } } } } CIBlockSectionPropertyLink::DeleteBySection($ID); $DB->Query("DELETE FROM b_iblock_section_element WHERE IBLOCK_SECTION_ID=" . IntVal($ID), false, $err_mess . __LINE__); if (CModule::IncludeModule("search")) { CSearch::DeleteIndex("iblock", "S" . $ID); } $GLOBALS["USER_FIELD_MANAGER"]->Delete("IBLOCK_" . $s["IBLOCK_ID"] . "_SECTION", $ID); //Delete the hole in the tree $ss = $DB->Query("\n\t\t\t\tSELECT\n\t\t\t\t\tIBLOCK_ID,\n\t\t\t\t\tLEFT_MARGIN,\n\t\t\t\t\tRIGHT_MARGIN\n\t\t\t\tFROM\n\t\t\t\t\tb_iblock_section\n\t\t\t\tWHERE\n\t\t\t\t\tID = " . $s["ID"] . "\n\t\t\t"); $ss = $ss->Fetch(); if ($ss["RIGHT_MARGIN"] > 0 && $ss["LEFT_MARGIN"] > 0) { $DB->Query("\n\t\t\t\t\tUPDATE b_iblock_section SET\n\t\t\t\t\t\tTIMESTAMP_X=" . ($DB->type == "ORACLE" ? "NULL" : "TIMESTAMP_X") . "\n\t\t\t\t\t\t,RIGHT_MARGIN = RIGHT_MARGIN - 2\n\t\t\t\t\tWHERE\n\t\t\t\t\t\tIBLOCK_ID = " . $ss["IBLOCK_ID"] . "\n\t\t\t\t\t\tAND RIGHT_MARGIN > " . $ss["RIGHT_MARGIN"] . "\n\t\t\t\t"); $DB->Query("\n\t\t\t\t\tUPDATE b_iblock_section SET\n\t\t\t\t\t\tTIMESTAMP_X=" . ($DB->type == "ORACLE" ? "NULL" : "TIMESTAMP_X") . "\n\t\t\t\t\t\t,LEFT_MARGIN = LEFT_MARGIN - 2\n\t\t\t\t\tWHERE\n\t\t\t\t\t\tIBLOCK_ID = " . $ss["IBLOCK_ID"] . "\n\t\t\t\t\t\tAND LEFT_MARGIN > " . $ss["LEFT_MARGIN"] . "\n\t\t\t\t"); } $obSectionRights = new CIBlockSectionRights($s["IBLOCK_ID"], $ID); $obSectionRights->DeleteAllRights(); /************* QUOTA *************/ $_SESSION["SESS_RECOUNT_DB"] = "Y"; /************* QUOTA *************/ $arIBlockFields = CIBlock::GetArrayByID($s["IBLOCK_ID"], "FIELDS"); if ($arIBlockFields["LOG_SECTION_DELETE"]["IS_REQUIRED"] == "Y") { $USER_ID = is_object($USER) ? intval($USER->GetID()) : 0; $db_events = GetModuleEvents("main", "OnBeforeEventLog"); $arEvent = $db_events->Fetch(); if (!$arEvent || ExecuteModuleEventEx($arEvent, array($USER_ID)) === false) { $rsSection = CIBlockSection::GetList(array(), array("=ID" => $ID, "CHECK_PERMISSIONS" => $bCheckPermissions ? "Y" : "N"), false, array("LIST_PAGE_URL", "NAME", "CODE")); $arSection = $rsSection->GetNext(); $res = array("ID" => $ID, "CODE" => $arSection["CODE"], "NAME" => $arSection["NAME"], "SECTION_NAME" => CIBlock::GetArrayByID($s["IBLOCK_ID"], "SECTION_NAME"), "USER_ID" => $USER_ID, "IBLOCK_PAGE_URL" => $arSection["LIST_PAGE_URL"]); CEventLog::Log("IBLOCK", "IBLOCK_SECTION_DELETE", "iblock", $s["IBLOCK_ID"], serialize($res)); } } $res = $DB->Query("DELETE FROM b_iblock_section WHERE ID=" . IntVal($ID), false, $err_mess . __LINE__); if ($res) { $db_events = GetModuleEvents("iblock", "OnAfterIBlockSectionDelete"); while ($arEvent = $db_events->Fetch()) { ExecuteModuleEventEx($arEvent, array($s)); } if (defined("BX_COMP_MANAGED_CACHE")) { $GLOBALS["CACHE_MANAGER"]->ClearByTag("iblock_id_" . $s["IBLOCK_ID"]); } } return $res; } return true; }
function _delete_section($sectionID) { static $onDeleteEventSet = false; $result = true; if ($onDeleteEventSet == false && ($this->workflow == 'bizproc' || $this->workflow == 'bizproc_limited')) { AddEventHandler("iblock", "OnBeforeIBlockElementDelete", array($this, "_onDeleteElement")); AddEventHandler("iblock", "OnBeforeIBlockSectionDelete", array($this, "_onDeleteSection")); } $arSections = array(); $sectionID = intval($sectionID); $s = CIBlockSection::GetList(array(), array("ID" => $sectionID, 'CHECK_PERMISSIONS' => 'N'), false, array('ID', 'NAME', 'LEFT_MARGIN', 'RIGHT_MARGIN', 'DEPTH_LEVEL', 'IBLOCK_ID')); if ($arParentSection = $s->Fetch()) { CWebDavSymlinkHelper::setSectionOriginalName($sectionID, $arParentSection['NAME']); if (!$this->GetPermission('SECTION', $sectionID, 'section_delete', false)) { $result = GetMessage('WD_ERR_DELETE_FOLDER_NO_PERMS', array('ID' => $sectionID, 'NAME' => "")); } else { $arSections[] = $sectionID; $rSection = CIBlockSection::GetList(array('LEFT_MARGIN' => 'DESC'), array('CHECK_PERMISSIONS' => 'N', 'IBLOCK_ID' => $arParentSection['IBLOCK_ID'], '>LEFT_MARGIN' => $arParentSection['LEFT_MARGIN'], '<RIGHT_MARGIN' => $arParentSection['RIGHT_MARGIN'], '>DEPTH_LEVEL' => $arParentSection['DEPTH_LEVEL']), false, array('ID', 'NAME')); if ($rSection) { while ($arSection = $rSection->Fetch()) { if (!$this->GetPermission('SECTION', $arSection['ID'], 'section_delete')) { $result = GetMessage('WD_ERR_DELETE_FOLDER_NO_PERMS', array('ID' => $arSection['ID'], 'NAME' => htmlspecialcharsbx($arSection['NAME']))); break; } else { $arSections[] = $arSection['ID']; } } } } if ($result === true) { $se = new CIBlockSection(); if (!$se->Delete($arParentSection['ID'], false)) { $result = GetMessage('WD_FILE_ERROR16'); } } } return $result === true ? $result : $this->ThrowError("423 Locked", "423", $result); }
public static function OnSocNetGroupDelete($groupId) { $iblockIds = self::GetGroupIblock(); foreach ($iblockIds as $iblockId) { $result = CIBlockWebdavSocnet::GetSectionID($iblockId, 'group', $groupId); if (intval($result) > 0) { if (!empty($groupId)) { $dispatcher = new \Bitrix\Webdav\InviteDispatcher(); $attachObjectType = CWebDavSymlinkHelper::ENTITY_TYPE_GROUP; $attachObjectId = (int) $groupId; $inviteComponentParams = array('attachObject' => array('id' => $attachObjectId, 'type' => $attachObjectType), 'unshareUserIds' => array()); $response = $dispatcher->processActionUnshare($inviteComponentParams); if ($response['status'] == $dispatcher::STATUS_SUCCESS) { } } CIBlockSection::Delete($result); } } CIBlockWebdavSocnet::ClearTagCache('wd_socnet'); }
/** * Delete subject record * @param $id * @param null $dbVersion * @return ApplyResult */ public function delete($id, $dbVersion = null) { $dbVersion && ($id = $this->getCurrentVersionId($id, $dbVersion)); !$dbVersion && !$this->hasCurrentReference($id) && $this->registerCurrentVersionId($id); $sec = new \CIBlockSection(); $res = new ApplyResult(); $res->setSuccess((bool) $sec->Delete($id))->setMessage($sec->LAST_ERROR); $res->isSuccess() && $this->removeCurrentVersion($id); return $res; }
function DeactivateSections($action) { if (array_key_exists("bUpdateOnly", $this->next_step) && $this->next_step["bUpdateOnly"]) { return; } if (!$this->next_step["XML_SECTIONS_PARENT"]) { return; } if ($action != "D" && $action != "A") { return; } $bDelete = $action == "D"; //This will protect us from deactivating when next_step is lost $IBLOCK_ID = intval($this->next_step["IBLOCK_ID"]); if ($IBLOCK_ID < 1) { return; } $arFilter = array("IBLOCK_ID" => $IBLOCK_ID); if (!$bDelete) { $arFilter["ACTIVE"] = "Y"; } $obSection = new CIBlockSection(); $rsSection = $obSection->GetList(array("ID" => "asc"), $arFilter); while ($arSection = $rsSection->Fetch()) { $rs = $this->_xml_file->GetList(array(), array("PARENT_ID+0" => 0, "LEFT_MARGIN" => $arSection["ID"]), array("ID")); $ar = $rs->Fetch(); if (!$ar) { if ($bDelete) { $obSection->Delete($arSection["ID"]); } else { $obSection->Update($arSection["ID"], array("ACTIVE" => "N")); } } else { $this->_xml_file->Delete($ar["ID"]); } } return; }
/** * <p>Метод обновляет привязки Wiki-страницы к категориям. Динамичный метод.</p> * * * @param int $ID Идентификатор Wiki-страницы * * @param int $IBLOCK_ID Идентификатор Инфо.блока * * @param array $arCats Массив наименований категорий страницы * * @return void * * <h4>Example</h4> * <pre> * <?<br> * // Обновим категории страницы с идентификатором 13 из инфо.блока с идентификатором 2 * $arCats = array('Категория 1', 'Категория 2'); * $ID = 13; * $IBLOCK_ID = 2; * * $CWiki = new CWiki(); * $CWiki->UpdateCategory($ID, $IBLOCK_ID, $arCats);<br>?> * </pre> * * * <h4>See Also</h4> * <ul> <li> <a href="http://dev.1c-bitrix.ru/api_help/wiki/classes/cwiki/GetCategory.php">CWiki::GetCategory</a> </li> * </ul><a name="examples"></a> * * * @static * @link http://dev.1c-bitrix.ru/api_help/wiki/classes/cwiki/UpdateCategory.php * @author Bitrix */ public function UpdateCategory($ID, $IBLOCK_ID, $arCats) { $this->CleanCacheById($ID, $IBLOCK_ID); $arFilter = array('IBLOCK_ID' => $IBLOCK_ID, 'CHECK_PERMISSIONS' => 'N'); $arElement = self::GetElementById($ID, $arFilter); $bCategoryPage = false; $sCatName = ''; $arCatsID = array(); if (CWikiUtils::IsCategoryPage($arElement['~NAME'], $sCatName)) { $bCategoryPage = true; } if ($bCategoryPage) { // get current category $arFilter = array('NAME' => $sCatName, 'IBLOCK_ID' => $IBLOCK_ID, 'CHECK_PERMISSIONS' => 'N'); if (CWikiSocnet::IsSocNet()) { $arFilter['>LEFT_BORDER'] = CWikiSocnet::$iCatLeftBorder; $arFilter['<RIGHT_BORDER'] = CWikiSocnet::$iCatRightBorder; } $rsCurCats = CIBlockSection::GetList(array(), $arFilter); $arCurCat = $rsCurCats->GetNext(); if (empty($arCurCat)) { $CIB_S = new CIBlockSection(); $_arFields = array(); $_arFields['IBLOCK_ID'] = $IBLOCK_ID; $_arFields['ACTIVE'] = 'Y'; $_arFields['NAME'] = $sCatName; $_arFields['XML_ID'] = $sCatName; if (CWikiSocnet::IsSocNet()) { $_arFields['IBLOCK_SECTION_ID'] = CWikiSocnet::$iCatId; } $iCurCatID = $CIB_S->Add($_arFields); if ($iCurCatID != false) { $arCatsID[] = $iCurCatID; } } else { $iCurCatID = $arCurCat['ID']; $arCatsID[] = $arCurCat['ID']; } // Page bind only to this category CIBlockElement::SetElementSection($ID, $arCatsID); $CIB_S = new CIBlockSection(); if (!empty($arCats)) { // Nova create a category if it still has no $arFilter = array('NAME' => $arCats[0], 'IBLOCK_ID' => $IBLOCK_ID, 'CHECK_PERMISSIONS' => 'N'); if (CWikiSocnet::IsSocNet()) { $arFilter['>LEFT_BORDER'] = CWikiSocnet::$iCatLeftBorder; $arFilter['<RIGHT_BORDER'] = CWikiSocnet::$iCatRightBorder; } $rsCats = CIBlockSection::GetList(array(), $arFilter); $arCat = $rsCats->GetNext(); if (empty($arCat)) { $_arFields = array(); $_arFields['IBLOCK_ID'] = $IBLOCK_ID; $_arFields['ACTIVE'] = 'Y'; $_arFields['NAME'] = CWikiUtils::htmlspecialcharsback($arCats[0]); $_arFields['XML_ID'] = CWikiUtils::htmlspecialcharsback($arCats[0]); $_arFields['CHECK_PERMISSIONS'] = 'N'; if (CWikiSocnet::IsSocNet()) { $_arFields['IBLOCK_SECTION_ID'] = CWikiSocnet::$iCatId; } $iCatID = $CIB_S->Add($_arFields); } else { $iCatID = $arCat['ID']; } $_arFields = array(); $_arFields['IBLOCK_ID'] = $IBLOCK_ID; $_arFields['ACTIVE'] = 'Y'; $_arFields['IBLOCK_SECTION_ID'] = $iCatID; // current category doing this subcategory $CIB_S->Update($iCurCatID, $_arFields); } else { $_arFields = array(); $_arFields['IBLOCK_ID'] = $IBLOCK_ID; $_arFields['ACTIVE'] = 'Y'; $_arFields['IBLOCK_SECTION_ID'] = 0; if (CWikiSocnet::IsSocNet()) { $_arFields['IBLOCK_SECTION_ID'] = CWikiSocnet::$iCatId; } // bind to the root category $CIB_S->Update($iCurCatID, $_arFields); } } else { $arExistsCatsId = array(); $arDelCatId = array(); $rsSect = CIBlockElement::GetElementGroups($ID, false); //$arResult['SECTIONS'] = array(); //erase candidat while ($arSect = $rsSect->GetNext()) { $arExistsCatsId[] = $arSect['ID']; } if (!empty($arCats)) { $arFilter = array('NAME' => $arCats, 'IBLOCK_ID' => $IBLOCK_ID, 'CHECK_PERMISSIONS' => 'N'); if (CWikiSocnet::IsSocNet()) { $arFilter['>LEFT_BORDER'] = CWikiSocnet::$iCatLeftBorder; $arFilter['<RIGHT_BORDER'] = CWikiSocnet::$iCatRightBorder; } $rsCats = CIBlockSection::GetList(array(), $arFilter); while ($arCat = $rsCats->GetNext()) { $arExiststInBlockCats[] = $arCat['~NAME']; $arCatsID[] = $arCat['ID']; } $CIB_S = new CIBlockSection(); foreach ($arCats as $sCatName) { if (!in_array($sCatName, $arExiststInBlockCats)) { $_arFields = array(); $_arFields['IBLOCK_ID'] = $IBLOCK_ID; $_arFields['ACTIVE'] = 'Y'; $_arFields['NAME'] = CWikiUtils::htmlspecialcharsback($sCatName, false); $_arFields['XML_ID'] = CWikiUtils::htmlspecialcharsback($sCatName, false); $_arFields['CHECK_PERMISSIONS'] = 'N'; if (CWikiSocnet::IsSocNet()) { $_arFields['IBLOCK_SECTION_ID'] = CWikiSocnet::$iCatId; } $iCatID = $CIB_S->Add($_arFields); if ($iCatID != false) { $arCatsID[] = $iCatID; } } } //bind to the item if (!empty($arCatsID)) { //if (CWikiSocnet::IsSocNet()) // $arCatsID[] = CWikiSocnet::$iCatId; CIBlockElement::SetElementSection($ID, $arCatsID); } } else { $arCatsID = array(); if (CWikiSocnet::IsSocNet()) { $arCatsID = CWikiSocnet::$iCatId; } CIBlockElement::SetElementSection($ID, $arCatsID); } if (is_array($arCatsID)) { $arDelCatId = array_diff($arExistsCatsId, $arCatsID); } if (!empty($arDelCatId)) { foreach ($arDelCatId as $_iCatId) { $obRes = CIBlockSection::GetList(array(), array('ID' => $_iCatId, 'IBLOCK_ID' => $IBLOCK_ID), true); $arCatProp = $obRes->Fetch(); if ($arCatProp['ELEMENT_CNT'] == 0) { CIBlockSection::Delete($_iCatId); } } } } }
// activate 'in-file' elements if ($bAllLinesLoaded && $inFileAction == "A" && !$bDeactivationStarted) { $res = CIBlockElement::GetList(array(), array("IBLOCK_ID" => $IBLOCK_ID, "TMP_ID" => $tmpid, "ACTIVE" => "N"), false, false, array('ID')); while ($arr = $res->Fetch()) { $el->Update($arr["ID"], array("ACTIVE" => "Y")); if (!($bAllLinesLoaded = CSVCheckTimeout($max_execution_time))) { break; } } } // update or delete 'not-in-file sections' if ($bAllLinesLoaded && $outFileAction != 'F' && $bThereIsGroups) { $res = CIBlockSection::GetList(array(), array("IBLOCK_ID" => $IBLOCK_ID, "!TMP_ID" => $tmpid, 'CHECK_PERMISSIONS' => 'N'), false, array('ID', 'NAME')); while ($arr = $res->Fetch()) { if ($outFileAction == "D") { CIBlockSection::Delete($arr["ID"]); } elseif ($outFileAction == "F") { } else { $bDeactivationStarted = true; $bs->Update($arr["ID"], array("NAME" => $arr["NAME"], "ACTIVE" => "N", "TMP_ID" => $tmpid)); } if (!($bAllLinesLoaded = CSVCheckTimeout($max_execution_time))) { break; } } } // update or delete 'not-in-file' elements if ($bAllLinesLoaded && $outFileAction != "F") { $arProductArray = array('QUANTITY' => 0, 'QUANTITY_TRACE' => 'Y', 'CAN_BUY_ZERO' => 'N', 'NEGATIVE_AMOUNT_TRACE' => 'N'); $res = CIBlockElement::GetList(array(), array("IBLOCK_ID" => $IBLOCK_ID, "!TMP_ID" => $tmpid), false, false, array('ID')); while ($arr = $res->Fetch()) {
public function deleteSection($sectionId) { $ib = new \CIBlockSection(); if ($ib->Delete($sectionId)) { return true; } $this->throwException(__METHOD__, $ib->LAST_ERROR); }