- pass $username through strtolower()
- get(): error check first for better readability (avoids long if block)
- get(): fixed a forgotten return behaviour change
- get(): renamed $new_list to $filtered_list (self-explaining code)
- update(): migrated to new return behaviour of get()
- update(): use db_update etc.
- some minor changes
- added various TODO notes
git-svn-id: https://svn.code.sf.net/p/postfixadmin/code/trunk@915 a1433add-5e2c-0410-b055-b7f2511e0802
* @param array $addresses - list of aliases to set for the user.
* @param array $addresses - list of aliases to set for the user.
* @param string flags - forward_and_store or remote_only or ''
* @param string flags - forward_and_store or remote_only or ''
* @param boolean $vacation_persist - set to false to stop the vacation address persisting across updates
* @param boolean $vacation_persist - set to false to stop the vacation address persisting across updates
* Set the user's aliases to those provided. If $addresses ends up being empty the alias record is removed.
* Set the user's aliases to those provided. If $addresses ends up being empty the alias record is removed. # TODO: deleting that's buggy behaviour, error out instead
*/
*/
public function update($addresses, $flags = '', $vacation_persist=true) {
public function update($addresses, $flags = '', $vacation_persist=true) {
// find out if the user is on vacation or not; if they are,
// find out if the user is on vacation or not; if they are,
// then the vacation alias needs adding to the db (as we strip it out in the get method)
// then the vacation alias needs adding to the db (as we strip it out in the get method)
// likewise with the alias_control address.
// likewise with the alias_control address.
# TODO: move all validation from edit-alias/create-alias and users/edit-alias here
die("Invalid flag passed into update()... : $flag - valid options are :" . implode(',', $valid_flags));
die("Invalid flag passed into update()... : $flag - valid options are :" . implode(',', $valid_flags));
}
}
$addresses = array_unique($addresses);
$addresses = array_unique($addresses);
$original = $this->get(true);
list (/*NULL*/, $domain) = explode('@', $this->username);
$tmp = preg_split('/@/', $this->username);
$domain = $tmp[1];
if ( ! $this->get(true) ) die("Alias not existing?"); # TODO: better error behaviour
foreach($original as $address) {
foreach($this->return as $address) {
if($vacation_persist) {
if($vacation_persist) {
if($this->is_vacation_address($address)) {
if($this->is_vacation_address($address)) {
$addresses[] = $address;
$addresses[] = $address;
@ -117,7 +130,7 @@ class AliasHandler {
$new_list = array();
$new_list = array();
if($flags == 'remote_only') {
if($flags == 'remote_only') {
foreach($addresses as $address) {
foreach($addresses as $address) { # TODO: write a remove_from_array function, see http://tech.petegraham.co.uk/2007/03/22/php-remove-values-from-array/
// strip out our username... if it's in the list given.
// strip out our username... if it's in the list given.
if($address != $this->username) {
if($address != $this->username) {
$new_list[] = $address;
$new_list[] = $address;
@ -134,29 +147,40 @@ class AliasHandler {
$new_list = array();
$new_list = array();
foreach($addresses as $address) {
foreach($addresses as $address) {
if($address != '') {
if($address != '') {
$new_list[] = $address;
$new_list[] = $address; # TODO use remove_from_array, see above
}
}
}
}
$addresses = array_unique($new_list);
$addresses = array_unique($new_list);
$username = escape_string($this->username);
$E_username = escape_string($this->username);
$goto = escape_string(implode(',', $addresses));
$goto = implode(',', $addresses);
$table_alias = table_by_key('alias');
# $table_alias = table_by_key('alias');
if(sizeof($addresses) == 0) {
if(sizeof($addresses) == 0) {
$sql = "DELETE FROM $table_alias WHERE address = '$username'"; # TODO: should never happen
# $result = db_delete('alias', 'address', $this->username); # '"DELETE FROM $table_alias WHERE address = '$username'"; # TODO: should never happen and causes broken behaviour
error_log("Alias set to empty / deleted: $username"); # TODO: more/better error handling - maybe just return false?
error_log("Alias set to empty / Attemp to delete: " . $this->username); # TODO: more/better error handling - maybe just return false?
}
}
if($this->hasAliasRecord() == false) {
if($this->hasAliasRecord() == false) { # TODO should never happen in update() - see also the comments on handling DELETE above