1. REGISTRATION REQUIREMENTS:

    Register with your xenforo.com Username then start a conversation at xenforo.com w/Bob and provide the following:
    1. Your XenForo License Validation Token
    2. The Domain Name associated with the License
    NOTE: Your account will be validated once ALL requirements are verified/met. Thank you for your patience.

Fixed Undefined index market_value (guest permission issue)

Discussion in 'Stock Trader Resolved Bug Reports' started by SneakyDave, Nov 11, 2014.

  1. SneakyDave

    SneakyDave Member Sportsbook

    I have 2 stock trader licenses, but one installation is throwing this error. I assume it's an upgrade issue where the market_value index wasn't created?

    ErrorException: Undefined index: market_value - library/NFLJ/StockTrader/Model/Stock.php:855
    Generated By: Unknown Account, Today at 9:36 AM
    Stack Trace
    #0 /public/library/NFLJ/StockTrader/Model/Stock.php(855): XenForo_Application::handlePhpError(8, 'Undefined index...', '/home/nginx/dom...', 855, Array)
    #1 /public/library/NFLJ/StockTrader/ControllerPublic/Portfolio.php(153): NFLJ_StockTrader_Model_Stock->formatPortfolioValues(false, false)
    #2 /public/library/XenForo/FrontController.php(347): NFLJ_StockTrader_ControllerPublic_Portfolio->actionHistory()
    #3 /public/library/XenForo/FrontController.php(134): XenForo_FrontController->dispatch(Object(XenForo_RouteMatch))
    #4 /public/index.php(13): XenForo_FrontController->run()
    #5 {main}
    Request State
    array(3) {
    ["url"] => string(50) "/stocktrader/portfolio/history"
    ["_GET"] => array(1) {
    ["/stocktrader/portfolio/history"] => string(0) ""
    }
    ["_POST"] => array(0) {
    }
    }
     
  2. Bob

    Bob Developer Staff Member

    Thats a weird one. Undefined Index doesn't mean DB Index, its a php array index. In most cases, its because the FIELD is missing from the DB Table. Whats weird about this one is that is a field that has been in that table since version 1.

    This is how its been since day 1
    PHP:
            $db->query("      
                CREATE TABLE IF NOT EXISTS xf_xi_stocktrader_portfolio (
                    user_id int(10) unsigned NOT NULL,              
                    total_invested decimal(15,2) NOT NULL DEFAULT '0.00',              
                    market_value decimal(15,2) NOT NULL DEFAULT '0.00',
                    gain_amount decimal(15,2) NOT NULL DEFAULT '0.00',
                    gain_percent decimal(15,2) NOT NULL DEFAULT '0.00',                                              
                    PRIMARY KEY (user_id)
                ) ENGINE = InnoDB CHARACTER SET utf8 COLLATE utf8_general_ci
            "
    );
    This changed the tables names to unbrand from XenFluence (XI) in version 4. (It has no effect on that field, just pointing out the table name difference)
    PHP:
            //  rename all tables from xf_xi_ to xf_nflj_
            
    $db->query("ALTER TABLE xf_xi_stocktrader_portfolio RENAME TO xf_nflj_stocktrader_portfolio");    
    This is the code in the new installer...
    PHP:
            $tables['xf_nflj_stocktrader_portfolio'] = "  
                CREATE TABLE IF NOT EXISTS xf_nflj_stocktrader_portfolio (
                    user_id int(10) unsigned NOT NULL,
                    total_invested decimal(15,2) NOT NULL DEFAULT '0.00',
                    market_value decimal(15,2) NOT NULL DEFAULT '0.00',
                    gain_amount decimal(15,2) NOT NULL DEFAULT '0.00',
                    gain_percent decimal(15,2) NOT NULL DEFAULT '0.00',
                    PRIMARY KEY (user_id)
                ) ENGINE = InnoDB CHARACTER SET utf8 COLLATE utf8_general_ci
            "
    ;
    There is NO WAY that the table was installed, but not one of the fields as the entire create process would fail, not just a single field.

    Looks like either the entire TABLE is missing or someone deleted just that field. You might want to look at the table and see if any other fields are missing.
     
  3. SneakyDave

    SneakyDave Member Sportsbook

    I'll compare the tables on the 2 installations, and see how they compare.

    I haven't noticed any problems with stock trader,but I don't think I've used the portfolio history method very much.
     
  4. Bob

    Bob Developer Staff Member

    Let me know if the field was missing or not. If the field isn't missing, then something else is very very wrong lol
     
  5. SneakyDave

    SneakyDave Member Sportsbook

    Looking at this more, both of my installations receive this error occasionally, but the table structure looks fine.

    Code:
    CREATE TABLE IF NOT EXISTS `xf_nflj_stocktrader_portfolio` (
      `user_id` int(10) unsigned NOT NULL,
      `total_invested` decimal(15,2) NOT NULL DEFAULT '0.00',
      `market_value` decimal(15,2) NOT NULL DEFAULT '0.00',
      `gain_amount` decimal(15,2) NOT NULL DEFAULT '0.00',
      `gain_percent` decimal(15,2) NOT NULL DEFAULT '0.00'
    ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
    
    So I wonder if there is a SELECT happening somewhere that doesn't include the market_value column when that array is passed to formatPortfolioValues method in the Stock class?


    I think I've only seen this error when the stocktrader/portfolio/history method is fired, and I believe only when an unregistered visitor or bot tries to see it.
     
    Last edited: Nov 14, 2014
  6. SneakyDave

    SneakyDave Member Sportsbook

    Doesn't line #1 indicate that the entire array isn't available, not just the market_value index?

    #0 /library/NFLJ/StockTrader/Model/Stock.php(855): XenForo_Application::handlePhpError(8, 'Undefined index...', '/usr/share/ngin...', 855, Array)
    #1 /library/NFLJ/StockTrader/ControllerPublic/Portfolio.php(153): NFLJ_StockTrader_Model_Stock->formatPortfolioValues(false, false)
    #2 /library/XenForo/FrontController.php(347): NFLJ_StockTrader_ControllerPublic_Portfolio->actionHistory()
    #3 /library/XenForo/FrontController.php(134): XenForo_FrontController->dispatch(Object(XenForo_RouteMatch))
    #4 /index.php(13): XenForo_FrontController->run()
    #5 {main}
     
  7. SneakyDave

    SneakyDave Member Sportsbook

    Yeah, it can be reproduced by visiting this method as an unregistered user:
    /stocktrader/portfolio/history

    It doesn't matter if the unregistered group has permission to view Stock Trader or not, same error happens.

    Maybe it just needs to check to see if there is any portfolio available before rendering the history. (Talking like I know what I'm talking about)
     
  8. SneakyDave

    SneakyDave Member Sportsbook

    I lied, the error will only happen if guests have permission to view the stock trader (although that permissions doesn't really grant them much to do), and then they try to view portfolio history at stocktrader/portfolio/history

    It doesn't happen here obviously, because guests must not have the "view stock trader" permission set.

    This error can be fixed by just not giving guests that permission, but then guests can't see ANY type of stock activity it appears, such as top portfolios, etc.
     
  9. Bob

    Bob Developer Staff Member

    Guests shouldn't even have access to the LINK (which is the first problem), so I've modified the nflj_stocktrader_tab_links template to now only display the LINKS to "Your Portfolio" and "Your History" if the viewing user has a user_id.

    I've also added code to the history action to basically do the same (if a guest tries to direct access, it will now throw an error).
     
  10. Bob

    Bob Developer Staff Member

    To fix this now:

    edit the file: /library/NFLJ/StockTrader/ControllerPublic/Portfolio.php

    FIND:
    PHP:
        public function actionHistory()
        {
    Add the assertRegistrationRequired helper as shown below:
    PHP:
        public function actionHistory()
        {
            
    $this->_assertRegistrationRequired();

    Also, you should replace your nflj_stocktrader_tab_links template with this one:
    HTML:
    <ul class="secondaryContent blockLinksList">
        <li><a href="{xen:link 'stocktrader/top-portfolios'}">{xen:phrase nflj_stocktrader_tab_link_top_portfolios}</a></li>
        <li><a href="{xen:link 'stocktrader/popular'}">{xen:phrase nflj_stocktrader_tab_link_popular_stocks}</a></li>
        <xen:if is="{$visitor.user_id}">
            <li><a href="{xen:link 'stocktrader'}">{xen:phrase nflj_stocktrader_tab_link_your_portfolio}</a></li>
            <li><a href="{xen:link 'stocktrader/portfolio/history'}">{xen:phrase nflj_stocktrader_tab_link_your_history}</a></li>
        </xen:if>
    </ul>
     
  11. SneakyDave

    SneakyDave Member Sportsbook

    I can confirm that the edit fixed the problem. thanks, Bob.
     
    Bob likes this.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.