Skip to content

Commit

Permalink
Fix for duplicate manga
Browse files Browse the repository at this point in the history
  • Loading branch information
hernantas committed Oct 20, 2016
1 parent 472d78c commit 4dbfe07
Showing 1 changed file with 28 additions and 18 deletions.
46 changes: 28 additions & 18 deletions app/library/Scan.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,25 +154,41 @@ private function scanManga($mangas)
foreach ($mangas as $manga)
{
$fmanga = page()->manga->toFriendlyName($manga);
$dataManga = $this->model->getMangaF($fmanga);
$duplicate = false;

if (!$this->model->hasMangaF($fmanga))
if ($dataManga !== false)
{
// Insert new manga
$newManga[] = [$manga, $fmanga];
if (strcmp($dataManga->name, $manga) === 0)
{
// Manga exists and has same name
$existsManga[] = $fmanga;
}
else
{
// Manga exists but name is different
$this->scanWarning[] = "Found almost identical/duplicate manga:".
"<ul><li>$dataManga->name</li><li>$manga</li></ul>";
$duplicate = true;
}
}
else
{
$existsManga[] = $fmanga;
// Insert new manga
$newManga[] = [$manga, $fmanga];
}

$chapterDirs = new \FilesystemIterator($this->mangaPath . '/' . $manga,
\FilesystemIterator::SKIP_DOTS);

foreach ($chapterDirs as $chapter)
if (!$duplicate)
{
if ($chapter->isDir())
$chapterDirs = new \FilesystemIterator($this->mangaPath . '/' . $manga,
\FilesystemIterator::SKIP_DOTS);

foreach ($chapterDirs as $chapter)
{
$this->addScan([$manga, $chapter->getFilename()]);
if ($chapter->isDir())
{
$this->addScan([$manga, $chapter->getFilename()]);
}
}
}
}
Expand Down Expand Up @@ -213,12 +229,6 @@ private function scanChapter($chapters)
$id = $dataManga->id;
$lastId = $id;
$lastFManga = $fmanga;

if (strcasecmp($dataManga->name, $manga) !== 0)
{
$this->scanWarning[] = "Found almost identical/duplicate manga:".
"<ul><li>$dataManga->name</li><li>$manga</li></ul>";
}
}

$chp = $this->model->getChapterF($id, $fchapter);
Expand All @@ -229,13 +239,13 @@ private function scanChapter($chapters)
}
else
{
if (strcasecmp($chp->name, $chapter) === 0)
if (strcmp($chp->name, $chapter) === 0)
{
$scChapter[] = [$id, $chp->id, $manga, $chapter];
}
else
{
$this->scanWarning[] = "Found almost identical/duplicate chapters:".
$this->scanWarning[] = "Found almost identical/duplicate '$manga' chapters:".
"<ul><li>$chapter</li><li>$chp->name</li></ul>";
}
}
Expand Down

0 comments on commit 4dbfe07

Please sign in to comment.