Alexander Nicolaysen Sørnes : Cache whether a version as a maintainer

Alexander Nicolaysen Sørnes asornes at winehq.org
Thu Nov 12 17:08:08 CST 2009


Module: appdb
Branch: master
Commit: 6b51c62a3f022fe139ae6648b7acbdc46967d82e
URL:    http://source.winehq.org/git/appdb.git/?a=commit;h=6b51c62a3f022fe139ae6648b7acbdc46967d82e

Author: Alexander Nicolaysen Sørnes <alexander at linux-xqqm.(none)>
Date:   Thu Nov 12 00:36:48 2009 +0100

Cache whether a version as a maintainer

---

 include/maintainer.php  |   44 +++++++++++++++++++++++++++++++++++++++-----
 include/version.php     |    9 +++++++++
 tables/appdb_tables.sql |    1 +
 3 files changed, 49 insertions(+), 5 deletions(-)

diff --git a/include/maintainer.php b/include/maintainer.php
index 9285f8f..3741264 100644
--- a/include/maintainer.php
+++ b/include/maintainer.php
@@ -230,7 +230,7 @@ class maintainer
         $this->iMaintainerId = query_appdb_insert_id();
 
         if(!$this->mustBeQueued())
-            $this->updateAppMaintainerState();
+            $this->updateMaintainerState();
 
         /* If this is a non-queued maintainer submission, remove the user's non-
            super maintainer entries for the application's versions.  This check is
@@ -260,7 +260,7 @@ class maintainer
             {
                 $sStatusMessage = "<p>The maintainer was successfully added into the database</p>\n";
 
-                $this->updateAppMaintainerState();
+                $this->updateMaintainerState();
 
                 //Send Status Email
                 $sEmail = $oUser->sEmail;
@@ -353,7 +353,7 @@ class maintainer
         if(!$hResult)
             return FALSE;
 
-        $this->updateAppMaintainerState();
+        $this->updateMaintainerState();
 
         return TRUE;
     }
@@ -424,12 +424,33 @@ class maintainer
         return $hResult;
     }
 
-    public function updateAppMaintainerState()
+    public function updateMaintainerState()
     {
-        $oApp = new application($this->iAppId);
+        if($this->bSuperMaintainer)
+        {
+            $this->updateAppMaintainerState($this->iAppId);
+            $oApp = new application($this->iAppId);
+            $aVersions = $oApp->objectGetChildrenClassSpecific('version');
+            foreach($aVersions as $oVersion)
+                $this->updateVersionMaintainerState($oVersion->objectGetId());
+        } else
+        {
+            $this->updateVersionMaintainerState($this->iVersionId);
+        }
+    }
+
+    public function updateAppMaintainerState($iAppId)
+    {
+        $oApp = new application($iAppId);
         $oApp->updateMaintainerState();
     }
 
+    public function updateVersionMaintainerState($iVersionId)
+    {
+        $oVersion = new version($iVersionId);
+        $oVersion->updateMaintainerState();
+    }
+
     function getSubmitterEmails()
     {
         $sRecipients = '';
@@ -623,6 +644,19 @@ class maintainer
         return $oRow->count > 0;
     }
 
+    /* Returns true if the given version has a maintainer, false otherwise */
+    public function versionHasMaintainer($iVersionId)
+    {
+        $oVersion = new version($iVersionId);
+        $hResult = query_parameters("SELECT COUNT(maintainerId) as count FROM appMaintainers WHERE (appId = '?' AND superMaintainer = '1') OR (versionId = '?') AND state = 'accepted'", $oVersion->iAppId, $iVersionId);
+
+        if(!$hResult)
+            return false;
+
+        $oRow = mysql_fetch_object($hResult);
+        return $oRow->count > 0;
+    }
+
     /* if given an appid or a version id return a handle for a query that has */
     /* the user ids that are maintainers for this particular appid or version id */
     function getMaintainersForAppIdVersionId($iAppId = null, $iVersionId = null)
diff --git a/include/version.php b/include/version.php
index 70a5b37..4fccfd0 100644
--- a/include/version.php
+++ b/include/version.php
@@ -36,6 +36,7 @@ class version {
     var $iSubmitterId;
     private $sState;
     var $sLicense;
+    var $bHasMaintainer;
     var $aTestResults; /* Array of test result objects. Especially useful when
                           we want to preview a version before submitting it;
                           in that case there is no data in the database */
@@ -81,6 +82,7 @@ class version {
             $this->sState = $oRow->state;
             $this->sLicense = $oRow->license;
             $this->iObsoleteBy = $oRow->obsoleteBy;
+            $this->bHasMaintainer = $oRow->hasMaintainer == 'true' ? true : false;
         }
     }
 
@@ -1532,6 +1534,13 @@ class version {
         $this->sState = $sState;
     }
 
+    public function updateMaintainerState()
+    {
+        $this->bHasMaintainer = maintainer::versionHasMaintainer($this->iVersionId);
+
+        $hResult = query_parameters("UPDATE appVersion SET hasMaintainer = '?' WHERE versionId = '?'", $this->bHasMaintainer ? 'true' : 'false', $this->iVersionId);
+    }
+
     public function canEdit()
     {
         if($_SESSION['current']->hasPriv("admin"))
diff --git a/tables/appdb_tables.sql b/tables/appdb_tables.sql
index 69ab049..d2bfbb8 100644
--- a/tables/appdb_tables.sql
+++ b/tables/appdb_tables.sql
@@ -60,6 +60,7 @@ create table appVersion (
   license		enum('Retail','Open Source','Demo','Shareware','Free to use','Free to use and share'),
   obsoleteBy            int(11) NOT NULL default '0',
   state                 enum('accepted','queued','rejected','pending','deleted') NOT NULL default 'accepted',
+  hasMaintainer enum('true','false') NOT NULL default 'false',
   key(versionId),
   index(appId)
 );




More information about the wine-cvs mailing list