PageRenderTime 26ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/components/bitrix/sale.crm.site.master/wizard/datainstallstep.php

https://gitlab.com/alexprowars/bitrix
PHP | 326 lines | 215 code | 52 blank | 59 comment | 23 complexity | 48c54fd3afdcecde54d422247073c415 MD5 | raw file
  1. <?php
  2. namespace Bitrix\Sale\CrmSiteMaster\Steps;
  3. if (!defined('B_PROLOG_INCLUDED') || B_PROLOG_INCLUDED !== true)
  4. {
  5. die();
  6. }
  7. use Bitrix\Main,
  8. Bitrix\Main\Config\Option,
  9. Bitrix\Main\Localization\Loc,
  10. Bitrix\Sale\CrmSiteMaster\Tools\SitePatcher;
  11. Loc::loadMessages(__FILE__);
  12. require_once($_SERVER["DOCUMENT_ROOT"]."/bitrix/wizards/bitrix/portal/wizard.php");
  13. /** @noinspection PhpUndefinedClassInspection */
  14. /**
  15. * Class DataInstallStep
  16. * Install portal and services
  17. *
  18. * @package Bitrix\Sale\CrmSiteMaster\Steps
  19. */
  20. class DataInstallStep extends \DataInstallStep
  21. {
  22. private $currentStepName = __CLASS__;
  23. /** @var \SaleCrmSiteMaster */
  24. private $component = null;
  25. /**
  26. * Initialization step id and title
  27. */
  28. public function initStep()
  29. {
  30. define("ADDITIONAL_INSTALL", "Y");
  31. $this->component = $this->GetWizard()->GetVar("component");
  32. $this->SetStepID($this->currentStepName);
  33. $this->SetTitle(Loc::getMessage("SALE_CSM_WIZARD_DATAINSTALLSTEP_TITLE"));
  34. }
  35. /**
  36. * @return bool
  37. * @throws Main\ArgumentException
  38. * @throws Main\ArgumentNullException
  39. * @throws Main\ArgumentOutOfRangeException
  40. * @throws Main\LoaderException
  41. * @throws Main\ObjectPropertyException
  42. * @throws Main\SystemException
  43. */
  44. public function showStep()
  45. {
  46. $this->prepareWizardVars();
  47. if ($this->GetErrors())
  48. {
  49. return false;
  50. }
  51. ob_start();
  52. ?>
  53. <div class="adm-crm-site-master-timer">
  54. <img class="adm-crm-site-master-timer-image" src="<?=$this->component->getPath()?>/wizard/images/timer.svg" alt="">
  55. </div>
  56. <div class="adm-crm-site-master-timer-description">
  57. <?=Loc::getMessage("SALE_CSM_WIZARD_DATAINSTALLSTEP_DESCR")?>
  58. </div>
  59. <div id="error_container" style="display: none; margin-top: 25px">
  60. <div class="ui-alert ui-alert-danger ui-alert-inline ui-alert-icon-danger">
  61. <span class="ui-alert-message" id="error_text"></span>
  62. </div>
  63. <div class="adm-crm-slider-buttons" id="error_buttons">
  64. <div class="ui-btn-container ui-btn-container-center">
  65. <button type="button" id="error_retry_button" class="ui-btn ui-btn-primary" onclick="">
  66. <?=Loc::getMessage("SALE_CSM_WIZARD_DATAINSTALLSTEP_RETRY_BUTTON")?>
  67. </button>
  68. <button type="button" id="error_skip_button" class="ui-btn ui-btn-primary" onclick="">
  69. <?=Loc::getMessage("SALE_CSM_WIZARD_DATAINSTALLSTEP_SKIP_BUTTON")?>
  70. </button>
  71. </div>
  72. </div>
  73. </div>
  74. <?
  75. echo $this->ShowHiddenField("nextStep", "main");
  76. echo $this->ShowHiddenField("nextStepStage", "database");
  77. ?><iframe style="display:none;" id="iframe-post-form" name="iframe-post-form" src="javascript:''"></iframe><?
  78. $wizard =& $this->GetWizard();
  79. $arServices = \WizardServices::GetServices($_SERVER["DOCUMENT_ROOT"].$wizard->GetPath(), "/site/services/");
  80. list($firstService, $stage, $status) = $this->GetFirstStep($arServices);
  81. $formName = $wizard->GetFormName();
  82. $nextStepVarName = $wizard->GetRealName("nextStep");
  83. $messages = Loc::loadLanguageFile(__FILE__);
  84. ?>
  85. <script type="text/javascript">
  86. BX.message(<?=\CUtil::PhpToJSObject($messages)?>);
  87. var ajaxForm = new CAjaxForm("<?=$formName?>", "iframe-post-form", "<?=$nextStepVarName?>");
  88. ajaxForm.Post("<?=$firstService?>", "<?=$stage?>", "<?=$status?>");
  89. ajaxForm.SetEventBeforeUnloadWindow();
  90. </script>
  91. <?
  92. $content = ob_get_contents();
  93. ob_end_clean();
  94. $this->content = $content;
  95. return true;
  96. }
  97. /**
  98. * @return bool
  99. * @throws Main\ArgumentException
  100. * @throws Main\ArgumentNullException
  101. * @throws Main\ArgumentOutOfRangeException
  102. * @throws Main\LoaderException
  103. * @throws Main\ObjectPropertyException
  104. * @throws Main\SystemException
  105. */
  106. public function onPostForm()
  107. {
  108. $wizard =& $this->GetWizard();
  109. $serviceID = $wizard->GetVar("nextStep");
  110. if ($serviceID !== "finish")
  111. {
  112. /** @noinspection PhpVariableNamingConventionInspection */
  113. global $APPLICATION;
  114. $APPLICATION->RestartBuffer();
  115. }
  116. parent::OnPostForm();
  117. $this->prepareSite();
  118. $steps = $this->component->getSteps($this->currentStepName);
  119. if (isset($steps["NEXT_STEP"]))
  120. {
  121. $this->GetWizard()->SetCurrentStep($steps["NEXT_STEP"]);
  122. }
  123. return true;
  124. }
  125. /**
  126. * @param $serviceID
  127. * @param $serviceStage
  128. * @return bool
  129. * @throws Main\ArgumentException
  130. * @throws Main\ArgumentNullException
  131. * @throws Main\ArgumentOutOfRangeException
  132. * @throws Main\LoaderException
  133. * @throws Main\ObjectPropertyException
  134. * @throws Main\SystemException
  135. */
  136. public function installService($serviceID, $serviceStage)
  137. {
  138. $wizard =& $this->GetWizard();
  139. $siteId = SitePatcher::getInstance()->getCrmSiteId();
  140. $wizardSiteRootPath = SitePatcher::getInstance()->getCrmSitePath();
  141. define("WIZARD_SITE_ID", $siteId);
  142. define("WIZARD_SITE_ROOT_PATH", $wizardSiteRootPath);
  143. $siteFolder = $wizard->GetVar("siteFolder");
  144. if ($siteFolder)
  145. {
  146. define("WIZARD_SITE_DIR", $siteFolder);
  147. }
  148. else
  149. {
  150. define("WIZARD_SITE_DIR", "/");
  151. }
  152. define("WIZARD_SITE_PATH", str_replace("//", "/", WIZARD_SITE_ROOT_PATH."/".WIZARD_SITE_DIR));
  153. $wizardPath = $wizard->GetPath();
  154. define("WIZARD_RELATIVE_PATH", $wizardPath);
  155. define("WIZARD_ABSOLUTE_PATH", $wizardSiteRootPath.$wizardPath);
  156. $templatesPath = \WizardServices::GetTemplatesPath("/bitrix/modules/intranet/install");
  157. $templateID = $wizard->GetVar("templateID");
  158. define("WIZARD_TEMPLATE_ID", "bitrix24");
  159. define("WIZARD_TEMPLATE_RELATIVE_PATH", $templatesPath."/".WIZARD_TEMPLATE_ID);
  160. define("WIZARD_TEMPLATE_ABSOLUTE_PATH", $wizardSiteRootPath.WIZARD_TEMPLATE_RELATIVE_PATH);
  161. $themeID = $wizard->GetVar($templateID."_themeID");
  162. define("WIZARD_THEME_ID", $themeID);
  163. define("WIZARD_THEME_RELATIVE_PATH", WIZARD_TEMPLATE_RELATIVE_PATH."/themes/".WIZARD_THEME_ID);
  164. define("WIZARD_THEME_ABSOLUTE_PATH", $wizardSiteRootPath.WIZARD_THEME_RELATIVE_PATH);
  165. $servicePath = WIZARD_RELATIVE_PATH."/site/services/".$serviceID;
  166. define("WIZARD_SERVICE_RELATIVE_PATH", $servicePath);
  167. define("WIZARD_SERVICE_ABSOLUTE_PATH", $wizardSiteRootPath.$servicePath);
  168. define("WIZARD_IS_RERUN", false);
  169. define("WIZARD_B24_TO_CP", false);
  170. $firstStep = Option::get(
  171. "main",
  172. "wizard_first".mb_substr($wizard->GetID(), 7)."_".$siteId,
  173. false,
  174. $siteId
  175. );
  176. define("WIZARD_FIRST_INSTAL", $firstStep);
  177. define("WIZARD_SITE_NAME", $wizard->GetVar("siteName"));
  178. define("WIZARD_INSTALL_DEMO_DATA", $wizard->GetVar("installDemoData") == "Y");
  179. define("WIZARD_INSTALL_MOBILE", $wizard->GetVar("installMobile") == "Y");
  180. if($firstStep == "N" || $wizard->GetVar("installDemoData") == "Y")
  181. {
  182. Option::set("main", "wizard_clear_exec", "N", $siteId);
  183. }
  184. define("WIZARD_NEW_2011", false);
  185. $dbGroupUsers = \CGroup::GetList("id", "asc", Array("ACTIVE" => "Y"));
  186. $arGroupsId = Array("ADMIN_SECTION", "SUPPORT", "CREATE_GROUPS", "PERSONNEL_DEPARTMENT", "DIRECTION", "MARKETING_AND_SALES", "RATING_VOTE", "RATING_VOTE_AUTHORITY");
  187. while ($arGroupUser = $dbGroupUsers->Fetch())
  188. {
  189. if(in_array($arGroupUser["STRING_ID"], $arGroupsId))
  190. {
  191. define("WIZARD_".$arGroupUser["STRING_ID"]."_GROUP", $arGroupUser["ID"]);
  192. }
  193. else
  194. {
  195. if(mb_substr($arGroupUser["STRING_ID"], -2) == $siteId)
  196. {
  197. define("WIZARD_".mb_substr($arGroupUser["STRING_ID"], 0, -3)."_GROUP", $arGroupUser["ID"]);
  198. }
  199. }
  200. }
  201. if (!Main\IO\File::isFileExists(WIZARD_SERVICE_ABSOLUTE_PATH."/".$serviceStage))
  202. return false;
  203. if (LANGUAGE_ID != "en" && LANGUAGE_ID != "ru")
  204. {
  205. if (Main\IO\File::isFileExists(WIZARD_SERVICE_ABSOLUTE_PATH."/lang/en/".$serviceStage))
  206. {
  207. Loc::loadMessages(WIZARD_SERVICE_ABSOLUTE_PATH."/lang/en/".$serviceStage);
  208. }
  209. }
  210. if (Main\IO\File::isFileExists(WIZARD_SERVICE_ABSOLUTE_PATH."/lang/".LANGUAGE_ID."/".$serviceStage))
  211. {
  212. Loc::loadMessages(WIZARD_SERVICE_ABSOLUTE_PATH."/lang/".LANGUAGE_ID."/".$serviceStage);
  213. }
  214. @set_time_limit(3600);
  215. /** @noinspection PhpUnusedLocalVariableInspection */
  216. /** @noinspection PhpVariableNamingConventionInspection */
  217. global $DB, $DBType, $APPLICATION, $USER, $CACHE_MANAGER;
  218. include(WIZARD_SERVICE_ABSOLUTE_PATH."/".$serviceStage);
  219. return true;
  220. }
  221. /**
  222. * @throws Main\ArgumentException
  223. * @throws Main\ArgumentNullException
  224. * @throws Main\ArgumentOutOfRangeException
  225. * @throws Main\LoaderException
  226. * @throws Main\ObjectPropertyException
  227. * @throws Main\SystemException
  228. */
  229. private function prepareWizardVars()
  230. {
  231. $wizard = $this->GetWizard();
  232. $sitePatcher = SitePatcher::getInstance();
  233. $siteId = $sitePatcher->getCrmSiteId();
  234. $siteName = $sitePatcher->getCrmSiteName();
  235. $siteDir = $sitePatcher->getCrmSiteDir();
  236. Option::set("main", "site_name", $siteName, $siteId);
  237. $wizard->SetVar("siteID", $siteId);
  238. $wizard->SetVar("templateID", "bitrix24");
  239. $wizard->SetVar("installDemoData", "Y");
  240. $wizard->SetVar("installStructureData", "N");
  241. $wizard->SetVar("siteName", $siteName);
  242. $wizard->SetVar("siteFolder", $siteDir);
  243. $wizard->SetVar("allowGuests","N");
  244. $wizard->SetVar("allowGroup", "N");
  245. }
  246. /**
  247. * @throws Main\ArgumentException
  248. * @throws Main\ArgumentNullException
  249. * @throws Main\ArgumentOutOfRangeException
  250. * @throws Main\ObjectPropertyException
  251. * @throws Main\SystemException
  252. */
  253. private function prepareSite()
  254. {
  255. $sitePatcher = SitePatcher::getInstance();
  256. SitePatcher::updateSiteTemplateConditions();
  257. $sitePatcher->addUrlRewrite();
  258. $sitePatcher->deleteFiles();
  259. // patch modules
  260. $sitePatcher->patchDisk();
  261. $sitePatcher->patchDav();
  262. $sitePatcher->patchTimeman();
  263. $sitePatcher->patchMeeting();
  264. $sitePatcher->patchImconnector();
  265. $sitePatcher->patchImopenlines();
  266. $sitePatcher->patchVoximplant();
  267. $sitePatcher->patchMobile();
  268. $sitePatcher->patchIm();
  269. Option::set("crm", "crm_shop_enabled", "Y");
  270. $sitePatcher->createDepartment(Loc::getMessage("SALE_CSM_WIZARD_DATAINSTALLSTEP_DEPARTMENT_NAME"));
  271. $sitePatcher->prepareCrmCatalog();
  272. $sitePatcher->addSiteToCatalog();
  273. }
  274. }