<commit_before><?php defined('SYSPATH') OR die('No direct script access.');

use Ddeboer\Transcoder\Transcoder;

 /**
  * This is a task to migrate client database from SmartResponder csv dump
  * It can accept -csv option.
  * csv should have format: "Email","Name"
  * @category Helpers
  * @author Oreolek
  * @license AGPL
  **/
class Task_Migrate_Smartresponder extends Minion_Task
{
  protected $_options = array(
    'csv' => NULL,
    'group_id' => NULL,
  );

  public function build_validation(Validation $validation)
  {
    return parent::build_validation($validation)
      ->rule('csv', 'not_empty') // Require this param
      ->rule('group_id', 'not_empty'); // Require this param
  }

  /**
   * This is a migration task
   *
   * @return null
   */
  protected function _execute()
  {
    $params = $this->get_options();
    $path = $params['csv'];

    if ( ! file_exists($path))
    {
      echo "ERROR: File not found.";
      return;
    }

    $db = Database::instance();
    $db->begin();
    $transcoder = Transcoder::create();

    $group = ORM::factory('Group')->where('id', '=', $params['group_id'])->find();
    if ( ! $group->loaded()) {
      echo "No group with id ".$params['group_id'  " found.\n";
      return;
    }

    try
    {
      if (($handle = fopen($path, "r")) !== FALSE) {
        echo "File opened.\n";
        while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
          $client = ORM::factory('Client')->where('email', '=', $data[0]);
          if ( ! $client->loaded()) {
            $client = ORM::factory('Client');
            $client->email = $data[0];
          }
          $name = trim($transcoder->transcode($data[1].' '.$data[2], 'cp1251'));
          $client->name = $name;
          $client->sex = $data[5];
          if ( ! empty($data[13]))<commit_msg>php fix<commit_after><?php defined('SYSPATH') OR die('No direct script access.');

use Ddeboer\Transcoder\Transcoder;

 /**
  * This is a task to migrate client database from SmartResponder csv dump
  * It can accept -csv option.
  * csv should have format: "Email","Name"
  * @category Helpers
  * @author Oreolek
  * @license AGPL
  **/
class Task_Migrate_Smartresponder extends Minion_Task
{
  protected $_options = array(
    'csv' => NULL,
    'group_id' => NULL,
  );

  public function build_validation(Validation $validation)
  {
    return parent::build_validation($validation)
      ->rule('csv', 'not_empty') // Require this param
      ->rule('group_id', 'not_empty'); // Require this param
  }

  /**
   * This is a migration task
   *
   * @return null
   */
  protected function _execute()
  {
    $params = $this->get_options();
    $path = $params['csv'];

    if ( ! file_exists($path))
    {
      echo "ERROR: File not found.";
      return;
    }

    $db = Database::instance();
    $db->begin();
    $transcoder = Transcoder::create();

    $group = ORM::factory('Group')->where('id', '=', $params['group_id'])->find();
    if ( ! $group->loaded()) {
      echo "No group with id ".$params['group_id']." found.\n";
      return;
    }

    try
    {
      if (($handle = fopen($path, "r")) !== FALSE) {
        echo "File opened.\n";
        while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
          $client = ORM::factory('Client')->where('email', '=', $data[0]);
          if ( ! $client->loaded()) {
            $client = ORM::factory('Client');
            $client->email = $data[0];
          }
          $name = trim($transcoder->transcode($data[1].' '.$data[2], 'cp1251'));
          $client->name = $name;
          $client->sex = $data[5];
          if ( ! empty($data[13]))
{'fraction_non_alphanumeric': 0.18691588785046728, 'fraction_numerical': 0.008246289169873557, 'mean_word_length': 2.657286432160804, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 33, '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': '6339900', 'n_tokens_mistral': 1207, 'n_tokens_neox': 1168, 'n_words': 274}