@elpollodiablo opened this Issue on November 5th 2014

I got an error today after adding Custom Variables and upgrading to Piwik 2.8.3 (although I think the variables and upgrade themselves may be unrelated and it was just some MySQL corruption):

    Notice: Undefined offset: 2 in /srv/app/piwik-2.8.3_RELEASE_2014-11-03_03.05.42.605263/core/DataArray.php on line 102 

    Backtrace -->

    <a href='/0'>#0</a> Piwik\Error::errorHandler(...) called at [/srv/app/piwik-2.8.3_RELEASE_2014-11-03_03.05.42.605263/core/DataArray.php:102]
    <a href='/1'>#1</a> Piwik\DataArray->doSumVisitsMetrics(...) called at [/srv/app/piwik-2.8.3_RELEASE_2014-11-03_03.05.42.605263/core/DataArray.php:307]
    <a href='/2'>#2</a> Piwik\DataArray->sumMetricsActionsPivot(...) called at [/srv/app/piwik-2.8.3_RELEASE_2014-11-03_03.05.42.605263/plugins/CustomVariables/Archiver.php:177]
    <a href='/3'>#3</a> Piwik\Plugins\CustomVariables\Archiver->aggregateActionByKeyAndValue(...) called at [/srv/app/piwik-2.8.3_RELEASE_2014-11-03_03.05.42.605263/plugins/CustomVariables/Archiver.php:135]
    <a href='/4'>#4</a> Piwik\Plugins\CustomVariables\Archiver->aggregateFromActions(...) called at [/srv/app/piwik-2.8.3_RELEASE_2014-11-03_03.05.42.605263/plugins/CustomVariables/Archiver.php:96]
    <a href='/5'>#5</a> Piwik\Plugins\CustomVariables\Archiver->aggregateCustomVariable(...) called at [/srv/app/piwik-2.8.3_RELEASE_2014-11-03_03.05.42.605263/plugins/CustomVariables/Archiver.php:64]
    <a href='/6'>#6</a> Piwik\Plugins\CustomVariables\Archiver->aggregateDayReport(...) called at [/srv/app/piwik-2.8.3_RELEASE_2014-11-03_03.05.42.605263/core/ArchiveProcessor/PluginsArchiver.php:100]
    <a href='/7'>#7</a> Piwik\ArchiveProcessor\PluginsArchiver->callAggregateAllPlugins(...) called at [/srv/app/piwik-2.8.3_RELEASE_2014-11-03_03.05.42.605263/core/ArchiveProcessor/Loader.php:122]
    <a href='/8'>#8</a> Piwik\ArchiveProcessor\Loader->prepareAllPluginsArchive(...) called at [/srv/app/piwik-2.8.3_RELEASE_2014-11-03_03.05.42.605263/core/ArchiveProcessor/Loader.php:72]
    <a href='/9'>#9</a> Piwik\ArchiveProcessor\Loader->prepareArchive(...) called at [/srv/app/piwik-2.8.3_RELEASE_2014-11-03_03.05.42.605263/core/Archive.php:801]
    <a href='/10'>#10</a> Piwik\Archive->prepareArchive(...) called at [/srv/app/piwik-2.8.3_RELEASE_2014-11-03_03.05.42.605263/core/Archive.php:614]
    <a href='/11'>#11</a> Piwik\Archive->cacheArchiveIdsAfterLaunching(...) called at [/srv/app/piwik-2.8.3_RELEASE_2014-11-03_03.05.42.605263/core/Archive.php:568]
    <a href='/12'>#12</a> Piwik\Archive->getArchiveIds(...) called at [/srv/app/piwik-2.8.3_RELEASE_2014-11-03_03.05.42.605263/core/Archive.php:508]
    <a href='/13'>#13</a> Piwik\Archive->get(...) called at [/srv/app/piwik-2.8.3_RELEASE_2014-11-03_03.05.42.605263/core/Archive.php:348]
    <a href='/14'>#14</a> Piwik\Archive->getDataTableFromNumeric(...) called at [/srv/app/piwik-2.8.3_RELEASE_2014-11-03_03.05.42.605263/plugins/VisitsSummary/API.php:59]
    <a href='/15'>#15</a> Piwik\Plugins\VisitsSummary\API->get(...) called at [:]
    <a href='/16'>#16</a> call_user_func_array(...) called at [/srv/app/piwik-2.8.3_RELEASE_2014-11-03_03.05.42.605263/core/API/Proxy.php:211]
    <a href='/17'>#17</a> Piwik\API\Proxy->call(...) called at [/srv/app/piwik-2.8.3_RELEASE_2014-11-03_03.05.42.605263/plugins/API/API.php:403]
    <a href='/18'>#18</a> Piwik\Plugins\API\API->get(...) called at [:]
    <a href='/19'>#19</a> call_user_func_array(...) called at [/srv/app/piwik-2.8.3_RELEASE_2014-11-03_03.05.42.605263/core/API/Proxy.php:211]
    <a href='/20'>#20</a> Piwik\API\Proxy->call(...) called at [/srv/app/piwik-2.8.3_RELEASE_2014-11-03_03.05.42.605263/core/API/Request.php:216]
    <a href='/21'>#21</a> Piwik\API\Request->process(...) called at [/srv/app/piwik-2.8.3_RELEASE_2014-11-03_03.05.42.605263/plugins/API/Controller.php:33]
    <a href='/22'>#22</a> Piwik\Plugins\API\Controller->index(...) called at [:]
    <a href='/23'>#23</a> call_user_func_array(...) called at [/srv/app/piwik-2.8.3_RELEASE_2014-11-03_03.05.42.605263/core/FrontController.php:587]
    <a href='/24'>#24</a> Piwik\FrontController->doDispatch(...) called at [/srv/app/piwik-2.8.3_RELEASE_2014-11-03_03.05.42.605263/core/FrontController.php:95]
    <a href='/25'>#25</a> Piwik\FrontController->dispatch(...) called at [/srv/app/piwik-2.8.3_RELEASE_2014-11-03_03.05.42.605263/core/dispatch.php:34]
    <a href='/26'>#26</a> require_once(...) called at [/srv/app/piwik-2.8.3_RELEASE_2014-11-03_03.05.42.605263/index.php:46]

I got three of those errors, one for each of these lines:

    $oldRowToUpdate[Metrics::INDEX_NB_VISITS] += $newRowToAdd[Metrics::INDEX_NB_VISITS];
    $oldRowToUpdate[Metrics::INDEX_NB_ACTIONS] += $newRowToAdd[Metrics::INDEX_NB_ACTIONS];
    $oldRowToUpdate[Metrics::INDEX_NB_UNIQ_VISITORS] += $newRowToAdd[Metrics::INDEX_NB_UNIQ_VISITORS];

after a bit of futzing around, I got the two relevant rows in question:

    Array
    (
        [10] => Array
            (
                [3] => Array
                    (
                        [1] => 15
                        [3] => 1
                        [2] => 0
                   )

            )

    )

    Array
    (
        [custom_var_k8] => fo
        [custom_var_v8] => 346
        [2] => 3
        [1] => 3
        [3] => 4
    )

Since my php-fu isn't sufficient to really debug this, I put a clumsy hotfix in, and let the issue be:

    if (!array_key_exists (Metrics::INDEX_NB_VISITS, $oldRowToUpdate) || !array_key_exists(Metrics::INDEX_NB_VISITS, $newRowToAdd) ||
            !array_key_exists (Metrics::INDEX_NB_ACTIONS, $oldRowToUpdate) || !array_key_exists(Metrics::INDEX_NB_ACTIONS, $newRowToAdd) ||
            !array_key_exists (Metrics::INDEX_NB_UNIQ_VISITORS, $oldRowToUpdate) || !array_key_exists(Metrics::INDEX_NB_UNIQ_VISITORS, $newRowToAdd)) {
            // log
    } else {
            $oldRowToUpdate[Metrics::INDEX_NB_VISITS] += $newRowToAdd[Metrics::INDEX_NB_VISITS];
            $oldRowToUpdate[Metrics::INDEX_NB_ACTIONS] += $newRowToAdd[Metrics::INDEX_NB_ACTIONS];
            $oldRowToUpdate[Metrics::INDEX_NB_UNIQ_VISITORS] += $newRowToAdd[Metrics::INDEX_NB_UNIQ_VISITORS];
    }
This Issue was closed on November 15th 2014
Powered by GitHub Issue Mirror