作者 邓超

修护文件夹同步的问题

@@ -204,7 +204,7 @@ trait DbQuery { @@ -204,7 +204,7 @@ trait DbQuery {
204 return $this->update($table,[$upFiled === true ? 'deleted_at' : $upFiled =>time()],$where); 204 return $this->update($table,[$upFiled === true ? 'deleted_at' : $upFiled =>time()],$where);
205 } 205 }
206 206
207 - $sql = "delete from `{$table}` where ".dbUpdate($where); 207 + $sql = "delete from `{$table}` where ".dbWhere($where);
208 208
209 $query = $this->query([$sql,$where]); 209 $query = $this->query([$sql,$where]);
210 210
@@ -121,23 +121,30 @@ class Mail { @@ -121,23 +121,30 @@ class Mail {
121 // 读取所有文件夹,未解密 121 // 读取所有文件夹,未解密
122 $folders = $this->client->getFolder(); 122 $folders = $this->client->getFolder();
123 123
124 -// $db->transaction();  
125 - foreach ($folders as $folder){  
126 - $pid = 0;  
127 - $uuid = md5($email_id.$folder['folder']);  
128 -  
129 - // 处理子父文件夹  
130 - if(str_contains($folder['folder'], '/')){  
131 - // 子目录  
132 - $folder['name'] = explode('/',$folder['parseFolder']);  
133 - // 查找pid  
134 - $pid = $db->value(folderSql::has(['uuid'=>md5($email_id.explode('/',$folder['folder'])[0])]));  
135 - // 去掉父目录名称  
136 - $folder['parseFolder'] = explode('/',$folder['parseFolder'])[1]; 124 + foreach ($folders as $k=>$item){
  125 + $pname = explode('/',$item['folder']);
  126 + if(count($pname)>1){
  127 + array_pop($pname);
  128 + $pname = implode('/',$pname);
  129 + }else{
  130 + $pname = '';
137 } 131 }
138 132
  133 + $folders[$k]['pname'] = $pname;
  134 + }
139 135
140 - try { 136 + $p = 0;
  137 + $uuids = [];
  138 + while ($folders){
  139 + foreach ($folders as $fk=>$folder){
  140 + $uuid = md5($email_id.$folder['folder']);
  141 + $uuids[$uuid] = $uuid;
  142 + // 查找/出现的次数
  143 + if (substr_count($folder['folder'],'/') == $p){
  144 +// 查找pid
  145 + $pid = $db->value(folderSql::has(['uuid'=>md5($email_id.$folder['pname'])]));
  146 + $pid = $pid ? $pid : 0;
  147 +// try {
141 $folder_name = ''; 148 $folder_name = '';
142 // 已发送 149 // 已发送
143 if(in_array('Send',$folder['check'])){ 150 if(in_array('Send',$folder['check'])){
@@ -157,7 +164,8 @@ class Mail { @@ -157,7 +164,8 @@ class Mail {
157 } 164 }
158 165
159 if(!$folder_name){ 166 if(!$folder_name){
160 - $folder_name = folderAlias($folder['parseFolder']); 167 + $fn = explode('/',$folder['parseFolder']);
  168 + $folder_name = folderAlias(end($fn));
161 } 169 }
162 if(!$db->count(folderSql::has(['uuid'=>$uuid]))){ 170 if(!$db->count(folderSql::has(['uuid'=>$uuid]))){
163 $db->insert(folderSql::$table,[ 171 $db->insert(folderSql::$table,[
@@ -176,14 +184,21 @@ class Mail { @@ -176,14 +184,21 @@ class Mail {
176 'pid' => $pid 184 'pid' => $pid
177 ],dbWhere(['email_id' => $email_id,'uuid' => $uuid]),false); 185 ],dbWhere(['email_id' => $email_id,'uuid' => $uuid]),false);
178 } 186 }
179 - }catch (\Throwable $e){ 187 +// }catch (\Throwable $e){
180 // 这里就不处理失败了 188 // 这里就不处理失败了
181 - } 189 +// }
182 190
  191 + unset($folders[$fk]);
183 192
  193 + }
  194 + }
  195 + $p++;
  196 + }
184 197
  198 + if($uuids){
  199 + // 删除以前的
  200 + $db->delete(folderSql::$table,['uuid.notin'=>$uuids,'email_id'=>$email_id]);
185 } 201 }
186 -// $db->commit();  
187 202
188 } 203 }
189 204