Piwik\API\Request::process PHP Method

process() public method

Post-processing includes: - flattening if **flat** is 0 - running generic filters unless **disable_generic_filters** is set to 1 - URL decoding label column values - running queued filters unless **disable_queued_filters** is set to 1 - removing columns based on the values of the **hideColumns** and **showColumns** query parameters - filtering rows if the **label** query parameter is set - converting the result to the appropriate format (ie, XML, JSON, etc.) If 'original' is supplied for the output format, the result is returned as a PHP object.
public process ( ) : DataTable | Map | string
return Piwik\DataTable | Map | string The data resulting from the API call.
    public function process()
    {
        // read the format requested for the output data
        $outputFormat = strtolower(Common::getRequestVar('format', 'xml', 'string', $this->request));
        // create the response
        $response = new ResponseBuilder($outputFormat, $this->request);
        $corsHandler = new CORSHandler();
        $corsHandler->handle();
        $tokenAuth = Common::getRequestVar('token_auth', '', 'string', $this->request);
        $shouldReloadAuth = false;
        try {
            // read parameters
            $moduleMethod = Common::getRequestVar('method', null, 'string', $this->request);
            list($module, $method) = $this->extractModuleAndMethod($moduleMethod);
            list($module, $method) = self::getRenamedModuleAndAction($module, $method);
            PluginManager::getInstance()->checkIsPluginActivated($module);
            $apiClassName = self::getClassNameAPI($module);
            if ($shouldReloadAuth = self::shouldReloadAuthUsingTokenAuth($this->request)) {
                $access = Access::getInstance();
                $tokenAuthToRestore = $access->getTokenAuth();
                $hadSuperUserAccess = $access->hasSuperUserAccess();
                self::forceReloadAuthUsingTokenAuth($tokenAuth);
            }
            // call the method
            $returnedValue = Proxy::getInstance()->call($apiClassName, $method, $this->request);
            $toReturn = $response->getResponse($returnedValue, $module, $method);
        } catch (Exception $e) {
            Log::debug($e);
            $toReturn = $response->getResponseException($e);
        }
        if ($shouldReloadAuth) {
            $this->restoreAuthUsingTokenAuth($tokenAuthToRestore, $hadSuperUserAccess);
        }
        return $toReturn;
    }

Usage Example

 /**
  * @depends      testApi
  * @dataProvider getAnotherApiForTesting
  */
 public function testAnotherApi($api, $params)
 {
     $idSite = self::$fixture->idSite;
     $idSite2 = self::$fixture->idSite2;
     // 1) Invalidate old reports for the 2 websites
     // Test invalidate 1 date only
     $r = new Request("module=API&method=CoreAdminHome.invalidateArchivedReports&idSites=4,5,6,55,-1,s',1&dates=2010-01-03");
     $this->assertApiResponseHasNoError($r->process());
     // Test invalidate comma separated dates
     $r = new Request("module=API&method=CoreAdminHome.invalidateArchivedReports&idSites=" . $idSite . "," . $idSite2 . "&dates=2010-01-06,2009-10-30");
     $this->assertApiResponseHasNoError($r->process());
     // test invalidate date in the past
     // Format=original will re-throw exception
     $r = new Request("module=API&method=CoreAdminHome.invalidateArchivedReports&idSites=" . $idSite2 . "&dates=2009-06-29&format=original");
     $this->assertApiResponseHasNoError($r->process());
     // invalidate a date more recent to check the date is only updated when it's earlier than current
     $r = new Request("module=API&method=CoreAdminHome.invalidateArchivedReports&idSites=" . $idSite2 . "&dates=2010-03-03");
     $this->assertApiResponseHasNoError($r->process());
     // Make an invalid call
     $idSiteNoAccess = 777;
     try {
         $request = new Request("module=API&method=CoreAdminHome.invalidateArchivedReports&idSites=" . $idSiteNoAccess . "&dates=2010-03-03&format=original");
         $request->process();
         $this->fail();
     } catch (Exception $e) {
     }
     // 2) Call API again, with an older date, which should now return data
     $this->runApiTests($api, $params);
 }
All Usage Examples Of Piwik\API\Request::process