PKPFileUploadWizardHandler::_checkForRevision PHP Method

_checkForRevision() public method

Check if the uploaded file has a similar name to an existing file which would then be a candidate for a revised file.
public _checkForRevision ( &$uploadedFile, &$submissionFiles ) : integer
$uploadedFile SubmissionFile
$submissionFiles array a list of submission files to check the uploaded file against.
return integer the if of the possibly revised file or null if no matches were found.
    function &_checkForRevision(&$uploadedFile, &$submissionFiles)
    {
        // Get the file name.
        $uploadedFileName = $uploadedFile->getOriginalFileName();
        // Start with the minimal required similarity.
        $minPercentage = Config::getVar('files', 'filename_revision_match', 70);
        // Find out whether one of the files belonging to the current
        // file stage matches the given file name.
        $possibleRevisedFileId = null;
        $matchedPercentage = 0;
        foreach ($submissionFiles as $submissionFile) {
            /* @var $submissionFile SubmissionFile */
            // Do not consider the uploaded file itself.
            if ($uploadedFile->getFileId() == $submissionFile->getFileId()) {
                continue;
            }
            // Do not consider files from different publication formats.
            if ($uploadedFile->getAssocType() == ASSOC_TYPE_REPRESENTATION && $submissionFile->getAssocType() == ASSOC_TYPE_REPRESENTATION && $uploadedFile->getAssocId() != $submissionFile->getAssocId()) {
                continue;
            }
            // Test whether the current submission file is similar
            // to the uploaded file. (Transliterate to ASCII -- the
            // similar_text function can't handle UTF-8.)
            import('lib.pkp.classes.core.Transcoder');
            $transcoder = new Transcoder('UTF-8', 'ASCII', true);
            similar_text($a = $transcoder->trans($uploadedFileName), $b = $transcoder->trans($submissionFile->getOriginalFileName()), $matchedPercentage);
            if ($matchedPercentage > $minPercentage && !$this->_onlyNumbersDiffer($a, $b)) {
                // We found a file that might be a possible revision.
                $possibleRevisedFileId = $submissionFile->getFileId();
                // Reset the min percentage to this comparison's precentage
                // so that only better matches will be considered from now on.
                $minPercentage = $matchedPercentage;
            }
        }
        // Return the id of the file that we found similar.
        return $possibleRevisedFileId;
    }