public function cliGetSizesAction() { if (!isset($this->_options['defaults']['list_size']['disabled']) || $this->_options['defaults']['list_size']['disabled']) { $this->getLogger()->info("MailboxController::cliGetSizesAction: List size option is disabled in application.ini."); echo "List size option is disabled in application.ini.\n"; return; } foreach ($this->getD2EM()->getRepository("\\Entities\\Domain")->findAll() as $domain) { $cnt = 0; if ($this->getParam('verbose')) { echo "Processing {$domain->getDomain()}...\n"; } foreach ($domain->getMailboxes() as $mailbox) { if ($this->getParam('debug')) { echo " - {$mailbox->getUsername()}"; } $msize = OSS_DiskUtils::du($mailbox->getCleanedMaildir()); if ($msize !== false) { if ($this->getParam('debug')) { echo " [Mail Size: {$msize}]"; } $mailbox->setMaildirSize($msize); $hsize = OSS_DiskUtils::du($mailbox->getHomedir()); if ($hsize !== false) { $mailbox->setHomedirSize($hsize - $msize); if ($this->getParam('debug')) { echo " [Home Size: {$hsize}]"; } } else { if ($this->getParam('debug')) { echo " [Unknown Home Size]"; } } } else { $mailbox->setMaildirSize(null); $mailbox->setHomedirSize(null); if ($this->getParam('debug')) { echo " [Unknown Mail Size]"; } } $mailbox->setSizeAt(new \DateTime()); if ($this->getParam('debug')) { echo "\n"; } $cnt++; if ($cnt % 200 == 0) { $this->getD2EM()->flush(); } } // mailboxes $this->getD2EM()->flush(); } // domains }
/** * Check file or directory size. * * Function checks if given path is directory if it is then it runs du -sh command * result is filtered to bytes and function returns int. Else it checks if path is not * file if it is it return filesize. If it was not directory or file function returns false. * * NOTICE: Directory size is sum of all subdirectories and file sizes inside recursively. * * @param string $path Path to file or directory for checking the file. * @return int|bool */ private function _checkSize($path) { if (is_dir($path)) { return OSS_DiskUtils::du($path); } else { if (file_exists($path)) { return filesize($path); } else { return false; } } }