/** * Maintenance script to collect video data (local and premium videos) and insert into video_info table * Note: video data come from embedded premium videos, local videos, and related videos (related videos list and global list) * Default setting: create video_info table, remove deleted videos (local) and add videos * @author Liz Lee, Saipetch Kongkatong */ function addVideo(&$videoList, $titleName) { global $dryrun, $added, $invalid, $duplicate, $dupInDb; $videoInfoHelper = new VideoInfoHelper(); $videoData = $videoInfoHelper->getVideoDataFromTitle($titleName); if (!empty($videoData)) { printText($videoData['videoTitle']); $titleHash = md5($videoData['videoTitle']); if (!in_array($titleHash, $videoList)) { $status = true; if (!$dryrun) { $videoInfo = new VideoInfo($videoData); $status = $videoInfo->addVideo(); } if ($status) { $added++; printText("..... ADDED.\n"); } else { $dupInDb++; printText("..... ALREADY ADDED TO DB.\n"); } $videoList[] = $titleHash; } else { $duplicate++; printText("..... ALREADY ADDED.\n"); } } else { $invalid++; printText("{$titleName}..... INVALID.\n"); } }
/** * Insert or update video info record from given file * @param LocalFile $file * @param bool $reupload * @return bool * @throws Exception */ public static function upsertVideoInfo(\LocalFile $file, $reupload) { if (!$file->isDataLoaded()) { $errMessage = 'Video file not loaded'; WikiaLogger::instance()->error($errMessage); throw new \Exception($errMessage); } $videoInfoHelper = new VideoInfoHelper(); $videoData = $videoInfoHelper->getVideoDataFromFile($file); if (empty($videoData)) { return true; } $videoInfo = new VideoInfo($videoData); // Force a reupload if the foreign video with the same title exists $reupload = $reupload || $videoInfoHelper->videoExists($file->getTitle(), true); if ($reupload) { $videoInfo->reuploadVideo(); } else { $videoInfo->addVideo(); } return true; }