]> git.mxchange.org Git - core.git/blobdiff - inc/classes/main/database/wrapper/class_UserDatabaseWrapper.php
Fixed a non-object call and added NullPointerException if searchInstance or updateIns...
[core.git] / inc / classes / main / database / wrapper / class_UserDatabaseWrapper.php
index 503fbadb02089e2e2f0007fec6b077d5e406135a..9687d4ab6e74e6738e664fe1a9975471fc9893f9 100644 (file)
@@ -21,7 +21,7 @@
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
-class UserDatabaseWrapper extends BaseDatabaseWrapper {
+class UserDatabaseWrapper extends BaseDatabaseWrapper implements ManageableAccountWrapper {
        // Constants for exceptions
        const EXCEPTION_CLIENT_USERNAME_NOT_FOUND = 0x180;
 
@@ -81,7 +81,7 @@ class UserDatabaseWrapper extends BaseDatabaseWrapper {
                $dataSetInstance = ObjectFactory::createObjectByConfiguredName('dataset_criteria_class', array(self::DB_TABLE_USER));
 
                // Set the primary key
-               $dataSetInstance->setUniqueKey('username');
+               $dataSetInstance->setUniqueKey(self::DB_COLUMN_USERNAME);
 
                // Add registration elements to the dataset
                $registrationInstance->addElementsToDataSet($dataSetInstance);
@@ -95,19 +95,44 @@ class UserDatabaseWrapper extends BaseDatabaseWrapper {
         *
         * @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('username');
+               $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);