Exemplo n.º 1
0
 function InstallDB()
 {
     /** @global string $DBType */
     global $DB, $DBType, $DBHost, $DBLogin, $DBPassword, $DBName, $APPLICATION;
     if (!is_object($APPLICATION)) {
         $APPLICATION = new CMain();
     }
     $DB = new CDatabase();
     $DB->DebugToFile = false;
     $DB->debug = true;
     if (!defined("DBPersistent")) {
         define("DBPersistent", false);
     }
     if (!$DB->Connect($DBHost, $DBName, $DBLogin, $DBPassword)) {
         $APPLICATION->ThrowException(GetMessage("MAIN_INSTALL_DB_ERROR"));
         return false;
     }
     $result = $DB->Query("SELECT * FROM b_module WHERE ID='main'", true, "", array("fixed_connection" => true));
     $success = $result && $result->Fetch();
     if ($success) {
         return true;
     }
     if ($DBType == "mysql" && defined("MYSQL_TABLE_TYPE") && strlen(MYSQL_TABLE_TYPE) > 0) {
         $DB->Query("SET storage_engine = '" . MYSQL_TABLE_TYPE . "'", true);
     }
     $errors = $DB->RunSQLBatch($_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/install/" . $DBType . "/install.sql");
     if ($errors !== false) {
         $APPLICATION->ThrowException(implode("", $errors));
         return false;
     }
     $this->InstallTasks();
     $group = new CGroup();
     $arGroups = array(array("~ID" => 1, "ACTIVE" => "Y", "C_SORT" => 1, "NAME" => GetMessage("MAIN_ADMIN_GROUP_NAME"), "ANONYMOUS" => "N", "DESCRIPTION" => GetMessage("MAIN_ADMIN_GROUP_DESC")), array("~ID" => 2, "ACTIVE" => "Y", "C_SORT" => 2, "NAME" => GetMessage("MAIN_EVERYONE_GROUP_NAME"), "ANONYMOUS" => "Y", "DESCRIPTION" => GetMessage("MAIN_EVERYONE_GROUP_DESC")), array("~ID" => 3, "ACTIVE" => "Y", "C_SORT" => 3, "NAME" => GetMessage("MAIN_VOTE_RATING_GROUP_NAME"), "ANONYMOUS" => "N", "DESCRIPTION" => GetMessage("MAIN_VOTE_RATING_GROUP_DESC"), "STRING_ID" => "RATING_VOTE"), array("~ID" => 4, "ACTIVE" => "Y", "C_SORT" => 4, "NAME" => GetMessage("MAIN_VOTE_AUTHORITY_GROUP_NAME"), "ANONYMOUS" => "N", "DESCRIPTION" => GetMessage("MAIN_VOTE_AUTHORITY_GROUP_DESC"), "STRING_ID" => "RATING_VOTE_AUTHORITY"));
     foreach ($arGroups as $arGroup) {
         $rsGroup = CGroup::GetByID($arGroup["~ID"]);
         if ($rsGroup->Fetch()) {
             continue;
         }
         //mssql does not allow insert identity by default
         if (strtolower($DB->type) == "mssql") {
             unset($arGroup["~ID"]);
         }
         $success = (bool) $group->Add($arGroup);
         if (!$success) {
             $APPLICATION->ThrowException($group->LAST_ERROR);
             return false;
         }
     }
     self::InstallRatings();
     $arLanguages = array(array("LID" => LANGUAGE_ID, "ACTIVE" => "Y", "SORT" => 1, "DEF" => "Y", "NAME" => GetMessage("MAIN_DEFAULT_LANGUAGE_NAME"), "FORMAT_DATE" => GetMessage("MAIN_DEFAULT_LANGUAGE_FORMAT_DATE"), "FORMAT_DATETIME" => GetMessage("MAIN_DEFAULT_LANGUAGE_FORMAT_DATETIME"), "FORMAT_NAME" => GetMessage("MAIN_DEFAULT_LANGUAGE_FORMAT_NAME"), "CHARSET" => defined("BX_UTF") ? "UTF-8" : GetMessage("MAIN_DEFAULT_LANGUAGE_FORMAT_CHARSET")));
     if (LANGUAGE_ID != "en") {
         $arLanguages[] = array("LID" => "en", "ACTIVE" => "Y", "SORT" => 2, "DEF" => "N", "NAME" => "English", "FORMAT_DATE" => "MM/DD/YYYY", "FORMAT_DATETIME" => "MM/DD/YYYY H:MI:SS T", "FORMAT_NAME" => "#NAME# #LAST_NAME#", "CHARSET" => defined("BX_UTF") ? "UTF-8" : "iso-8859-1");
     }
     if (LANGUAGE_ID != "de" && file_exists($_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/main/lang/de/install/index.php')) {
         $arLanguages[] = array("LID" => "de", "ACTIVE" => "Y", "SORT" => 3, "DEF" => "N", "NAME" => "German", "FORMAT_DATE" => "DD.MM.YYYY", "FORMAT_DATETIME" => "DD.MM.YYYY HH:MI:SS", "FORMAT_NAME" => "#NAME# #LAST_NAME#", "CHARSET" => defined("BX_UTF") ? "UTF-8" : "iso-8859-1");
     }
     if (LANGUAGE_ID != "ru" && file_exists($_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/main/lang/ru/install/index.php')) {
         $arLanguages[] = array("LID" => "ru", "ACTIVE" => "Y", "SORT" => 3, "DEF" => "N", "NAME" => "Russian", "FORMAT_DATE" => "DD.MM.YYYY", "FORMAT_DATETIME" => "DD.MM.YYYY HH:MI:SS", "FORMAT_NAME" => "#NAME# #LAST_NAME#", "CHARSET" => defined("BX_UTF") ? "UTF-8" : "windows-1251");
     }
     $lang = new CLanguage();
     foreach ($arLanguages as $arLanguage) {
         $rsLang = CLanguage::GetByID($arLanguage["LID"]);
         if ($rsLang->Fetch()) {
             continue;
         }
         $success = (bool) $lang->Add($arLanguage);
         if (!$success) {
             $APPLICATION->ThrowException($lang->LAST_ERROR);
             return false;
         }
     }
     $arSite = array("LID" => "s1", "ACTIVE" => "Y", "SORT" => 1, "DEF" => "Y", "NAME" => GetMessage("MAIN_DEFAULT_SITE_NAME"), "DIR" => "/", "FORMAT_DATE" => GetMessage("MAIN_DEFAULT_SITE_FORMAT_DATE"), "FORMAT_DATETIME" => GetMessage("MAIN_DEFAULT_SITE_FORMAT_DATETIME"), "FORMAT_NAME" => GetMessage("MAIN_DEFAULT_SITE_FORMAT_NAME"), "CHARSET" => defined("BX_UTF") ? "UTF-8" : GetMessage("MAIN_DEFAULT_SITE_FORMAT_CHARSET"), "LANGUAGE_ID" => LANGUAGE_ID);
     $rsSites = CSite::GetByID($arSite["LID"]);
     if (!$rsSites->Fetch()) {
         $site = new CSite();
         $success = (bool) $site->Add($arSite);
         if (!$success) {
             $APPLICATION->ThrowException($site->LAST_ERROR);
             return false;
         }
     }
     RegisterModule("main");
     RegisterModuleDependences('iblock', 'OnIBlockPropertyBuildList', 'main', 'CIBlockPropertyUserID', 'GetUserTypeDescription', 100, '/modules/main/tools/prop_userid.php');
     RegisterModuleDependences('main', 'OnUserDelete', 'main', 'CFavorites', 'OnUserDelete', 100, "/modules/main/classes/" . strtolower($GLOBALS["DB"]->type) . "/favorites.php");
     RegisterModuleDependences('main', 'OnLanguageDelete', 'main', 'CFavorites', 'OnLanguageDelete', 100, "/modules/main/classes/" . strtolower($GLOBALS["DB"]->type) . "/favorites.php");
     RegisterModuleDependences('main', 'OnUserDelete', 'main', 'CUserOptions', 'OnUserDelete');
     RegisterModuleDependences('main', 'OnChangeFile', 'main', 'CMain', 'OnChangeFileComponent');
     RegisterModuleDependences('main', 'OnUserTypeRightsCheck', 'main', 'CUser', 'UserTypeRightsCheck');
     RegisterModuleDependences('main', 'OnUserLogin', 'main', 'UpdateTools', 'CheckUpdates');
     RegisterModuleDependences('main', 'OnModuleUpdate', 'main', 'UpdateTools', 'SetUpdateResult');
     RegisterModuleDependences('main', 'OnUpdateCheck', 'main', 'UpdateTools', 'SetUpdateError');
     RegisterModuleDependences('main', 'OnPanelCreate', 'main', 'CUndo', 'CheckNotifyMessage');
     RegisterModuleDependences('main', 'OnAfterAddRating', 'main', 'CRatingsComponentsMain', 'OnAfterAddRating');
     RegisterModuleDependences('main', 'OnAfterUpdateRating', 'main', 'CRatingsComponentsMain', 'OnAfterUpdateRating');
     RegisterModuleDependences('main', 'OnSetRatingsConfigs', 'main', 'CRatingsComponentsMain', 'OnSetRatingConfigs');
     RegisterModuleDependences('main', 'OnGetRatingsConfigs', 'main', 'CRatingsComponentsMain', 'OnGetRatingConfigs');
     RegisterModuleDependences('main', 'OnGetRatingsObjects', 'main', 'CRatingsComponentsMain', 'OnGetRatingObject');
     RegisterModuleDependences('main', 'OnGetRatingContentOwner', 'main', 'CRatingsComponentsMain', 'OnGetRatingContentOwner');
     RegisterModuleDependences('main', 'OnAfterAddRatingRule', 'main', 'CRatingRulesMain', 'OnAfterAddRatingRule');
     RegisterModuleDependences('main', 'OnAfterUpdateRatingRule', 'main', 'CRatingRulesMain', 'OnAfterUpdateRatingRule');
     RegisterModuleDependences('main', 'OnGetRatingRuleObjects', 'main', 'CRatingRulesMain', 'OnGetRatingRuleObjects');
     RegisterModuleDependences('main', 'OnGetRatingRuleConfigs', 'main', 'CRatingRulesMain', 'OnGetRatingRuleConfigs');
     RegisterModuleDependences('main', 'OnAfterUserAdd', 'main', 'CRatings', 'OnAfterUserRegister');
     RegisterModuleDependences('main', 'OnUserDelete', 'main', 'CRatings', 'OnUserDelete');
     RegisterModuleDependences('main', 'OnUserDelete', 'main', 'CAccess', 'OnUserDelete');
     RegisterModuleDependences('main', 'OnAfterGroupAdd', 'main', 'CGroupAuthProvider', 'OnAfterGroupAdd');
     RegisterModuleDependences('main', 'OnBeforeGroupUpdate', 'main', 'CGroupAuthProvider', 'OnBeforeGroupUpdate');
     RegisterModuleDependences('main', 'OnBeforeGroupDelete', 'main', 'CGroupAuthProvider', 'OnBeforeGroupDelete');
     RegisterModuleDependences('main', 'OnAfterUserUpdate', 'main', 'CGroupAuthProvider', 'OnAfterUserUpdate');
     RegisterModuleDependences('main', 'OnUserLogin', 'main', 'CGroupAuthProvider', 'OnUserLogin');
     RegisterModuleDependences("main", "OnEventLogGetAuditTypes", "main", "CEventMain", "GetAuditTypes");
     RegisterModuleDependences("main", "OnEventLogGetAuditHandlers", "main", "CEventMain", "MakeMainObject");
     RegisterModuleDependences("perfmon", "OnGetTableSchema", "main", "CTableSchema", "OnGetTableSchema");
     RegisterModuleDependences("main", "OnUserTypeBuildList", "main", "CUserTypeString", "GetUserTypeDescription", 110);
     RegisterModuleDependences("main", "OnUserTypeBuildList", "main", "CUserTypeInteger", "GetUserTypeDescription", 120);
     RegisterModuleDependences("main", "OnUserTypeBuildList", "main", "CUserTypeDouble", "GetUserTypeDescription", 130);
     RegisterModuleDependences("main", "OnUserTypeBuildList", "main", "CUserTypeDateTime", "GetUserTypeDescription", 140);
     RegisterModuleDependences("main", "OnUserTypeBuildList", "main", "CUserTypeBoolean", "GetUserTypeDescription", 150);
     RegisterModuleDependences("main", "OnUserTypeBuildList", "main", "CUserTypeFile", "GetUserTypeDescription", 160);
     RegisterModuleDependences("main", "OnUserTypeBuildList", "main", "CUserTypeEnum", "GetUserTypeDescription", 170);
     RegisterModuleDependences("main", "OnUserTypeBuildList", "main", "CUserTypeIBlockSection", "GetUserTypeDescription", 180);
     RegisterModuleDependences("main", "OnUserTypeBuildList", "main", "CUserTypeIBlockElement", "GetUserTypeDescription", 190);
     RegisterModuleDependences("main", "OnUserTypeBuildList", "main", "CUserTypeStringFormatted", "GetUserTypeDescription", 200);
     COption::SetOptionString('main', 'auth_comp2', 'Y');
     COption::SetOptionString("main", "PARAM_MAX_SITES", "2");
     COption::SetOptionString("main", "PARAM_MAX_USERS", "0");
     COption::SetOptionString("main", "distributive6", "Y");
     COption::SetOptionString("main", "~new_license11_sign", "Y");
     COption::SetOptionString("main", "GROUP_DEFAULT_TASK", "1");
     if (LANGUAGE_ID == "ru") {
         COption::SetOptionString("main", "vendor", "1c_bitrix");
     } else {
         COption::SetOptionString("main", "vendor", "bitrix");
     }
     COption::SetOptionString("main", "admin_lid", LANGUAGE_ID);
     COption::SetOptionString("main", "update_site", "www.bitrixsoft.com");
     COption::SetOptionString("main", "update_site_ns", "Y");
     COption::SetOptionString("main", "optimize_css_files", "Y");
     COption::SetOptionString("main", "optimize_js_files", "Y");
     CAgent::AddAgent("CEvent::CleanUpAgent();", "main", "Y", 86400);
     CAgent::AddAgent("CUser::CleanUpHitAuthAgent();", "main", "Y", 86400);
     CAgent::AddAgent("CCaptchaAgent::DeleteOldCaptcha(3600);", "main", "N", 3600);
     CAgent::AddAgent("CUndo::CleanUpOld();", "main", "Y", 86400);
     self::InstallDesktop();
     self::InstallSmiles();
     return true;
 }