We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 33991
    • 65 Posts
    Hi everybody!

    I working on console import of goods from xml and i want to use system processors. But there is a strange error, when i try to do it.

    Here is my connection:
    define('MODX_API_MODE', true);
    require dirname(dirname(__FILE__)).'/index.php';
    
    $modx->getService('error','error.modError');
    $modx->setLogLevel(modX::LOG_LEVEL_INFO);
    $modx->setLogTarget(XPDO_CLI_MODE ? 'ECHO' : 'HTML');
    
    $response = $modx->runProcessor('security/login', array('username' => 'admin', 'password' => 'xxx'));
    if ($response->isError()) {
        $modx->log(modX::LOG_LEVEL_ERROR, $response->getMessage());
        return;
    }
    $modx->initialize('mgr');
    


    And now i can work with xPDO and do some other cool things as MODX admin. But, when i try to create new resource thought the system processor - i have unknown error.
    			
    $response = $modx->runProcessor('resource/create', array(
    	'pagetitle' => $subcat
    	,'parent' => $cat_id
    	,'template' => $categories_tpl[0]
    	,'isfolder' => 1
    	,'published' => 1
    ));
    if ($response->isError()) {
    	$modx->log(modX::LOG_LEVEL_ERROR, $response->getMessage());
    	return;
    }
    else {
    	print_r($response->response);
    }


    Error is:
    [2012-09-05 12:24:49] (ERROR @ /core/import.php)
    , i.e. it is empty unknown error.

    The same code (without connection, of course) works perfectly when it in snippet and runs from frontend.

    Can you help me? [ed. note: bezumkin2 last edited this post 11 years, 7 months ago.]
      • 33991
      • 65 Posts
      Here is attachment with debug info:
      $modx->setDebug(true);
      $response = $modx->runProcessor('resource/create', array(
      	'pagetitle' => $subcat
      	,'parent' => $cat_id
      	,'template' => $categories_tpl[0]
      	,'isfolder' => 1
      	,'published' => 1
      ));
      $modx->setDebug(false);


      Rename to import.html, for better view. [ed. note: bezumkin2 last edited this post 11 years, 7 months ago.]
        • 33991
        • 65 Posts
        The same code in API_MODE and in frontend give me different results:

        On frontent at beginnig of snippet
        var_dump(!$modx->error->hasError());die;
        returns true


        In file:
        <?php
        define('MODX_API_MODE', true);
        require dirname(dirname(__FILE__)).'/index.php';
        $modx->getService('error','error.modError');
        
        var_dump(!$modx->error->hasError());die;
        returns false!

        That is why connector does not works.

        I found that $modx->error->message on front is string, but in MODX_API_MODE - it is array. [ed. note: bezumkin2 last edited this post 11 years, 7 months ago.]
          • 33991
          • 65 Posts
          Solution found - here is:
          define('MODX_API_MODE', true);
          require dirname(dirname(__FILE__)).'/index.php';
          
          $modx->getService('error','error.modError');
          
          $modx->error->message = null;


          And connector works! [ed. note: bezumkin2 last edited this post 11 years, 7 months ago.]