Connect. Communicate. Collaborate. Securely.

Home » Developer Zone » API/SDK Writers » Trying to get / print diskSizeLimit
  •  
pcunix

Messages: 594
Karma: 33
Send a private message to this user
Why does this always produce 0?

printf('%d <br />',$user['diskSizeLimit']['limit'][value]);


Isn't limit here an array of

long value
ByteUnits units

?

                $userList = getUserList($domain['id']);
                foreach ($userList as $user) {
if (! $user['lastLoginInfo']['dateTime']) {
                        $id=$user['id'];
$set="Already set";
printf('%d <br />',$user['diskSizeLimit']['limit'][value]);
if (! $user['diskSizeLimit']['limit'][value]) {
$set="Will set to 1 MB";
$params = array(
  'userIds' => array(
    $user['id']
   ),

   'pattern' => array(
     'diskSizeLimit' => array(
       'isActive' => TRUE,
       'limit' => array(
         'value' => 1,
         'units' => 'MegaBytes'
       )
    )
  )
);
$response = $Api->sendRequest('Users.set', $params);
}
                        $username = $user['loginName'] . '<_at_>' . $domain['name'];
                        $fullname = $user['fullName'];
                        printf('%s (%s) %s  <br>', $username, $fullname, $set);
                }
}

Tony Lawrence
Kerio Preferred Partner and Reseller
Certified for Connect, Control
http://aplawrence.com
  •  
Lukas Nemec

Messages: 33
Karma: 0
Send a private message to this user
Hi Tony,

I like your example. It seems to be useful for admins to save the disk space if some users don't use their mailboxes.

I'm affraid you forgot quote marks in array value definition. I believe, this one should work as you expect:
printf('%d <br />',$user['diskSizeLimit']['limit']['value']);

Lukas Nemec
WebAdmin developer
Kerio Technologies
.............................................
Connect. Communicate. Collaborate. Securely.
  •  
pcunix

Messages: 594
Karma: 33
Send a private message to this user
Amazing how you (well, I) can look at something over and over and miss the obvious.

Tony Lawrence
Kerio Preferred Partner and Reseller
Certified for Connect, Control
http://aplawrence.com
  •  
pcunix

Messages: 594
Karma: 33
Send a private message to this user
However - it is still printing 0 and falling through to set the quota again.

      date_default_timezone_set('America/New_York');
        /* Login */
        $login = $Api->login($hostname, $username, $password);

        /* Get domain list */
        $domainList = getDomainList();
        foreach ($domainList as $domain) {
                $userList = getUserList($domain['id']);
                foreach ($userList as $user) {
if (! $user['lastLoginInfo']['dateTime']) {
                        $id=$user['id'];
$set="Already set";
if (! $user['diskSizeLimit']['limit']['value']) {
$set="Will set to 1 MB";
$params = array(
  'userIds' => array(
    $user['id']
   ),

   'pattern' => array(
     'diskSizeLimit' => array(
       'isActive' => TRUE,
       'limit' => array(
         'value' => 1,
         'units' => 'MegaBytes'
       )
    )
  )
);
$response = $Api->sendRequest('Users.set', $params);
}
                        $username = $user['loginName'] . '<_at_>' . $domain['name'];
                        $fullname = $user['fullName'];
                        printf('%s (%s) %s %d <br>', $username, $fullname, $set ,$user['diskSizeLimit']['limit']['value']);
                }
}
        }

} catch (Exception $error) {

        /* Catch possible errors */
        print $error->getColorMessage();
}

/* Logout */
if(isset($login)) {
        $Api->logout();
}


Tony Lawrence
Kerio Preferred Partner and Reseller
Certified for Connect, Control
http://aplawrence.com
  •  
Lukas Nemec

Messages: 33
Karma: 0
Send a private message to this user
Hi,

I tried your script and I think it works correctly. Disk size quota is set to 1MB for users that haven't been logged yet.

$user['diskSizeLimit']['limit']['value'] returns '0' if user's disk size quota is unlimited. Is it your case?

diskSizeLimit: {
    isActive: false,
    limit: {
         value: 0,
         units: "Bytes"
    }
},


My output:
new_user<_at_>localhost (New User) Already set 1
NewUserForTest<_at_>localhost (Tony Lawrence) Will set to 1 MB 0

Maybe, you should add some condition (true == $user['diskSizeLimit']['isActive']) for this case not to display Unlimited quota.

Lukas Nemec
WebAdmin developer
Kerio Technologies
.............................................
Connect. Communicate. Collaborate. Securely.
  •  
pcunix

Messages: 594
Karma: 33
Send a private message to this user
Yes, but if you run it again, it will set it again (and still print 0). That's what is confusing me. The intent is not to set something that has been set manually.

Tony Lawrence
Kerio Preferred Partner and Reseller
Certified for Connect, Control
http://aplawrence.com
  •  
Lukas Nemec

Messages: 33
Karma: 0
Send a private message to this user
Try this (it works repeatedly for me). If admin has set some quota, it is not overriden by this script.

require_once(dirname(__FILE__) . '/class/MyApi.php');
require_once(dirname(__FILE__) . '/config.php');

$name = 'Trying to get / print diskSizeLimit';
$Api = new MyApi($name, $vendor, $version);

/* Main application */
try {
	/* Login */
	$login = $Api->login($hostname, $username, $password);

	/* Get domain list */
	$domainList = $Api->getDomains(array('id', 'name'));
	foreach ($domainList as $domain) {

		$userList = $Api->getUsers(array('id','loginName', 'fullName', 'diskSizeLimit', 'lastLoginInfo'), $domain['id']);

		foreach ($userList as $user) {
			$quota = $user['diskSizeLimit']['limit']['value'];

			if (! $user['lastLoginInfo']['dateTime']) {
				$id=$user['id'];
				$set="Already set";

				if (false == $user['diskSizeLimit']['isActive']) {
					$set="Will set to 1 MB";
					$params = array(
						'userIds' => array(
							$user['id']
						),

						'pattern' => array(
							'diskSizeLimit' => array(
								'isActive' => TRUE,
								'limit' => array(
									'value' => 1,
									'units' => 'MegaBytes'
								)
							)
						)
					);

					$response = $Api->sendRequest('Users.set', $params);

					$quota = '(From unlimited)';
				}
				$username = $user['loginName'] . '<_at_>' . $domain['name'];
				$fullname = $user['fullName'];

				printf('%s (%s) %s %s <br>', $username, $fullname, $set , $quota);
			}
		}
	}

} catch (Exception $error) {

		/* Catch possible errors */
		print $error->getColorMessage();
}

/* Logout */
if(isset($login)) {
		$Api->logout();
}

Lukas Nemec
WebAdmin developer
Kerio Technologies
.............................................
Connect. Communicate. Collaborate. Securely.
  •  
pcunix

Messages: 594
Karma: 33
Send a private message to this user
Yes, that works.

I was using KConnect from older examples..

Thanks!!

Tony Lawrence
Kerio Preferred Partner and Reseller
Certified for Connect, Control
http://aplawrence.com
  •  
pcunix

Messages: 594
Karma: 33
Send a private message to this user
Thanks again. I published this code today at my website and of course gave credit to you for your help!

Tony Lawrence
Kerio Preferred Partner and Reseller
Certified for Connect, Control
http://aplawrence.com
  •  
Lukas Nemec

Messages: 33
Karma: 0
Send a private message to this user
Hi Tony,

I really appreciate it. Administration API should help you to write your own scripts according your needs, so we are glad you have found some real usage and gave us a valuable feedback.

Let me tell you one more trick: You don't need to define your own methods getDomainList() and getUserList() now, because they are included in the new version of MyApi class as most common methods.

Good luck with other scripts, feel free to write us if something wouldn't be clear.

Lukas Nemec
WebAdmin developer
Kerio Technologies
.............................................
Connect. Communicate. Collaborate. Securely.
Previous Topic: Set users quota?
Next Topic: Setting quotas on inactive users
Goto Forum:
  


Disclaimer:
Kerio discussion forums are intended for open communication between forum members and may contain information and material posted by members which may be useful in learning about Kerio products. The discussion forums are not intended to provide technical support for any specific product. Any information implied or expressed in the discussion forums is that of the posting member. Kerio is in no way responsible for the information posted in the forums, or its accuracy. Kerio employees may participate in the discussions, but their postings do not represent an offical position of the company on any issues raised or discussed. Kerio reserves the right to monitor and maintain the forums to promote free and accurate exchange of information.

Current Time: Sat Oct 21 03:16:41 CEST 2017

Total time taken to generate the page: 0.00444 seconds
.:: Contact :: Home ::.
Powered by: FUDforum 3.0.4.