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

modifyAccount (Account Status) not updating #56

Open
jmezz opened this issue Jan 16, 2023 · 3 comments
Open

modifyAccount (Account Status) not updating #56

jmezz opened this issue Jan 16, 2023 · 3 comments

Comments

@jmezz
Copy link

jmezz commented Jan 16, 2023

Hello,

I am not sure if its me or what is going on but I can't seem to get the account status to update. The request goes through without error but the account status isn't changed.

Relevant code below:
`

                    $account = $api->getAccount(new AccountSelector(AccountBy::NAME(), $userName));
                    $acctId = $account->getAccount()->getId();
                    try {
                            $statusAttr = new KeyValuePair('zimbraAccountStatus', 'closed');
                            $modifyAccount = $api->modifyAccount ($acctId, [$statusAttr]);
                            print_r($modifyAccount);
                             return true;

                    }

                    catch ( \   Zimbra\Common\Soap\Exception  $ex ) {
                            print_r($ex->getMessage());
                            echo "\r\n";
                            return false;

                    }

`

The response shows the status still being active so I assume either Zimbra is throwing an error and its not being caught for some reason or its ignoring the key value pair? In any event the catch block never runs and the print_r shows the following for account status:
[77] => Zimbra\Admin\Struct\Attr Object ( [key:Zimbra\Common\Struct\KeyValuePair:private] => zimbraAccountStatus [value:Zimbra\Common\Struct\KeyValuePair:private] => active )

I am able to create users as well as modify passwords so the API itself is working. Any help would be greatly appreciated.

@jmezz
Copy link
Author

jmezz commented Jan 17, 2023

I've confirmed the issue is with this package and NOT zimbra. The trace in Zimbra showed a blank modifyAccountRequest which was unexpected but sent me in the right direction.

After digging around with my limited skills I was able to narrow the issue down to the function below from Admin/Struct/AdminAttrsImplTrait.php

public function setAttrs(array $attrs): self { $this->attrs = array_filter($attrs, static fn ($attr) => $attr instanceof Attr); return $this; }

It looks like the key value pair isn't properly being instantiated? so the array_search returns false and the attributes are filtered.

I'll be honest this isn't really my forte so I am not sure where else to look. As a workaround I am skipping the array filter line and returning the attributes but I'd like to sort this out properly.

I think I understand what the array_filter line does but I am not sure where Attr is instantiated/what to look for. Hopefully someone smarter than myself can take a look and chime in.

Thank you all in advance!

@jpmorby
Copy link

jpmorby commented Jun 21, 2023

I'm experiencing similar problems here ... attempting to change zimbraAccountStatus to locked ... which is a little frustrating as it doesn't work and I'm not quite sure where to start with fixing it in the package :(

My code ... in case you can see anything obvious as to why it doesn't work?

`

<?php
declare(strict_types=1);

require __DIR__ . '/../vendor/autoload.php';
require __DIR__ . '/../shared/config.php';


use Psr\Log\LogLevel;

use Zimbra\Admin\AdminApi;
use Zimbra\Common\Enum\AccountBy;
use Zimbra\Common\Struct\AccountSelector;
use Zimbra\Common\Struct\KeyValuePair;


zimbraSuspend("user@domain.com");

function zimbraSuspend($user) {
    echo "Suspending [$user]\n";

    $api = new AdminApi(ZIMBRA_URL);
    $api->auth(ZIMBRA_USER, ZIMBRA_PASS);

    $account = new AccountSelector(AccountBy::NAME, $user);
    $response = $api->getAccount($account);
    $accountID = $response->getAccount()->getId();

    try {
        $zimbraAccountStatus = new KeyValuePair("zimbraAccountStatus", "locked");

        $res = $api->modifyAccount( $accountID,  [ $zimbraAccountStatus ] );

        print_r( $res );
    }
        catch ( \Zimbra\Common\Soap\Exception $ex ) {
            print_r($ex->getMessage());
            echo "\r\n";
            return false;

    }
    return;
}

`

@aaronsegbedzi
Copy link

I was experiencing similar problems until I changed

$zimbraAccountStatus = new KeyValuePair("zimbraAccountStatus", "locked");

to

$zimbraAccountStatus = new Attr("zimbraAccountStatus", "locked");

:)

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

3 participants