Implement version::objectMoveChildren() on top of version::objectGetChildren()

This commit is contained in:
Alexander Nicolaysen Sørnes
2009-07-23 01:40:25 +02:00
parent bd7081ebb4
commit e9c4d2ef16
10 changed files with 232 additions and 48 deletions

View File

@@ -118,6 +118,22 @@ class appData
return TRUE;
}
public function objectGetParent($sClass = '')
{
if($this->iVersionId)
return new version($this->iVersionId);
else
return new application($this->iAppId);
}
public function objectSetParent($iNewId, $sClass = '')
{
if($this->iVersionId)
$this->iVersionId = $iNewId;
else
$this->iAppId = $iNewId;
}
function listSubmittedBy($iUserId, $bQueued = true)
{
$sExtra = '';

View File

@@ -187,10 +187,20 @@ class Bug
}
}
//TODO: figure out what we might want to do here but lie and
// return true until then
function update()
{
$oBug = new bug($this->iLinkId);
if($this->iVersionId && $this->iVersionId != $oBug->iVersionId)
{
$hResult = query_parameters("UPDATE buglinks SET versionId = '?'
WHERE linkId = '?'",
$this->iVersionId, $this->iLinkId);
if(!$hResult)
return false;
}
return true;
}
@@ -278,6 +288,16 @@ class Bug
return array(null, null, null);
}
public function objectGetParent($sClass = '')
{
return new version($this->iVersionId);
}
public function objectSetParent($iNewId, $sClass = '')
{
$this->iVersionId = $iNewId;
}
function objectGetChildren($bIncludeDeleted = false)
{
return array();

View File

@@ -136,13 +136,20 @@ class Comment {
*/
function update($sSubject=null, $sBody=null, $iParentId=null, $iVersionId=null)
{
$oComment = new comment($this->iCommentId);
if(!$iVersionId && $this->iVersionId != $oComment->iVersionId)
$iVersionId = $this->iVersionId;
if(!$iParentId && $this->iParentId != $oComment->iParentId)
$iParentId = $this->iParentId;
if ($iParentId)
{
if (!query_parameters("UPDATE appComments SET parentId = '?' WHERE commentId = '?'",
$iParentId, $this->iCommentId))
return false;
$this->iParentId = $iParentId;
}
}
if ($iVersionId)
{
@@ -523,6 +530,32 @@ class Comment {
return array($sSubject, $sMessage, $aRecipients);
}
public function objectGetParent($sClass = '')
{
switch($sClass)
{
case 'version':
return new version($this->iVersionId);
case 'comment':
return new comment($this->iParentId);
}
}
public function objectSetParent($iNewId, $sClass = '')
{
switch($sClass)
{
case 'version':
$this->iVersionId = $iNewId;
break;
case 'comment':
$this->iParentId = $iNewId;
break;
}
}
function objectGetChildren($bIncludeDeleted = false)
{
$aObjects = array();

View File

@@ -63,9 +63,16 @@ class downloadurl
return $sReturn;
}
public function objectSetParent($iId, $sClass = 'version')
public function objectGetParent($sClass = '')
{
$this->iVersionId = $iId;
$oAppData = new appData($this->iId, null, $this);
return $oAppData->objectGetParent();
}
public function objectSetParent($iNewId, $sClass = '')
{
$oAppData = new appData($this->iId, null, $this);
return $oAppData->objectSetParent($iNewId, $sClass);
}
function objectGetChildren($bIncludeDeleted = false)

View File

@@ -899,15 +899,52 @@ class maintainer
return array($aItemsPerPage, $iDefaultPerPage);
}
public function objectGetParent($sClass = '')
{
if($this->iVersionId)
return new version($this->iVersionId);
else
return new application($this->iAppId);
}
public function objectSetParent($iNewId, $sClass = '')
{
if($this->iVersionId)
$this->iVersionId = $iNewId;
else
$this->iAppId = $iNewId;
}
function objectGetChildren($bIncludeDeleted = false)
{
/* We have none */
return array();
}
function update()
public function update()
{
/* STUB: No updating possible at the moment */
$oMaintainer = new maintainer($this->iMaintainerId);
if($this->iVersionId && $oMaintainer->iVersionId != $this->iVersionId)
{
$hResult = query_parameters("UPDATE appMaintainers SET versionId = '?'
WHERE maintainerId = '?'",
$this->iVersionId, $this->iMaintainerId);
if(!$hResult)
return FALSE;
}
if($this->iAppId && $oMaintainer->iAppId != $this->iAppId)
{
$hResult = query_parameters("UPDATE appMaintainers SET appId = '?'
WHERE maintainerId = '?'",
$this->iAppId, $this->iMaintainerId);
if(!$hResult)
return FALSE;
}
return TRUE;
}

View File

@@ -61,6 +61,22 @@ class Monitor {
}
}
public function objectGetParent($sClass = '')
{
if($this->iVersionId)
return new version($this->iVersionId);
else
return new application($this->iAppId);
}
public function objectSetParent($iNewId, $sClass = '')
{
if($this->iVersionId)
$this->iVersionId = $iNewId;
else
$this->iAppId = $iNewId;
}
function objectGetChildren($bIncludeDeleted = false)
{
/* We have none */
@@ -103,7 +119,28 @@ class Monitor {
function update()
{
/* Stub */
$oMonitor = new monitor($this->iMonitorId);
if($this->iVersionId && $oMonitor->iVersionId != $this->iVersionId)
{
$hResult = query_parameters("UPDATE appMonitors SET versionId = '?'
WHERE monitorId = '?'",
$this->iVersionId, $this->iMonitorId);
if(!$hResult)
return FALSE;
}
if($this->iAppId && $oMonitor->iAppId != $this->iAppId)
{
$hResult = query_parameters("UPDATE appMonitors SET appId = '?'
WHERE monitorId = '?'",
$this->iAppId, $this->iMonitorId);
if(!$hResult)
return FALSE;
}
return TRUE;
}

View File

@@ -378,6 +378,22 @@ class Note {
return array(null, null, null);
}
public function objectGetParent($sClass = '')
{
if($this->iVersionId)
return new version($this->iVersionId);
else
return new application($this->iAppId);
}
public function objectSetParent($iNewId, $sClass = '')
{
if($this->iVersionId)
$this->iVersionId = $iNewId;
else
$this->iAppId = $iNewId;
}
function objectGetChildren($bIncludeDeleted = false)
{
return array();

View File

@@ -294,6 +294,18 @@ class screenshot
return $this->oScreenshotImage->get_width();
}
public function objectGetParent($sClass = '')
{
$oAppData = new appData($this->iScreenshotId, null, $this);
return $oAppData->objectGetParent();
}
public function objectSetParent($iNewId, $sClass = '')
{
$oAppData = new appData($this->iScreenshotId, null, $this);
return $oAppData->objectSetParent($iNewId, $sClass);
}
function objectGetChildren($bIncludeDeleted = false)
{
/* We have none */

View File

@@ -511,6 +511,18 @@ class Url {
return array(null, null, null);
}
public function objectGetParent($sClass = '')
{
$oAppData = new appData($this->iUrlId, null, $this);
return $oAppData->objectGetParent();
}
public function objectSetParent($iNewId, $sClass = '')
{
$oAppData = new appData($this->iUrlId, null, $this);
return $oAppData->objectSetParent($iNewId, $sClass);
}
function objectGetChildren($bIncludeDeleted = false)
{
return array();

View File

@@ -1723,18 +1723,19 @@ class version {
return $aTests;
}
public function objectGetChildren($bIncludeDeleted = false)
public function objectGetChildren($bIncludeDeleted = false, $bRecursive = true)
{
return $this->objectGetChildrenClassSpecific('', $bIncludeDeleted);
return $this->objectGetChildrenClassSpecific('', $bIncludeDeleted, $bRecursive);
}
public function objectGetChildrenClassSpecific($sClass = '', $bIncludeDeleted = false)
public function objectGetChildrenClassSpecific($sClass = '', $bIncludeDeleted = false, $bRecursive = true)
{
$aChildren = array();
foreach($this->getTestResults($bIncludeDeleted) as $oTest)
{
$aChildren += $oTest->objectGetChildren($bIncludeDeleted);
if($bRecursive)
$aChildren += $oTest->objectGetChildren($bIncludeDeleted);
$aChildren[] = $oTest;
}
@@ -1748,7 +1749,9 @@ class version {
while($oRow = mysql_fetch_object($hResult))
{
$oMaintainer = new maintainer(0, $oRow);
$aChildren += $oMaintainer->objectGetChildren($bIncludeDeleted);
if($bRecursive)
$aChildren += $oMaintainer->objectGetChildren($bIncludeDeleted);
$aChildren[] = $oMaintainer;
}
@@ -1762,7 +1765,9 @@ class version {
while($oRow = mysql_fetch_object($hResult))
{
$oMonitor = new monitor(0, $oRow);
$aChildren += $oMonitor->objectGetChildren($bIncludeDeleted);
if($bRecursive)
$aChildren += $oMonitor->objectGetChildren($bIncludeDeleted);
$aChildren[] = $oMonitor;
}
@@ -1776,7 +1781,9 @@ class version {
while($oRow = mysql_fetch_object($hResult))
{
$oNote = new note(0, $oRow);
$aChildren += $oNote->objectGetChildren($bIncludeDeleted);
if($bRecursive)
$aChildren += $oNote->objectGetChildren($bIncludeDeleted);
$aChildren[] = $oNote;
}
@@ -1790,7 +1797,9 @@ class version {
while($oRow = mysql_fetch_object($hResult))
{
$oScreenshot = new screenshot(0, $oRow);
$aChildren += $oScreenshot->objectGetChildren($bIncludeDeleted);
if($bRecursive)
$aChildren += $oScreenshot->objectGetChildren($bIncludeDeleted);
$aChildren[] = $oScreenshot;
}
@@ -1798,7 +1807,9 @@ class version {
foreach($this->get_buglink_ids() as $iBugId)
{
$oBug = new bug($iBugId);
$aChildren += $oBug->objectGetChildren($bIncludeDeleted);
if($bRecursive)
$aChildren += $oBug->objectGetChildren($bIncludeDeleted);
$aChildren[] = $oBug;
}
@@ -1812,7 +1823,8 @@ class version {
while($oRow = mysql_fetch_object($hResult))
{
$oComment = new comment(0, $oRow);
$aChildren += $oComment->objectGetChildren($bIncludeDeleted);
/* No need to grab child comments since they're all part of the SQL result */
$aChildren[] = $oComment;
}
@@ -1826,7 +1838,9 @@ class version {
while($oRow = mysql_fetch_object($hResult))
{
$oUrl = new url(0, $oRow);
$aChildren += $oUrl->objectGetChildren($bIncludeDeleted);
if($bRecursive)
$aChildren += $oUrl->objectGetChildren($bIncludeDeleted);
$aChildren[] = $oUrl;
}
@@ -1840,7 +1854,9 @@ class version {
while($oRow = mysql_fetch_object($hResult))
{
$oDownload = new downloadurl(0, $oRow);
$aChildren += $oDownload->objectGetChildren($bIncludeDeleted);
if($bRecursive)
$aChildren += $oDownload->objectGetChildren($bIncludeDeleted);
$aChildren[] = $oDownload;
}
@@ -1852,38 +1868,16 @@ class version {
/* 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);
/* We also move entries marked as deleted */
$aChildren = $this->objectGetChildren(true, false);
if(!$hResult)
return FALSE;
while($oRow = query_fetch_object($hResult))
foreach($aChildren as $oChild)
{
$oTestData = new testData($oRow->testingId);
$oTestData->iVersionId = $iNewId;
if($oTestData->update())
$oChild->objectSetParent($iNewId, 'version');
if($oChild->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 = query_fetch_object($hResult))
{
$oAppData = new appData($oRow->testingId);
$oAppData->iVersionId = $iNewId;
if($oAppData->update(TRUE))
$iCount++;
else
return FALSE;
return false;
}
/* Return the number of updated objects if everything was successful */