Changeset 251

Show
Ignore:
Timestamp:
04/08/08 01:16:17 (9 months ago)
Author:
shupp
Message:

Lots of changes to Fowards - use exceptions instead of PEAR_Error

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/Framework/Module/Forwards.php

    r247 r251  
    7070        // Pagintation setup 
    7171        $full_alias_array = $this->user->listAlias($this->domain); 
    72         if (PEAR::isError($full_alias_array)) return $full_alias_array; 
    7372        // Format the valias outpt from vpopmaild 
    7473        $aliasesParsed = $this->user->parseAliases($full_alias_array, 'forwards'); 
     
    248247    protected function deleteForwardLine() { 
    249248        $contents = $this->user->readFile($this->domain, '', ".qmail-" . $this->data['forward']); 
    250         if (PEAR::isError($contents)) { 
    251             // Go back to list aliases, which will display the messgae 
    252             return PEAR::raiseError($contents->getMessage(), 1); 
    253         } 
    254249     
    255250        // Now build a new array without that forward 
    256251        if (!in_array($this->data['line'], $contents)) { 
    257             return PEAR::raiseError(_('Error: forward line does not exist'), 2); 
     252            throw new Framewor_Exception(_('Error: forward line does not exist'), 2); 
    258253        } 
    259254 
    260255        if (count($contents) == 1) { 
    261256            // tell caller to delete instead 
    262             return PEAR::raiseError(_("Only one line, use delete instead"), 3); 
     257            throw new Framework_Exception(_("Only one line, use delete instead"), 3); 
    263258        } 
    264259        $newContents = array(); 
     
    270265        } 
    271266        $result = $this->user->writeFile($newContents, $this->domain, '', ".qmail-" . $this->data['forward']); 
    272         if (PEAR::isError($result)) { 
    273             return $result; 
    274         } 
    275267        return true; 
    276268    } 
     
    290282        } 
    291283 
    292         $forward = ereg_replace('^.qmail-', '', $_REQUEST['forward']); 
     284        $forward = preg_replace('/^.qmail-/', '', $_REQUEST['forward']); 
    293285     
    294286        // Get forward info if it exists 
    295287        $contents = $this->user->ReadFile($this->domain, '', ".qmail-$forward"); 
    296         if ($this->user->Error) return PEAR::raiseError(_("Error: ") . $this->user->Error); 
    297288     
    298289        // Set template data 
     
    337328        // Get forward info if it exists 
    338329        $contents = $this->user->ReadFile($this->domain, '', ".qmail-$forward"); 
    339         if ($this->user->Error) return PEAR::raiseError(_("Error: ") . $this->user->Error); 
    340330 
    341331        $form = $this->modifyForwardForm(); 
     
    415405        $this->setData('line', $_REQUEST['line']); 
    416406 
    417         $result = $this->deleteForwardLine(); 
    418         if (PEAR::isError($result)) { 
    419             if ($result->getCode() == 1) { 
    420                 $this->setData('message', $result->getMessage()); 
     407        try { 
     408            $result = $this->deleteForwardLine(); 
     409        } catch (Framework_Exception $e) { 
     410            if ($e->getCode() == 1) { 
     411                $this->setData('message', $e->getMessage()); 
    421412                return $this->listAliases(); 
    422             } else if ($result->getCode() == 2) { 
    423                 $this->setData('message', $result->getMessage()); 
     413            } else if ($e->getCode() == 2) { 
     414                $this->setData('message', $e->getMessage()); 
    424415                return $this->modifyForward(); 
    425             } else if ($result->getCode() == 3) { 
     416            } else if ($e->getCode() == 3) { 
    426417                return $this->deleteForward(); 
    427418            } else { 
    428                 return $result
     419                throw new Framework_Exception($e->getMessage(), $e->getCode())
    429420            } 
    430421        } 
     
    447438        $forward = ereg_replace('^.qmail-', '', $_REQUEST['forward']); 
    448439        $contents = $this->user->readFile($this->domain, '', ".qmail-" . $forward); 
    449         if (PEAR::isError($contents)) 
    450             return $contents; 
    451440        $result = $this->user->rmFile($this->domain, '', '.qmail-' . $forward); 
    452         if (PEAR::isError($contents)) return $contents; 
    453441        $this->setData('message', _("Forward Deleted Successfully")); 
    454442        return $this->listForwards();