Added series removal utils.
This commit is contained in:
parent
ae9b793318
commit
0dad5b0d68
|
@ -6,7 +6,7 @@ const inquirer = require('inquirer');
|
|||
const logger = require('./logger')(__filename);
|
||||
const argv = require('./argv');
|
||||
const knex = require('./knex');
|
||||
const { deleteScenes, deleteMovies } = require('./releases');
|
||||
const { deleteScenes, deleteMovies, deleteSeries } = require('./releases');
|
||||
const { flushOrphanedMedia } = require('./media');
|
||||
const { resolveScraper, resolveLayoutScraper } = require('./scrapers/resolve');
|
||||
|
||||
|
@ -359,29 +359,39 @@ async function flushEntities(networkSlugs = [], channelSlugs = []) {
|
|||
.leftJoin('movies', 'movies.entity_id', 'selected_entities.id')
|
||||
.pluck('movies.id');
|
||||
|
||||
if (sceneIds.length === 0 && movieIds.length === 0) {
|
||||
logger.info(`No scenes or movies found to remove for ${entitySlugs}`);
|
||||
const serieIds = await entityQuery
|
||||
.clone()
|
||||
.select('series.id')
|
||||
.distinct('series.id')
|
||||
.whereNotNull('series.id')
|
||||
.from('selected_entities')
|
||||
.leftJoin('series', 'series.entity_id', 'selected_entities.id')
|
||||
.pluck('series.id');
|
||||
|
||||
if (sceneIds.length === 0 && movieIds.length === 0 && serieIds.length === 0) {
|
||||
logger.info(`No scenes, movies or series found to remove for ${entitySlugs}`);
|
||||
return;
|
||||
}
|
||||
|
||||
const confirmed = await inquirer.prompt([{
|
||||
type: 'confirm',
|
||||
name: 'flushEntities',
|
||||
message: `You are about to remove ${sceneIds.length} scenes and ${movieIds.length} movies for ${entitySlugs}. Are you sure?`,
|
||||
message: `You are about to remove ${sceneIds.length} scenes, ${movieIds.length} movies and ${serieIds.length} series for ${entitySlugs}. Are you sure?`,
|
||||
default: false,
|
||||
}]);
|
||||
|
||||
if (!confirmed.flushEntities) {
|
||||
logger.warn(`Confirmation rejected, not flushing scenes or movies for: ${entitySlugs}`);
|
||||
logger.warn(`Confirmation rejected, not flushing scenes, movies or series for: ${entitySlugs}`);
|
||||
return;
|
||||
}
|
||||
|
||||
const [deletedScenesCount, deletedMoviesCount] = await Promise.all([
|
||||
const [deletedScenesCount, deletedMoviesCount, deletedSeriesCount] = await Promise.all([
|
||||
deleteScenes(sceneIds),
|
||||
deleteMovies(movieIds),
|
||||
deleteSeries(serieIds),
|
||||
]);
|
||||
|
||||
logger.info(`Removed ${deletedScenesCount} scenes and ${deletedMoviesCount} movies for ${entitySlugs}`);
|
||||
logger.info(`Removed ${deletedScenesCount} scenes, ${deletedMoviesCount} movies and ${deletedSeriesCount} series for ${entitySlugs}`);
|
||||
|
||||
await flushOrphanedMedia();
|
||||
}
|
||||
|
|
|
@ -325,6 +325,24 @@ async function deleteMovies(movieIds) {
|
|||
return deleteCount;
|
||||
}
|
||||
|
||||
async function deleteSeries(serieIds) {
|
||||
if (serieIds.length === 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
await knex('series_scenes')
|
||||
.whereIn('serie_id', serieIds)
|
||||
.delete();
|
||||
|
||||
const deleteCount = await knex('series')
|
||||
.whereIn('id', serieIds)
|
||||
.delete();
|
||||
|
||||
logger.info(`Removed ${deleteCount}/${serieIds.length} series`);
|
||||
|
||||
return deleteCount;
|
||||
}
|
||||
|
||||
async function flushScenes() {
|
||||
const sceneIds = await knex('releases').select('id').pluck('id');
|
||||
|
||||
|
@ -367,6 +385,27 @@ async function flushMovies() {
|
|||
logger.info(`Removed ${deleteCount}/${movieIds.length} movies`);
|
||||
}
|
||||
|
||||
async function flushSeries() {
|
||||
const serieIds = await knex('series').select('id').pluck('id');
|
||||
|
||||
const confirmed = await inquirer.prompt([{
|
||||
type: 'confirm',
|
||||
name: 'flushSeries',
|
||||
message: `You are about to remove ${serieIds.length} series. Are you sure?`,
|
||||
default: false,
|
||||
}]);
|
||||
|
||||
if (!confirmed.flushSeries) {
|
||||
logger.warn('Confirmation rejected, not flushing series');
|
||||
return;
|
||||
}
|
||||
const deleteCount = await deleteSeries(serieIds);
|
||||
|
||||
await flushOrphanedMedia();
|
||||
|
||||
logger.info(`Removed ${deleteCount}/${serieIds.length} series`);
|
||||
}
|
||||
|
||||
async function flushBatches(batchIds) {
|
||||
const [sceneIds, movieIds] = await Promise.all([
|
||||
knex('releases')
|
||||
|
@ -407,8 +446,10 @@ module.exports = {
|
|||
fetchScenes,
|
||||
flushBatches,
|
||||
flushMovies,
|
||||
flushSeries,
|
||||
flushScenes,
|
||||
searchScenes,
|
||||
deleteScenes,
|
||||
deleteMovies,
|
||||
deleteSeries,
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue