Example #1
0
 .then((type) => {
     if (!type) {
         return TaxonomyType.create(data);
     }
     if (Generator.override('TaxonomyType') && typeof data !== 'string' && type.diff(data)) {
         SCli.debug('lackey/modules/cms/server/models/taxonomy-type/generator', 'Override ' + data.name);
         return type.save();
     }
     return type;
 })
Example #2
0
                }).then((media) => {
                    if (!media) {
                        SCli.debug('lackey/modules/media/server/models/media/generator', 'Creating media ' + sourceResult.source);
                        return Media.create(_.merge({
                                attributes: data.attributes || {},
                                name: data.name || sourceResult.source
                            },
                            sourceResult));
                    }

                    if (Generator.override('Media') && media.diff(data)) {
                        return media.save();
                    }
                    return media;
                });
Example #3
0
            SCli.debug('lackey/modules/media/server/models/media/generator', 'Ensure that media ' + sourceResult.source + ' exists');

            return Media
                .lookupMime(sourceResult.source, sourceResult.mime)
                .then((mime) => {
                    return Media.findByPathAndType(sourceResult.source, mime);
                }).then((media) => {
                    if (!media) {
                        SCli.debug('lackey/modules/media/server/models/media/generator', 'Creating media ' + sourceResult.source);
                        return Media.create(_.merge({
                                attributes: data.attributes || {},
                                name: data.name || sourceResult.source
                            },
                            sourceResult));
                    }

                    if (Generator.override('Media') && media.diff(data)) {
                        return media.save();
                    }
                    return media;
                });
        })
        .then((media) => {
            SCli.debug('lackey/modules/media/server/models/media/generator', 'Ensured that media ' +
                JSON.stringify(data) + ' exists');
            return media;
        });
};

Generator.registerMapper('Media', module.exports);
Example #4
0
module.exports = (data) => {
    return require('./index')
        .then((type) => {
            TaxonomyType = type;

            if (typeof data === 'string') {
                SCli.debug('lackey/modules/cms/server/models/taxonomy-type/generator', 'Gets taxonomy type ' + data + ' by name');
                return TaxonomyType.getByName(data);
            }

            SCli.debug('lackey/modules/cms/server/models/taxonomy-type/generator', 'Ensure that taxonomy type ' + data.name + ' exists');
            return TaxonomyType.getByName(data.name);
        })
        .then((type) => {
            if (!type) {
                return TaxonomyType.create(data);
            }
            if (Generator.override('TaxonomyType') && typeof data !== 'string' && type.diff(data)) {
                SCli.debug('lackey/modules/cms/server/models/taxonomy-type/generator', 'Override ' + data.name);
                return type.save();
            }
            return type;
        })
        .then((type) => {
            SCli.debug('lackey/modules/cms/server/models/taxonomy-type/generator', 'Ensured that taxonomy type ' + data.name + ' exists');
            return type;
        });
};

Generator.registerMapper('TaxonomyType', module.exports);