After update to 2.14.0 - PHP API fatal error


#1

Hello,
After update Piwik to version 2.14.0 stopped working PHP API.

Piwik only returns the error:


Fatal error: Uncaught exception 'Piwik\Container\ContainerDoesNotExistException' with message 'The root container has not been created yet.' in /data/web/virtuals/63604/virtual/www/piwik/core/Container/StaticContainer.php:40 Stack trace: #0 /data/web/virtuals/63604/virtual/www/piwik/core/Container/StaticContainer.php(80): Piwik\Container\StaticContainer::getContainer() #1 /data/web/virtuals/63604/virtual/www/piwik/core/FrontController.php(206): Piwik\Container\StaticContainer::get('path.tmp') #2 /data/web/virtuals/63604/virtual/www/admin/testy/piwik.php(16): Piwik\FrontController->init() #3 {main} thrown in /data/web/virtuals/63604/virtual/www/piwik/core/Container/StaticContainer.php on line 40

Fatal error: Uncaught exception 'Piwik\Container\ContainerDoesNotExistException' with message 'The root container has not been created yet.' in /data/web/virtuals/63604/virtual/www/piwik/core/Container/StaticContainer.php:40 Stack trace: #0 /data/web/virtuals/63604/virtual/www/piwik/core/Container/StaticContainer.php(80): Piwik\Container\StaticContainer::getContainer() #1 /data/web/virtuals/63604/virtual/www/piwik/core/Config.php(62): Piwik\Container\StaticContainer::get('Piwik\\Config') #2 /data/web/virtuals/63604/virtual/www/piwik/core/Url.php(347): Piwik\Config::getInstance() #3 /data/web/virtuals/63604/virtual/www/piwik/core/Url.php(67): Piwik\Url::getCurrentHost() #4 /data/web/virtuals/63604/virtual/www/piwik/core/FrontController.php(87): Piwik\Url::getCurrentUrl() #5 /data/web/virtuals/63604/virtual/www/piwik/core/FrontController.php(181): Piwik\FrontController->dispatch('CorePluginsAdmi...', 'safemode', Array) #6 [internal function]: Piwik\FrontController::triggerSafeModeWhenError() #7 {main} thrown in /data/web/virtuals/63604/virtual/www/piwik/core/Container/StaticContainer.php on line 40

I found the bug report also on WP forum - Topic: After update to PIWIK 2.14.0, no stats, website broken « WordPress.org Forums.

Thank you for resolving the problem, kosata6.

Edit 15:20:
This error is also in Piwik demo script - http://demo.piwik.org/misc/others/api_internal_call.php.


(Matthieu Aubry) #2

Hi there, thanks for the report! I created an issue at: misc/others/api_internal_call.php is broken · Issue #8311 · matomo-org/piwik · GitHub


#3

Hi,

it looks like there’s a new “StaticContainer” which gets initialized when dispatching or calling the console, but in the API Request it’s missing.

Here’s a little workaround to get the scripts running again:
Put the following code before initializing the FrontController:


$environment = new \Piwik\Application\Environment('tracker');
$environment->init();

In the example code from Call the Piwik API in PHP it looks like this:


<?php
use Piwik\API\Request;
use Piwik\FrontController;

define('PIWIK_INCLUDE_PATH', realpath('../..'));
define('PIWIK_USER_PATH', realpath('../..'));
define('PIWIK_ENABLE_DISPATCH', false);
define('PIWIK_ENABLE_ERROR_HANDLER', false);
define('PIWIK_ENABLE_SESSION_START', false);

// if you prefer not to include 'index.php', you must also define here PIWIK_DOCUMENT_ROOT
// and include "libs/upgradephp/upgrade.php" and "core/Loader.php"
require_once PIWIK_INCLUDE_PATH . "/index.php";
require_once PIWIK_INCLUDE_PATH . "/core/API/Request.php";

[b]// Workaround for 2.14.0 bug
$environment = new \Piwik\Application\Environment('tracker');
$environment->init();[/b]

FrontController::getInstance()->init();

// This inits the API Request with the specified parameters
$request = new Request('
			module=API
			&method=Resolution.getResolution
			&idSite=7
			&date=yesterday
			&period=week
			&format=XML
			&filter_limit=3
			&token_auth=anonymous
');
// Calls the API and fetch XML data back
$result = $request->process();
echo $result;

Maybe that’ll help someone…

Regards,
Michael


#4

Yes, this works for me.

Thanks Pampy.