public function update() { $directories = Config::get('mediasite')['directories']; $math = new Arithmetic(); $disk = new LinuxOperationsHelper(); $convert = new ConvertHelper(); foreach ($directories as $directory) { $organisations = $disk->getFolderNamesFromDirectory($directory); foreach ($organisations as $organisation) { $sizeB = $disk->getSpaceUsedByMediasiteOrg($directory, $organisation); $sizeMiB = $convert->bytesToMegabytes($sizeB); $criteria = array(MediaSiteSchema::ORG => $organisation); $lastKnownUsedSize = $this->producedMoreSinceLastSave($organisation); if ($lastKnownUsedSize !== $sizeMiB) { $storage = array(MediaSiteSchema::DATE => new MongoDate(), MediaSiteSchema::SIZE => $sizeMiB); $success = $this->mongo->update($criteria, '$push', MediaSiteSchema::STORAGE, $storage, 1); if ($success) { $this->numberInserted = $this->numberInserted + 1; $diff = $math->subtract($lastKnownUsedSize, $sizeMiB); $this->LogInfo("{$diff}MiB diff for {$organisation}"); } } else { $this->LogInfo("No change in storage for {$organisation}"); } } } $this->LogInfo("Aggregated data and inserted {$this->numberInserted} items"); }
public function update() { $this->LogInfo("Start"); $math = new Arithmetic(); $aggregatedSize = 0.0; $u = new UserHelper(); $directories = Config::get('folders_to_scan_for_files'); foreach ($directories as $directory) { if (is_dir($directory)) { $users = $u->findUsersInDatabaseInDirectoryOnDisk($directory); foreach ($users as $feideUsername => $arrayOfPossibleUsernamesForAUser) { $criteria = array(UserDiskUsageSchema::USERNAME => $feideUsername); $userDiskusageDocument = $this->userDiskUsageCollection->findOne($criteria); $diskSize = 0.0; foreach ($arrayOfPossibleUsernamesForAUser as $usernameAndDir) { if (is_dir($usernameAndDir)) { $diskSize = $math->add($diskSize, $this->_calculateSize($usernameAndDir)); } } $dbSize = $this->_producedMoreSinceLastSave($feideUsername); if ($this->_userExistsInCollection($userDiskusageDocument)) { if (!$math->consideredToBeEqual($dbSize, $diskSize)) { $storage = array(UserDiskUsageSchema::DATE => new Mongodate(), UserDiskUsageSchema::SIZE => $diskSize); $operationOK = $this->_updateDocumentInCollection($criteria, $storage); } else { continue; } } else { $userDocument = $this->userCollection->findOne($criteria); $org = $userDocument[UsersSchema::ORG]; $newUser = $this->_createUser($feideUsername, $diskSize, $org); $operationOK = $this->_insertDocumentToMongoDatabase($newUser); } if ($operationOK) { $this->LogInfo("Aggregated " . $feideUsername . " (" . $math->subtract($diskSize, $dbSize) . "MiB diff). Last size was " . $dbSize . "MiB"); $this->numberInserted = $this->numberInserted + 1; $aggregatedSize = $math->add($aggregatedSize, $diskSize); } else { $this->LogError("Could not update " . $feideUsername . var_dump($criteria)); } } } } $this->LogInfo("Aggregated " . $aggregatedSize . "MiB for {$this->numberInserted} users "); }
public function update() { $this->LogInfo("Start"); $math = new Arithmetic(); $u = new UserHelper(); $allOrgsInIOrgsCollection = $u->findUsersInOrganisationsInDatabase(); if (count($allOrgsInIOrgsCollection) == 0) { $this->LogError("Did not find any organisations to aggregate size used for"); } $aggregatedSize = 0.0; foreach ($allOrgsInIOrgsCollection as $orgName => $arrayOfUsersInOrg) { $diskSize = 0.0; $dbSize = 0.0; foreach ($arrayOfUsersInOrg as $userPath) { $diskSize = $math->add($diskSize, $this->calculateSize($userPath)); } $criteria = array(OrgSchema::ORG => $orgName); $orgToUpdate = $this->mongo->findOne($criteria); if ($this->organisationExists($orgToUpdate)) { $dbSize = $this->hasProducedMoreSinceLastSave($orgName); if ($math->consideredToBeEqual($diskSize, $dbSize)) { $this->LogInfo("No change in size used by " . $orgName); continue; } else { $storage = array(OrgSchema::DATE => new MongoDate(), OrgSchema::SIZE => $diskSize); $newArrayWasPushedToCollection = $this->mongo->update($criteria, '$push', OrgSchema::STORAGE, $storage, 0); if ($newArrayWasPushedToCollection) { $this->numberFound = $this->numberFound + 1; $aggregatedSize = $math->add($aggregatedSize, $diskSize); } } $this->LogInfo("Aggregated " . $orgName . " (" . $math->subtract($diskSize, $dbSize) . "MiB diff). Last size was " . $dbSize . "MiB"); } else { $this->LogError("Did not find " . $orgName . " in db"); } } $this->numberFound = (int) ceil($this->numberFound); $this->LogInfo("Aggregated daily disk usage; " . $aggregatedSize . "MiB" . " for {$this->numberFound} users"); }