public function importSingleMovie(\SplFileInfo $source) { if (!$source->isReadable()) { return $this->output->writelnError(sprintf("File %s not readable", $source->getFilename())); } $this->output->writelnInfo(sprintf("Importing %s ...", $source->getRealPath())); $file = $source->openFile(); /** @var Movies $movie */ $movie = $this->getMovie($file->fread($file->getSize()), $file->getBasename('.html')); if (!$movie) { return $this->output->writelnError(sprintf("Not found dmm id", $source->getFilename())); } $this->currentDmmId = $movie->banngo; if (Movies::findFirstById($movie->id)) { return $this->output->writelnWarning(sprintf("Movie %s already exists, insert skipped", $movie->banngo)); } /** @var Mysql $db */ $db = $this->getDI()->get('dbMaster'); $db->begin(); if (false === $movie->save()) { $db->rollback(); return $this->output->writelnError(sprintf("Movie saving failed by %s", implode(',', $movie->getMessages()))); } $db->commit(); $this->output->writelnSuccess(sprintf("Movie %s saving success as %s, detail: %s", $movie->banngo, $movie->id, '')); }
/** * @param $dmmId * @return bool | Movies */ public function checkDmmIdInDb($dmmId) { return Movies::findFirstById(self::dmmMovieIDToYinxingID($dmmId)); }