Advertisement:

Author Topic: Help fixing some undefined variable notices from a plugin  (Read 127 times)

Dimal

  • Full Member
  • ***
  • Posts: 135
Help fixing some undefined variable notices from a plugin
« on: August 30, 2019, 10:06:13 pm »
Hello.

Trying to fix a huge ammount of notices, can somebody help me on this:

I have a few hundreds per day of these:

PHP Notice:  Undefined variable: item in /home/oc-content/plugins/plugincache/index.php on line 230

PHP Notice:  Undefined variable: item in /home/oc-content/plugins/plugincache/index.php on line 233


Those come from some cache plugin installed, that has been developed by osclass but i can't find it in Market.

The code in error is:

Code: [Select]
function cacheplugin_delete_item($id) {
                $ItemStorageFolder = osc_get_preference('item_storage_folder', 'cacheplugin') ;
        $PubbDate = $item['dt_pub_date'];
    $DatePubb = date_create($PubbDate);
    $cachePubbDate = date_format($DatePubb, $ItemStorageFolder);
             $IdItem = $item['pk_i_id'];
osc_goto_first_locale();
$locales = osc_get_locales();
foreach($locales as $locale){
      $files = rglob(osc_get_preference('upload_path', 'cacheplugin')."item/".$cachePubbDate."/".$locale['pk_c_code']."_".$IdItem.".html");
        foreach($files as $f) {
            @unlink($f);
        }
}
                $files = rglob(osc_get_preference('upload_path', 'cacheplugin')."main/*");
          foreach($files as $f) {
            @unlink($f);
            }
        }

Line 230 is: $PubbDate = $item['dt_pub_date'];


Line 233 is: $IdItem = $item['pk_i_id'];


Any help appreciated.
« Last Edit: August 31, 2019, 01:15:31 am by Dimal »

elizabeth

  • Jr. Member
  • **
  • Posts: 80
Re: Help fixing some undefined variable notices
« Reply #1 on: August 31, 2019, 12:36:31 am »
Hello.

Trying to fix a huge ammount of notices, can somebody help me on this:

I have a few hundreds per day of these:

PHP Notice:  Undefined variable: item in /home/oc-content/plugins/plugincache/index.php on line 230

PHP Notice:  Undefined variable: item in /home/oc-content/plugins/plugincache/index.php on line 233


Those come from some cache plugin installed, that has been developed by osclass but i can't find it in Market.

The code in error is:

Code: [Select]
function cacheplugin_delete_item($id) {
                $ItemStorageFolder = osc_get_preference('item_storage_folder', 'cacheplugin') ;
        $PubbDate = $item['dt_pub_date'];
    $DatePubb = date_create($PubbDate);
    $cachePubbDate = date_format($DatePubb, $ItemStorageFolder);
             $IdItem = $item['pk_i_id'];
osc_goto_first_locale();
$locales = osc_get_locales();
foreach($locales as $locale){
      $files = rglob(osc_get_preference('upload_path', 'cacheplugin')."item/".$cachePubbDate."/".$locale['pk_c_code']."_".$IdItem.".html");
        foreach($files as $f) {
            @unlink($f);
        }
}
                $files = rglob(osc_get_preference('upload_path', 'cacheplugin')."main/*");
          foreach($files as $f) {
            @unlink($f);
            }
        }

Line 230 is: $PubbDate = $item['dt_pub_date'];


Line 233 is: $IdItem = $item['pk_i_id'];


Any help appreciated.


I m not quite sure if this will work but did you try to do something like that ?

Code: [Select]
$item="";
Let me know if it worked or not.

marius-ciclistu

  • issues
  • Hero Member
  • *
  • Posts: 1716
  • "BE GRATEFUL TO THOSE THAT SUPPORTED YOU"
Re: Help fixing some undefined variable notices
« Reply #2 on: August 31, 2019, 12:52:29 am »
UPDATE: Problem solved in 3.8

Notices and warnings are all over osclass:) just now I fixed some in mine and wanted to start a new topic, but since you did, here goes:

\ItemActions::checkSize
PHP Notice:  Undefined index: error in /oc-includes/osclass/ItemActions.php on line 1422
PHP Warning:  Invalid argument supplied for foreach() in /oc-includes/osclass/ItemActions.php on line 1422

\ItemActions::checkAllowedExt
PHP Notice:  Undefined index: error in /oc-includes/osclass/ItemActions.php on line 1382
PHP Warning:  Invalid argument supplied for foreach() in /oc-includes/osclass/ItemActions.php on line 1382

\ItemActions::uploadItemResources
PHP Notice:  Undefined index: error in /oc-includes/osclass/ItemActions.php on line 1463
PHP Warning:  Invalid argument supplied for foreach() in /oc-includes/osclass/ItemActions.php on line 1463

ItemActions.php


                                array_push($aMimesAllowed, $mime );
                            }
                        }
                    }
                }
                if (!isset($aResources['error'])) {
                    return $success;
                }
                foreach ($aResources['error'] as $key => $error) {
instead of
                                array_push($aMimesAllowed, $mime );
                            }
                        }
                    }
                }
                foreach ($aResources['error'] as $key => $error) {

--------------
                $maxSize = osc_max_size_kb() * 1024;
                if(!isset($aResources['error'])) {
                    return $success;
                }
                foreach ($aResources['error'] as $key => $error) {
instead of

                $maxSize = osc_max_size_kb() * 1024;
                foreach ($aResources['error'] as $key => $error) {

\ItemActions::uploadItemResources is called in 2 places after the first 2 are called so no need for changes there:)

I don't know how the error key was not there. I remember I has issues uploading images when these warnings appeared.
« Last Edit: September 01, 2019, 12:54:09 am by marius-ciclistu »

Dimal

  • Full Member
  • ***
  • Posts: 135
Re: Help fixing some undefined variable notices
« Reply #3 on: August 31, 2019, 12:58:59 am »
@marius-ciclistu What those fixes have to do with my notiices ?

have they ?

Mine come from a plugin.

As for those you mention, i don't have them. None of them. I run an almost stock 3.8 with several plugins and OsclassWizards theme.

I have seen that some notices/warnings appear in code of the core BUT come from other plugins or themes.


marius-ciclistu

  • issues
  • Hero Member
  • *
  • Posts: 1716
  • "BE GRATEFUL TO THOSE THAT SUPPORTED YOU"
Re: Help fixing some undefined variable notices
« Reply #4 on: August 31, 2019, 01:04:53 am »
I did not have them until today either:)
Your title is: Re: Help fixing some undefined variable notices so I thought it's ok to post here.
If it bothers you I can remove the message and put it in a separate post :)

Regarding your problem:
assuming $item is a global, it should work. If not, Then you must make $item = Item::newInstance()->findByPrimaryKey($id);

Code: [Select]
function cacheplugin_delete_item($id) {
                $ItemStorageFolder = osc_get_preference('item_storage_folder', 'cacheplugin') ;
        $PubbDate = $item['dt_pub_date'];
    $DatePubb = date_create($PubbDate);
    $cachePubbDate = date_format($DatePubb, $ItemStorageFolder);
             $IdItem = $item['pk_i_id'];
osc_goto_first_locale();
$locales = osc_get_locales();
foreach($locales as $locale){
      $files = rglob(osc_get_preference('upload_path', 'cacheplugin')."item/".$cachePubbDate."/".$locale['pk_c_code']."_".$IdItem.".html");
        foreach($files as $f) {
            @unlink($f);
        }
}
                $files = rglob(osc_get_preference('upload_path', 'cacheplugin')."main/*");
          foreach($files as $f) {
            @unlink($f);
            }
        }

Also $IdItem = $item['pk_i_id']; is nonsense as the Id is the function's parameter that is never used.
« Last Edit: August 31, 2019, 01:10:02 am by marius-ciclistu »

Dimal

  • Full Member
  • ***
  • Posts: 135
Re: Help fixing some undefined variable notices
« Reply #5 on: August 31, 2019, 01:15:13 am »
@marius-ciclistu

I have no idea about all that. Global or not, or whatever. You are talking to a non-programmer  ;D

Checking the index.php i see that it is:

/*
Plugin Name: Cache Plugin
Plugin URI: http://www.osclass.org/
Description: Cache system for OSClass, make your website load faster!
Version: 2.0.5
Author: OSClass
Author URI: http://www.osclass.org/
Short Name: cacheplugin
Plugin update URI: plugin-cache
*/

And i found it available after searching a bit better now at github:

https://github.com/PluginCache-osclass/plugincache


marius-ciclistu

  • issues
  • Hero Member
  • *
  • Posts: 1716
  • "BE GRATEFUL TO THOSE THAT SUPPORTED YOU"
Re: Help fixing some undefined variable notices from a plugin
« Reply #6 on: August 31, 2019, 01:22:04 am »
https://github.com/PluginCache-osclass/plugincache/blob/master/index.php

Your code is not from master branch. Copy the plugin's content from github.

I can't help more in plugins' regard( i see only problems with them, besides their purpose of generating revenue).

Dimal

  • Full Member
  • ***
  • Posts: 135
Re: Help fixing some undefined variable notices from a plugin
« Reply #7 on: August 31, 2019, 01:40:09 am »
Well i will remove that plugins. It seems old and not working well.

marius-ciclistu

  • issues
  • Hero Member
  • *
  • Posts: 1716
  • "BE GRATEFUL TO THOSE THAT SUPPORTED YOU"
Re: Help fixing some undefined variable notices from a plugin
« Reply #8 on: September 01, 2019, 12:34:38 am »
I made an update to https://forums.osclass.org/development/help-fixing-some-undefined-variable-notices/msg170364/#msg170364

just in case someone used that solution.
return $success instead of return false to allow users to publish ads without photos
.

Problem was solved in 3.8 with
Code: [Select]
if(!empty($aResources)) {
« Last Edit: September 01, 2019, 12:55:07 am by marius-ciclistu »