Пример #1
0
 public static function storeUploadedFile($filename, $release, $target, $userid = 0, &$warnings = null)
 {
     $output = "";
     if (!file_exists($filename)) {
         return "Could not find uploaded package file";
     }
     //Check if release is not in production
     $state = $release->getCommRepoState()->name;
     if (strtolower($state) === "production") {
         return "Current release is in production. No uploads are permitted";
     }
     //Check if file type can be managed
     $ftype = self::getFileType($filename);
     if ($ftype === false) {
         return "Unsupported file type";
     }
     //Check if file type is valid for the specified target
     if (self::isSupportedArtifactType($target, $ftype) === false) {
         return "File type " . $ftype . " is not supported for this release";
     }
     //Retrieve package information to check architecture
     $info = true;
     //in case of generic tar packages
     if ($ftype == "rpm") {
         $info = RepositoryPackage::getRpmInfo($filename);
     } else {
         if ($ftype == "deb") {
             $info = RepositoryPackage::getDebInfo($filename);
         } else {
             if ($ftype == "gzip") {
                 $info = RepositoryPackage::getGzipInfo($filename);
             }
         }
     }
     if ($info === false || count($info) === 0) {
         return "Cannot retrieve " . $ftype . " package information";
     }
     $fileexists = RepositoryFS::fileExists(basename($filename), $release, $target, $release->getSoftwareId(), $info["type"]);
     if ($fileexists == true) {
         return "File with the same name already uploaded for this release";
     }
     //Retrieve or create POA release
     $poa = Repository::createPoa($release, $target, $userid, $output);
     if ($poa === false) {
         return $output;
     }
     $poaid = $poa->id;
     //retriev destination path
     $storagepath = RepositoryFS::getStoragePath($error);
     $storagepath = $storagepath === false ? "" : $storagepath;
     $poapath = RepositoryFS::getDatabankForPoa($poa, $release->getSoftwareId(), $output, true);
     if ($poapath === false) {
         $info["pkgfilepath"] = "";
     } else {
         $poarelpath = str_replace($storagepath, "", $poapath);
         $info["pkgfilepath"] = $poarelpath . $info["type"] . DIRECTORY_SEPARATOR;
         $poa->poaPath = $info["pkgfilepath"];
         $poa->save();
     }
     //Check if file already exists in POA release
     $exists = Repository::hasPOAPackage($poaid, $info);
     if ($exists === false) {
         //Save POA Release package
         $pkg = Repository::createPoaPackage($poaid, $info, $userid, $output);
         //Calculate package version indexing upon package creation success
         if ($pkg !== false) {
             RepositoryBackend::calculatePackageVersionIndex($pkg);
         }
     } else {
         //Update POA release package
         $pkg = Repository::updatePoaPackage($exists, $info, $output);
     }
     if ($pkg === false) {
         return $output;
     }
     //move POA Release package to databank
     RepositoryFS::makePath($poapath . $info["type"] . DIRECTORY_SEPARATOR);
     if (copy($filename, $storagepath . $info["pkgfilepath"] . $info["filename"])) {
         unlink($filename);
     }
     $archname = $target->getArch()->name;
     $archname = strtolower($archname);
     return $pkg->id;
 }