<commit_before><?php

namespace Kula\Core\Component\Record;

use Kula\Core\Component\DefinitionLoader\DefinitionLoader;


class RecordLoader {
  
  private $records = array();
  
  public function getRecordsFromBundles(array $bundles) {
    
    $records = DefinitionLoader::loadDefinitionsFromBundles($bundles, 'record');
    
    if ($records) {
      foreach($records as $path => $record) {
        $this->loadRecord($record, $path);
      }
    }
    
  }
  
  public function loadRecord($records, $path) {
    
    foreach($records as $recordName => $record) {
      
      $this->records[$recordName] = $record;
      
    }
  }
  
  public function synchronizeDatabaseCatalog(\Kula\Core\Component\DB\DB $db) {
    
    foreach($this->records as $recordName => $record) {
      
      // Check table exists in database
      $catalogRecordTable = $db->db_select('CORE_RECORD_TYPES', 'record_types')
        ->fields('record_types')
        ->condition('RECORD_NAME', $recordName)
        ->execute()->fetch();
      
      if ($catalogRecordTable['RECORD_TYPE_ID']) {
        
        if ($catalogRecordTable['CLASS'] != $record['class']) 
          $recordFields['CLASS'] = $record['class'];
        if (count($recordFields) > 0)
          $db->db_update('CORE_RECORD_TYPES')->fields($recordFields)->condition('RECORD_NAME', $recordName)->execute();
        
      } else {
        
        $recordFields['RECORD_NAME'] = $recordName;
        $recordFields['PORTAL'] = strtolower(substr($recordName, 0, strrpos($recordName, '.')));
        $recordFields['CLASS'] = (isset($record['class'])) ? $record['class'] : null;
        $recordID = $db->db_insert('CORE_RECORD_TYPES')->fields($recordFields)->execute();
        
      }
      
      
    }
  
  }
  
}<commit_msg>Fixed recod loader undefined variable bug<commit_after><?php

namespace Kula\Core\Component\Record;

use Kula\Core\Component\DefinitionLoader\DefinitionLoader;


class RecordLoader {
  
  private $records = array();
  
  public function getRecordsFromBundles(array $bundles) {
    
    $records = DefinitionLoader::loadDefinitionsFromBundles($bundles, 'record');
    
    if ($records) {
      foreach($records as $path => $record) {
        $this->loadRecord($record, $path);
      }
    }
    
  }
  
  public function loadRecord($records, $path) {
    
    foreach($records as $recordName => $record) {
      
      $this->records[$recordName] = $record;
      
    }
  }
  
  public function synchronizeDatabaseCatalog(\Kula\Core\Component\DB\DB $db) {
    
    foreach($this->records as $recordName => $record) {
      
      // Check table exists in database
      $catalogRecordTable = $db->db_select('CORE_RECORD_TYPES', 'record_types')
        ->fields('record_types')
        ->condition('RECORD_NAME', $recordName)
        ->execute()->fetch();
      
      $recordFields = array();
      
      if ($catalogRecordTable['RECORD_TYPE_ID']) {
        
        if ($catalogRecordTable['CLASS'] != $record['class']) 
          $recordFields['CLASS'] = $record['class'];
        if (count($recordFields) > 0)
          $db->db_update('CORE_RECORD_TYPES')->fields($recordFields)->condition('RECORD_NAME', $recordName)->execute();
        
      } else {
        
        $recordFields['RECORD_NAME'] = $recordName;
        $recordFields['PORTAL'] = strtolower(substr($recordName, 0, strrpos($recordName, '.')));
        $recordFields['CLASS'] = (isset($record['class'])) ? $record['class'] : null;
        $recordID = $db->db_insert('CORE_RECORD_TYPES')->fields($recordFields)->execute();
        
      }
      
      
    }
  
  }
  
}
{'fraction_non_alphanumeric': 0.15726920950801548, 'fraction_numerical': 0.001105583195135434, 'mean_word_length': 2.817510548523207, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 41, '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': '2482524', 'n_tokens_mistral': 1093, 'n_tokens_neox': 1091, 'n_words': 167}