Sfoglia il codice sorgente

#294 Uploader with crop: error when deleting profile, switch to correct profile when profile is deleted

Alex Trofimov 10 anni fa
parent
commit
8bc9d03bfe

+ 12 - 5
inc/classes/BxDolAccount.php

@@ -248,20 +248,27 @@ class BxDolAccount extends BxDol
     /**
      * Get all profile ids associated with the account
      */
-    public function getProfilesIds ()
+    public function getProfilesIds ($isFilterNonSwitchableProfiles = true)
     {
-        $oProfileQuery = BxDolProfileQuery::getInstance();
-        $a = $oProfileQuery->getProfilesByAccount($this->_iAccountID);
+        $a = $this->getProfiles ($isFilterNonSwitchableProfiles);
         return $a ? array_keys($a) : array();
     }
 
     /**
      * Get all profiles associated with the account
      */
-    public function getProfiles ()
+    public function getProfiles ($isFilterNonSwitchableProfiles = true)
     {
         $oProfileQuery = BxDolProfileQuery::getInstance();
-        return $oProfileQuery->getProfilesByAccount($this->_iAccountID);
+        $aProfiles = $oProfileQuery->getProfilesByAccount($this->_iAccountID);
+
+        if ($isFilterNonSwitchableProfiles) {
+            foreach ($aProfiles as $iProfileId => $aProfile)
+                if (!BxDolService::call($aProfile['type'], 'act_as_profile'))
+                    unset($aProfiles[$iProfileId]);
+        }
+
+        return $aProfiles;
     }
 
     /**

+ 18 - 1
inc/classes/BxDolProfile.php

@@ -304,8 +304,25 @@ class BxDolProfile extends BxDol implements iBxDolProfile
         $oAccount = BxDolAccount::getInstance ($aProfileInfo['account_id']);
         $aAccountInfo = $oAccount->getInfo();
         if (!$bForceDelete && $ID == $aAccountInfo['profile_id']) {
+
+            $aProfiles = $oAccount->getProfiles();            
             $oProfileAccount = BxDolProfile::getInstanceAccountProfile($aProfileInfo['account_id']);
-            $oAccount->updateProfileContext($oProfileAccount->id());
+
+            // unset deleted profile and account profile
+            unset($aProfiles[$ID]);
+            unset($aProfiles[$oProfileAccount->id()]);
+
+            if ($aProfiles) {
+                // try to use another profile
+                reset($aProfiles);
+                $iProfileId = key($aProfiles);
+            } 
+            else {
+                // if no profiles exist, use account profile
+                $iProfileId = $oProfileAccount->id();
+            }
+
+            $oAccount->updateProfileContext($iProfileId);
         }
 
         // create system event before deletion

+ 2 - 2
modules/base/profile/classes/BxBaseModProfileFormEntry.php

@@ -102,11 +102,11 @@ class BxBaseModProfileFormEntry extends BxBaseModGeneralFormEntry
     {
         $CNF = &$this->_oModule->_oConfig->CNF;
 
-        $iProfileId = $this->getContentOwnerProfileId($iContentId);
-        $aFiles = $oStorage->getGhosts($iProfileId, $iContentId);
+        $iProfileId = $this->getContentOwnerProfileId($iContentId);        
 
         foreach ($this->_aImageFields as $sField => $aParams) {
             $oStorage = BxDolStorage::getObjectInstance($aParams['storage_object']);
+            $aFiles = $oStorage->getGhosts($iProfileId, $iContentId);
 
             foreach ($aFiles as $aFile) {
                 if (!$oStorage->getFile($aFile['id']))