Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use WaitSet? #42

Open
vladus-06 opened this issue Jan 23, 2020 · 1 comment
Open

How to use WaitSet? #42

vladus-06 opened this issue Jan 23, 2020 · 1 comment

Comments

@vladus-06
Copy link

vladus-06 commented Jan 23, 2020

Hi.
How i can use WaitSet? I want to listen to all Zimbra accounts тo see when new letters arrive.

require 'vendor/autoload.php';

use Zimbra\Admin\AdminFactory;
use Zimbra\Admin\Request\AdminCreateWaitSet;
use Zimbra\Common\TypedSequence;
use Zimbra\Enum\InterestType;
use Zimbra\Struct\WaitSetSpec;

$api = AdminFactory::instance('https://localhost:7071/service/admin/soap');
$api->auth('admin', 'paddword');

$accounts = array();
$interests = array('m');

$waitset = new AdminCreateWaitSet();
$waitset->setAllAccounts(TRUE);
........
var_dump($waitset);

@vladus06
Copy link

Can someone help me with this code? What am I doing wrong?


class ApiTest
{
    private $_api;
    

 public function testAdminWaitSet()
	 {
	$api = AdminFactory::instance('https://localhost:7071/service/admin/soap');
        $api->auth('admin', '************');  
	  $name = 'admin@mail.local.com';
	  $id = '7ac0ebb7-2bd5-4c48-828c-74cbc0e636d1';
	  $token = '0_78f6491445198621727b10d20104482cc46fa509_69643d33363a37616330656262372d326264352d346334382d383238632d3734636263306536333664313b6578703d31333a313630333835323430383236383b61646d696e3d313a313b747970653d363a7a696d6272613b753d313a613b7469643d393a3835363634343238383b76657273696f6e3d31343a382e382e31355f47415f333836393b';
	  $waitSet = 1;//self::randomName();
	  $seq = 1;//self::randomName();
	  $timeout = 1000; //mt_rand(0, 1000);
	  $a = new \Zimbra\Struct\WaitSetAddSpec($name, $id, $token, [InterestType::FOLDERS(), InterestType::MESSAGES(), InterestType::CONTACTS()]);
	  $add = new \Zimbra\Struct\WaitSetSpec([$a]);
	  $update = new \Zimbra\Struct\WaitSetSpec([$a]);
	  $a = new \Zimbra\Struct\Id($id);
	  $remove = new \Zimbra\Struct\WaitSetId([$a]);
	  $api->adminWaitSet($waitSet, $seq, $add, $update, $remove, true, [InterestType::FOLDERS(), InterestType::MESSAGES()], $timeout);
	  $client = $api->client();
	  $req = $client->lastRequest();
	  $xml = '<?xml version="1.0"?>' . 
	  "\n" . '<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:urn="urn:zimbra" xmlns:urn1="urn:zimbraAdmin">' . 
	  '<env:Body>' . '<urn1:AdminWaitSetRequest waitSet="' . 
	  $waitSet . '" seq="' . $seq . '" block="true" defTypes="f,m" timeout="' . $timeout . '" >' . '<urn1:add>' . '<urn1:a name="' . 
	  $name . '" id="' . $id . '" token="' . $token . '" types="f,m,c" />' . '</urn1:add>' . '<urn1:update>' . '<urn1:a name="' . 
	  $name . '" id="' . $id . '" token="' . $token . '" types="f,m,c" />' . '</urn1:update>' . '<urn1:remove>' . '<urn1:a id="' . 
	  $id . '" />' . '</urn1:remove>' . '</urn1:AdminWaitSetRequest>' . '</env:Body>' . '</env:Envelope>';
//	  $this->assertXmlStringEqualsXmlString($xml, (string) $req);
	    return $xml;
	  }
}

$qwe = new ApiTest;
echo $qwe->testAdminWaitSet();

PHP Fatal error: Uncaught GuzzleHttp\Exception\ServerException: Server error: POST https://localhost:7071/service/admin/soap resulted in a 500 Server Error response:
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">soap:Header<change tok (truncated...)
in /root/zmadmin/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php:113
Stack trace:
#0 /root/zmadmin/vendor/guzzlehttp/guzzle/src/Middleware.php(65): GuzzleHttp\Exception\RequestException::create()
#1 /root/zmadmin/vendor/guzzlehttp/promises/src/Promise.php(204): GuzzleHttp\Middleware::GuzzleHttp{closure}()
#2 /root/zmadmin/vendor/guzzlehttp/promises/src/Promise.php(153): GuzzleHttp\Promise\Promise::callHandler()
#3 /root/zmadmin/vendor/guzzlehttp/promises/src/TaskQueue.php(48): GuzzleHttp\Promise\Promise::GuzzleHttp\Promise{closure}()
#4 /root/zmadmin/vendor/guzzlehttp/promises/src/Promise.php(248): GuzzleHttp\Promise\TaskQueue->run()
#5 /root/zmadmin/vendor/guzzlehttp/promises/src/Promise.php(224): GuzzleHttp\P in /root/zmadmin/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php on line 113

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants