Advertisement:

Author Topic: SOLVED I'm getting php notices in my log files  (Read 2895 times)

marius-ciclistu

  • issues
  • Hero Member
  • *
  • Posts: 1652
  • "BE GRATEFUL TO THOSE THAT SUPPORTED YOU"
Re: I'm getting php notices in my log files
« Reply #30 on: July 25, 2017, 09:27:19 am »
TY for the patience:)
I don't use it as my modification to the osclass 3.7.1. Osclass uses it by default as it uses it in 3.7.1.
I don't use plugins(except analitycs), I'm using bender theme that came with osclass.3.7.1.

Today I got a notice:
[25-Jul-2017 08:19:20 ] PHP Notice:  Undefined variable: cat in /oc-includes/osclass/helpers/hDefines.php on line 488

Code: [Select]
487:       if( isset($item["fk_i_category_id"]) ) {          $cat = Category::newInstance()->hierarchy($item['fk_i_category_id']);    }
488:                for ($i = (count($cat)); $i > 0; $i--) {
                    $sanitized_categories[] = $cat[$i - 1]['s_slug'];

So i gues this function is still being called with uncomplete item array....

What page do use that function ? Is used in a theme ?   Core  only ? Can you post some code here  if theme file ?
Search page ? Different categories , different views ? (Grid,list)
 Enter that page ..  check logs .. sql logs .
The osc_item_url_from_item is a helper function .
 It is called  only inside  osc_item_url  function , and  do use item from exported view 
Code: [Select]
/**
     * Create automatically the url of the item details page
     *
     * @param string $locale
     * @return string
     */
    function osc_item_url($locale = '')
    {
        return osc_item_url_from_item(osc_item(), $locale);
    }
in my setup is used  322 times admin and front-end ,so any page  that do use items can throw that notices .

marius-ciclistu

  • issues
  • Hero Member
  • *
  • Posts: 1652
  • "BE GRATEFUL TO THOSE THAT SUPPORTED YOU"
Re: I'm getting php notices in my log files
« Reply #31 on: July 27, 2017, 01:02:47 am »
The item array gets null from here:
hItems.php:
Code: [Select]
    /**
    * Gets current item array from view
    *
    * @return array $item, or null if not exist
    */
    function osc_item() {
        if(View::newInstance()->_exists('item')) {
            $item = View::newInstance()->_get('item');
        } else {
            $item = null;
        }

        return($item);
    }


The solution is:

Code: [Select]
/**
     * Create item url from item data without exported to view.
     *
     * @since 3.3
     * @param array $item
     * @param string $locale
     * @return string
     */
    function osc_item_url_from_item($item, $locale = '')
    {
        if ( osc_rewrite_enabled() ) {
            $url = osc_get_preference('rewrite_item_url');
            if( preg_match('|{CATEGORIES}|', $url) ) {
                $sanitized_categories = array();
487:       if( isset($item["fk_i_category_id"]) ) { //new line
               $cat = Category::newInstance()->hierarchy($item['fk_i_category_id']);   
                for ($i = (count($cat)); $i > 0; $i--) {
                    $sanitized_categories[] = $cat[$i - 1]['s_slug'];
                }
                $url = str_replace('{CATEGORIES}', implode("/", $sanitized_categories), $url);
                } // new line
            }
495            if( isset($item["pk_i_id"]) ) {      $url = str_replace('{ITEM_ID}', osc_sanitizeString($item['pk_i_id']), $url); }
496            if( isset($item["s_city"]) ) {       $url = str_replace('{ITEM_CITY}', osc_sanitizeString($item['s_city']), $url); }
497            if( isset($item["s_title"]) ) {       $url = str_replace('{ITEM_TITLE}', osc_sanitizeString($item['s_title']), $url); }
            $url = str_replace('?', '', $url);
            if($locale!='') {
                $path = osc_base_url().$locale."/".$url;
            } else {
                $path = osc_base_url().$url;
            }
        } else {
            $path = osc_item_url_ns($item['pk_i_id'], $locale);
        }
        return $path;
    }