From: Roland Häder Date: Mon, 22 Dec 2008 11:15:34 +0000 (+0000) Subject: Fixed a non-object call and added NullPointerException if searchInstance or updateIns... X-Git-Url: https://git.mxchange.org/?p=core.git;a=commitdiff_plain;h=1e58a8d1ef99b38855c8d9d72ce18e9cdd0f1f08 Fixed a non-object call and added NullPointerException if searchInstance or updateInstance are null --- diff --git a/inc/classes/main/database/wrapper/class_UserDatabaseWrapper.php b/inc/classes/main/database/wrapper/class_UserDatabaseWrapper.php index 3d1cd78c..9687d4ab 100644 --- a/inc/classes/main/database/wrapper/class_UserDatabaseWrapper.php +++ b/inc/classes/main/database/wrapper/class_UserDatabaseWrapper.php @@ -95,20 +95,45 @@ class UserDatabaseWrapper extends BaseDatabaseWrapper implements ManageableAccou * * @param $resultInstance An instance of a Updateable database result * @return void + * @throws NullPointerException If $updateInstance or $searchInstance is null */ public function doUpdateByResult (UpdateableResult $resultInstance) { + // Get the search instance from result + $searchInstance = $resultInstance->getSearchInstance(); + + // Is this null? + if (is_null($searchInstance)) { + // Get the update instance + $updateInstance = $resultInstance->getUpdateInstance(); + + // Is this null? + if (is_null($updateInstance)) { + // Throw an exception here + throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER); + } // END - if + + // Get search instance from update instance + $searchInstance = $updateInstance->getSearchInstance(); + + // Is it still null? + if (is_null($searchInstance)) { + // Throw an exception here + throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER); + } // END - if + } // END - if + // Generate a data set object $dataSetInstance = ObjectFactory::createObjectByConfiguredName('dataset_criteria_class', array(self::DB_TABLE_USER)); - // Add all update criteria to the database set - $resultInstance->addElementsToDataSet($dataSetInstance); - // Add seach criteria - $dataSetInstance->setSearchInstance($resultInstance->getSearchInstance()); + $dataSetInstance->setSearchInstance($searchInstance); // Set the primary key $dataSetInstance->setUniqueKey(self::DB_COLUMN_USERNAME); + // Add all update criteria to the database set + $resultInstance->addElementsToDataSet($dataSetInstance); + // "Update" this request with the database $this->getDatabaseInstance()->queryUpdateDataSet($dataSetInstance); }