Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Actions plugin: cannot use object of type Piwik_DataTable_Row as array #1082

Closed
robocoder opened this Issue · 36 comments

3 participants

Anthon Pang Anonymous Piwik user Matthieu Aubry
Anthon Pang
Collaborator

http://forum.piwik.org/index.php?showtopic=2971&view=findpost&p=10951

IchBins reports:

PHP Fatal error: Cannot use object of type Piwik_DataTable_Row as array in /..../id/piwik/plugins/Actions/Actions.php on line 380
Matthieu Aubry
Owner

(In [1721]) Refs #1082 Fixes error Actions plugin: cannot use object of type Piwik_DataTable_Row as array

Anonymous Piwik user

I have still this problem witch newer version:

/www/piwik/misc/cron/archive.sh

Fatal error: Cannot use object of type Piwik_DataTable_Row as array in /www/piwik/plugins/Actions/Actions.php on line 385

Anonymous Piwik user

I added some test lines:

                       // currentTable is now the array element corresponding the the action
                        // at this point we may be for example at the 4th level of depth in the hierarchy
                        try {
                                if(!is_object($currentTable[$actionName]))
                                        throw new Exception('not object: '.var_export($currentTable[$actionName],true));
                                else
                                        $currentTable =& $currentTable[$actionName];
                        } catch (Exception $e) {
                                echo 'Caught exception: ',  $e->getMessage(), "\n";
                        }

And script return:

# /www/piwik/misc/cron/archive.sh 
Caught exception: not object: NULL

Fatal error: Cannot use object of type Piwik_DataTable_Row as array in /www/piwik/plugins/Actions/Actions.php on line 387
Anonymous Piwik user

Ok, We find solutions, here is patch:

--- plugins/Actions/Actions.php      2009-12-17 19:15:00.000000000 +0100
+++ plugins/Actions/Actions.php   2009-12-30 18:54:30.000000000 +0100
@@ -364,7 +364,10 @@
                        for($level = 0 ; $level < $end; $level++)
                        {
                                $actionCategory = $actionExplodedNames[$level];
-                               $currentTable =& $currentTable[$actionCategory];
+                               if(is_array($currentTable))
+                               {
+                                       $currentTable =& $currentTable[$actionCategory];
+                               }
                        }
                        $actionName = $actionExplodedNames[$end];

@@ -382,9 +385,11 @@

                        // currentTable is now the array element corresponding the the action
                        // at this point we may be for example at the 4th level of depth in the hierarchy
-                       $currentTable =& $currentTable[$actionName];
-
-                       // add the row to the matching sub category subtable
+                       if(is_array($currentTable))
+                       {
+                               $currentTable =& $currentTable[$actionName];
+                       }
+
                        if(!($currentTable instanceof Piwik_DataTable_Row))
                        {
                                if( $row['type'] == Piwik_Tracker_Action::TYPE_ACTION_NAME )

Anthon Pang
Collaborator

That should catch the bad data not handled by [1372]. However, we still need to determine the root cause for the bad data.

Anthon Pang
Collaborator

(In [1754]) refs #1082 - catch other cases of bad data

Anthon Pang
Collaborator

(In [refs #1082, revert 1754) per matt's review

Matthieu Aubry
Owner

Dear users, do you still experience the issue in 0.5.4?

Matthieu Aubry
Owner

problem still exists in 0.5.4, problem is that I wasn't able to replicate it yet.

Anonymous Piwik user

suddenly, since two days, I got the same issue on archiving:
www/misc/cron/archive.sh

Fatal error: Cannot use object of type Piwik_DataTable_Row as array in /home/myphorum/tracking-host/www/plugins/Actions/Actions.php on line 385

Fatal error: Cannot use object of type Piwik_DataTable_Row as array in /home/myphorum/tracking-host/www/plugins/Actions/Actions.php on line 385

Fatal error: Cannot use object of type Piwik_DataTable_Row as array in /home/myphorum/tracking-host/www/plugins/Actions/Actions.php on line 385

No more stats updates with that :-/ on 0.5.4.
Any quick fix?

Anonymous Piwik user

Also suddenly since January 16th I get the error
Fatal error: Cannot use object of type Piwik_DataTable_Row as array in .../piwik/plugins/Actions/Actions.php on line 367

It appears on archiving and only on the site with the 1st id on

  • Last visits graph,
  • Visitors --> Overview, Frequency & Loyalty
  • Referers --> Evolution
  • Goals
  • MultiSites for every date since January 16th.

The error occurs on Actions only when the date is set to January 16th. There is no error on January 17th.

I copied the database to another server and there is the same mistake. So there were written wrong information into the database on January 16th?

Anonymous Piwik user

deactivating and reactivating "actions" in "Plugins Management" panel fixed this error at my site.

Anonymous Piwik user

That didn't help for me.
But enclosing the line in an !is_object condition helped for me ...

                        // currentTable is now the array element corresponding the the action
                        // at this point we may be for example at the 4th level of depth in the hierarchy
                        if(!is_object($currentTable)) {
                            $currentTable =& $currentTable[$actionName];
                        }
Anonymous Piwik user

Its a little strange. Deactivated and reactivated the actions plugin some days ago on my testserver with the copied data and it didnt work. After doing this today, it works excepting that there is 'no data for this table' in the action plugin on January 16th.

Matthieu Aubry
Owner

users who experience the issue, can you please apply the modifications in: http://forum.piwik.org/index.php?s=&showtopic=2971&view=findpost&p=13161

and attach the output error message to this ticket? this will help me find how to replicate and fix it. thanks

Anonymous Piwik user

@ts77: That didn't work for me.

@matt:

 array(1) { ["sixcms"]=>  &NULL } NULL array(2) { [0]=>  string(6) "sixcms" [1]=>  string(36) "detail.php?id=2826&_nav_id1=2591" } string(1) "1" 

After de- and reactivating the action plugin (it worked fine excepting actions on Jan 16th) I deleted the two tables archive_blob_2010_01 and archive_numeric_2010_01 and the error appeared again. The error disappeared after I de- and reactivated the action plugin again.

Anonymous Piwik user

Finally got that issue again.
I'll try to attach the resulting file as a gzipped log (305kB extracted).

Let me know how to continue here as my stats are down until I remove the "die" ;).

Anonymous Piwik user

I've this problem too.
@piwik team: do you fix it in 0.5.5?

Anonymous Piwik user

I might be mad for it, but, ... any update?

Anonymous Piwik user

Spontaneously the error occured again yesterday. Hope that deactivating and activating the action plugin fixed it...

Anonymous Piwik user

Yesterday the error again. This case should be cleared as fast as possible, because

  • the error appears without changing the system in smaller intervals
  • the error appears at many users
  • the importants thing: there is "no data" for the page views of the "error days"!!
Anonymous Piwik user

and now that the later one (in line 385) is "handled" or better just ignored I got a similar one some lines up:
Fatal error: Cannot use object of type Piwik_DataTable_Row as array in [...]www/plugins/Actions/Actions.php on line 367

Anonymous Piwik user

Meanwhile error 367 appears almost every day. After deactivating the action-plugin, executing the archive.sh and activating the action-plugin it works. Problem is, that there is 'no data' in the action-plugin but not only for the site with id=1 but also for all other sites! The problem should be immediately solved.

Can I help you localize the mistake? Is there a difference between the workaround-order?
1. deactivating the action-plugin > executing the archive.sh > activating the action-plugin
2. deactivating the action-plugin > activating the action-plugin > executing the archive.sh
Because some weeks ago the 'no data' problem corresponded only to the site with id=1 and now to all sites.

Anonymous Piwik user

maze, I agree and was about to post the same.
But the solution in #1082 did the trick for me.
Did you try that too?

Anonymous Piwik user

Yes, that patch works. (Thank you ts77, don't know why I haven't tried this before.)

But the error is only masked with that patch. We analyse our websites so that we display the page views in a hierarchical order. On these days where the 'error appears' only the first hierarchy is displayed. It's better than the error message before - but not perfect, because for our analysis we need every part of our page views displayed in the hierarchy. And the former days where the error appeared are still display 'no data'...

Matthieu Aubry
Owner

(In [1898]) Refs #1082
Fixes the "cannot use object of type Piwik_DataTable_Row as array" error.
The error happens when two outlinks with the same name, one being a URL, the other one being a plain name, are seen in the same day. eg. http://string/ and string. Fixed issue by prepending a space to make these two different (same trick already used for pages and categories with similar name).

Matthieu Aubry
Owner

Hello Guys,
can you please try the patch in: http://dev.piwik.org/trac/changeset/1898 and report here if the patch fixes the issue for you? thanks!

Anthon Pang
Collaborator

Good catch, Matt!

Anonymous Piwik user

Hey Matt, thank you for your help. Just patched the file. Now I have to wait and see if the error occurs in the next days.

I still have the problem that, on the days where the error occured before, I have 'no data' or no hierarchical order. Would it be helpful to delete the archiving-tables for the mentioned days and run archiving.sh again?

Anonymous Piwik user

I had the same Error Message. Examining the Data turn out that there are 3 Different scenarios where it happens
URL
http:///www.cnn.com => http://www.cnn.com
http://http://www.cnn.com => http://www.cnn.com
http:/www.cnn.com => http://www.cnn.com

So i changed the File piwik/plugins/Actions/Actions.php
Function : updateActionsTableWithRowQuery


    protected function updateActionsTableWithRowQuery($query)
    {
        $rowsProcessed = 0;
        while( $row = $query->fetch() )
        {
            // in some unknown case, the type field is NULL, as reported in #1082 - we ignore this page view
            if(empty($row['type'])) {
                continue;
            }

            // change urls like http:///www.cnn.com => http://www.cnn.com
            $row['name']=str_replace("///","//",$row['name']);
            // change urls like http://http://www.cnn.com => http://www.cnn.com
            $row['name']=str_replace("http://http://","http://",$row['name']);
            // change urls like http:/www.cnn.com => http://www.cnn.com
            if( strpos($row['name'], "http://" ) === FALSE){
                $row['name']=str_replace("http:/","http://",$row['name']);
            }

            $actionExplodedNames = $this->getActionExplodedNames($row['name'], $row['type']);

            // we work on the root table of the given TYPE (either ACTION_URL or DOWNLOAD or OUTLINK etc.)
            $currentTable =& $this->actionsTablesByType[$row['type']];
            // go to the level of the subcategory
            $end = count($actionExplodedNames)-1;
            for($level = 0 ; $level < $end; $level++)
            {
                $actionCategory = $actionExplodedNames[$level];
                $currentTable =& $currentTable[$actionCategory];
            }
            $actionName = $actionExplodedNames[$end];

            // we are careful to prefix the page URL / name with some value
            // so that if a page has the same name as a category 
            // we don't merge both entries 
            if($row['type'] == Piwik_Tracker_Action::TYPE_ACTION_URL )
            {
                $actionName = '/' . $actionName;
            }
            else if( $row['type'] == Piwik_Tracker_Action::TYPE_ACTION_NAME )
            {
                $actionName = ' ' . $actionName;
            }

            // currentTable is now the array element corresponding the the action
            // at this point we may be for example at the 4th level of depth in the hierarchy
            $currentTable =& $currentTable[$actionName];

            // add the row to the matching sub category subtable
            if(!($currentTable instanceof Piwik_DataTable_Row))
            {
                if( $row['type'] == Piwik_Tracker_Action::TYPE_ACTION_NAME )
                {
                    $currentTable = new Piwik_DataTable_Row(array(
                            Piwik_DataTable_Row::COLUMNS => array('label' => (string)$actionName),
                        )); 
                }
                else
                {
                    $currentTable = new Piwik_DataTable_Row(array(
                            Piwik_DataTable_Row::COLUMNS => array('label' => (string)$actionName),
                            Piwik_DataTable_Row::METADATA => array('url' => (string)$row['name']),
                        ));
                }
            }

            foreach($row as $name => $value)
            {
                // we don't add this information as itnot pertinent
                // name is already set as the label // and it has been cleaned from the categories and extracted from the initial string
                // type is used to partition the different actions type in different table. Adding the info to the row would be a duplicate. 
                if($name != 'name' 
                    && $name != 'type')
                {
                    // in some edge cases, we have twice the same action name with 2 different idaction
                    // this happens when 2 visitors visit the same new page at the same time, there is a SELECT and an INSERT for each new page, 
                    // and in between the two the other visitor comes. 
                    // here we handle the case where there is already a row for this action name, if this is the case we add the value
                    if(($alreadyValue = $currentTable->getColumn($name)) !== false)
                    {
                        $currentTable->setColumn($name, $alreadyValue+$value);
                    }
                    else
                    {
                        $currentTable->addColumn($name, $value);
                    }
                }
            }

            // if the exit_action was not recorded properly in the log_link_visit_action
            // there would be an error message when getting the nb_hits column
            // we must fake the record and add the columns
            if($currentTable->getColumn('nb_hits') === false)
            {
                // to test this code: delete the entries in log_link_action_visit for
                //  a given exit_idaction_url
                foreach($this->defaultRow->getColumns() as $name => $value)
                {
                    $currentTable->addColumn($name, $value);
                }
            }
            // simple count 
            $rowsProcessed++;
        }

        // just to make sure php copies the last $currentTable in the $parentTable array
        $currentTable =& $this->actionsTablesByType;
        return $rowsProcessed;
    }


This fixed the Problem for me.
Regards
Nifty

Matthieu Aubry
Owner

Nifty, instead of your patch, can you try the official patch in http://dev.piwik.org/trac/changeset/1898 ? This is the one that will make it in 0.5.5 if I don't hear from more users... thanks

Anonymous Piwik user

Matt,
Your code will not resolve my problems - if i read it correctly.

This are the changes i had to implement to get it up and running.


            // change urls like http:///www.cnn.com => http://www.cnn.com
            $row['name']=str_replace("///","//",$row['name']);
            // change urls like http://http://www.cnn.com => http://www.cnn.com
            $row['name']=str_replace("http://http://","http://",$row['name']);
            // change urls like http:/www.cnn.com => http://www.cnn.com
            if( strpos($row['name'], "http://" ) === FALSE){
                $row['name']=str_replace("http:/","http://",$row['name']);
            }

Matthieu Aubry
Owner

Nifty, could you try the patch? It might not work, in that case I will work on it more, but I need to know, thx (your solution is not desirable as it deals with special cases and we need to solve this problem in a more generic way)

Anonymous Piwik user

Hey matt, three days without an error. Your patch seems to work! :)

Matthieu Aubry
Owner

Closing for now.. if anyone still experiences issues after applying the patch in [1898] please let us know

Anthon Pang robocoder added this to the Piwik 0.5.5 milestone
Matthieu Aubry mattab was assigned by robocoder
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.