Przeglądaj źródła

Implement: remove attachment when the page remove completely

Sotaro KARASAWA 9 lat temu
rodzic
commit
53cee5aed3
1 zmienionych plików z 16 dodań i 10 usunięć
  1. 16 10
      lib/models/attachment.js

+ 16 - 10
lib/models/attachment.js

@@ -108,16 +108,22 @@ module.exports = function(crowi) {
   attachmentSchema.statics.removeAttachmentsByPageId = function(pageId) {
   attachmentSchema.statics.removeAttachmentsByPageId = function(pageId) {
     var Attachment = this;
     var Attachment = this;
 
 
-    // todo
-    return Promise.resolve();
-    //return new Promise(function(resolve, reject) {
-    //  // target find
-    //  Attachment.getListByPageId(pageId)
-    //  .then(function(attachments) {
-    //  }).then(function(done) {
-    //  }).catch(function(err) {
-    //  });
-    //});
+    return new Promise((resolve, reject) => {
+      Attachment.getListByPageId(pageId)
+      .then((attachments) => {
+        for (attachment of attachments) {
+          Attachment.removeAttachment(attachment).then((res) => {
+            // do nothing
+          }).catch((err) => {
+            debug('Attachment remove error', err);
+          });
+        }
+
+        resolve(attachments);
+      }).catch((err) => {
+        reject(err);
+      });
+    });
 
 
   };
   };