diff --git a/lib/Stats/Collector/BaseCollector.php b/lib/Stats/Collector/BaseCollector.php index b5a521f8a3abbcb4028f519bb655c8cf87d43951..9efcc1765b01847c765a2d0198cfcafe0ae0330c 100644 --- a/lib/Stats/Collector/BaseCollector.php +++ b/lib/Stats/Collector/BaseCollector.php @@ -2,12 +2,31 @@ namespace OCA\SccuotNG\Stats\Collector; +use OCA\SccuotNG\Service\ConfigService; + +use OCA\SccuotNG\Util\OutputProxy; +use OCP\IDBConnection; + abstract class BaseCollector implements ICollector { + public function collect(IDBConnection $db, int $timestamp, ConfigService $config) { + $dataName = $this->dataName(); + $startTime = microtime(true); + OutputProxy::print(" Collecting {$this->dataName()}... "); + $data = $this->collectData($db, $timestamp, $config); + $timeElapsed = number_format(microtime(true) - $startTime, 3); + OutputProxy::println("done ({$timeElapsed}s)"); + return $data; + } + public function dataName() { // Get the class name, remove 'Collector' from the end and split the result by capital letters $tokens = explode('\\', get_class($this)); $pieces = preg_split('/(?=[A-Z])/', end($tokens)); array_pop($pieces); - return join(' ', array_map('strtolower', $pieces)); + return join(' ', array_filter(array_map('strtolower', $pieces))); } + + protected function collectData(IDBConnection $db, int $timestamp, ConfigService $config) { + return null; + } } diff --git a/lib/Stats/Collector/FileTypesCountsCollector.php b/lib/Stats/Collector/FileTypesCountsCollector.php index 7d423d563b18d5db74f7e1989ec659eccfaa0056..484b17306851f1e0aac8cbdec8c0409b9279376a 100644 --- a/lib/Stats/Collector/FileTypesCountsCollector.php +++ b/lib/Stats/Collector/FileTypesCountsCollector.php @@ -10,7 +10,7 @@ use OCP\IDBConnection; use OC\User\Account; class FileTypesCountsCollector extends BaseCollector { - public function collect(IDBConnection $db, int $timestamp, ConfigService $config) { + protected function collectData(IDBConnection $db, int $timestamp, ConfigService $config) { $fileCounts = []; $mapper = new FilecacheMapper($db, Account::STATE_ENABLED); foreach ($config->getSnapshotFileTypes()->groups() as $groupName => $group) { diff --git a/lib/Stats/Collector/FilesCountCollector.php b/lib/Stats/Collector/FilesCountCollector.php index da754873f44432baf732b11873806effdeaeab2d..fe0015e3474320586361a73827bb262546047eb8 100644 --- a/lib/Stats/Collector/FilesCountCollector.php +++ b/lib/Stats/Collector/FilesCountCollector.php @@ -11,7 +11,7 @@ use OCP\IDBConnection; use OC\User\Account; class FilesCountCollector extends BaseCollector { - public function collect(IDBConnection $db, int $timestamp, ConfigService $config) { + protected function collectData(IDBConnection $db, int $timestamp, ConfigService $config) { $mapper = new FilecacheMapper($db); $totalCount = $mapper->queryTotalFilesCount(); $mapper->setAccountsState(Account::STATE_DISABLED); diff --git a/lib/Stats/Collector/FilesSizeCollector.php b/lib/Stats/Collector/FilesSizeCollector.php index d390aa9d1fda0f65d2a03cbaef5d1e4c0186488f..0c6925c5dd416407116f5e9e99ea7a02b4b501ec 100644 --- a/lib/Stats/Collector/FilesSizeCollector.php +++ b/lib/Stats/Collector/FilesSizeCollector.php @@ -11,7 +11,7 @@ use OCP\IDBConnection; use OC\User\Account; class FilesSizeCollector extends BaseCollector { - public function collect(IDBConnection $db, int $timestamp, ConfigService $config) { + protected function collectData(IDBConnection $db, int $timestamp, ConfigService $config) { $mapper = new FilecacheMapper($db); $totalCount = $mapper->queryTotalFilesSize(); $mapper->setAccountsState(Account::STATE_DISABLED); diff --git a/lib/Stats/Collector/GroupsCountCollector.php b/lib/Stats/Collector/GroupsCountCollector.php index 55815f608301eac017c43baadc0bd01141a0fcbd..652235296c9d27722285a58c436788313be3f4bc 100644 --- a/lib/Stats/Collector/GroupsCountCollector.php +++ b/lib/Stats/Collector/GroupsCountCollector.php @@ -8,7 +8,7 @@ use OCA\SccuotNG\Service\ConfigService; use OCP\IDBConnection; class GroupsCountCollector extends BaseCollector { - public function collect(IDBConnection $db, int $timestamp, ConfigService $config) { + protected function collectData(IDBConnection $db, int $timestamp, ConfigService $config) { $mapper = new GroupsMapper($db); return $mapper->queryTotalCount(true); } diff --git a/lib/Stats/Collector/SharesCountCollector.php b/lib/Stats/Collector/SharesCountCollector.php index c2eb43f2ce04991831d6a1c421f967dd454f0405..9a73543f5fa103135813040e89d9e64f39bdeaf9 100644 --- a/lib/Stats/Collector/SharesCountCollector.php +++ b/lib/Stats/Collector/SharesCountCollector.php @@ -12,7 +12,7 @@ use OCA\SccuotNG\Stats\Value\SharesCountValue; use OCP\IDBConnection; class SharesCountCollector extends BaseCollector { - public function collect(IDBConnection $db, int $timestamp, ConfigService $config) { + protected function collectData(IDBConnection $db, int $timestamp, ConfigService $config) { $mapper = new SharesMapper($db); $extMapper = new ExternalSharesMapper($db); return [ diff --git a/lib/Stats/Collector/UsersCountCollector.php b/lib/Stats/Collector/UsersCountCollector.php index 9b940191b7c37ccad9640e0c997778cf9fb28140..e589d01dc59571526909c0554a83a8410417db6f 100644 --- a/lib/Stats/Collector/UsersCountCollector.php +++ b/lib/Stats/Collector/UsersCountCollector.php @@ -12,7 +12,7 @@ use OCP\IDBConnection; use OC\User\Account; class UsersCountCollector extends BaseCollector { - public function collect(IDBConnection $db, int $timestamp, ConfigService $config) { + protected function collectData(IDBConnection $db, int $timestamp, ConfigService $config) { $mapper = new AccountsMapper($db); $activeUsers = $mapper->queryTotalCount(Account::STATE_ENABLED); $closedUsers = $mapper->queryTotalCount(Account::STATE_DISABLED); diff --git a/lib/Stats/Collector/UsersQuotaCollector.php b/lib/Stats/Collector/UsersQuotaCollector.php index 6225c4a2a243e3ecd6637e3c17a2f150284e3d0a..b5bebbb08698abc598bc849bb3bfbcef6c25fcf7 100644 --- a/lib/Stats/Collector/UsersQuotaCollector.php +++ b/lib/Stats/Collector/UsersQuotaCollector.php @@ -11,7 +11,7 @@ use OCA\SccuotNG\Util\FileSize; use OCP\IDBConnection; class UsersQuotaCollector extends BaseCollector { - public function collect(IDBConnection $db, int $timestamp, ConfigService $config) { + protected function collectData(IDBConnection $db, int $timestamp, ConfigService $config) { $accMapper = new AccountsMapper($db); $storeMapper = new StoragesMapper($db); $userQuotas = $accMapper->queryUserQuotas($this->getDefaultQuotas($config)); diff --git a/lib/Stats/Collector/UsersStorageCollector.php b/lib/Stats/Collector/UsersStorageCollector.php index 86503e2c82bb8bc5cd17a67068766bc1d9ccbd5f..c3345d06f2cc86859e4c74c36c012d944d10b24b 100644 --- a/lib/Stats/Collector/UsersStorageCollector.php +++ b/lib/Stats/Collector/UsersStorageCollector.php @@ -8,7 +8,7 @@ use OCA\SccuotNG\Service\ConfigService; use OCP\IDBConnection; class UsersStorageCollector extends BaseCollector { - public function collect(IDBConnection $db, int $timestamp, ConfigService $config) { + protected function collectData(IDBConnection $db, int $timestamp, ConfigService $config) { $mapper = new AccountsMapper($db); $filesSizes = $mapper->queryUsedStorages(); sort($filesSizes);