/** * Copies the file to it's final destination and persists * the file meta-data to the database. * @param $sourceFile string the path to the file to be copied * @param $monographFile MonographFile the file metadata * @param $copyOnly boolean set to true if the file has not been uploaded * but already exists on the file system. * @return MonographFile */ function &_persistFile($sourceFile, &$monographFile, $copyOnly = false) { // Persist the file meta-data (without the file name) and generate a file id. $submissionFileDao =& DAORegistry::getDAO('SubmissionFileDAO'); /* @var $submissionFileDao SubmissionFileDAO */ if (!$submissionFileDao->insertObject($monographFile)) { return false; } // Generate and set a file name (requires the monograph id // that we generated when inserting the monograph data). MonographFileManager::_generateAndPopulateFileName($monographFile); // Determine the final destination of the file (requires // the name we just generated). $targetFile = $monographFile->getFilePath(); // If the "copy only" flag is set then copy the file from its // current place to the target destination. Otherwise upload // the file to the target folder. if (!($copyOnly && MonographFileManager::copyFile($sourceFile, $targetFile) || MonographFileManager::uploadFile($sourceFile, $targetFile))) { // If the copy/upload operation fails then remove // the already inserted meta-data. $submissionFileDao->deleteRevision($monographFile); return false; } // Determine and set the file size of the target file. $monographFile->setFileSize(filesize($targetFile)); // Update the monograph with the file name and file size. $submissionFileDao->updateObject($monographFile); // Return the file. return $monographFile; }