作者 邓超

修护文件夹同步的问题

... ... @@ -204,7 +204,7 @@ trait DbQuery {
return $this->update($table,[$upFiled === true ? 'deleted_at' : $upFiled =>time()],$where);
}
$sql = "delete from `{$table}` where ".dbUpdate($where);
$sql = "delete from `{$table}` where ".dbWhere($where);
$query = $this->query([$sql,$where]);
... ...
... ... @@ -121,23 +121,30 @@ class Mail {
// 读取所有文件夹,未解密
$folders = $this->client->getFolder();
// $db->transaction();
foreach ($folders as $folder){
$pid = 0;
$uuid = md5($email_id.$folder['folder']);
// 处理子父文件夹
if(str_contains($folder['folder'], '/')){
// 子目录
$folder['name'] = explode('/',$folder['parseFolder']);
// 查找pid
$pid = $db->value(folderSql::has(['uuid'=>md5($email_id.explode('/',$folder['folder'])[0])]));
// 去掉父目录名称
$folder['parseFolder'] = explode('/',$folder['parseFolder'])[1];
foreach ($folders as $k=>$item){
$pname = explode('/',$item['folder']);
if(count($pname)>1){
array_pop($pname);
$pname = implode('/',$pname);
}else{
$pname = '';
}
$folders[$k]['pname'] = $pname;
}
try {
$p = 0;
$uuids = [];
while ($folders){
foreach ($folders as $fk=>$folder){
$uuid = md5($email_id.$folder['folder']);
$uuids[$uuid] = $uuid;
// 查找/出现的次数
if (substr_count($folder['folder'],'/') == $p){
// 查找pid
$pid = $db->value(folderSql::has(['uuid'=>md5($email_id.$folder['pname'])]));
$pid = $pid ? $pid : 0;
// try {
$folder_name = '';
// 已发送
if(in_array('Send',$folder['check'])){
... ... @@ -157,7 +164,8 @@ class Mail {
}
if(!$folder_name){
$folder_name = folderAlias($folder['parseFolder']);
$fn = explode('/',$folder['parseFolder']);
$folder_name = folderAlias(end($fn));
}
if(!$db->count(folderSql::has(['uuid'=>$uuid]))){
$db->insert(folderSql::$table,[
... ... @@ -176,14 +184,21 @@ class Mail {
'pid' => $pid
],dbWhere(['email_id' => $email_id,'uuid' => $uuid]),false);
}
}catch (\Throwable $e){
// }catch (\Throwable $e){
// 这里就不处理失败了
}
// }
unset($folders[$fk]);
}
}
$p++;
}
if($uuids){
// 删除以前的
$db->delete(folderSql::$table,['uuid.notin'=>$uuids,'email_id'=>$email_id]);
}
// $db->commit();
}
... ...