51 private static $listRuLanguage = array(
'ua',
'by',
'kz');
60 public static function export($iblockId)
62 $iblockId = intval($iblockId);
66 $db = \CIBlock::GetList(Array(), Array(
"ID" => $iblockId,
"CHECK_PERMISSIONS" =>
"N"));
67 $iblock = $db->Fetch();
74 foreach(\CIBlock::getMessages($iblockId) as $messageKey => $message)
75 $iblock[$messageKey] = $message;
77 $list = new \CList($iblockId);
78 $fields = $list->getFields();
79 foreach($fields as $fieldId => $field)
81 if ($field[
"TYPE"] ==
"NAME")
83 $iblock[
"~NAME_FIELD"] = array(
84 "NAME" => $field[
"NAME"],
85 "SETTINGS" => $field[
"SETTlINGS"],
86 "DEFAULT_VALUE" => $field[
"DEFAULT_VALUE"],
87 "SORT" => $field[
"SORT"],
93 $iblockUtf8 = Main\Text\Encoding::convertEncodingArray($iblock, LANG_CHARSET,
"UTF-8");
94 $iblockUtf8 = serialize($iblockUtf8);
95 $iblockUtf8Length = Main\Text\BinaryString::getLength($iblockUtf8);
96 $datum = str_pad($iblockUtf8Length, 10,
"0", STR_PAD_LEFT).$iblockUtf8;
98 if (intval($iblock[
"PICTURE"]) > 0)
100 $picture = \CFile::MakeFileArray($iblock[
"PICTURE"]);
101 if (isset($picture[
"tmp_name"]) && !empty($picture[
"tmp_name"]))
103 $f = fopen($picture[
"tmp_name"],
"rb");
104 $pictureData = fread($f, filesize($picture[
"tmp_name"]));
107 $pictureTypeLength = Main\Text\BinaryString::getLength($picture[
"type"]);
108 $pictureLength = Main\Text\BinaryString::getLength($pictureData);
109 $datum .=
"P".str_pad($pictureTypeLength, 10,
"0", STR_PAD_LEFT).$picture[
"type"].str_pad($pictureLength, 10,
"0", STR_PAD_LEFT).$pictureData;
115 $templatesList = \CBPWorkflowTemplateLoader::GetList(
117 array(
"DOCUMENT_TYPE" => $documentType),
120 array(
"ID",
"AUTO_EXECUTE",
"NAME",
"DESCRIPTION",
"SYSTEM_CODE")
122 while ($templatesListItem = $templatesList->Fetch())
124 $bpDescrUtf8 = Main\Text\Encoding::convertEncodingArray($templatesListItem, LANG_CHARSET,
"UTF-8");
125 $bpDescrUtf8 = serialize($bpDescrUtf8);
126 $bpDescrUtf8Length = Main\Text\BinaryString::getLength($bpDescrUtf8);
127 $datum .=
"B".str_pad($bpDescrUtf8Length, 10,
"0", STR_PAD_LEFT).$bpDescrUtf8;
129 $bp = \CBPWorkflowTemplateLoader::ExportTemplate($templatesListItem[
"ID"],
false);
130 $bpLength = Main\Text\BinaryString::getLength($bp);
131 $datum .= str_pad($bpLength, 10,
"0", STR_PAD_LEFT).$bp;
134 if (function_exists(
"gzcompress"))
135 $datum =
"compressed".gzcompress($datum, 9);
146 $f = fopen($filePath,
"rb");
147 $datum = fread($f, filesize($filePath));
150 if (mb_substr($datum, 0, 10) ===
"compressed")
154 $dataSerialized = Main\Text\BinaryString::getSubstring($datum, 10, $len);
156 $data = CheckSerializedData($dataSerialized) ? unserialize($dataSerialized, [
"allowed_classes" =>
false]) : [];
157 $data = Main\Text\Encoding::convertEncodingArray($data,
"UTF-8", LANG_CHARSET);
168 public static function import($iblockType, $datum, $siteId =
null)
173 if (mb_substr($datum, 0, 10) ===
"compressed")
177 $iblockSerialized = Main\Text\BinaryString::getSubstring($datum, 10, $len);
178 $datum = Main\Text\BinaryString::getSubstring($datum, $len + 10);
180 $marker = Main\Text\BinaryString::getSubstring($datum, 0, 1);
186 $pictureType = Main\Text\BinaryString::getSubstring($datum, 11, $len);
187 $datum = Main\Text\BinaryString::getSubstring($datum, $len + 11);
190 $picture = Main\Text\BinaryString::getSubstring($datum, 10, $len);
191 $datum = Main\Text\BinaryString::getSubstring($datum, $len + 10);
193 $marker = Main\Text\BinaryString::getSubstring($datum, 0, 1);
196 $iblock = CheckSerializedData($iblockSerialized) ? unserialize($iblockSerialized, [
'allowed_classes' =>
false]) : [];
197 $iblock = Main\Text\Encoding::convertEncodingArray($iblock,
"UTF-8", LANG_CHARSET);
198 $iblockId = static::createIBlock($iblockType, $iblock, $pictureType, $picture, $siteId);
204 while (!empty($datum))
209 $bpDescr = Main\Text\BinaryString::getSubstring($datum, 11, $len);
210 $datum = Main\Text\BinaryString::getSubstring($datum, $len + 11);
212 $bpDescr = CheckSerializedData($bpDescr) ? unserialize($bpDescr, [
"allowed_classes" =>
false]) : [];
213 $bpDescr = Main\Text\Encoding::convertEncodingArray($bpDescr,
"UTF-8", LANG_CHARSET);
216 $bp = Main\Text\BinaryString::getSubstring($datum, 10, $len);
217 $datum = Main\Text\BinaryString::getSubstring($datum, $len + 10);
219 static::importTemplate($documentType, $bpDescr, $bp);
229 $marker = Main\Text\BinaryString::getSubstring($datum, 0, 1);
234 private static function importTemplate($documentType, $bpDescr, $bp)
238 $db = \CBPWorkflowTemplateLoader::GetList(
240 array(
"DOCUMENT_TYPE" => $documentType,
"SYSTEM_CODE" => $bpDescr[
"SYSTEM_CODE"]),
243 array(
"ID",
"IS_MODIFIED")
245 if ($res = $db->Fetch())
247 if ($res[
"IS_MODIFIED"] ==
"Y")
255 \CBPWorkflowTemplateLoader::ImportTemplate(
258 $bpDescr[
"AUTO_EXECUTE"],
260 $bpDescr[
"DESCRIPTION"],
262 $bpDescr[
"SYSTEM_CODE"],
266 catch (\Exception $e)
271 private static function createIBlock($iblockType, $iblock, $pictureType, $picture, $siteId =
null)
273 if (is_null($siteId))
274 $siteId = \CSite::GetDefSite();
276 $db = \CIBlock::GetList(
278 array(
"IBLOCK_TYPE_ID" => $iblockType,
"CODE" => $iblock[
"CODE"],
"CHECK_PERMISSIONS" =>
"N",
"SITE_ID" => $siteId)
280 if ($res = $db->Fetch())
284 "NAME" => $iblock[
"NAME"],
285 "DESCRIPTION" => $iblock[
"DESCRIPTION"],
286 "IBLOCK_TYPE_ID" => $iblockType,
287 "SORT" => $iblock[
"SORT"],
288 "CODE" => $iblock[
"CODE"],
290 "ELEMENTS_NAME" => $iblock[
"ELEMENTS_NAME"],
291 "ELEMENT_NAME" => $iblock[
"ELEMENT_NAME"],
292 "ELEMENT_ADD" => $iblock[
"ELEMENT_ADD"] ??
null,
293 "ELEMENT_EDIT" => $iblock[
"ELEMENT_EDIT"] ??
null,
294 "ELEMENT_DELETE" => $iblock[
"ELEMENT_DELETE"] ??
null,
295 "SECTIONS_NAME" => $iblock[
"SECTIONS_NAME"] ??
null,
296 "SECTION_NAME" => $iblock[
"SECTION_NAME"] ??
null,
297 "SECTION_ADD" => $iblock[
"SECTION_ADD"] ??
null,
298 "SECTION_EDIT" => $iblock[
"SECTION_EDIT"] ??
null,
299 "SECTION_DELETE" => $iblock[
"SECTION_DELETE"] ??
null,
301 "SITE_ID" => array($siteId),
302 "RIGHTS_MODE" =>
"E",
305 if ($iblock[
"SOCNET_GROUP_ID"])
307 $fields[
"SOCNET_GROUP_ID"] = $iblock[
"SOCNET_GROUP_ID"];
310 static $exts = array(
311 "image/jpeg" =>
"jpg",
312 "image/png" =>
"png",
313 "image/gif" =>
"gif",
315 if (!empty($picture) && isset($exts[$pictureType]))
317 $fn = \CTempFile::GetFileName();
318 Main\IO\Directory::createDirectory($fn);
320 $fn .= md5(mt_rand()).
".".$exts[$pictureType];
322 $f = fopen($fn,
"wb");
323 fwrite($f, $picture);
326 $fields[
"PICTURE"] = \CFile::MakeFileArray($fn);
330 $res = $ob->Add($fields);
333 self::createIBlockRights($res);
335 $list = new \CList($res);
337 if (isset($iblock[
"~NAME_FIELD"]))
338 $list->UpdateField(
"NAME", $iblock[
"~NAME_FIELD"]);
342 \CLists::setLiveFeed(1, $res);
352 $iblockType = Main\Config\Option::get(
"lists",
"livefeed_iblock_type_id",
"bitrix_processes");
353 if (empty($iblockType))
354 $iblockType =
"bitrix_processes";
361 if ($iblockType == static::getIBlockType())
362 $documentType = array(
'lists',
'BizprocDocument',
'iblock_'.$iblockId);
364 $documentType = array(
'lists',
'Bitrix\Lists\BizprocDocumentLists',
'iblock_'.$iblockId);
366 return $documentType;
372 private static function createIBlockRights($iblockId)
374 $rightObject = new \CIBlockRights($iblockId);
375 $rights = $rightObject->getRights();
376 $rightsList = $rightObject->getRightsList(
false);
378 $rightId = array_search(
'iblock_full', $rightsList);
379 $rights[
'n0'] = array(
'GROUP_CODE' =>
"G1",
'TASK_ID' => $rightId);
380 $rights[
'n1'] = array(
'GROUP_CODE' =>
"U1",
'TASK_ID' => $rightId);
382 $rightId = array_search(
'iblock_element_add', $rightsList);
383 $rights[
'n2'] = array(
'GROUP_CODE' =>
"G2",
'TASK_ID' => $rightId);
385 $rightObject->setRights($rights);
388 const PATH =
"/bitrix/modules/lists/install/bizproc/process/";
397 public static function installProcesses($lang, $siteId =
null)
402 if (! Main\Loader::includeModule(
"bizproc"))
405 $iblockType = static::getIBlockType();
407 $db = \CIBlockType::GetList(array(), array(
"=ID" => $iblockType));
410 static::createIBlockType();
412 if(in_array($lang, self::$listRuLanguage))
415 $dir =
new Main\IO\Directory(Main\Loader::getDocumentRoot() . static::PATH . $lang .
"/");
416 if(!$dir->isExists())
417 $dir =
new Main\IO\Directory(Main\Loader::getDocumentRoot() . static::PATH .
"en/");
419 if ($dir->isExists())
421 $children = $dir->getChildren();
422 foreach ($children as $child)
425 if ($child->isFile() && ($child->getExtension() ==
"prc"))
427 static::import($iblockType, $child->getContents(), $siteId);
444 if (!Main\Loader::includeModule(
"bizproc"))
447 $path = Main\Loader::getDocumentRoot() . $path;
448 $iblockType = static::getIBlockType();
450 $db = \CIBlockType::GetList(array(), array(
"=ID" => $iblockType));
453 static::createIBlockType();
456 if($file->isExists() && $file->getExtension() ==
"prc")
458 static::import($iblockType, $file->getContents(), $siteId);
470 public static function loadDataProcesses($lang, $systemProcesses =
true, &$fileData, $path =
null)
475 if(in_array($lang, self::$listRuLanguage))
480 $path = rtrim($path,
"/");
485 $path = self::getPathToProcesses($lang, $systemProcesses);
488 $dir =
new Main\IO\Directory($path);
489 if (!$dir->isExists() && $lang ===
'en')
494 if ($dir->isExists())
496 $children = $dir->getChildren();
497 foreach ($children as $key => $child)
500 if ($child->isFile() && ($child->getExtension() ==
"prc"))
503 $fileData[$data[
'CODE']][
'FILE_NAME'] = $child->getName();
504 $fileData[$data[
'CODE']][
'FILE_PATH'] = str_replace(Main\Loader::getDocumentRoot(),
'', $child->getPath());
505 $fileData[$data[
'CODE']][
'NAME'] = $data[
'NAME'];
506 $fileData[$data[
'CODE']][
'DESCRIPTION'] = $data[
'DESCRIPTION'];
507 $fileData[$data[
'CODE']][
'CODE'] = $data[
'CODE'];
508 $fileData[$data[
'CODE']][
'IBLOCK_TYPE_ID'] = $data[
'IBLOCK_TYPE_ID'];
509 $fileData[$data[
'CODE']][
'DIRECTORY_NAME'] = $child->getDirectory()->getName();
511 elseif($child->isDirectory())
513 self::loadDataProcesses($lang, $systemProcesses, $fileData, $child->getPath());
519 $path = self::getPathToProcesses(
"en", $systemProcesses);
520 self::loadDataProcesses(
'en', $systemProcesses, $fileData, $path);
524 private static function getPathToProcesses($lang, $systemProcesses =
true)
528 $path = Main\Loader::getDocumentRoot() . static::PATH . $lang .
"/";
532 $path = Main\Loader::getDocumentRoot() . static::PATH_USER_PROCESSES . $lang .
"/";
541 'ID' =>
'bitrix_processes',
547 $langList = \CLanguage::GetList(
'lid',
'asc', array(
"ACTIVE" =>
"Y"));
548 while ($lang = $langList->Fetch())
549 $iblockType[
'LANG'][$lang[
'LID']][
'NAME'] =
"Processes";
551 $iblockTypeList = \CIBlockType::GetList(array(), array(
'=ID' => $iblockType[
'ID']));
552 $res = $iblockTypeList->fetch();
555 $iblockTypeObject = new \CIBlockType;
556 $iblockTypeObject->add($iblockType);
558 $con = Main\Application::getConnection();
560 insert into b_lists_permission (IBLOCK_TYPE_ID, GROUP_ID)
561 select 'bitrix_processes', p.GROUP_ID
564 left join b_lists_permission p2 on p2.GROUP_ID = p.GROUP_ID and p2.IBLOCK_TYPE_ID = 'bitrix_processes'
566 p.IBLOCK_TYPE_ID = 'lists'
567 and p2.IBLOCK_TYPE_ID is null
570 global $CACHE_MANAGER;
571 $CACHE_MANAGER->Clean(
"b_lists_permission");
574 Main\Config\Option::set(
"lists",
"livefeed_iblock_type_id",
"bitrix_processes");
585 if (ModuleManager::isModuleInstalled(
"bizproc"))
587 self::installProcesses($lang);
592 return '\Bitrix\Lists\Importer::onAgent("'.$lang.
'");';
602 $db = \CIBlock::GetList(
604 array(
"ID" => $id,
"IBLOCK_TYPE_ID" =>
"lists",
"CHECK_PERMISSIONS" =>
"N")
606 $iblock = $db->Fetch();
610 $iblockType = static::getIBlockType();
613 $res = $ob->Update($id, array(
"IBLOCK_TYPE_ID" => $iblockType));
616 \CLists::setLiveFeed(1, $id);
619 \CBPDocument::MigrateDocumentType(
620 array(
"lists",
'Bitrix\Lists\BizprocDocumentLists',
"iblock_".$id),
621 array(
"lists",
"BizprocDocument",
"iblock_".$id)
static getSubstring($str, $start,... $args)