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

    #0 Piwik\Error::errorHandler(...) called at [/srv/app/piwik-2.8.3_RELEASE_2014-11-03_03.05.42.605263/core/DataArray.php:102]
    #1 Piwik\DataArray->doSumVisitsMetrics(...) called at [/srv/app/piwik-2.8.3_RELEASE_2014-11-03_03.05.42.605263/core/DataArray.php:307]
    #2 Piwik\DataArray->sumMetricsActionsPivot(...) called at [/srv/app/piwik-2.8.3_RELEASE_2014-11-03_03.05.42.605263/plugins/CustomVariables/Archiver.php:177]
    #3 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]
    #4 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]
    #5 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]
    #6 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]
    #7 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]
    #8 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]
    #9 Piwik\ArchiveProcessor\Loader->prepareArchive(...) called at [/srv/app/piwik-2.8.3_RELEASE_2014-11-03_03.05.42.605263/core/Archive.php:801]
    #10 Piwik\Archive->prepareArchive(...) called at [/srv/app/piwik-2.8.3_RELEASE_2014-11-03_03.05.42.605263/core/Archive.php:614]
    #11 Piwik\Archive->cacheArchiveIdsAfterLaunching(...) called at [/srv/app/piwik-2.8.3_RELEASE_2014-11-03_03.05.42.605263/core/Archive.php:568]
    #12 Piwik\Archive->getArchiveIds(...) called at [/srv/app/piwik-2.8.3_RELEASE_2014-11-03_03.05.42.605263/core/Archive.php:508]
    #13 Piwik\Archive->get(...) called at [/srv/app/piwik-2.8.3_RELEASE_2014-11-03_03.05.42.605263/core/Archive.php:348]
    #14 Piwik\Archive->getDataTableFromNumeric(...) called at [/srv/app/piwik-2.8.3_RELEASE_2014-11-03_03.05.42.605263/plugins/VisitsSummary/API.php:59]
    #15 Piwik\Plugins\VisitsSummary\API->get(...) called at [:]
    #16 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]
    #17 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]
    #18 Piwik\Plugins\API\API->get(...) called at [:]
    #19 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]
    #20 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]
    #21 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]
    #22 Piwik\Plugins\API\Controller->index(...) called at [:]
    #23 call_user_func_array(...) called at [/srv/app/piwik-2.8.3_RELEASE_2014-11-03_03.05.42.605263/core/FrontController.php:587]
    #24 Piwik\FrontController->doDispatch(...) called at [/srv/app/piwik-2.8.3_RELEASE_2014-11-03_03.05.42.605263/core/FrontController.php:95]
    #25 Piwik\FrontController->dispatch(...) called at [/srv/app/piwik-2.8.3_RELEASE_2014-11-03_03.05.42.605263/core/dispatch.php:34]
    #26 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