appdb/ ./objectManager.php include/appData.php ...

WineHQ wineowner at wine.codeweavers.com
Mon Apr 23 18:31:24 CDT 2007


ChangeSet ID:	31091
CVSROOT:	/opt/cvs-commit
Module name:	appdb
Changes by:	wineowner at winehq.org	2007/04/23 18:31:24

Modified files:
	.              : objectManager.php 
	include        : appData.php objectManager.php version.php 
	                 version_queue.php 

Log message:
	Alexander Nicolaysen Sørnes <alex at thehandofagony.com>
	Add a moveChildren method to the objectManager and implement objectMoveChildren for version
	and version_queue. Use this to move versions.

Patch: http://cvs.winehq.org/patch.py?id=31091

Old revision  New revision  Changes     Path
 1.6           1.7           +5 -0       appdb/objectManager.php
 1.17          1.18          +23 -0      appdb/include/appData.php
 1.15          1.16          +29 -0      appdb/include/objectManager.php
 1.120         1.121         +43 -0      appdb/include/version.php
 1.6           1.7           +9 -4       appdb/include/version_queue.php

Index: appdb/objectManager.php
diff -u -p appdb/objectManager.php:1.6 appdb/objectManager.php:1.7
--- appdb/objectManager.php:1.6	23 Apr 2007 23:31:24 -0000
+++ appdb/objectManager.php	23 Apr 2007 23:31:24 -0000
@@ -64,6 +64,11 @@ if($sErrors === TRUE)
 if($oObject->iId && $aClean['sAction'] == "delete")
     $oObject->delete_entry();
 
+/* Provided the necessary values are present, an object's children may be moved
+   without any confirmation */
+if($oObject->iId && $aClean['sAction'] == "moveChildren" && $aClean['iNewId'])
+    $oObject->move_children($aClean['iNewId']);
+
 apidb_header($oObject->sTitle);
 
 /* display a particular element */
Index: appdb/include/appData.php
diff -u -p appdb/include/appData.php:1.17 appdb/include/appData.php:1.18
--- appdb/include/appData.php:1.17	23 Apr 2007 23:31:24 -0000
+++ appdb/include/appData.php	23 Apr 2007 23:31:24 -0000
@@ -52,6 +52,29 @@ class appData
         return $hResult;
     }
 
+    function update($bSilent = FALSE)
+    {
+        if(!$this->canEdit())
+            return FALSE;
+
+        $sQuery = "UPDATE appData SET versionId = '?', appId = '?', sDescription = '?'
+                        WHERE id = '?'";
+        $hResult = query_parameters($this->iVersionId, $this->iAppId,
+                                    $this->sDescription, $this->iId);
+ 
+        if(!$hResult)
+        {
+            if(!$bResult)
+                addmsg("Failed to update add data", "red");
+            return FALSE;
+        }
+
+        if(!$bSilent)
+            addmsg("Updated app data successfully", "green");
+
+        return TRUE;
+    }
+
     function listSubmittedBy($iUserId, $bQueued = true)
     {
         $hResult = query_parameters("SELECT * FROM appData WHERE
Index: appdb/include/objectManager.php
diff -u -p appdb/include/objectManager.php:1.15 appdb/include/objectManager.php:1.16
--- appdb/include/objectManager.php:1.15	23 Apr 2007 23:31:24 -0000
+++ appdb/include/objectManager.php	23 Apr 2007 23:31:24 -0000
@@ -220,6 +220,35 @@ class ObjectManager
             echo "Failure.\n";
     }
 
+    /* Move all the object's children to another object of the same type, and
+       delete the original object afterwards */
+    function move_children($iNewId)
+    {
+        $oObject = new $this->sClass($this->iId);
+        $oNewObject = new $this->sClass($iNewId);
+
+        /* The user needs to have edit rights to both the old and the new object
+           If you have edit rights to an object then you should have edit rights
+           to its child objects as well */
+        if(!$oObject->canEdit() || !$oNewObject->canEdit())
+            return FALSE;
+
+        $iAffected = $oObject->objectMoveChildren($iNewId);
+
+        if($iAffected)
+        {
+            $sPlural = ($iAffected == 1) ? "": "s";
+            addmsg("Moved $iAffected child object$sPlural", "green");
+        } else if($iAfffected === FALSE)
+        {
+            /* We don't want to delete this object if some children were not moved */
+            addmsg("Failed to move child objects", "red");
+            return FALSE;
+        }
+
+        $this->delete_entry();
+    }
+
     /* Display screen for submitting a new entry of given type */
     function add_entry($sBackLink, $sErrors = "")
     {
Index: appdb/include/version.php
diff -u -p appdb/include/version.php:1.120 appdb/include/version.php:1.121
--- appdb/include/version.php:1.120	23 Apr 2007 23:31:24 -0000
+++ appdb/include/version.php	23 Apr 2007 23:31:24 -0000
@@ -1366,6 +1366,49 @@ class Version {
         echo "<p>To view a submission, click on its name. ".
              "From that page you can edit, delete or approve it into the AppDB.</p>\n";
     }
+
+    function objectMoveChildren($iNewId)
+    {
+        /* Keep track of how many items we have updated */
+        $iCount = 0;
+
+        /* Move test results */
+        $sQuery = "SELECT * FROM testResults WHERE versionId = '?'";
+        $hResult = query_parameters($sQuery, $this->iVersionId);
+
+        if(!$hResult)
+            return FALSE;
+
+        while($oRow = mysql_fetch_object($hResult))
+        {
+            $oTestData = new testData($oRow->testingId);
+            $oTestData->iVersionId = $iNewId;
+            if($oTestData->update())
+                $iCount++;
+            else
+                return FALSE;
+        }
+
+        /* Move all app data */
+        $sQuery = "SELECT * FROM appData WHERE versionId = '?'";
+        $hResult = query_parameters($sQuery, $this->iVersionId);
+
+        if(!$hResult)
+            return FALSE;
+
+        while($oRow = mysql_fetch_object($hResult))
+        {
+            $oAppData = new appData($oRow->testingId);
+            $oAppData->iVersionId = $iNewId;
+            if($oAppData->update(TRUE))
+                $iCount++;
+            else
+                return FALSE;
+        }
+
+        /* Return the number of updated objects if everything was successful */
+        return $iCount;
+    }
 }
 
 ?>
Index: appdb/include/version_queue.php
diff -u -p appdb/include/version_queue.php:1.6 appdb/include/version_queue.php:1.7
--- appdb/include/version_queue.php:1.6	23 Apr 2007 23:31:24 -0000
+++ appdb/include/version_queue.php	23 Apr 2007 23:31:24 -0000
@@ -197,10 +197,10 @@ class version_queue
                         array(Comment::get_comment_count_for_versionid(
                             $oVersion->iVersionId), 'align="center"'),
                         html_ahref("Move here",
-                          "admin/adminAppQueue.php?sSub=movetest&sAppType=version&".
-                          "iVersionId="
-                          .$this->oVersion->iVersionId."&iVersionIdMergeTo=".
-                          $oVersion->iVersionId)
+                          "objectManager.php?sClass=version_queue&bIsQueue=true&".
+                          "sAction=moveChildren&iId=".
+                          $this->oVersion->iVersionId."&iNewId=".
+                          $oVersion->iVersionId."&sTitle=Version+Queue"),
                                   ),
                             ($i % 2) ? "color0" : "color1");
 
@@ -215,6 +215,11 @@ class version_queue
     {
         version::objectDisplayQueueProcessingHelp();
     }
+
+    function objectMoveChildren($iNewId)
+    {
+        return $this->oVersion->objectMoveChildren($iNewId);
+    }
 }
 
 ?>



More information about the wine-cvs mailing list