<commit_before>#!/usr/bin/php
<?php

    //pre-req: create table sc_bookmark
    //pre-req: remove everything from sc_bookmark
    //pre-req: start redis // flushdb redis

    include('sc-app.inc');
    include(APP_CLASS_LOADER);
    include(WEBGLOO_LIB_ROOT . '/com/indigloo/error.inc');

    use \com\indigloo\mysql as MySQL;
    use \com\indigloo\sc\util\PseudoId ;
    use \com\indigloo\sc\Constants as AppConstants ;

    set_exception_handler('offline_exception_handler');

    function user_bookmark_to_bookmark($mysqli) {
        $sql = " select * from sc_user_bookmark order by id" ;
        $rows = MySQL\Helper::fetchRows($mysqli,$sql);
        $userDao = new \com\indigloo\sc\dao\User();
        $postDao = new \com\indigloo\sc\dao\Post();

        $bookmarkDao = new \com\indigloo\sc\dao\Bookmark();

        foreach($rows as $row) {

            $loginId = $row['login_id'];
            $itemId = $row['item_id'];

            $userDBRow = $userDao->getOnLoginId($loginId);
            $name = $userDBRow['name'];

            $postId = PseudoId::decode($itemId);
            $postDBRow = $postDao->getOnId($postId);


            $title = $postDBRow['title'];
            $ownerId = $postDBRow['login_id'];

            $action = $row['action'];
            settype($action,"integer");

            $verb = -1 ;
            if($action == 1 ) $verb = AppConstants::LIKE_VERB ;
            if($action == 2 ) $verb = AppConstants::FAVORITE_VERB ;

            //push to sc_user_bookmark
            $bookmarkDao->add($ownerId, $loginId, $name, $itemId, $title, $verb);
            //push to redis

        }

    }

    function follower_to_feed($mysqli) {
        $sql = " select * from sc_follow order by id" ;
        $rows = MySQL\Helper::fetchRows($mysqli,$sql);

        $userDao = new \com\indigloo\sc\dao\User();
        $activityDao = new \com\indigloo\sc\dao\ActivityFeed();

        foreach($rows as $row) {
            $followerId = $row['follower_id'] ;
            $followingId = $row['following_id'] ;

            $row1 = $userDao->getOnLoginId($followerId);
            $row2 = $userDao->getOnLoginId($followingId);
            $followerName = $row1['name'];
            $followingName = $row2['name'];
            $verb = AppConstants::FOLLOWING_VERB ;
            $activityDao->addFollower($followerId, $followerName, $followingId, $followingName, $verb);

        }
    }

    function comment_to_feed($mysqli) {
        $sql = " select * from sc_comment order by id " ;
        $rows = MySQL\Helper::fetchRows($mysqli,$sql);

        $userDao = new \com\indigloo\sc\dao\User();
        $activityDao = new \com\indigloo\sc\dao\ActivityFeed();
        $postDao = new \com\indigloo\sc\dao\Post();

        foreach($rows as $row) {
            $postId = $row['post_id'];
            $postDBRow = $postDao->getOnId($postId);
            $image = $postDao->getImageOnId($postId);


            $loginId = $row['login_id'];
            $userDBRow = $userDao->getOnLoginId($loginId);
            $name = $userDBRow['name'];
            $ownerId = $postDBRow['login_id'];
            $itemId = PseudoId::encode($postId);
            $title = $row['title'] ;
            $content = $row['description'];

            $verb = AppConstants::COMMENT_VERB ;
            $activityDao->addComment($ownerId, $loginId, $name, $itemId, $title, $content, $image, $verb);

        }

    }

    $mysqli = MySQL\Connection::getInstance()->getHandle();
    user_bookmark_to_bookmark($mysqli);
    sleep(1);
    follower_to_feed($mysqli);
    sleep(1);
    comment_to_feed($mysqli);

?><commit_msg>fixed: populate redis from DB script<commit_after>#!/usr/bin/php
<?php

    /* pre-req: 
        sc_bookmark, sc_post, sc_comment, sc_follow table should exist
        turn off site worker cron job (put an exit at top)
        redis- issue command flushdb - get rid of old keys 
        
        After running the script
        -------------------------------
        remove global job queue and jobs.
        
        del  sc:global:queue:new 
        del  sc:global:jobs
        del sc:global:nextJobId

        exists sc:global:nextJobId
        exists sc:global:jobs
        exists sc:global:queue:new

    

        turn on cron job
        @todo- do we need to reset sc:global:nextJobId ?

    */

    include('sc-app.inc');
    include(APP_CLASS_LOADER);
    include(WEBGLOO_LIB_ROOT . '/com/indigloo/error.inc');

    use \com\indigloo\mysql as MySQL;
    use \com\indigloo\sc\util\PseudoId ;
    use \com\indigloo\sc\Constants as AppConstants ;
    use \com\indigloo\Util ;

    set_exception_handler('offline_exception_handler');

    function user_bookmark_to_feed($mysqli) {
        
        $sql = " select * from sc_bookmark order by id" ;
        $rows = MySQL\Helper::fetchRows($mysqli,$sql);


        $userDao = new \com\indigloo\sc\dao\User();
        $postDao = new \com\indigloo\sc\dao\Post();
        $activityDao = new \com\indigloo\sc\dao\ActivityFeed();

        foreach($rows as $row) {


            $loginId = $row['subject_id'];
            $ownerId = $row['owner_id'];
            $name = $row['subject'];
            $itemId = $row['object_id'];
            $title = $row['object_title'];
            $title = Util::filterBadUtf8($title);

            //number 1|2 stored in table
            $action = $row['verb'];

            $verb = -1 ;
            if($action == 1 ) $verb = AppConstants::LIKE_VERB ;
            if($action == 2 ) $verb = AppConstants::FAVORITE_VERB ;

            $postId = PseudoId::decode($itemId);
            $image = $postDao->getImageOnId($postId);

            //push to redis
            // get image from item.
           
            $postId = PseudoId::decode($itemId);
            $image = $postDao->getImageOnId($postId);

            $activityDao->addBookmark($ownerId,$loginId,$name,$itemId,$title,$image,$verb);

        }

    }

    function follower_to_feed($mysqli) {
        $sql = " select * from sc_follow order by id" ;
        $rows = MySQL\Helper::fetchRows($mysqli,$sql);

        $userDao = new \com\indigloo\sc\dao\User();
        $activityDao = new \com\indigloo\sc\dao\ActivityFeed();

        foreach($rows as $row) {
            $followerId = $row['follower_id'] ;
            $followingId = $row['following_id'] ;

            $row1 = $userDao->getOnLoginId($followerId);
            $row2 = $userDao->getOnLoginId($followingId);
            $followerName = $row1['name'];
            $followingName = $row2['name'];
            $verb = AppConstants::FOLLOWING_VERB ;

            $activityDao->addFollower($followerId, $followerName, $followingId, $followingName, $verb);

        }
    }

    function comment_to_feed($mysqli) {
        $sql = " select * from sc_comment order by id " ;
        $rows = MySQL\Helper::fetchRows($mysqli,$sql);

        $userDao = new \com\indigloo\sc\dao\User();
        $activityDao = new \com\indigloo\sc\dao\ActivityFeed();
        $postDao = new \com\indigloo\sc\dao\Post();

        foreach($rows as $row) {
            $postId = $row['post_id'];
            $postDBRow = $postDao->getOnId($postId);
            $image = $postDao->getImageOnId($postId);


            $loginId = $row['login_id'];
            $userDBRow = $userDao->getOnLoginId($loginId);
            $name = $userDBRow['name'];
            $ownerId = $postDBRow['login_id'];
            $itemId = PseudoId::encode($postId);

            $title = $row['title'] ;
            $title = Util::filterBadUtf8($title);

            $content = $row['description'];
            $content = Util::filterBadUtf8($content);

            $verb = AppConstants::COMMENT_VERB ;
            $activityDao->addComment($ownerId, $loginId, $name, $itemId, $title, $content, $image, $verb);

        }

    }

    function post_to_feed($mysqli) {
        
        $sql = " select * from sc_post order by id " ;
        $rows = MySQL\Helper::fetchRows($mysqli,$sql);

        $userDao = new \com\indigloo\sc\dao\User();
        $activityDao = new \com\indigloo\sc\dao\ActivityFeed();
        $postDao = new \com\indigloo\sc\dao\Post();

        foreach($rows as $row) {

            $loginId = $row['login_id'];
            $postId = $row['id'];
            $itemId = PseudoId::encode($postId);
            $image = $postDao->getImageOnId($postId);

           
            $userDBRow = $userDao->getOnLoginId($loginId);
            $name = $userDBRow['name'];

            $title = $row['title'] ;
            $title = Util::filterBadUtf8($title);

            $verb = \com\indigloo\sc\Constants::POST_VERB ;
            $activityDao->addPost($loginId, $name, $itemId, $title,$image,$verb);

        }

    }

    $mysqli = MySQL\Connection::getInstance()->getHandle();
    user_bookmark_to_feed($mysqli);
    sleep(1);
    follower_to_feed($mysqli);
    sleep(1);
    comment_to_feed($mysqli);
    sleep(1);
    post_to_feed($mysqli);

?>
{'fraction_non_alphanumeric': 0.1539410247785626, 'fraction_numerical': 0.0028030048211682922, 'mean_word_length': 2.1834403997144896, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 30, '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': '3688029', 'n_tokens_mistral': 3013, 'n_tokens_neox': 2915, 'n_words': 497}