From cf81d542ee9be28b5f0cfb86991d3c58fac3803a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Nicolaysen=20S=C3=B8rnes?= Date: Mon, 23 Apr 2007 23:31:24 +0000 Subject: [PATCH] Add a moveChildren method to the objectManager and implement objectMoveChildren for version and version_queue. Use this to move versions. --- include/appData.php | 23 +++++++++++++++++++++ include/objectManager.php | 29 ++++++++++++++++++++++++++ include/version.php | 43 +++++++++++++++++++++++++++++++++++++++ include/version_queue.php | 13 ++++++++---- objectManager.php | 5 +++++ 5 files changed, 109 insertions(+), 4 deletions(-) diff --git a/include/appData.php b/include/appData.php index 6803bad..b5a92eb 100644 --- a/include/appData.php +++ b/include/appData.php @@ -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 diff --git a/include/objectManager.php b/include/objectManager.php index 9751836..d4cfe4a 100644 --- a/include/objectManager.php +++ b/include/objectManager.php @@ -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 = "") { diff --git a/include/version.php b/include/version.php index 5d612b0..ebab144 100644 --- a/include/version.php +++ b/include/version.php @@ -1366,6 +1366,49 @@ class Version { echo "

To view a submission, click on its name. ". "From that page you can edit, delete or approve it into the AppDB.

\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; + } } ?> diff --git a/include/version_queue.php b/include/version_queue.php index 62d61ed..7511f67 100644 --- a/include/version_queue.php +++ b/include/version_queue.php @@ -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); + } } ?> diff --git a/objectManager.php b/objectManager.php index 0e89404..9836b35 100644 --- a/objectManager.php +++ b/objectManager.php @@ -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 */