Created
April 22, 2011 11:26
-
-
Save itechGroup/936471 to your computer and use it in GitHub Desktop.
и еще 2 функции, которые я юзая для создания английской версии, путем копирования русской. Эти функции копируют инфоблоки
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
function copy_iblock ($IBLOCK_ID,$site='en',$signature='(English)') { | |
if ($IBLOCK_ID) { | |
CModule::IncludeModule('iblock'); | |
$iblock = CIBlock::GetById($IBLOCK_ID)->Fetch(); | |
if (!$iblock) return; | |
unset($iblock['ID']); | |
$iblock['LID'] = $site; | |
$iblock['NAME'] = $signature.' '.$iblock['NAME']; | |
$iblock['SITE_ID'] = array($site); | |
unset($iblock['PICTURE']); | |
$ib = new CIBlock; | |
$ID = $ib->Add($iblock); | |
$ib->SetMessages($ID,CIBlock::GetMessages($IBLOCK_ID)); | |
$ib->SetPermission($ID,CIBlock::GetGroupPermissions($IBLOCK_ID)); | |
$ib->SetFields($ID,CIBlock::GetFields($IBLOCK_ID)); | |
$properties = CIBlockProperty::GetList(Array("sort"=>"asc", "name"=>"asc"), Array("ACTIVE"=>"Y", "IBLOCK_ID"=>$IBLOCK_ID)); | |
while ($prop_fields = $properties->GetNext()) { | |
$prop = CIBlockProperty::GetByID($prop_fields["ID"])->Fetch(); | |
$prop['IBLOCK_ID'] = $ID; | |
$OLD_PROP = $prop['ID']; | |
unset($prop['ID']); | |
if ($prop['PROPERTY_TYPE']=='L') { | |
$ibp = new CIBlockProperty; | |
$PropID = $ibp->Add($prop); | |
$cnt = 0; | |
$ar_all_values = Array(); | |
$db_enum_list = CIBlockProperty::GetPropertyEnum($OLD_PROP, Array('SORT'=>'ASC')); | |
while($ar_enum = $db_enum_list->Fetch()) { | |
$ar_all_values[] = Array('SORT'=>$ar_enum['SORT'], 'VALUE'=>$ar_enum['VALUE']); | |
} | |
$ibp->UpdateEnum($PropID, $ar_all_values); | |
} else { | |
$ibp = new CIBlockProperty; | |
$PropID = $ibp->Add($prop); | |
} | |
} | |
} | |
} | |
function copy_iblocks ($from='s1',$to='en',$signature='(English)') { | |
$iblock_links = array(); | |
CModule::IncludeModule('iblock'); | |
$res = CIBlock::GetList(Array(), Array('SITE_ID'=>$from, 'ACTIVE'=>'Y')); | |
while($ar_res = $res->Fetch()) { | |
$IBLOCK_ID = $ar_res['ID']; | |
echo $IBLOCK_ID."-"; | |
if ($IBLOCK_ID) { | |
$iblock = CIBlock::GetById($IBLOCK_ID)->Fetch(); | |
if (!$iblock) return; | |
unset($iblock['ID']); | |
$iblock['LID'] = $to; | |
$iblock['CODE'] = $iblock['CODE']."_".$to; | |
$iblock['NAME'] = $signature.' '.$iblock['NAME']; | |
$iblock['SITE_ID'] = array($to); | |
unset($iblock['PICTURE']); | |
$ib = new CIBlock; | |
$ID = $ib->Add($iblock); | |
echo "Error: ".$ib->LAST_ERROR; | |
$iblock_links[$IBLOCK_ID] = $ID; | |
$ib->SetMessages($ID,CIBlock::GetMessages($IBLOCK_ID)); | |
$ib->SetPermission($ID,CIBlock::GetGroupPermissions($IBLOCK_ID)); | |
$ib->SetFields($ID,CIBlock::GetFields($IBLOCK_ID)); | |
echo $ID."<br/>"; | |
$properties = CIBlockProperty::GetList(Array("sort"=>"asc", "name"=>"asc"), Array("ACTIVE"=>"Y", "IBLOCK_ID"=>$IBLOCK_ID)); | |
while ($prop_fields = $properties->GetNext()) { | |
$prop = CIBlockProperty::GetByID($prop_fields["ID"])->Fetch(); | |
$prop['IBLOCK_ID'] = $ID; | |
$OLD_PROP = $prop['ID']; | |
unset($prop['ID']); | |
if ($prop['PROPERTY_TYPE']=='L') { | |
$ibp = new CIBlockProperty; | |
$PropID = $ibp->Add($prop); | |
$cnt = 0; | |
$ar_all_values = Array(); | |
$db_enum_list = CIBlockProperty::GetPropertyEnum($OLD_PROP, Array('SORT'=>'ASC')); | |
while($ar_enum = $db_enum_list->Fetch()) { | |
$ar_all_values[] = Array('SORT'=>$ar_enum['SORT'], 'VALUE'=>$ar_enum['VALUE']); | |
} | |
$ibp->UpdateEnum($PropID, $ar_all_values); | |
} else { | |
$ibp = new CIBlockProperty; | |
$PropID = $ibp->Add($prop); | |
} | |
} | |
} | |
} | |
foreach ($iblock_links as $old=>$new) { | |
$iblock = CIBlock::GetById($new)->Fetch(); | |
$properties = CIBlockProperty::GetList(Array("sort"=>"asc", "name"=>"asc"), Array("ACTIVE"=>"Y", "IBLOCK_ID"=>$new)); | |
while ($prop_fields = $properties->GetNext()) { | |
$prop = CIBlockProperty::GetByID($prop_fields["ID"])->Fetch(); | |
if ($prop['PROPERTY_TYPE']=='E' || $prop['PROPERTY_TYPE']=='G') { | |
$prop["LINK_IBLOCK_ID"] = $iblock_links[$prop["LINK_IBLOCK_ID"]]; | |
$ibp = new CIBlockProperty; | |
$PropID = $ibp->Update($prop['ID'],$prop); | |
} | |
} | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment