<commit_before><?php
Yii::import('application.modules.user.models.*');
Yii::import('application.modules.yupe.components.*');
Yii::import('application.modules.yupe.models.*');
Yii::import('application.modules.blog.models.*');
Yii::import('application.modules.comment.models.*');
Yii::import('application.modules.yupe.helpers.*');

// for livestreet url mapping
//'/blog/<slug>'     => 'blog/blog/show', 
//'/blog/<blog_name>/<id>.html' => 'blog/post/view',
//'/profile/<username:\w+>/' => 'user/people/userInfo',
//'/tag/<tag>'  => 'blog/post/list',
//'/people'     => 'user/people/index'

class ImportLsCommand extends CConsoleCommand
{

    public function run()
    {
        $this->actionUsers();
        $this->actionBlogs();
        $this->actionTags();
        $this->actionPosts();         
        $this->actionComments(); 
        $this->actionMembers();
    }
   

    public function actionUsers()
    {       
        $data = Yii::app()->ls->createCommand('SELECT * FROM prefix_user')->queryAll();

        $transaction = Yii::app()->db->beginTransaction();

        User::model()->deleteAll();

        try
        {
            foreach($data as $user) {

                echo "Import user with ncik '{$user['user_login']}' !\n";

                if(!isset( $user['user_login'],  $user['user_password'])) {
                    echo "Skip user...\n";
                    continue;
                }

                $status = $user['user_activate'] == 1 ? 1 : 2;

                $genderMap = array(
                    'woman' => 2,
                    'man'   => 1
                );

                $gender = isset($genderMap[$user['user_profile_sex']]) ? $genderMap[$user['user_profile_sex']] : 0;

                $location = array($user['user_profile_country'], $user['user_profile_region'], $user['user_profile_city']);

                $about = $user['user_profile_about'] ? $user['user_profile_about'] : '';

                $changeDate = $user['user_profile_date'] ? $user['user_profile_date'] : new CDbExpression('NOW()');

                $email = $user['user_mail'] ? $user['user_mail'] : md5($user['user_login']);

                Yii::app()->db->createCommand('
                    INSERT INTO {{user_user}} (id, nick_name, email, hash, registration_date, status, gender, location, birth_date, about, change_date, avatar)
                                       VALUES(:id,:nick_name,:email,:hash, :registration_date, :status, :gender, :location, :birth_date, :about, :change_date, :avatar)
                ')->bindValue(':id', $user['user_id'])
                  ->bindValue(':nick_name', $user['user_login'])
                  ->bindValue(':email', $email)
                  ->bindValue(':hash',sha1($user['user_password']))
                  ->bindValue(':registration_date',$user['user_date_register'])
                  ->bindValue(':status', $status)
                  ->bindValue(':gender',$gender)
                  ->bindValue(':location', implode(' ', $location))
                  ->bindValue(':birth_date', $user['user_profile_birthday'])
                  ->bindValue(':about', $about)
                  ->bindValue(':change_date', $changeDate)
                  ->bindValue(':avatar', $user['user_profile_avatar'])
                  ->execute();
            }

            $transaction->commit();
        }
        catch(Exception $e)
        {
            CVarDumper::dump($e);
            $transaction->rollback();
            die;
        }
    }

    public function actionBlogs()
    {
        $data = Yii::app()->ls->createCommand('SELECT * FROM prefix_blog')->queryAll();

        $transaction = Yii::app()->db->beginTransaction();

        try
        {<commit_msg>fix ls importer<commit_after><?php
Yii::import('application.modules.user.models.*');
Yii::import('application.modules.yupe.components.*');
Yii::import('application.modules.yupe.models.*');
Yii::import('application.modules.blog.models.*');
Yii::import('application.modules.comment.models.*');
Yii::import('application.modules.yupe.helpers.*');

// for livestreet url mapping
//'/blog/<slug>'     => 'blog/blog/show', 
//'/blog/<blog_name>/<id>.html' => 'blog/post/view',
//'/profile/<username:\w+>/' => 'user/people/userInfo',
//'/tag/<tag>'  => 'blog/post/list',
//'/people'     => 'user/people/index'

class ImportLsCommand extends CConsoleCommand
{

    public function run()
    {
        $this->actionUsers();
        $this->actionBlogs();
        $this->actionTags();
        $this->actionPosts();         
        $this->actionComments(); 
        $this->actionMembers();
    }
   

    public function actionUsers()
    {       
        $data = Yii::app()->ls->createCommand('SELECT * FROM prefix_user')->queryAll();

        $transaction = Yii::app()->db->beginTransaction();

        User::model()->deleteAll();

        try
        {
            foreach($data as $user) {

                echo "Import user with ncik '{$user['user_login']}' !\n";

                if(!isset( $user['user_login'],  $user['user_password'])) {
                    echo "Skip user...\n";
                    continue;
                }

                $status = $user['user_activate'] == 1 ? 1 : 2;

                $genderMap = array(
                    'woman' => 2,
                    'man'   => 1
                );

                $gender = isset($genderMap[$user['user_profile_sex']]) ? $genderMap[$user['user_profile_sex']] : 0;

                $location = array($user['user_profile_country'], $user['user_profile_region'], $user['user_profile_city']);

                $about = $user['user_profile_about'] ? $user['user_profile_about'] : '';

                $changeDate = $user['user_profile_date'] ? $user['user_profile_date'] : new CDbExpression('NOW()');

                $email = $user['user_mail'] ? $user['user_mail'] : md5($user['user_login']);

                Yii::app()->db->createCommand('
                    INSERT INTO {{user_user}} (id, nick_name, email, hash, registration_date, status, gender, location, birth_date, about, change_date, avatar, last_visit)
                                       VALUES(:id,:nick_name,:email,:hash, :registration_date, :status, :gender, :location, :birth_date, :about, :change_date, :avatar, :last_visit)
                ')->bindValue(':id', $user['user_id'])
                  ->bindValue(':nick_name', $user['user_login'])
                  ->bindValue(':email', $email)
                  ->bindValue(':hash',sha1($user['user_password']))
                  ->bindValue(':registration_date',$user['user_date_register'])
                  ->bindValue(':status', $status)
                  ->bindValue(':gender',$gender)
                  ->bindValue(':location', implode(' ', $location))
                  ->bindValue(':birth_date', $user['user_profile_birthday'])
                  ->bindValue(':about', $about)
                  ->bindValue(':change_date', $changeDate)
                  ->bindValue(':avatar', $user['user_profile_avatar'])
                  ->bindValue(':last_visit', $user['user_profile_date'])
                  ->execute();
            }

            $transaction->commit();
        }
        catch(Exception $e)
        {
            CVarDumper::dump($e);
            $transaction->rollback();
            die;
        }
    }

    public function actionBlogs()
    {
        $data = Yii::app()->ls->createCommand('SELECT * FROM prefix_blog')->queryAll();

        $transaction = Yii::app()->db->beginTransaction();

        try
        {
{'fraction_non_alphanumeric': 0.18358129649309246, 'fraction_numerical': 0.0021253985122210413, 'mean_word_length': 2.1607892527287995, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 96, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3001388', 'n_tokens_mistral': 2263, 'n_tokens_neox': 2108, 'n_words': 320}