mirror of
https://github.com/EGroupware/egroupware.git
synced 2025-01-13 01:18:20 +01:00
use new dialog.show_prompt for rename; handle encoding issues; catch possible exceptions and try to handle it correctly by attempting some kind of rollback
This commit is contained in:
parent
d3a2dff6a9
commit
95021fe0fc
@ -1688,9 +1688,9 @@ class mail_bo
|
||||
*/
|
||||
function renameFolder($_oldFolderName, $_parent, $_folderName)
|
||||
{
|
||||
$oldFolderName = $this->_encodeFolderName($_oldFolderName);
|
||||
$parent = $this->_encodeFolderName($_parent);
|
||||
$folderName = $this->_encodeFolderName($_folderName);
|
||||
$oldFolderName = $_oldFolderName;//$this->_encodeFolderName($_oldFolderName);
|
||||
$parent = $_parent;//$this->_encodeFolderName($_parent);
|
||||
$folderName = $_folderName;//$this->_encodeFolderName($_folderName);
|
||||
|
||||
if(empty($parent)) {
|
||||
$newFolderName = $folderName;
|
||||
@ -1699,10 +1699,13 @@ class mail_bo
|
||||
$newFolderName = $parent . $HierarchyDelimiter . $folderName;
|
||||
}
|
||||
if (self::$debug) error_log("create folder: $newFolderName");
|
||||
$rv = $this->icServer->renameMailbox($oldFolderName, $newFolderName);
|
||||
if ( PEAR::isError($rv) ) {
|
||||
if (self::$debug) error_log(__METHOD__." failed for $oldFolderName, $newFolderName with error: ".print_r($rv->message,true));
|
||||
return false;
|
||||
try
|
||||
{
|
||||
$rv = $this->icServer->renameMailbox($oldFolderName, $newFolderName);
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
throw new egw_exception(__METHOD__." failed for $oldFolderName (rename to: $newFolderName) with error:".$e->getMessage());;
|
||||
}
|
||||
|
||||
return $newFolderName;
|
||||
|
@ -3229,11 +3229,11 @@ blockquote[type=cite] {
|
||||
*/
|
||||
function ajax_renameFolder($_folderName, $_newName)
|
||||
{
|
||||
//error_log(__METHOD__.__LINE__.' OldFolderName:'.array2string($_folderName).' NewName:'.array2string($_newName));
|
||||
error_log(__METHOD__.__LINE__.' OldFolderName:'.array2string($_folderName).' NewName:'.array2string($_newName));
|
||||
if ($_folderName)
|
||||
{
|
||||
$decodedFolderName = $this->mail_bo->decodeEntityFolderName($_folderName);
|
||||
$_newName = translation::convert($this->mail_bo->decodeEntityFolderName($_newName), $this->charset, 'UTF7-IMAP');
|
||||
$_newName = $this->mail_bo->decodeEntityFolderName($_newName);
|
||||
$del = $this->mail_bo->getHierarchyDelimiter(false);
|
||||
$oA = array();
|
||||
list($profileID,$folderName) = explode(self::$delimiter,$decodedFolderName,2);
|
||||
@ -3275,11 +3275,21 @@ blockquote[type=cite] {
|
||||
}
|
||||
|
||||
$this->mail_bo->reopen('INBOX');
|
||||
if($newFolderName = $this->mail_bo->renameFolder($folderName, $parentFolder, $_newName)) {
|
||||
$this->mail_bo->resetFolderObjectCache($profileID);
|
||||
//enforce the subscription to the newly named server, as it seems to fail for names with umlauts
|
||||
$rv = $this->mail_bo->subscribe($newFolderName, true);
|
||||
$rv = $this->mail_bo->subscribe($folderName, false);
|
||||
$success = false;
|
||||
try
|
||||
{
|
||||
if($newFolderName = $this->mail_bo->renameFolder($folderName, $parentFolder, $_newName)) {
|
||||
$this->mail_bo->resetFolderObjectCache($profileID);
|
||||
//enforce the subscription to the newly named server, as it seems to fail for names with umlauts
|
||||
$rv = $this->mail_bo->subscribe($newFolderName, true);
|
||||
$rv = $this->mail_bo->subscribe($folderName, false);
|
||||
$success = true;
|
||||
}
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
$newFolderName=$folderName;
|
||||
$msg = $e->getMessage();
|
||||
}
|
||||
$this->mail_bo->reopen($newFolderName);
|
||||
$fS = $this->mail_bo->getFolderStatus($newFolderName,false);
|
||||
@ -3337,11 +3347,15 @@ blockquote[type=cite] {
|
||||
$this->mail_bo->saveSessionData();
|
||||
}
|
||||
//error_log(__METHOD__.__LINE__.array2string($oA));
|
||||
if ($oA)
|
||||
if ($oA && $success)
|
||||
{
|
||||
$response = egw_json_response::get();
|
||||
$response->call('app.mail.mail_setLeaf',$oA,'mail');
|
||||
}
|
||||
else
|
||||
{
|
||||
$response->call('egw_refresh',lang('failed to rename %1 ! Reason: %2',$oldFolderName,$msg),'mail');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1826,15 +1826,34 @@ app.classes.mail = AppJS.extend(
|
||||
OldFolderName = OldFolderName.trim();
|
||||
OldFolderName = OldFolderName.replace(/\([0-9]*\)/g,'').trim();
|
||||
//console.log(OldFolderName);
|
||||
NewFolderName = prompt(this.egw.lang("Rename Folder %1 to:",OldFolderName));
|
||||
if (jQuery(NewFolderName).text().length>0) NewFolderName = jQuery(NewFolderName).text();
|
||||
//alert(NewFolderName);
|
||||
if (NewFolderName && NewFolderName.length>0)
|
||||
{
|
||||
app.mail.app_refresh(this.egw.lang("Renaming Folder %1 to %2",OldFolderName,NewFolderName, 'mail'));
|
||||
egw.json('mail.mail_ui.ajax_renameFolder',[_senders[0].iface.id, NewFolderName])
|
||||
.sendRequest(true);
|
||||
}
|
||||
var buttons = [
|
||||
{text: this.egw.lang("Rename"), id: "rename", class: "ui-priority-primary", "default": true},
|
||||
{text: this.egw.lang("Cancel"), id:"cancel"},
|
||||
];
|
||||
var dialog = et2_dialog.show_prompt(function(_button_id, _value) {
|
||||
var senders = this.my_data.data;
|
||||
var NewFolderName = null;
|
||||
if (_value.length>0) NewFolderName = _value;
|
||||
//alert(NewFolderName);
|
||||
if (NewFolderName && NewFolderName.length>0)
|
||||
{
|
||||
switch (_button_id)
|
||||
{
|
||||
case "rename":
|
||||
egw.json('mail.mail_ui.ajax_renameFolder',[senders[0].iface.id, NewFolderName])
|
||||
.sendRequest(true);
|
||||
return;
|
||||
case "cancel":
|
||||
}
|
||||
}
|
||||
},
|
||||
this.egw.lang("Rename Folder %1 to:",OldFolderName),
|
||||
this.egw.lang("Rename Folder %1 ?",OldFolderName),
|
||||
OldFolderName, buttons);
|
||||
// setting required data for callback in as my_data
|
||||
dialog.my_data = {
|
||||
data: _senders,
|
||||
};
|
||||
},
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user