All Websites dashboard fails in php strict mode with error output "Array to string conversion" #2999

Closed
mattab opened this Issue Mar 2, 2012 · 2 comments

2 participants

@mattab
Piwik Open Source Analytics member

This was reported in the forums

Dorious submitted a patch to fix the problem, see below.
I'm still unsure what the problem is so hopefully we can replicate it and improve Dorious patch.

templates/sitedata.tpl


    {foreach from=$sitesData key=i item=site}
        allSites[{$i}] = new setRowData({$site.idsite}, {$site.visits}, {$site.actions}, {if empty($site.revenue)}0{else}{$site.revenue}{/if}, '{$site.name|escape:"javascript"}', '{$site.main_url|escape:"javascript"}', '{if isset($site.visits_evolution)}{$site.visits_evolution|replace:",":"."}{/if}', '{if isset($site.actions_evolution)}{$site.actions_evolution|replace:",":"."}{/if}', '{if isset($site.revenue_evolution)}{$site.revenue_evolution|replace:",":"."}{/if}');
    {/foreach}
</script>
<script type="text/javascript">
prepareRows(allSites, params, '{$orderBy}');

{if $autoRefreshTodayReport}
piwikHelper.refreshAfter({$autoRefreshTodayReport} *1000);
{/if}
</script>

</body>
</html>


Index: Controller.php

===================================================================

--- Controller.php  (revision 5891)

+++ Controller.php  (working copy)

@@ -48,6 +48,7 @@

        $piwikDefaultTimezone = Piwik_SitesManager_API::getInstance()->getDefaultTimezone();
        $dateRequest = Piwik_Common::getRequestVar('date', 'today');
        $period = Piwik_Common::getRequestVar('period', 'day'); 
+                $idSite = Piwik_Common::getRequestVar('idSite', false);
        $date = $dateRequest;
        if($period != 'range')
        {
@@ -63,14 +64,28 @@


        // put data into a form the template will understand better
        $digestableData = array();
+                
+                // iLoop Optimization
+                $implodedSiteIds = implode(',', $siteIds);
+                $sitesInfo = Piwik_FetchAll("SELECT idsite, name, main_url FROM ". Piwik_Common::prefixTable('site')." WHERE idsite IN (".$implodedSiteIds.")");
+                $sitesInfoArray = array();
+
+                foreach($sitesInfo as $site) {
+                    $sitesInfoArray[ $site['idsite'] ] = $site;
+                }
+                destroy($sitesInfo);
+                
        foreach($siteIds as $idSite)
        {
            $isEcommerceEnabled = Piwik_Site::isEcommerceEnabledFor($idSite);

            $digestableData[$idSite] = array(
                'idsite' => $idSite,
-               'main_url' => Piwik_Site::getMainUrlFor($idSite),
-               'name' => Piwik_Site::getNameFor($idSite),
+                                // iLoop Optimization
+               //'main_url' => Piwik_Site::getMainUrlFor($idSite),
+               //'name' => Piwik_Site::getNameFor($idSite),
+                                'main_url' => isset( $sitesInfoArray[$idSite] ) ? $sitesInfoArray[$idSite]['main_url'] : "Unknown URL",
+                                'name' => isset( $sitesInfoArray[$idSite] ) ? $sitesInfoArray[$idSite]['name'] : "Unknown",
                'visits' => 0,
                'actions' => 0
            );
@@ -91,6 +106,7 @@

                }
            }
        }
+                destroy($sitesInfoArray);

        foreach($dataTable->getRows() as $row)
        {
@@ -126,20 +142,22 @@

        }

        $this->applyPrettyMoney($digestableData);
-
+                
        $view = new Piwik_View("MultiSites/templates/index.tpl");
-       $view->sitesData = array_values($digestableData);
+                $view2 = new Piwik_View("MultiSites/templates/sitedata.tpl");
+                $view2->sitesData = array_values($digestableData);
        $view->evolutionBy = $this->evolutionBy;
        $view->period = $period;
        $view->dateRequest = $dateRequest;
        $view->page = $this->page;
        $view->limit = $this->limit;
-       $view->orderBy = $this->orderBy;
+       $view->orderBy = $view2->orderBy = $this->orderBy;
        $view->order = $this->order;
        $view->totalVisits = $totalVisits;
        $view->totalRevenue = $totalRevenue;
        $view->displayRevenueColumn = $displayRevenueColumn;
        $view->totalActions = $totalActions;
+                $view->idSite = $idSite;

        $params = $this->getGraphParamsModified();
        $view->dateSparkline = $period == 'range' ? $dateRequest : $params['date'];
@@ -152,7 +170,7 @@

                                            Piwik_Date::factory('now', 'UTC+14')->toString('Y-m-d'))))
        {

-           $view->autoRefreshTodayReport = Zend_Registry::get('config')->General->multisites_refresh_after_seconds;
+           $view2->autoRefreshTodayReport = Zend_Registry::get('config')->General->multisites_refresh_after_seconds;
        }
        $this->setGeneralVariablesView($view);
        $this->setMinDateView($minDate, $view);
@@ -160,6 +178,7 @@

        $view->show_sparklines = Zend_Registry::get('config')->General->show_multisites_sparklines;

        echo $view->render();
+                echo '<script>'.$view2->render();
    }

    /**
Index: templates/index.tpl

===================================================================

--- templates/index.tpl (revision 5891)

+++ templates/index.tpl (working copy)

@@ -7,15 +7,12 @@

 <script type="text/javascript">
    var allSites = new Array();
    var params = new Array();
-   {foreach from=$sitesData key=i item=site}
-       allSites[{$i}] = new setRowData({$site.idsite}, {$site.visits}, {$site.actions}, {if empty($site.revenue)}0{else}{$site.revenue}{/if}, '{$site.name|escape:"javascript"}', '{$site.main_url|escape:"javascript"}', '{if isset($site.visits_evolution)}{$site.visits_evolution|replace:",":"."}{/if}', '{if isset($site.actions_evolution)}{$site.actions_evolution|replace:",":"."}{/if}', '{if isset($site.revenue_evolution)}{$site.revenue_evolution|replace:",":"."}{/if}');
-   {/foreach}
    params['period'] = '{$period}';
    params['date'] = '{$dateRequest}';
    params['evolutionBy'] = '{$evolutionBy}';
    params['mOrderBy'] = '{$orderBy}';
    params['order'] = '{$order}';
-   params['site'] = '{$site}';
+   params['site'] = '{$idSite}';
    params['limit'] = '{$limit}';
    params['page'] = 1;
    params['prev'] = "{'General_Previous'|translate|escape:"javascript"}";
@@ -75,11 +72,11 @@


    <tfoot>
    {if $isSuperUser}
-   <tr>
+   {* <tr>
        <td colspan="8" class="clean" style="text-align: right; padding-top: 15px;padding-right:10px">
            <a href="{url}&module=SitesManager&action=index&showaddsite=1"><img src='plugins/UsersManager/images/add.png' alt="" style="margin: 0;" /> {'SitesManager_AddSite'|translate}</a>
        </td>
-   </tr>
+   </tr> *}
    {/if}
    <tr row_id="last" >
        <td colspan="8" class="clean" style="padding: 20px">
@@ -94,18 +91,10 @@

    </tfoot>
 </table>
 </div>
-<script type="text/javascript">
-prepareRows(allSites, params, '{$orderBy}');
-
-{if $autoRefreshTodayReport}
-piwikHelper.refreshAfter({$autoRefreshTodayReport} *1000);
-{/if}
-</script>
 </div>
 </div>

 {include file="CoreHome/templates/piwik_tag.tpl"}

 </div>
-</body>
-</html>
+


@mattab
Piwik Open Source Analytics member

(In [6066]) Refs #2999 Fixing Notice which could have caused this bug?

    Notice:&lt;/strong> &lt;i>Array to string conversion&lt;/i> in &lt;b>/var/www/piwik/tmp/templates_c/%%9A^9A3^9A34FA06%%index.tpl.php&lt;/b> on line &lt;b>49&lt;/b>
@mattab mattab added this to the 1.12.x - Piwik 1.12.x milestone Jul 8, 2014
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment