public function update() { $this->LogInfo("Start"); $u = new UserHelper(); $directories = Config::get('folders_to_scan_for_files'); foreach ($directories as $directory) { $users = $u->findUsersInDatabaseInDirectoryOnDisk($directory); $this->validateUsersInDirectory($users); } $this->LogInfo("Affiliation was set for " . $this->numberOfUsersInserted . " users"); }
private function updateStatusForUsers() { $userStatus = Config::get('userStatus'); $user = new UserHelper(); $users = $user->findUsersInDatabase(); foreach ($users as $feideUsername => $arrayOfPossibleUsernamesForAUser) { $userHasFolderOnDisk = $user->hasFolderOnDisk($arrayOfPossibleUsernamesForAUser); $query = "SELECT userName FROM tblUser WHERE userName LIKE '" . $feideUsername . "'"; $userExistsInRelayDb = $this->relaySQL->query($query); $criteria = array(UsersSchema::USERNAME => $feideUsername); $userDocument = $this->mongo->findOne($criteria); $statusFrom = $userDocument[UsersSchema::STATUS]; if ($userExistsInRelayDb && !$userHasFolderOnDisk) { if ($userDocument[UsersSchema::STATUS] == 1) { continue; } else { $statusTo = 1; } } elseif ($userExistsInRelayDb && $userHasFolderOnDisk) { if ($userDocument[UsersSchema::STATUS] == 2) { continue; } else { $statusTo = 2; } } elseif (!$userExistsInRelayDb && $userHasFolderOnDisk) { if ($userDocument[UsersSchema::STATUS] == 3) { continue; } else { $statusTo = 3; } } elseif (!$userExistsInRelayDb && !$userHasFolderOnDisk) { if ($userDocument[UsersSchema::STATUS] == 4) { continue; } else { $statusTo = 4; } } else { $this->LogError("None matched when checking statuses. This should never happen."); continue; } $success = $this->mongo->update($criteria, '$set', UsersSchema::STATUS, $statusTo, 0); if ($success) { $this->LogInfo("Changed status for " . $userDocument[UsersSchema::USERNAME] . " from: " . $userStatus[$statusFrom] . " to: " . $userStatus[$statusTo]); $this->numberOfStatusChanges = $this->numberOfStatusChanges + 1; } } }
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"); }