示例#1
0
 /**
  * Posts a new version of this package for a given person.
  * @param Person $objPerson
  * @param string $strQpmXml
  * @param QDateTime $dttPostDate optional, uses Now() if not specified
  * @return PackageContribution
  */
 public function PostContributionVersion(Person $objPerson, $strQpmXml, QDateTime $dttPostDate = null)
 {
     // Get PackageContribution
     $objContribution = PackageContribution::LoadByPackageIdPersonId($this->intId, $objPerson->Id);
     // Parse the QPM XML
     try {
         $objQpmXml = new SimpleXMLElement($strQpmXml);
     } catch (Exception $objExc) {
         throw new Exception('Invalid QPM Schema');
     }
     // Compress the XML
     $strQpmXmlCompressed = gzencode($strQpmXml, 9);
     // Validate the XML
     $strQpmVersion = (string) $objQpmXml['version'];
     if ($strQpmVersion != '1.0') {
         throw new Exception('Invalid QPM Schema Version: ' . $strQpmVersion);
     }
     // Pull out the rest of the data and validate it all
     $strPackageName = (string) $objQpmXml->package['name'];
     $strPackageUsername = (string) $objQpmXml->package['user'];
     $intVersionNumber = (string) $objQpmXml->package['version'];
     $strQcodoVersionNumber = (string) $objQpmXml->package['qcodoVersion'];
     $strNotes = (string) $objQpmXml->package->notes;
     $intNewFileCount = count($objQpmXml->package->newFiles->children());
     $intChangedFileCount = count($objQpmXml->package->changedFiles->children());
     if ($strPackageName != $this->Token) {
         throw new Exception('Invalid QPM Package Name: ' . $strPackageName);
     }
     if ($strPackageUsername != $objPerson->Username) {
         throw new Exception('Invalid QPM Package User: '******'Invalid QPM Package Version: ' . $intVersionNumber);
         }
     } else {
         if ($intVersionNumber != 1) {
             throw new Exception('Invalid QPM Package Version: ' . $intVersionNumber);
         }
     }
     preg_match('/[0-9]+\\.[0-9]+\\.[0-9]+/', $strQcodoVersionNumber, $arrMatches);
     if ($arrMatches[0] != $strQcodoVersionNumber) {
         throw new Exception('Invalid Qcodo Version Number in QpmXml: ' . $strQcodoVersionNumber);
     }
     // Create PackageContribution (if none exists)
     if (!$objContribution) {
         $objContribution = new PackageContribution();
         $objContribution->Package = $this;
         $objContribution->Person = $objPerson;
         $objContribution->Save();
     }
     $objVersion = new PackageVersion();
     $objVersion->PackageContribution = $objContribution;
     $objVersion->Notes = $strNotes;
     $objVersion->QcodoVersion = $strQcodoVersionNumber;
     $objVersion->NewFileCount = $intNewFileCount;
     $objVersion->ChangedFileCount = $intChangedFileCount;
     $objVersion->PostDate = $dttPostDate ? $dttPostDate : QDateTime::Now();
     $objVersion->DownloadCount = 0;
     $objVersion->VersionNumber = $intVersionNumber;
     $objVersion->Save();
     $objContribution->CurrentPackageVersion = $objVersion;
     $objContribution->CurrentPostDate = $objVersion->PostDate;
     $objContribution->RefreshStats();
     $this->LastPostDate = $objVersion->PostDate;
     $this->LastPostedByPerson = $objPerson;
     $this->Save();
     $objVersion->SaveFile($strQpmXml, $strQpmXmlCompressed);
     $this->PackageCategory->RefreshStats();
     return $objContribution;
 }