SF.net SVN: postfixadmin:[1579] trunk
Brought to you by:
christian_boltz,
gingerdog
From: <chr...@us...> - 2013-11-14 22:10:07
|
Revision: 1579 http://sourceforge.net/p/postfixadmin/code/1579 Author: christian_boltz Date: 2013-11-14 22:10:05 +0000 (Thu, 14 Nov 2013) Log Message: ----------- functions.inc.php, DomainHandler, MailboxHandler: - move mailbox_postdeletion() to MailboxHandler - move domain_postcreation() and domain_postdeletion() to DomainHandler - adopt those functions for usage inside the *Handler (replace print with $this->errormsg etc.) Modified Paths: -------------- trunk/functions.inc.php trunk/model/DomainHandler.php trunk/model/MailboxHandler.php Modified: trunk/functions.inc.php =================================================================== --- trunk/functions.inc.php 2013-11-14 21:48:52 UTC (rev 1578) +++ trunk/functions.inc.php 2013-11-14 22:10:05 UTC (rev 1579) @@ -1607,104 +1607,6 @@ /* - Called after a mailbox has been deleted in the DBMS. - Returns: boolean. - */ -function mailbox_postdeletion($username,$domain) { - $cmd = Config::read('mailbox_postdeletion_script'); - - if ( empty($cmd) ) { - return true; - } - - if (empty($username) || empty($domain)) { - print '<p>Warning: empty username and/or domain parameter.</p>'; - return false; - } - - $cmdarg1=escapeshellarg($username); - $cmdarg2=escapeshellarg($domain); - $command = "$cmd $cmdarg1 $cmdarg2"; - $retval=0; - $output=array(); - $firstline=''; - $firstline=exec($command,$output,$retval); - if (0!=$retval) { - error_log("Running $command yielded return value=$retval, first line of output=$firstline"); - print '<p>WARNING: Problems running mailbox postdeletion script!</p>'; - return FALSE; - } - - return TRUE; -} - -/* - Called after a domain has been added in the DBMS. - Returns: boolean. - */ -# TODO: move to DomainHandler -# TODO: replace "print" with $this->errormsg (or infomsg?) -function domain_postcreation($domain) { - $script=Config::read('domain_postcreation_script'); - - if (empty($script)) { - return true; - } - - if (empty($domain)) { - print '<p>Warning: empty domain parameter.</p>'; - return false; - } - - $cmdarg1=escapeshellarg($domain); - $command= "$script $cmdarg1"; - $retval=0; - $output=array(); - $firstline=''; - $firstline=exec($command,$output,$retval); - if (0!=$retval) { - error_log("Running $command yielded return value=$retval, first line of output=$firstline"); - print '<p>WARNING: Problems running domain postcreation script!</p>'; - return FALSE; - } - - return TRUE; -} - -/* - Called after a domain has been deleted in the DBMS. - Returns: boolean. - */ -# TODO: move to DomainHandler (after moving the delete code there) -# TODO: replace "print" with $this->errormsg (or infomsg?) -function domain_postdeletion($domain) { - $script=Config::read('domain_postdeletion_script'); - - if (empty($script)) { - return true; - } - - if (empty($domain)) { - print '<p>Warning: empty domain parameter.</p>'; - return false; - } - - $cmdarg1=escapeshellarg($domain); - $command= "$script $cmdarg1"; - $retval=0; - $output=array(); - $firstline=''; - $firstline=exec($command,$output,$retval); - if (0!=$retval) { - error_log("Running $command yielded return value=$retval, first line of output=$firstline"); - print '<p>WARNING: Problems running domain postdeletion script!</p>'; - return FALSE; - } - - return TRUE; -} - -/* Called after an alias_domain has been deleted in the DBMS. Returns: boolean. */ Modified: trunk/model/DomainHandler.php =================================================================== --- trunk/model/DomainHandler.php 2013-11-14 21:48:52 UTC (rev 1578) +++ trunk/model/DomainHandler.php 2013-11-14 22:10:05 UTC (rev 1579) @@ -122,7 +122,7 @@ } if ($this->new) { - if (!domain_postcreation($this->id)) { + if (!$this->domain_postcreation()) { $this->errormsg[] = Config::lang('pAdminCreate_domain_error'); } } else { @@ -174,7 +174,7 @@ # finally delete the domain db_delete($this->db_table, $this->id_field, $this->id); - if ( !domain_postdeletion($this->id) ) { + if ( !$this->domain_postdeletion() ) { $this->error_msg[] = $PALANG['domain_postdel_failed']; } @@ -194,5 +194,69 @@ public function _formatted_mailboxes($item) { return $item['mailbox_count'] . ' / ' . $item['mailboxes']; } public function _formatted_quota ($item) { return $item['total_quota'] . ' / ' . $item['quota'] ; } + /** + * Called after a domain has been added + * + * @return boolean + */ + protected function domain_postcreation() { + $script=Config::read('domain_postcreation_script'); + + if (empty($script)) { + return true; + } + + if (empty($this->id)) { + $this->errormsg[] = 'Empty domain parameter in domain_postcreation'; + return false; + } + + $cmdarg1=escapeshellarg($this->id); + $command= "$script $cmdarg1"; + $retval=0; + $output=array(); + $firstline=''; + $firstline=exec($command,$output,$retval); + if (0!=$retval) { + error_log("Running $command yielded return value=$retval, first line of output=$firstline"); + $this->errormsg[] = 'Problems running domain postcreation script!'; + return FALSE; + } + + return TRUE; + } + + /** + * Called after a domain has been deleted + * + * @return boolean + */ + protected function domain_postdeletion() { + $script=Config::read('domain_postdeletion_script'); + + if (empty($script)) { + return true; + } + + if (empty($this->id)) { + $this->errormsg[] = 'Empty domain parameter in domain_postdeletion'; + return false; + } + + $cmdarg1=escapeshellarg($this->id); + $command= "$script $cmdarg1"; + $retval=0; + $output=array(); + $firstline=''; + $firstline=exec($command,$output,$retval); + if (0!=$retval) { + error_log("Running $command yielded return value=$retval, first line of output=$firstline"); + $this->errormsg[] = 'Problems running domain postdeletion script!'; + return FALSE; + } + + return TRUE; + } + } /* vim: set expandtab softtabstop=4 tabstop=4 shiftwidth=4: */ Modified: trunk/model/MailboxHandler.php =================================================================== --- trunk/model/MailboxHandler.php 2013-11-14 21:48:52 UTC (rev 1578) +++ trunk/model/MailboxHandler.php 2013-11-14 22:10:05 UTC (rev 1579) @@ -292,8 +292,7 @@ db_delete('alias', 'address', $this->id); db_delete($this->db_table, $this->id_field, $this->id); # finally delete the mailbox - list(/*NULL*/,$domain) = explode('@', $this->id); - if ( !mailbox_postdeletion($username,$domain) ) { + if ( !$this->mailbox_postdeletion() ) { $this->error_msg[] = 'Mailbox postdeletion failed!'; # TODO: make translateable } @@ -553,6 +552,44 @@ } /** + * Called after a mailbox has been deleted + * + * @return boolean true on success, false on failure + * also adds a detailed error message to $this->errormsg[] + */ + protected function mailbox_postdeletion() { + $cmd = Config::read('mailbox_postdeletion_script'); + + if ( empty($cmd) ) { + return true; + } + + list(/*NULL*/,$domain) = explode('@', $this->id); + + if (empty($this->id) || empty($domain)) { + $this->errormsg[] = 'Empty username and/or domain parameter in mailbox_postdeletion'; + return false; + } + + $cmdarg1=escapeshellarg($this->id); + $cmdarg2=escapeshellarg($domain); + $command = "$cmd $cmdarg1 $cmdarg2"; + $retval=0; + $output=array(); + $firstline=''; + $firstline=exec($command,$output,$retval); + if (0!=$retval) { + error_log("Running $command yielded return value=$retval, first line of output=$firstline"); + $this->errormsg[] = 'Problems running mailbox postdeletion script!'; + return FALSE; + } + + return TRUE; + } + + + + /** * Called by storemore() after a mailbox has been created. * Immediately returns, unless configuration indicates * that one or more sub-folders should be created. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |