private function calculateSize($path) { $lop = new LinuxOperationsHelper(); $sizeByte = $lop->getSpaceUsedInDirectory($path); $convert = new ConvertHelper(); return $convert->bytesToMegabytes($sizeByte); }
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"); }
private function validateUsersInDirectory($users) { $diskOperation = new ConvertHelper(); foreach ($users as $feideUsername => $userArrays) { foreach ($userArrays as $userPath) { if (is_dir($userPath)) { $criteria = array(UsersSchema::AFFILIATION => 'willBeSetIfFolderExistsAndUserSetAffiliationHaveDoneItsThing', UsersSchema::USERNAME => $feideUsername); $cursor = $this->_mongoDatabaseConnection->collection->find($criteria)->limit(1); if ($this->resultExists($cursor->count())) { $affiliation = $diskOperation->getAffiliationFromPath($userPath); $success = $this->updateAffiliationInMongoDb($criteria, $affiliation); if (!$success) { $this->LogError("Could not update affiliation for " . $userPath); } else { $this->numberOfUsersInserted = $this->numberOfUsersInserted + 1; } break; } } } } }
public function createPresentationFromArrayResult($presentationXmlFiles) { $haveFilledInGeneralInfo = false; $convert = new ConvertHelper(); $newPresentation = new PresentationModel(); foreach ($presentationXmlFiles as $xmlFile) { $xml = simplexml_load_file($xmlFile['path']); if ($xml->getName() == "presentation") { $newPresentation->setPresentationId($xmlFile['id']); if ($haveFilledInGeneralInfo == false) { $newPresentation->setTitle((string) $xml->title); $newPresentation->setDescription((string) $xml->description); $newPresentation->setCreated((string) $xml->utcDate); $newPresentation->setDeleted((int) 0); $newPresentation->setRecordedBy((string) $xml->recordedBy->displayName); $newPresentation->setUsername((string) $xml->presenter->userName); $newPresentation->setTotalDuration($convert->millisecondsToSeconds($xml->totalDuration)); $newPresentation->setTrimmedDuration($convert->millisecondsToSeconds($xml->trimmedDuration)); $newPresentation->setHits((int) 0); // Format varies depending on Relay version (\\\\kastra.binsys... or \\\\samba ... or https://screencast...) // Convert the path/url to the absolute path on the fileserver $dUrl = $convert->convertExternalToLocalPath((string) $xml->destinationUrl); // Convert absolute path to relative path (which is stored in the document in the presentation collection) $newPresentation->setPath($this->destUrlToRootPath($dUrl)); $org = explode('@', $xml->presenter->userName); if (isset($org[1])) { $newPresentation->setOrg($org[1]); } $haveFilledInGeneralInfo = true; } $newFile = new PresentationFilesModel(); $newFile->setEncodingPreset((string) $xml->serverInfo->encodingPreset); $newFile->setTimeToEncode($convert->millisecondsToSeconds($xml->serverInfo->timeToEncode)); $newFile->setTimeInQueue($convert->millisecondsToSeconds($xml->serverInfo->timeInQueue)); $newFile->setHits(0); $fileOutputSize = 0; $destinationPath = ""; foreach ($xml->outputFiles->fileList as $fileList) { foreach ($fileList as $file) { $fileOutputSize = $file['size']; // $destinationPath .= $file['destinationPath']; $destinationPath = $file['destinationPath']; $res = (string) $file['resolution']; $resSplit = explode("x", $res); if (!isset($resSplit[0]) || !isset($resSplit[1])) { $presentation_id = $newPresentation->getpresentationId(); $presentation_path = $newPresentation->getPath(); $this->LogError("Did not find attribute resolution in presentation with id {$presentation_id} and path {$presentation_path}"); } $newFile->setX((int) $resSplit[0]); $newFile->setY((int) $resSplit[1]); $resArr = array(PresentationSchema::X => $newFile->getX(), PresentationSchema::Y => $newFile->getY()); $newFile->setResolution($resArr); break; } } $size = $convert->bytesToMegabytes($fileOutputSize); $newFile->setSize($size); $newPresentation->setSize($this->math->add($newPresentation->getSize(), $size)); /* At this point, destinationPath is to an xml file for some mp3 or mp4 file * To make it easy to check if a file exists and calculate hits later, * is the destinationPath converted to a local path on the computer * this script is running on and xml is swapped with mp3 or mp4. */ $convertedPath = $convert->convertExternalToLocalPath($destinationPath); $strippedPath = $convert->getFilePathWithoutMediaPath($convertedPath); $newFile->setPath($strippedPath); $newPresentation->addFileToFilesArray($newFile); } else { $this->LogError("Tried to create a presentation but one of the xml documents root element did not\n match, therefore presentation will not be created. Rootelement was: " . $xml->getName()); return NULL; } } return $newPresentation; }
private function findAndInsertNewVideos() { // $this->find = new PresentationFind(new RelaySQLConnection()); // $convertedPath = new ConvertHelper(); // $objectCreator = new PresentationCreate(); // $presentationsNotFound = 0; // Last presentation entry in Relay SQL DB $largestPresentationIdFromSource = $this->findLargestPresentationIdFromSource(); // If Relay SQL returned no data if ($largestPresentationIdFromSource === false) { $this->LogError("Could not retrieve largest presentationId from database"); return; } // Inexact number, but will do ok as an indication of how many presentations will be checked. $this->LogInfo("Checking " . ($largestPresentationIdFromSource - $this->currentPresentationId) . " new presentations"); // Scan Relay SQL for each and every new presentation since last run // Updated by Simon@01.11.2016: This loop never used to include the last presentation ID in the table... while ($largestPresentationIdFromSource >= $this->currentPresentationId) { //while($largestPresentationIdFromSource != $this->currentPresentationId) { // All XML file entries for a single presentation (filePresentation_presId, fileId, filePath, createdOn) // Typically returns 4 rows; one per XML-file $query = $this->find->findXMLsForPresentationWithId($this->currentPresentationId); // Will hold the paths to XML metadata files pertaining to a SINGLE presentation (typically 4 paths, one per encoding format) $arrayWithPathToXMLFilesForPresentation = array(); // If we got a hit on our queried presentation ID from Relay SQL if ($this->presentationIdContainsPresentation($query)) { // Counter $this->numberFound = $this->numberFound + 1; // Unused? $presentationIdFromResult = NULL; // Loop all XML files (typically 4) for a single presentation while ($presentation = mssql_fetch_assoc($query)) { // Convert FROM filePath in XML (can be kastra, screencast, samba, whatever) TO exact path to XML file // on current system (e.g. /.../.../.../relaymedia/ansatt/simonuninett.no/2015/14.09/89400/filename.xml $path = $convertedPath->convertExternalToLocalPath($presentation['filePath']); // If an XML file is not found, break out and assume presentation is deleted if ($this->presentationDoesNotExistOnDisk($path)) { $this->LogError("Presentation path " . $path . ' not found on disk.'); break; } else { // Add path to this XML-file to array) $arr = array('path' => $path, 'id' => $presentation['filePresentation_presId']); array_push($arrayWithPathToXMLFilesForPresentation, $arr); } } // If we have the path to one or more XML files for this presentation, // pass them on to the presentation creator for processing if (count($arrayWithPathToXMLFilesForPresentation) > 0) { // PresentationCreate will use XML metadata to create a presentation JSON object that can be // entered into the collection $newPresentation = $objectCreator->createPresentationFromArrayResult($arrayWithPathToXMLFilesForPresentation); // As long as the XML files we sent to the creator are OK, we won't have any problems here. if (!is_null($newPresentation)) { $this->insertPresentationToMongoDb($newPresentation); } } } else { $presentationsNotFound = $presentationsNotFound + 1; } // Go to next presentationID and start new loop. $this->currentPresentationId = $this->currentPresentationId + 1; } }