PHP code example of izica / bitrix-migrations

1. Go to this page and download the library: Download izica/bitrix-migrations library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

izica / bitrix-migrations example snippets




use Izica\Migration;
use CModule;

class CreateIblockNews_1550830432 extends Migration {
    public function up() {
        CModule::IncludeModule('iblock');

        $obIblock = new CIBlock;
        $arFields = [
            "ACTIVE"           => 'Y',
            "NAME"             => 'Новости',
            "CODE"             => 'news',
            "IBLOCK_TYPE_ID"   => 'info',
            "SITE_ID"          => ["s1"],
            "GROUP_ID"         => ["2" => "D", "3" => "R"]
        ];

        $nId = $obIblock->Add($arFields);
        
        $this->log('CIBlock news created');
    }

    public function down() {
        CModule::IncludeModule('iblock');

        CIBlock::Delete($this->getIblockIdByCode('news'));

        $this->log('CIBlock news deleted');
    }
}

<?
class Example extends Migration {
    public function up() {
        /*
         * тут создается свойсво
         */
        $nPropertyId = $obProperty->Add($arFields);
        $this->set('PROPERTY_CODE', $nPropertyId);
        $this->log('CIBlock news created');
    }

    public function down() {
        CModule::IncludeModule('iblock');
        
        $nPropertyId = $this->get('PROPERTY_CODE');
        CIBlockProperty::Delete($nPropertyId);

        $this->log('Property PROPERTY_CODE deleted');
    }
}

php php_interface/vendor/izica/bitrix-migrations/bxm.php init --root=../

php vendor/izica/bitrix-migrations/bxm.php init --root=../../

php bxm

php bxm create create-news-iblock

php bxm create create-iblock-news --template={templateName}
php bxm create create-iblock-news --template=iblock