作者 邓超

修护文件夹同步的问题

@@ -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,69 +121,84 @@ class Mail { @@ -121,69 +121,84 @@ 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 {  
141 - $folder_name = '';  
142 - // 已发送  
143 - if(in_array('Send',$folder['check'])){  
144 - $folder_name = folderAlias('Send');  
145 - }  
146 - // 草稿  
147 - elseif(in_array('Drafts',$folder['check'])){  
148 - $folder_name = folderAlias('Drafts');  
149 - }  
150 - // 垃圾  
151 - elseif(in_array('Junk',$folder['check'])){  
152 - $folder_name = folderAlias('Junk');  
153 - }  
154 - // 回收站  
155 - elseif(in_array('Trash',$folder['check'])){  
156 - $folder_name = folderAlias('Trash');  
157 - } 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 {
  148 + $folder_name = '';
  149 + // 已发送
  150 + if(in_array('Send',$folder['check'])){
  151 + $folder_name = folderAlias('Send');
  152 + }
  153 + // 草稿
  154 + elseif(in_array('Drafts',$folder['check'])){
  155 + $folder_name = folderAlias('Drafts');
  156 + }
  157 + // 垃圾
  158 + elseif(in_array('Junk',$folder['check'])){
  159 + $folder_name = folderAlias('Junk');
  160 + }
  161 + // 回收站
  162 + elseif(in_array('Trash',$folder['check'])){
  163 + $folder_name = folderAlias('Trash');
  164 + }
158 165
159 - if(!$folder_name){  
160 - $folder_name = folderAlias($folder['parseFolder']);  
161 - }  
162 - if(!$db->count(folderSql::has(['uuid'=>$uuid]))){  
163 - $db->insert(folderSql::$table,[  
164 - 'email_id' => $email_id,  
165 - 'folder' => folderAlias($folder_name),  
166 - 'origin_folder' => $folder['folder'],  
167 - 'uuid' => $uuid,  
168 - 'pid' => $pid  
169 - ],false);  
170 - }else{  
171 - $db->update(folderSql::$table,[  
172 - 'email_id' => $email_id,  
173 - 'folder' => folderAlias($folder_name),  
174 - 'origin_folder' => $folder['folder'],  
175 - 'uuid' => $uuid,  
176 - 'pid' => $pid  
177 - ],dbWhere(['email_id' => $email_id,'uuid' => $uuid]),false);  
178 - }  
179 - }catch (\Throwable $e){  
180 - // 这里就不处理失败了  
181 - } 166 + if(!$folder_name){
  167 + $fn = explode('/',$folder['parseFolder']);
  168 + $folder_name = folderAlias(end($fn));
  169 + }
  170 + if(!$db->count(folderSql::has(['uuid'=>$uuid]))){
  171 + $db->insert(folderSql::$table,[
  172 + 'email_id' => $email_id,
  173 + 'folder' => folderAlias($folder_name),
  174 + 'origin_folder' => $folder['folder'],
  175 + 'uuid' => $uuid,
  176 + 'pid' => $pid
  177 + ],false);
  178 + }else{
  179 + $db->update(folderSql::$table,[
  180 + 'email_id' => $email_id,
  181 + 'folder' => folderAlias($folder_name),
  182 + 'origin_folder' => $folder['folder'],
  183 + 'uuid' => $uuid,
  184 + 'pid' => $pid
  185 + ],dbWhere(['email_id' => $email_id,'uuid' => $uuid]),false);
  186 + }
  187 +// }catch (\Throwable $e){
  188 + // 这里就不处理失败了
  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