<?php
/*
 * 删除指定名称的章节
 */
require_once dirname(dirname(__FILE__)) . '/init.php';

$bookId = $argv[1];
$c1 = $argv[2];
$c2 = $argv[3];

if (empty($bookId) || empty($c1) || empty($c2))
{
    echo "用法：php DeleteChapter.php 小说ID 大于章节ID 小于章节ID\n";
    exit(0);
}
$sql = "SELECT chapterid,bookid FROM ".Chapter::table()." WHERE `bookid` = {$bookId} AND chapterid >= {$c1} AND chapterid <= {$c2}";
$result = $db->setQueryString($sql)->find();
foreach ($result as $chapter)
{
    $chapterId = $chapter['chapterid'];
    $bookId = $chapter['bookid'];
    Chapter::single()->delete($chapterId, $bookId);
}