Opened 4 years ago

Closed 4 years ago

#1082 closed Bug (fixed)

Actions plugin: cannot use object of type Piwik_DataTable_Row as array

Reported by: vipsoft Owned by: matt
Priority: critical Milestone: Piwik 0.5.5
Component: Core Keywords:
Cc: Sensitive: no

Description

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

Attachments (1)

archive-output.txt.gz (26.1 KB) - added by ts77 4 years ago.

Download all attachments as: .zip

Change History (38)

comment:1 Changed 4 years ago by matt (mattab)

  • Priority changed from major to critical

comment:2 Changed 4 years ago by matt (mattab)

  • Owner set to matt

comment:3 Changed 4 years ago by matt (mattab)

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

comment:4 Changed 4 years ago by virus

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

comment:5 Changed 4 years ago by virus

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

comment:6 Changed 4 years ago by virus

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 )

comment:7 Changed 4 years ago by vipsoft (robocoder)

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

comment:8 Changed 4 years ago by vipsoft (robocoder)

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

comment:9 Changed 4 years ago by vipsoft (robocoder)

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

comment:10 Changed 4 years ago by matt (mattab)

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

comment:11 Changed 4 years ago by matt (mattab)

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

comment:12 Changed 4 years ago by ts77

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?

comment:13 Changed 4 years ago by maze

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?

comment:14 Changed 4 years ago by thilo

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

comment:15 Changed 4 years ago by ts77

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];
                        }

comment:16 Changed 4 years ago by maze

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.

comment:17 Changed 4 years ago by matt (mattab)

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

comment:18 Changed 4 years ago by maze

@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.

comment:19 Changed 4 years ago by ts77

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" ;).

Changed 4 years ago by ts77

comment:20 Changed 4 years ago by Kevin Häfeli

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

comment:21 Changed 4 years ago by ts77

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

comment:22 Changed 4 years ago by maze

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

comment:23 Changed 4 years ago by maze

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"!!

comment:24 Changed 4 years ago by ts77

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

comment:25 Changed 4 years ago by maze

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.

comment:26 Changed 4 years ago by ts77

maze, I agree and was about to post the same.
But the solution in http://dev.piwik.org/trac/ticket/1082#comment:6 did the trick for me.
Did you try that too?

comment:27 Changed 4 years ago by maze

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'...

comment:28 Changed 4 years ago by matt (mattab)

(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).

comment:29 Changed 4 years ago by matt (mattab)

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!

comment:30 Changed 4 years ago by vipsoft (robocoder)

Good catch, Matt!

comment:31 Changed 4 years ago by maze

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?

comment:32 Changed 4 years ago by Nifty

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

comment:33 Changed 4 years ago by matt (mattab)

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

comment:34 Changed 4 years ago by Nifty

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']);
			}

comment:35 Changed 4 years ago by matt (mattab)

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)

comment:36 Changed 4 years ago by maze

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

comment:37 Changed 4 years ago by matt (mattab)

  • Resolution set to fixed
  • Status changed from new to closed

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

Note: See TracTickets for help on using tickets.