批处理操作永久删除(循环依赖)

时间:2018-09-06 18:15:44

标签: apostrophe-cms

我想添加仅在垃圾桶中发生的新批处理操作,永久删除应该在没有循环依赖性的情况下运行。但是首先,让我们看一下我的addBatchOperations

  // In lib/modules/likes/index.js
   addBatchOperations : [
    {
        name : 'delete',
        label: 'Permanent Delete',
        unlessFilter: {
            trash: false
        }
    }
   ],

现在,我创建带有超级模式的路线。在构造中:

var superRoutes = self.createRoutes;
self.createRoutes = function () {
    superRoutes();
    self.route('post', 'delete', self.routes.delete);
};

然后我创建新的BatchSimpleRoute:

self.routes.delete = function (req, res) {
    return self.batchSimpleRoute(req,'delete' , function (req, piece, data, callback) {
        console.log("req object?", req.body);
        console.log("Any Piece ?" , piece);
        return self.apos.docs.deleteFromTrash(req,callback);
    });
};

然后在public/js/manager-modal.js中覆盖,我这样做了:

// in lib/modules/likes/public/js/manager-modal.js
apos.define('apostrophe-pieces-manager-modal', {
    construct: function (self, options) {
        // calling from batchOperations {name : 'delete'} to self.batchDelete
        self.batchDelete = function () {
            return self.batchSimple(
                'delete',
                "Are you sure you want to delete " + self.choices.length + " items?", {}
            );
        };
    }
});
  

以上代码显示运行cyclic dependency detected错误的错误。因此,我已经在网上进行了一些研究,说它需要在一个文档中而不是整个文档中运行。因此,我深入研究了self.routes.trash的撇号node_modules代码,发现了一个有趣的代码。在这里,我尝试实现它,但是它不起作用。

self.routes.delete = function (req, res) {
    return self.batchSimpleRoute(req,'delete' , function (req, piece, data, callback) {
        console.log("req object?", req.body);
        console.log("Any Piece ?" , piece);
        var ids;
        if (req.body.job) {
            // New way
            return self.apos.modules['apostrophe-jobs'].run(req, function (req, id, callback) {
                return one(id, callback);
            });
        }

        // bc and single id case

        if (Array.isArray(req.body.ids)) {
            ids = self.apos.launder.ids(req.body.ids);
        } else {
            ids = [self.apos.launder.id(req.body._id)];
        }

        function one(id , callback){
            return async.series({
                delete : function(callback){
                    return self.apos.docs.deleteFromTrash(req, id, callback);
                }
            }, function(err){
                return callback(err);
            })
        }
    });
};

0 个答案:

没有答案