Fix #5837 - Errors on import
authorEdward <edward@roojs.com>
Wed, 3 Apr 2019 06:51:27 +0000 (14:51 +0800)
committerEdward <edward@roojs.com>
Wed, 3 Apr 2019 06:51:27 +0000 (14:51 +0800)
DataObjects/Core_person.php
DataObjects/Core_person_settings.php

index b72ecbe..a11f1bd 100644 (file)
@@ -702,9 +702,7 @@ class Pman_Core_DataObjects_Core_person extends DB_DataObject
             'person_id' => $this->id
         ));
         
-        foreach ($core_person_settings->fetchAll() as $k => $v) {
-            $aur['core_person_settings'][$v->scope] = $v->toArray();
-        }
+        $aur['core_person_settings'] = $core_person_settings->fetchAll('scope', 'data');
         
         return $aur;
     }
index 0dd1ac7..be3035e 100644 (file)
@@ -20,23 +20,62 @@ class Pman_Core_DataObjects_Core_person_settings extends DB_DataObject
     
     function beforeInsert($q, $roo)
     {
-        if(
-                !$roo->authUser ||
-                (!empty($this->person_id) && $this->person_id != $roo->authUser->id)
-        ) {
+        if(!$this->hasPermission($roo)) {
             $roo->jerr('Access Dennied');
         }
         
+        $o = $this->isExist();
+        
+        if(!empty($o)) {
+            $oo = clone ($o);
+            $o->setFrom(array(
+                'data' => $this->data
+            ));
+            $o->update($oo);
+            $roo->jok('OK');
+        }
+        
     }
     
     function beforeUpdate($old, $q, $roo)
+    {
+        if(!$this->hasPermission($roo)) {
+            $roo->jerr('Access Dennied');
+        }
+    }
+    
+    function beforeDelete($dependants_array, $roo)
+    {
+        if(!$this->hasPermission($roo)) {
+            $roo->jerr('Access Dennied');
+        }
+    }
+    
+    function hasPermission($roo)
     {
         if(
                 !$roo->authUser ||
                 (!empty($this->person_id) && $this->person_id != $roo->authUser->id)
         ) {
-            $roo->jerr('Access Dennied');
+            return false;
+        }
+        
+        return true;
+    }
+    
+    function isExist()
+    {
+        $core_person_settings = DB_DataObject::factory('core_person_settings');
+        $core_person_settings->setFrom(array(
+            'scope' => $this->scope,
+            'person_id' => $this->person_id
+        ));
+        
+        if($core_person_settings->find(true)) {
+            return $core_person_settings;
         }
+        
+        return false;
     }
     
  }