diff --git a/include/appData.php b/include/appData.php index aa768f0..5c29523 100644 --- a/include/appData.php +++ b/include/appData.php @@ -17,7 +17,7 @@ class appData function appData($iId = null, $oRow = null) { - if(!$iId) + if(!$iId && !$oRow) return; if(!$oRow) diff --git a/include/application.php b/include/application.php index d359be4..9539b91 100644 --- a/include/application.php +++ b/include/application.php @@ -46,51 +46,51 @@ class Application { function Application($iAppId = null, $oRow = null) { // we are working on an existing application - if(is_numeric($iAppId)) + if(!$iAppId && !$oRow) + return; + + if(!$oRow) { - if(!$oRow) - { - /* fetch this applications information */ - $sQuery = "SELECT * - FROM appFamily - WHERE appId = '?'"; - if($hResult = query_parameters($sQuery, $iAppId)) - $oRow = mysql_fetch_object($hResult); - } + /* fetch this applications information */ + $sQuery = "SELECT * + FROM appFamily + WHERE appId = '?'"; + if($hResult = query_parameters($sQuery, $iAppId)) + $oRow = mysql_fetch_object($hResult); + } - if($oRow) - { - $this->iAppId = $iAppId; - $this->iVendorId = $oRow->vendorId; - $this->iCatId = $oRow->catId; - $this->iSubmitterId = $oRow->submitterId; - $this->sSubmitTime = $oRow->submitTime; - $this->sDate = $oRow->submitTime; - $this->sName = $oRow->appName; - $this->sKeywords = $oRow->keywords; - $this->sDescription = $oRow->description; - $this->sWebpage = $oRow->webPage; - $this->sQueued = $oRow->queued; - } + if($oRow) + { + $this->iAppId = $oRow->appId; + $this->iVendorId = $oRow->vendorId; + $this->iCatId = $oRow->catId; + $this->iSubmitterId = $oRow->submitterId; + $this->sSubmitTime = $oRow->submitTime; + $this->sDate = $oRow->submitTime; + $this->sName = $oRow->appName; + $this->sKeywords = $oRow->keywords; + $this->sDescription = $oRow->description; + $this->sWebpage = $oRow->webPage; + $this->sQueued = $oRow->queued; + } - /* fetch versions of this application, if there are any */ - $this->aVersionsIds = array(); + /* fetch versions of this application, if there are any */ + $this->aVersionsIds = array(); - /* only admins can view all versions */ - //FIXME: it would be nice to move this permission into the user class as well as keep it generic - if($_SESSION['current']->hasPriv("admin")) + /* only admins can view all versions */ + //FIXME: it would be nice to move this permission into the user class as well as keep it generic + if($_SESSION['current']->hasPriv("admin")) + { + $hResult = $this->_internal_retrieve_all_versions(); + } else + { + $hResult = $this->_internal_retrieve_unqueued_versions(); + } + if($hResult) + { + while($oRow = mysql_fetch_object($hResult)) { - $hResult = $this->_internal_retrieve_all_versions(); - } else - { - $hResult = $this->_internal_retrieve_unqueued_versions(); - } - if($hResult) - { - while($oRow = mysql_fetch_object($hResult)) - { - $this->aVersionsIds[] = $oRow->versionId; - } + $this->aVersionsIds[] = $oRow->versionId; } } } @@ -847,11 +847,6 @@ class Application { return $aCells; } - function objectGetInstanceFromRow($oRow) - { - return new application($oRow->appId, $oRow); - } - function objectOutputTableRow($oObject, $sClass, $sEditLinkLabel) { $oUser = new user($this->iSubmitterId); diff --git a/include/application_queue.php b/include/application_queue.php index 0c6cdb4..802fa70 100644 --- a/include/application_queue.php +++ b/include/application_queue.php @@ -10,13 +10,13 @@ class application_queue var $oApp; var $oVendor; - function application_queue($iAppId = null) + function application_queue($iAppId = null, $oRow = null) { - $this->oApp = new application($iAppId); + $this->oApp = new application($iAppId, $oRow); /* If this is an existing application then there must be a version accompanying it */ - if($iAppId) + if($this->oApp->iAppId) { /* Normal users do not get a aVersionsIds property, so we have to fetch the versionId manually. Normal users only have access to rejected @@ -302,11 +302,6 @@ class application_queue return $this->oApp->objectGetHeader(); } - function objectGetInstanceFromRow($oRow) - { - return application::objectGetInstanceFromRow($oRow); - } - function objectOutputTableRow($oObject, $sClass, $sEditLinkLabel) { return $this->oApp->objectOutputTableRow($oObject, $sClass, $sEditLinkLabel); diff --git a/include/distribution.php b/include/distribution.php index 49a274c..3999728 100644 --- a/include/distribution.php +++ b/include/distribution.php @@ -20,58 +20,58 @@ class distribution { function distribution($iDistributionId = null, $oRow = null) { // we are working on an existing distribution. - if(is_numeric($iDistributionId)) + if(!$iDistributionId && !$oRow) + return; + + // We fetch the data related to this distribution. + if(!$oRow) { - // We fetch the data related to this distribution. - if(!$oRow) - { - $sQuery = "SELECT * - FROM distributions - WHERE distributionId = '?'"; - if($hResult = query_parameters($sQuery, $iDistributionId)) - $oRow = mysql_fetch_object($hResult); - } - - if($oRow) - { - $this->iDistributionId = $iDistributionId; - $this->sName = $oRow->name; - $this->sUrl = $oRow->url; - $this->sSubmitTime = $oRow->submitTime; - $this->iSubmitterId = $oRow->submitterId; - $this->sQueued = $oRow->queued; - } - - /* - * We fetch Test Result Ids. - */ - - if($_SESSION['current']->hasPriv("admin")) - { - $sQuery = "SELECT testingId - FROM testResults - WHERE distributionId = '?' - ORDER BY testedRating;" ; - } else /* only let users view test results that aren't queued and for apps that */ - /* aren't queued or versions that aren't queued */ - { - $sQuery = "SELECT testingId - FROM testResults, appFamily, appVersion - WHERE testResults.queued = 'false' AND - testResults.versionId = appVersion.versionId AND - appFamily.appId = appVersion.appId AND - appFamily.queued = 'false' AND - appVersion.queued = 'false' AND - distributionId = '?' - ORDER BY testedRating;"; - } - + $sQuery = "SELECT * + FROM distributions + WHERE distributionId = '?'"; if($hResult = query_parameters($sQuery, $iDistributionId)) + $oRow = mysql_fetch_object($hResult); + } + + if($oRow) + { + $this->iDistributionId = $oRow->distributionId; + $this->sName = $oRow->name; + $this->sUrl = $oRow->url; + $this->sSubmitTime = $oRow->submitTime; + $this->iSubmitterId = $oRow->submitterId; + $this->sQueued = $oRow->queued; + } + + /* + * We fetch Test Result Ids. + */ + + if($_SESSION['current']->hasPriv("admin")) + { + $sQuery = "SELECT testingId + FROM testResults + WHERE distributionId = '?' + ORDER BY testedRating;" ; + } else /* only let users view test results that aren't queued and for apps that */ + /* aren't queued or versions that aren't queued */ + { + $sQuery = "SELECT testingId + FROM testResults, appFamily, appVersion + WHERE testResults.queued = 'false' AND + testResults.versionId = appVersion.versionId AND + appFamily.appId = appVersion.appId AND + appFamily.queued = 'false' AND + appVersion.queued = 'false' AND + distributionId = '?' + ORDER BY testedRating;"; + } + + if($hResult = query_parameters($sQuery, $iDistributionId)) + { + while($oRow = mysql_fetch_object($hResult)) { - while($oRow = mysql_fetch_object($hResult)) - { - $this->aTestingIds[] = $oRow->testingId; - } + $this->aTestingIds[] = $oRow->testingId; } } } @@ -453,11 +453,6 @@ class distribution { $iStart, $iRows); } - function objectGetInstanceFromRow($oRow) - { - return new distribution($oRow->distributionId, $oRow); - } - /* arg1 = OM object, arg2 = CSS style, arg3 = text for edit link */ function objectOutputTableRow($oManager, $sClass, $sEditLinkLabel) { diff --git a/include/downloadurl.php b/include/downloadurl.php index 1ea345a..6447ee4 100644 --- a/include/downloadurl.php +++ b/include/downloadurl.php @@ -17,25 +17,30 @@ class downloadurl var $bQueued; /* Fetch the data if id is given */ - function downloadurl($iId = NULL) + function downloadurl($iId = NULL, $oRow = NULL) { - $hResult = query_parameters("SELECT id, versionId, description, url, - submitTime, submitterId, queued FROM appData WHERE id = '?'", - $iId); + if(!$iId && !$oRow) + return; - if($hResult && mysql_num_rows($hResult)) + if(!$oRow) { - $oRow = mysql_fetch_object($hResult); - if($oRow) - { - $this->iId = $oRow->id; - $this->iVersionId = $oRow->versionId; - $this->sDescription = $oRow->description; - $this->sUrl = $oRow->url; - $this->sSubmitTime = $oRow->submitTime; - $this->iSubmitterId = $oRow->submitterId; - $this->bQueued = ($oRow->queued == "true") ? TRUE : FALSE; - } + $hResult = query_parameters("SELECT id, versionId, description, url, + submitTime, submitterId, queued FROM appData WHERE id = '?'", + $iId); + + if($hResult && mysql_num_rows($hResult)) + $oRow = mysql_fetch_object($hResult); + } + + if($oRow) + { + $this->iId = $oRow->id; + $this->iVersionId = $oRow->versionId; + $this->sDescription = $oRow->description; + $this->sUrl = $oRow->url; + $this->sSubmitTime = $oRow->submitTime; + $this->iSubmitterId = $oRow->submitterId; + $this->bQueued = ($oRow->queued == "true") ? TRUE : FALSE; } } @@ -407,11 +412,6 @@ class downloadurl $oAppData->objectOutputTableRow($oObject, $sClass, $sEditLinkLabel); } - function objectGetInstanceFromRow($oRow) - { - return new appData($oRow->id, $oRow); - } - function getOutputEditorValues($aClean) { $this->sUrl = $aClean['sDownloadUrlUrl']; diff --git a/include/maintainer.php b/include/maintainer.php index 006a19f..247aad3 100644 --- a/include/maintainer.php +++ b/include/maintainer.php @@ -18,24 +18,29 @@ class maintainer var $bQueued; var $sReplyText; - function maintainer($iMaintainerId = "") + function maintainer($iMaintainerId = null, $oRow = null) { - $sQuery = "SELECT * FROM appMaintainers WHERE maintainerId = '?'"; - $hResult = query_parameters($sQuery, $iMaintainerId); - if($hResult) + if(!$iMaintainerId && !$oRow) + return; + + if(!$oRow) { - $oRow = mysql_fetch_object($hResult); - if($oRow) - { - $this->iMaintainerId = $oRow->maintainerId; - $this->iAppId = $oRow->appId; - $this->iVersionId = $oRow->versionId; - $this->iUserId = $oRow->userId; - $this->sMaintainReason = $oRow->maintainReason; - $this->bSuperMaintainer = $oRow->superMaintainer; - $this->aSubmitTime = $oRow->submitTime; - $this->bQueued = $oRow->queued; - } + $sQuery = "SELECT * FROM appMaintainers WHERE maintainerId = '?'"; + $hResult = query_parameters($sQuery, $iMaintainerId); + if($hResult) + $oRow = mysql_fetch_object($hResult); + } + + if($oRow) + { + $this->iMaintainerId = $oRow->maintainerId; + $this->iAppId = $oRow->appId; + $this->iVersionId = $oRow->versionId; + $this->iUserId = $oRow->userId; + $this->sMaintainReason = $oRow->maintainReason; + $this->bSuperMaintainer = $oRow->superMaintainer; + $this->aSubmitTime = $oRow->submitTime; + $this->bQueued = $oRow->queued; } } @@ -218,7 +223,7 @@ class maintainer /* Excluding requests for queued apps and versions, as these will be handled automatically */ - $sQuery = "SELECT DISTINCT maintainerId, appMaintainers.submitTime FROM + $sQuery = "SELECT DISTINCT appMaintainers.* FROM appMaintainers, appFamily, appVersion WHERE appMaintainers.queued = '?' AND @@ -486,11 +491,6 @@ class maintainer echo "\n\n"; } - function objectGetInstanceFromRow($oRow) - { - return new maintainer($oRow->maintainerId, $oRow); - } - function canEdit() { if($_SESSION['current']->hasPriv("admin")) diff --git a/include/objectManager.php b/include/objectManager.php index 6bd899c..52dd687 100644 --- a/include/objectManager.php +++ b/include/objectManager.php @@ -59,7 +59,7 @@ class ObjectManager function display_table($aClean) { $this->checkMethods(array("ObjectGetEntries", "ObjectGetHeader", - "ObjectGetInstanceFromRow", "ObjectOutputTableRow", "canEdit")); + "ObjectOutputTableRow", "canEdit")); $oObject = new $this->sClass(); @@ -108,8 +108,7 @@ class ObjectManager /* output each entry */ for($iCount = 0; $oRow = mysql_fetch_object($hResult); $iCount++) { - $oObject = call_user_func(array($this->sClass, - "objectGetInstanceFromRow"), $oRow); + $oObject = new $this->sClass(null, $oRow); /* arg1 = OM object, arg2 = CSS style, arg3 = text for edit link */ $oObject->objectOutputTableRow($this, ($iCount % 2) ? "color0" : "color1", @@ -295,7 +294,7 @@ class ObjectManager for($i = 0; $oRow = mysql_fetch_object($hResult); $i++) { - $oCandidate = $oObject->objectGetInstanceFromRow($oRow); + $oCandidate = new $this->sClass(null, $oRow); if($oCandidate->objectGetId() == $this->iId) { $i++; diff --git a/include/screenshot.php b/include/screenshot.php index 9a33433..e1c3cad 100644 --- a/include/screenshot.php +++ b/include/screenshot.php @@ -32,32 +32,34 @@ class Screenshot { /** * Constructor, fetches the data and image objects if $iScreenshotId is given. */ - function Screenshot($iScreenshotId = null) + function Screenshot($iScreenshotId = null, $oRow = null) { // we are working on an existing screenshot - if(is_numeric($iScreenshotId)) + if(!$iScreenshotId && !$oRow) + return; + + if(!$oRow) { $hResult = query_parameters("SELECT appData.*, appVersion.appId AS appId - FROM appData, appVersion - WHERE appData.versionId = appVersion.versionId - AND id = '?' - AND type = 'screenshot'", $iScreenshotId); + FROM appData, appVersion + WHERE appData.versionId = appVersion.versionId + AND id = '?' + AND type = 'screenshot'", $iScreenshotId); if($hResult) - { $oRow = mysql_fetch_object($hResult); - if($oRow) - { - $this->iScreenshotId = $iScreenshotId; - $this->sDescription = $oRow->description; - $this->iAppId = $oRow->appId; - $this->iVersionId = $oRow->versionId; - $this->sUrl = $oRow->url; - $this->bQueued = ($oRow->queued=="true")?true:false; - $this->sSubmitTime = $oRow->submitTime; - $this->iSubmitterId = $oRow->submitterId; - $this->hFile = null; - } - } + } + + if($oRow) + { + $this->iScreenshotId = $oRow->id; + $this->sDescription = $oRow->description; + $this->iAppId = $oRow->appId; + $this->iVersionId = $oRow->versionId; + $this->sUrl = $oRow->url; + $this->bQueued = ($oRow->queued=="true")?true:false; + $this->sSubmitTime = $oRow->submitTime; + $this->iSubmitterId = $oRow->submitterId; + $this->hFile = null; } } @@ -557,11 +559,6 @@ class Screenshot { return appData::mustBeQueued(); } - function objectGetInstanceFromRow($oRow) - { - return new appData($oRow->id, $oRow); - } - /* arg1 = OM object, arg2 = CSS style, arg3 = text for edit link */ function objectOutputTableRow($oObject, $sClass, $sEditLinkLabel) { diff --git a/include/testData.php b/include/testData.php index 12d4f27..a90f02c 100644 --- a/include/testData.php +++ b/include/testData.php @@ -27,36 +27,36 @@ class testData{ function testData($iTestingId = null, $oRow = null) { // we are working on an existing test - if($iTestingId) - { - // We fetch the data related to this test. - if(!$oRow) - { - $sQuery = "SELECT * - FROM testResults - WHERE testingId = '?'"; - if($hResult = query_parameters($sQuery, $iTestingId)) - $oRow = mysql_fetch_object($hResult); - } + if(!$iTestingId && !$oRow) + return; - if($oRow) - { - $this->iTestingId = $oRow->testingId; - $this->iVersionId = $oRow->versionId; - $this->shWhatWorks = $oRow->whatWorks; - $this->shWhatDoesnt = $oRow->whatDoesnt; - $this->shWhatNotTested = $oRow->whatNotTested; - $this->sTestedDate = $oRow->testedDate; - $this->iDistributionId = $oRow->distributionId; - $this->sTestedRelease = $oRow->testedRelease; - $this->sInstalls = $oRow->installs; - $this->sRuns = $oRow->runs; - $this->sTestedRating = $oRow->testedRating; - $this->sComments = $oRow->comments; - $this->sSubmitTime = $oRow->submitTime; - $this->iSubmitterId = $oRow->submitterId; - $this->sQueued = $oRow->queued; - } + // We fetch the data related to this test. + if(!$oRow) + { + $sQuery = "SELECT * + FROM testResults + WHERE testingId = '?'"; + if($hResult = query_parameters($sQuery, $iTestingId)) + $oRow = mysql_fetch_object($hResult); + } + + if($oRow) + { + $this->iTestingId = $oRow->testingId; + $this->iVersionId = $oRow->versionId; + $this->shWhatWorks = $oRow->whatWorks; + $this->shWhatDoesnt = $oRow->whatDoesnt; + $this->shWhatNotTested = $oRow->whatNotTested; + $this->sTestedDate = $oRow->testedDate; + $this->iDistributionId = $oRow->distributionId; + $this->sTestedRelease = $oRow->testedRelease; + $this->sInstalls = $oRow->installs; + $this->sRuns = $oRow->runs; + $this->sTestedRating = $oRow->testedRating; + $this->sComments = $oRow->comments; + $this->sSubmitTime = $oRow->submitTime; + $this->iSubmitterId = $oRow->submitterId; + $this->sQueued = $oRow->queued; } } @@ -552,7 +552,8 @@ class testData{ if(!$hResult) return 0; - $oRow = mysql_fetch_object($hResult); + if(!$oRow = mysql_fetch_object($hResult)) + return 0; return $oRow->testingId; } @@ -902,11 +903,6 @@ class testData{ return $aCells; } - function objectGetInstanceFromRow($oRow) - { - return new testData($oRow->testingId, $oRow); - } - function objectOutputTableRow($oObject, $sClass, $sEditLinkLabel) { $oVersion = new version($this->iVersionId); diff --git a/include/testData_queue.php b/include/testData_queue.php index fc37593..34459f5 100644 --- a/include/testData_queue.php +++ b/include/testData_queue.php @@ -5,9 +5,9 @@ class testData_queue var $oTestData; var $oDistribution; - function testData_queue($iTestId = null) + function testData_queue($iTestId = null, $oRow = null) { - $this->oTestData = new testData($iTestId); + $this->oTestData = new testData($iTestId, $oRow); $this->oDistribution = new distribution($this->oTestData->iDistributionId); } @@ -132,11 +132,6 @@ class testData_queue return $this->oTestData->objectGetHeader(); } - function objectGetInstanceFromRow($oRow) - { - return testData::objectGetInstanceFromRow($oRow); - } - function objectOutputTableRow($oObject, $sClass, $sEditLinkLabel) { return $this->oTestData->objectOutputTableRow($oObject, $sClass, $sEditLinkLabel); diff --git a/include/vendor.php b/include/vendor.php index 6cf2372..60c850b 100644 --- a/include/vendor.php +++ b/include/vendor.php @@ -19,40 +19,40 @@ class Vendor { function Vendor($iVendorId = null, $oRow = null) { // we are working on an existing vendor - if(is_numeric($iVendorId)) + if(!$iVendorId && !$oRow) + return; + + if(!$oRow) { - if(!$oRow) - { - /* - * We fetch the data related to this vendor. - */ - $sQuery = "SELECT * - FROM vendor - WHERE vendorId = '?'"; - if($hResult = query_parameters($sQuery, $iVendorId)) - $oRow = mysql_fetch_object($hResult); - } - - if($oRow) - { - $this->iVendorId = $iVendorId; - $this->sName = $oRow->vendorName; - $this->sWebpage = $oRow->vendorURL; - $this->sQueued = $oRow->queued; - } - /* - * We fetch applicationsIds. - */ - $sQuery = "SELECT appId - FROM appFamily - WHERE vendorId = '?'"; + * We fetch the data related to this vendor. + */ + $sQuery = "SELECT * + FROM vendor + WHERE vendorId = '?'"; if($hResult = query_parameters($sQuery, $iVendorId)) + $oRow = mysql_fetch_object($hResult); + } + + if($oRow) + { + $this->iVendorId = $oRow->vendorId; + $this->sName = $oRow->vendorName; + $this->sWebpage = $oRow->vendorURL; + $this->sQueued = $oRow->queued; + } + + /* + * We fetch applicationsIds. + */ + $sQuery = "SELECT appId + FROM appFamily + WHERE vendorId = '?'"; + if($hResult = query_parameters($sQuery, $this->iVendorId)) + { + while($oRow = mysql_fetch_object($hResult)) { - while($oRow = mysql_fetch_object($hResult)) - { - $this->aApplicationsIds[] = $oRow->appId; - } + $this->aApplicationsIds[] = $oRow->appId; } } } @@ -222,11 +222,6 @@ class Vendor { return $aCells; } - function objectGetInstanceFromRow($oRow) - { - return new vendor($oRow->vendorId, $oRow); - } - /* arg1 = OM object, arg2 = CSS style, arg3 = text for edit link */ function objectOutputTableRow($oObject, $sClass = "", $sEditLinkLabel) { diff --git a/include/version.php b/include/version.php index ea13f8c..71b0847 100644 --- a/include/version.php +++ b/include/version.php @@ -44,36 +44,36 @@ class Version { function Version($iVersionId = null, $oRow = null) { // we are working on an existing version - if(is_numeric($iVersionId)) - { - /* - * We fetch the data related to this version. - */ - if(!$this->iVersionId) - { - if(!$oRow) - { - $sQuery = "SELECT * - FROM appVersion - WHERE versionId = '?'"; - if($hResult = query_parameters($sQuery, $iVersionId)) - $oRow = mysql_fetch_object($hResult); - } + if(!$iVersionId && !$oRow) + return; - if($oRow) - { - $this->iVersionId = $iVersionId; - $this->iAppId = $oRow->appId; - $this->iSubmitterId = $oRow->submitterId; - $this->sSubmitTime = $oRow->submitTime; - $this->sDate = $oRow->submitTime; - $this->sName = $oRow->versionName; - $this->sDescription = $oRow->description; - $this->sTestedRelease = $oRow->maintainer_release; - $this->sTestedRating = $oRow->maintainer_rating; - $this->sQueued = $oRow->queued; - $this->sLicense = $oRow->license; - } + /* + * We fetch the data related to this version. + */ + if(!$this->iVersionId) + { + if(!$oRow) + { + $sQuery = "SELECT * + FROM appVersion + WHERE versionId = '?'"; + if($hResult = query_parameters($sQuery, $iVersionId)) + $oRow = mysql_fetch_object($hResult); + } + + if($oRow) + { + $this->iVersionId = $oRow->versionId; + $this->iAppId = $oRow->appId; + $this->iSubmitterId = $oRow->submitterId; + $this->sSubmitTime = $oRow->submitTime; + $this->sDate = $oRow->submitTime; + $this->sName = $oRow->versionName; + $this->sDescription = $oRow->description; + $this->sTestedRelease = $oRow->maintainer_release; + $this->sTestedRating = $oRow->maintainer_rating; + $this->sQueued = $oRow->queued; + $this->sLicense = $oRow->license; } } } @@ -1362,11 +1362,6 @@ class Version { echo html_tr($aCells, $sClass); } - function objectGetInstanceFromRow($oRow) - { - return new version($oRow->versionId, $oRow); - } - function objectDisplayQueueProcessingHelp() { echo "
This is the list of versions waiting for your approval, ". diff --git a/include/version_queue.php b/include/version_queue.php index a338ddd..33f94b6 100644 --- a/include/version_queue.php +++ b/include/version_queue.php @@ -6,12 +6,15 @@ class version_queue var $oVersion; var $oDownloadUrl; - function version_queue($iVersionId = null) + function version_queue($iVersionId = null, $oRow = null) { - $this->oVersion = new version($iVersionId); + $this->oVersion = new version($iVersionId, $oRow); $iTestingId = null; $iDownloadUrlId = null; + if(!$iVersionId) + $iVersionId = $this->oVersion->iVersionId; + if($iVersionId) { $iTestingId = testData::getNewestTestIdFromVersionId($iVersionId, @@ -163,11 +166,6 @@ class version_queue return $this->oVersion->objectGetHeader(); } - function objectGetInstanceFromRow($oRow) - { - return version::objectGetInstanceFromRow($oRow); - } - function objectOutputTableRow($oObject, $sClass, $sEditLinkLabel) { return $this->oVersion->objectOutputTableRow($oObject, $sClass, $sEditLinkLabel); diff --git a/unit_test/test_om_objects.php b/unit_test/test_om_objects.php index a88e785..6a031a0 100644 --- a/unit_test/test_om_objects.php +++ b/unit_test/test_om_objects.php @@ -17,6 +17,8 @@ function test_class($sClassName, $aTestMethods) $oObject = new ObjectManager(""); $oObject->sClass = $sClassName; + $iAppId = 65555; + /* Check whether the required methods are present */ if(!$oObject->checkMethods($aTestMethods, false)) { @@ -32,6 +34,82 @@ function test_class($sClassName, $aTestMethods) echo "Failed to create and log in user.\n"; return FALSE; } + + /* Test the class constructor */ + if(!$oTestObject = create_object($sClassName, $oUser, $iAppId)) + return FALSE; + + /* Should return 1 or more, since there may be entries present already */ + $hResult = $oTestObject->objectGetEntries(false, false); + + if(!$hResult) + { + echo "Got '$hResult' instead of a valid MySQL handle\n"; + echo "FAILED\t\t$sClassName::$sClassName\n"; + $oTestObject->delete(); + return FALSE; + } + + if(!($oRow = mysql_fetch_object($hResult))) + { + echo "Failed to fetch MySQL object\n"; + echo "FAILED\t\t$sClassName::$sClassName\n"; + $oTestObject->delete(); + return FALSE; + } + + $oNewTestObject = new $sClassName(null, $oRow); + switch($sClassName) + { + case "application": + $iReceived = $oNewTestObject->iAppId; + break; + case "application_queue": + $iReceived = $oNewTestObject->oApp->iAppId; + break; + case "distribution": + $iReceived = $oNewTestObject->iDistributionId; + break; + case "downloadurl": + $iReceived = $oNewTestObject->iId; + break; + case "maintainer": + $iReceived = $oNewTestObject->iMaintainerId; + break; + case "testData": + $iReceived = $oNewTestObject->iTestingId; + break; + case "testData_queue": + $iReceived = $oNewTestObject->oTestData->iTestingId; + break; + case "vendor": + $iReceived = $oNewTestObject->iVendorId; + break; + case "version": + $iReceived = $oNewTestObject->iVersionId; + break; + case "version_queue": + $iReceived = $oNewTestObject->oVersion->iVersionId; + break; + case "screenshot": + $iReceived = $oNewTestObject->iScreenshotId; + break; + } + + if(!$iReceived || !is_numeric($iReceived)) + { + echo "Got '$iReceived' instead of a valid id\n"; + echo "FAILED\t\t$sClassName::$sClassName()\n"; + $oTestObject->delete(); + return FALSE; + } + + echo "PASSED\t\t$sClassName::$sClassName\n"; + + $oTestObject->delete(); + + cleanup($sClassName, $iAppId); + /* Test the methods' functionality */ foreach($aTestMethods as $sMethod) { @@ -40,58 +118,8 @@ function test_class($sClassName, $aTestMethods) /* Should also test for queued entries, but vendor does not support queueing yet */ case "objectGetEntries": - $oUser->addPriv("admin"); - $oTestObject = new $sClassName(); - /* Set up one test entry, depending on class */ - switch($sClassName) - { - case "distribution": - $oTestObject->sName = "Silly test distribution"; - $oTestObject->sUrl = "http://appdb.winehq.org/"; - break; - case "downloadurl": - $oTestObject->sUrl = "http://appdb.winehq.org/"; - $oTestObject->sDescription = "DANGER"; - $oTestObject->iVersionId = 65000; // Just needs to be != 0 - case "maintainer": - $iAppId = 65555; - $oApp = new application(); - - if(!$oApp->create()) - { - echo "Failed to create application"; - return FALSE; - } - $oApp->iAppId = $iAppId; - $oApp->update(); - $oTestObject->iUserId = $oUser->iUserId; - $oTestObject->iAppId = $iAppId; - $oTestObject->sMaintainReason = "I need it"; - break; - } - - /* We cannot use screenshot::create() because it requires an image */ - if($sClassName != "screenshot") - { - if(!$oTestObject->create()) - { - echo "FAILED\t\t$sClassName::create()\n"; - return FALSE; - } - } else - { - $sQuery = "INSERT INTO appData - (versionId, type, description, queued, submitterId) - VALUES('?','?','?','?','?')"; - $hResult = query_parameters($sQuery, 0, "screenshot", "", "false", - $oUser->iUserId); - if(!$hResult) - { - echo "FAILED\t\t$sClassName to create screenshot entry"; - returN FALSE; - } - $oTestObject->iScreenshotId = mysql_insert_id(); - } + if(!$oTestObject = create_object($sClassName, $oUser, $iAppId)) + return FALSE; /* Should return 1 or more, since there may be entries present already */ $iExpected = 1; @@ -102,15 +130,13 @@ function test_class($sClassName, $aTestMethods) { echo "Got $iReceived instead of >= $iExpected\n"; echo "FAILED\t\t$sClassName::$sMethod\n"; + $oTestObject->delete(); return FALSE; } + /* Class specific clean-up */ - switch($sClassName) - { - case "maintainer": - $oApp->delete(); - break; - } + cleanup($sClassName, $iAppId); + echo "PASSED\t\t$sClassName::$sMethod\n"; break; } @@ -122,6 +148,75 @@ function test_class($sClassName, $aTestMethods) return TRUE; } +function cleanup($sClassName, $iAppId) +{ + switch($sClassName) + { + case "maintainer": + $oApp = new application($iAppId); + $oApp->delete(); + break; + } +} + +function create_object($sClassName, $oUser, $iAppId) +{ + $oUser->addPriv("admin"); + $oTestObject = new $sClassName(); + /* Set up one test entry, depending on class */ + switch($sClassName) + { + case "distribution": + $oTestObject->sName = "Silly test distribution"; + $oTestObject->sUrl = "http://appdb.winehq.org/"; + break; + case "downloadurl": + $oTestObject->sUrl = "http://appdb.winehq.org/"; + $oTestObject->sDescription = "DANGER"; + $oTestObject->iVersionId = 65000; // Just needs to be != 0 + break; + case "maintainer": + $oApp = new application(); + + if(!$oApp->create()) + { + echo "Failed to create application"; + return FALSE; + } + $oApp->iAppId = $iAppId; + $oApp->update(); + $oTestObject->iUserId = $oUser->iUserId; + $oTestObject->iAppId = $iAppId; + $oTestObject->sMaintainReason = "I need it"; + break; + } + + /* We cannot use screenshot::create() because it requires an image */ + if($sClassName != "screenshot") + { + if(!$oTestObject->create()) + { + echo "FAILED\t\t$sClassName::create()\n"; + return FALSE; + } + } else + { + $sQuery = "INSERT INTO appData + (versionId, type, description, queued, submitterId) + VALUES('?','?','?','?','?')"; + $hResult = query_parameters($sQuery, 0, "screenshot", "", "false", + $oUser->iUserId); + if(!$hResult) + { + echo "FAILED\t\t$sClassName to create screenshot entry"; + return FALSE; + } + $oTestObject->iScreenshotId = mysql_insert_id(); + } + + return $oTestObject; +} + function test_object_methods() { test_start(__FUNCTION__); @@ -132,7 +227,6 @@ function test_object_methods() "getOutputEditorValues", "objectGetEntries", "objectGetHeader", - "objectGetInstanceFromRow", "objectOutputTableRow", "objectMakeLink", "objectMakeUrl",