diff --git a/cli/update-mailbox-quotas.php b/cli/update-mailbox-quotas.php index 8f0b8b1..bdae8a8 100755 --- a/cli/update-mailbox-quotas.php +++ b/cli/update-mailbox-quotas.php @@ -1,100 +1,100 @@ #!/usr/bin/php . require __DIR__ . '/../load.php'; /** * Script to update Mailbox quotas * * See https://gitpull.it/T101 */ // 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 = exec( sprintf( - 'du --summarize -- %s | cut -f1', + 'du --summarize --bytes -- %s | cut -f1', escapeshellarg( $expected_path ) ) ); $bytes = (int) $bytes_raw; } // store the value in the history ( new MailboxSizeAPI() ) ->insertRow( [ 'mailbox_ID' => $mailbox->getMailboxID(), 'mailboxsize_bytes' => $bytes, new DBCol( 'mailboxsize_date', 'NOW()', '-' ), ] ); // update the denormalized latest Mailbox data ( new MailboxAPI() ) ->whereMailbox( $mailbox ) ->update( [ 'mailbox_lastsizebytes' => $bytes, ] ); } query( 'COMMIT' ); }