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"); $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"); }
public function __construct($collection) { $this->debug = Config::get('settings')['debug']; try { $authString = sprintf('mongodb://%s:%s@%s/%s', getenv('MONGO_USERNAME'), getenv('MONGO_PASSWORD'), getenv('MONGO_HOST'), getenv('MONGO_DATABASE')); $mongoClient = new MongoClient($authString); $this->database = $mongoClient->selectDB(getenv('MONGO_DATABASE')); } catch (MongoConnectionException $e) { die('Error connecting to MongoDB server: ' . $e->getMessage() . PHP_EOL); } $this->collection = new MongoCollection($this->database, $collection); return $this->collection; }
public function getDistinctOrgsFromDisk() { $arr = array(); foreach (Config::get('folders_to_scan_for_files') as $directory) { exec('ls -l ' . $directory . '| egrep ^d | cut -d "@" -f2 | sort | uniq', $y); foreach ($y as $value) { if (!in_array($value, $arr)) { $arr[] = $value; } } return $arr; } }
private function createCollection() { $cursor = $this->mongo->findLimitOneCount($this->criteria); if (empty($cursor)) { //Returns true if inserted //Somehow User and FileId needs (int) before 0. Don't know why. $document = array(LastUpdatesSchema::DOCUMENT_KEY => Config::get('settings')['lastupdates_doc_key'], LastUpdatesSchema::USER_ID => (int) 0, LastUpdatesSchema::PRESENTATION_ID => (int) 0, LastUpdatesSchema::LAST_IMPORTED_REQUESTS_DATE => new MongoDate(strtotime(Config::get('settings')['startDateToImportIISLogs']))); $success = $this->mongo->createLastUpdates($document); if ($success) { $this->log->addNotice("Created collection: " . LastUpdatesSchema::COLLECTION_NAME); } return $success; } return false; }
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 findUsersInOrganisationsInDatabase() { $directories = Config::get('folders_to_scan_for_files'); $cursor = $this->mongo->distinct("org"); $users = array(); foreach ($cursor as $org) { $array = array(); foreach ($directories as $directory) { $dir = $directory . DIRECTORY_SEPARATOR; $usersInOrg = $this->mongo->find(array(UsersSchema::ORG => $org)); foreach ($usersInOrg as $u) { if (is_dir($dir . $u[UsersSchema::USERNAME_ON_DISK])) { $array[] = $dir . $u[UsersSchema::USERNAME_ON_DISK]; } if (is_dir($dir . $u[UsersSchema::USERNAME])) { $array[] = $dir . $u[UsersSchema::USERNAME]; } } } $users[$org] = $array; } return $users; }
public function __construct() { $this->object = new DailyUniqueTrafficModel(); $this->reader = new Reader(Config::get('settings')['root'] . DIRECTORY_SEPARATOR . 'GeoLite2-City.mmdb'); }
/** UNNECESSARY * private function onePresentationFileDoesNotExist($path) { * return !file_exists($path); * }*/ private function convertToLocalPath($presentation) { return Config::get('settings')['relaymedia'] . DIRECTORY_SEPARATOR . $presentation; }
/** NEW 27.10.2015: A rewrite to make it mote future-proof... */ private function destUrlToRootPath($path) { //Input, complete path on disk, e.g.: // /var/www/mnt/relaymedia/ansatt/simonuninett.no/2015/14.09/89400/TechSmith_Relay_innfring_p_130_-_20150914_085355_36.mp4 //Output, stripped to part that is used in URL, e.g.: // ansatt/simonuninett.no/2015/14.09/89400/ // 1. Remove relaymedia-path as defined in config (e.g. '/var/www/mnt/relaymedia' + '/') from complete path... $baseURL = str_replace(Config::get('settings')['relaymedia'] . DIRECTORY_SEPARATOR, '', $path); // 2. Remove filename from path ('ansatt/simonuninett.no/2015/14.09/89400/TechSmith_Relay_innfring_p_130_-_20150914_085355_36.mp4') return pathinfo($baseURL)['dirname'] . DIRECTORY_SEPARATOR; }
public function subtract($num1, $num2) { return (double) round($num1 - $num2, Config::get('arithmetic')['numberOfDecimals'], PHP_ROUND_HALF_UP); }
/** * @param $bytes * * @return double */ public function bytesToMegabytes($bytes) { return (double) round($bytes / pow(1024, 2), Config::get('arithmetic')['numberOfDecimals'], PHP_ROUND_HALF_UP); }