diff --git a/cli/update-mailbox-quotas.php b/cli/update-mailbox-quotas.php index e038f34..9364415 100755 --- a/cli/update-mailbox-quotas.php +++ b/cli/update-mailbox-quotas.php @@ -1,92 +1,92 @@ #!/usr/bin/php . require __DIR__ . '/../load.php'; /** * Script to update Mailbox quotas * */ // get every active domain $domains = ( new DomainAPI() ) ->select( [ 'domain.domain_ID', 'domain_name', ] ) ->whereDomainIsActive() ->queryGenerator(); // for each active domain foreach( $domains as $domain ) { $domain_name = $domain->getDomainName(); // validate domain name if( strpos( $domain_name, __ ) !== false ) { error( "domain '$domain_name' is bad" ); continue; } // get every active mailbox of this domain $mailboxes = ( new MailboxAPI() ) ->select( [ 'mailbox_ID', 'mailbox_username', ] ) ->whereDomain( $domain ) ->whereMailboxIsActive() ->queryGenerator(); query( 'START TRANSACTION' ); // for each mailboxes foreach( $mailboxes as $mailbox ) { $mailbox_username = $mailbox->getMailboxUsername(); // validate mailbox name if( strpos( $mailbox_username, __ ) !== false ) { error( "$domain_name.$mailbox_username is bad" ); continue; } // calculate the quota size $bytes = 0; $expected_path = MAILBOX_BASE_PATH . __ . $domain_name . __ . $mailbox_username; if( file_exists( $expected_path ) ) { - $bytes_raw = system( sprintf( + $bytes_raw = exec( sprintf( "du --summarize -- %s | cut -f1", escapeshellarg( $expected_path ) ) ); $bytes = (int) $bytes_raw; } // store the value ( new MailboxSizeAPI() ) ->insertRow( [ - 'mailbox_ID' => $mailbox->getMailboxID(), + 'mailbox_ID' => $mailbox->getMailboxID(), 'mailboxsize_bytes' => $bytes, new DBCol( 'mailboxsize_date', 'NOW()', '-' ), ] ); } query( 'COMMIT' ); }