<commit_before><?php
/**
 * @author <NAME> <<EMAIL>>
 */

namespace WS\Migrations\SubjectHandlers;

use WS\Migrations\Module;

class IblockPropertyHandler extends BaseSubjectHandler {

    /**
     * Name of Handler in Web interface
     * @return string
     */
    public function getName() {
        return $this->getLocalization()->getDataByPath('iblockProperty.name');
    }

    public function getIdByChangeMethod($method, $data = array()) {
        switch ($method) {
            case Module::FIX_CHANGES_ADD_KEY:
            case Module::FIX_CHANGES_BEFORE_CHANGE_KEY:
            case Module::FIX_CHANGES_AFTER_CHANGE_KEY:
                return $data[0]['ID'];
            case Module::FIX_CHANGES_BEFORE_DELETE_KEY:
            case Module::FIX_CHANGES_AFTER_DELETE_KEY:
                return $data[0];
        }
        return null;
    }

    public function getSnapshot($id) {
        return \CIBlockProperty::GetByID($id)->Fetch();
    }

    public function applySnapshot($data) {
        $data = $this->handleNullValues($data);
        $prop = new \CIBlockProperty();
        $res = false;
        if (!\CIBlockProperty::GetByID($data['ID'])->Fetch()) {
            $res = $prop->Add($data);
        } else {
            $res = $prop->Update($data['ID'], $data);
        }
        return (bool)$res;
    }

    /**
     * Delete subject record
     * @param $id
     * @return mixed
     */<commit_msg>Строгое добавление инфоблока. Корректировка добавления свойства ИБ 2.0<commit_after><?php
/**
 * @author <NAME> <<EMAIL>>
 */

namespace WS\Migrations\SubjectHandlers;

use WS\Migrations\Module;

class IblockPropertyHandler extends BaseSubjectHandler {

    /**
     * Name of Handler in Web interface
     * @return string
     */
    public function getName() {
        return $this->getLocalization()->getDataByPath('iblockProperty.name');
    }

    public function getIdByChangeMethod($method, $data = array()) {
        switch ($method) {
            case Module::FIX_CHANGES_ADD_KEY:
            case Module::FIX_CHANGES_BEFORE_CHANGE_KEY:
            case Module::FIX_CHANGES_AFTER_CHANGE_KEY:
                return $data[0]['ID'];
            case Module::FIX_CHANGES_BEFORE_DELETE_KEY:
            case Module::FIX_CHANGES_AFTER_DELETE_KEY:
                return $data[0];
        }
        return null;
    }

    public function getSnapshot($id) {
        return \CIBlockProperty::GetByID($id)->Fetch();
    }

    public function applySnapshot($data) {
        $data = $this->handleNullValues($data);
        global $DB;
        $prop = new \CIBlockProperty();
        if (!$DB->Query("select ID from b_iblock_property where ID=".((int) $data['ID']))->Fetch()) {
            /** @var $DB \CDatabase */
            $DB->Add("b_iblock_property", $data);
            $prop->_Add($data['ID'], $data);
        }
        $res = $prop->Update($data['ID'], $data);
        return (bool)$res;
    }

    /**
     * Delete subject record
     * @param $id
     * @return mixed
     */
{'fraction_non_alphanumeric': 0.1372093023255814, 'fraction_numerical': 0.0019933554817275745, 'mean_word_length': 2.364245810055866, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7049974', 'n_tokens_mistral': 926, 'n_tokens_neox': 922, 'n_words': 177}