forked from DebaucheryLibrarian/traxxx
Added date range to flush commands.
This commit is contained in:
parent
00653a7cab
commit
a0ed434360
16
src/argv.js
16
src/argv.js
|
@ -4,7 +4,7 @@ const config = require('config');
|
||||||
const yargs = require('yargs');
|
const yargs = require('yargs');
|
||||||
const moment = require('moment');
|
const moment = require('moment');
|
||||||
|
|
||||||
function interpretAfter(after, ignoreIfEmpty = false) {
|
function interpretDate(after, ignoreIfEmpty = false) {
|
||||||
if (!after && ignoreIfEmpty) {
|
if (!after && ignoreIfEmpty) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -341,6 +341,14 @@ const { argv } = yargs
|
||||||
describe: 'Remove all movies.',
|
describe: 'Remove all movies.',
|
||||||
type: 'boolean',
|
type: 'boolean',
|
||||||
})
|
})
|
||||||
|
.option('flush-after', {
|
||||||
|
describe: 'Only delete scenes release after including',
|
||||||
|
type: 'string',
|
||||||
|
})
|
||||||
|
.option('flush-before', {
|
||||||
|
describe: 'Only delete scenes released before including',
|
||||||
|
type: 'string',
|
||||||
|
})
|
||||||
.option('delete-actors', {
|
.option('delete-actors', {
|
||||||
describe: 'Remove actors by ID.',
|
describe: 'Remove actors by ID.',
|
||||||
type: 'array',
|
type: 'array',
|
||||||
|
@ -378,7 +386,9 @@ const { argv } = yargs
|
||||||
alias: ['showcase', 'batch-showcased'],
|
alias: ['showcase', 'batch-showcased'],
|
||||||
default: true,
|
default: true,
|
||||||
})
|
})
|
||||||
.coerce('after', interpretAfter)
|
.coerce('after', interpretDate)
|
||||||
.coerce('actors-update', (after) => interpretAfter(after, true));
|
.coerce('flush-after', interpretDate)
|
||||||
|
.coerce('flush-before', interpretDate)
|
||||||
|
.coerce('actors-update', (after) => interpretDate(after, true));
|
||||||
|
|
||||||
module.exports = argv;
|
module.exports = argv;
|
||||||
|
|
|
@ -372,27 +372,54 @@ async function flushEntities(networkSlugs = [], channelSlugs = []) {
|
||||||
.clone()
|
.clone()
|
||||||
.select('releases.id')
|
.select('releases.id')
|
||||||
.distinct('releases.id')
|
.distinct('releases.id')
|
||||||
.whereNotNull('releases.id')
|
|
||||||
.from('selected_entities')
|
.from('selected_entities')
|
||||||
.leftJoin('releases', 'releases.entity_id', 'selected_entities.id')
|
.leftJoin('releases', 'releases.entity_id', 'selected_entities.id')
|
||||||
|
.whereNotNull('releases.id')
|
||||||
|
.modify((builder) => {
|
||||||
|
if (argv.flushAfter) {
|
||||||
|
builder.where('effective_date', '>=', argv.flushAfter);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (argv.flushBefore) {
|
||||||
|
builder.where('effective_date', '<=', argv.flushBefore);
|
||||||
|
}
|
||||||
|
})
|
||||||
.pluck('releases.id');
|
.pluck('releases.id');
|
||||||
|
|
||||||
const movieIds = await entityQuery
|
const movieIds = await entityQuery
|
||||||
.clone()
|
.clone()
|
||||||
.select('movies.id')
|
.select('movies.id')
|
||||||
.distinct('movies.id')
|
.distinct('movies.id')
|
||||||
.whereNotNull('movies.id')
|
|
||||||
.from('selected_entities')
|
.from('selected_entities')
|
||||||
.leftJoin('movies', 'movies.entity_id', 'selected_entities.id')
|
.leftJoin('movies', 'movies.entity_id', 'selected_entities.id')
|
||||||
|
.whereNotNull('movies.id')
|
||||||
|
.modify((builder) => {
|
||||||
|
if (argv.flushAfter) {
|
||||||
|
builder.where('effective_date', '>=', argv.flushAfter);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (argv.flushBefore) {
|
||||||
|
builder.where('effective_date', '<=', argv.flushBefore);
|
||||||
|
}
|
||||||
|
})
|
||||||
.pluck('movies.id');
|
.pluck('movies.id');
|
||||||
|
|
||||||
const serieIds = await entityQuery
|
const serieIds = await entityQuery
|
||||||
.clone()
|
.clone()
|
||||||
.select('series.id')
|
.select('series.id')
|
||||||
.distinct('series.id')
|
.distinct('series.id')
|
||||||
.whereNotNull('series.id')
|
|
||||||
.from('selected_entities')
|
.from('selected_entities')
|
||||||
.leftJoin('series', 'series.entity_id', 'selected_entities.id')
|
.leftJoin('series', 'series.entity_id', 'selected_entities.id')
|
||||||
|
.whereNotNull('series.id')
|
||||||
|
.modify((builder) => {
|
||||||
|
if (argv.flushAfter) {
|
||||||
|
builder.where('date', '>=', argv.flushAfter);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (argv.flushBefore) {
|
||||||
|
builder.where('date', '<=', argv.flushBefore);
|
||||||
|
}
|
||||||
|
})
|
||||||
.pluck('series.id');
|
.pluck('series.id');
|
||||||
|
|
||||||
if (sceneIds.length === 0 && movieIds.length === 0 && serieIds.length === 0) {
|
if (sceneIds.length === 0 && movieIds.length === 0 && serieIds.length === 0) {
|
||||||
|
|
|
@ -348,7 +348,18 @@ async function deleteSeries(serieIds) {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function flushScenes() {
|
async function flushScenes() {
|
||||||
const sceneIds = await knex('releases').select('id').pluck('id');
|
const sceneIds = await knex('releases')
|
||||||
|
.select('id')
|
||||||
|
.modify((builder) => {
|
||||||
|
if (argv.flushAfter) {
|
||||||
|
builder.where('effective_date', '>=', argv.flushAfter);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (argv.flushBefore) {
|
||||||
|
builder.where('effective_date', '<=', argv.flushBefore);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.pluck('id');
|
||||||
|
|
||||||
const confirmed = await inquirer.prompt([{
|
const confirmed = await inquirer.prompt([{
|
||||||
type: 'confirm',
|
type: 'confirm',
|
||||||
|
@ -421,10 +432,28 @@ async function flushBatches(batchIds) {
|
||||||
knex('releases')
|
knex('releases')
|
||||||
.select('releases.id')
|
.select('releases.id')
|
||||||
.whereIn('created_batch_id', batchIds)
|
.whereIn('created_batch_id', batchIds)
|
||||||
|
.modify((builder) => {
|
||||||
|
if (argv.flushAfter) {
|
||||||
|
builder.where('effective_date', '>=', argv.flushAfter);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (argv.flushBefore) {
|
||||||
|
builder.where('effective_date', '<=', argv.flushBefore);
|
||||||
|
}
|
||||||
|
})
|
||||||
.pluck('releases.id'),
|
.pluck('releases.id'),
|
||||||
knex('movies').whereIn('created_batch_id', batchIds)
|
knex('movies').whereIn('created_batch_id', batchIds)
|
||||||
.select('movies.id')
|
.select('movies.id')
|
||||||
.whereIn('created_batch_id', batchIds)
|
.whereIn('created_batch_id', batchIds)
|
||||||
|
.modify((builder) => {
|
||||||
|
if (argv.flushAfter) {
|
||||||
|
builder.where('effective_date', '>=', argv.flushAfter);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (argv.flushBefore) {
|
||||||
|
builder.where('effective_date', '<=', argv.flushBefore);
|
||||||
|
}
|
||||||
|
})
|
||||||
.pluck('movies.id'),
|
.pluck('movies.id'),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue