Skip to content
This repository was archived by the owner on Jan 10, 2023. It is now read-only.

Commit b8c8367

Browse files
vkryukov76arrilot
authored andcommitted
Add Iblock type migration template (#4)
* Add Iblock type migration template * Add template description to Readme file * Add iblock_type migration template to collection * Add iblock_type migration template to collection properly * Fix for proper PSR2 compliance in migration template
1 parent b7fed41 commit b8c8367

File tree

3 files changed

+63
-0
lines changed

3 files changed

+63
-0
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,11 @@
100100
<td>Чистый шаблон по умолчанию</td>
101101
<td></td>
102102
</tr>
103+
<tr>
104+
<td>`add_iblock_type`</td>
105+
<td>Добавление типа инфоблока</td>
106+
<td></td>
107+
</tr>
103108
<tr>
104109
<td>`add_iblock`</td>
105110
<td>Добавление инфоблока</td>

src/TemplatesCollection.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ public function registerBasicTemplates()
5151
'path' => $this->dir.'/add_iblock.template',
5252
'description' => 'Add iblock',
5353
],
54+
[
55+
'name' => 'add_iblock_type',
56+
'path' => $this->dir.'/add_iblock_type.template',
57+
'description' => 'Add iblock type',
58+
],
5459
[
5560
'name' => 'add_iblock_element_property',
5661
'path' => $this->dir.'/add_iblock_element_property.template',

templates/add_iblock_type.template

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
3+
use Arrilot\BitrixMigrations\BaseMigrations\BitrixMigration;
4+
use Arrilot\BitrixMigrations\Exceptions\MigrationException;
5+
6+
class __className__ extends BitrixMigration
7+
{
8+
/**
9+
* Run the migration.
10+
*
11+
* @return mixed
12+
*/
13+
public function up()
14+
{
15+
CModule::IncludeModule('iblock');
16+
$cbt = new CIBlockType;
17+
$cbtRes = $cbt->Add([
18+
'ID'=>'__',
19+
'SECTIONS'=>'Y',
20+
'IN_RSS'=>'N',
21+
'SORT'=>100,
22+
'LANG'=>array(
23+
'ru'=>array(
24+
'NAME'=>'__',
25+
)
26+
)
27+
]);
28+
29+
if (!$cbtRes) {
30+
throw new MigrationException('Ошибка при добавлении типа инфоблока '.$cbt->LAST_ERROR);
31+
}
32+
}
33+
34+
/**
35+
* Reverse the migration.
36+
*
37+
* @return mixed
38+
*/
39+
public function down()
40+
{
41+
CModule::IncludeModule('iblock');
42+
43+
global $DB;
44+
$DB->StartTransaction();
45+
46+
if (!CIBlockType::Delete('__')) {
47+
$DB->Rollback();
48+
throw new MigrationException('Ошибка при удалении типа инфоблока __');
49+
}
50+
51+
$DB->Commit();
52+
}
53+
}

0 commit comments

Comments
 (0)