/** * This task is run when a video is uploaded but the provider does not have a * thumbnail for us to use. This gets triggered the first time a thumbnail * cannot be found, and is queued up again at longer intervals until we either * get a thumbnail from the provider, or exhaust all of our attempts. * @param $title * @param $delayIndex * @param $provider * @param $videoId * @return FileRepoStatus */ public function retryThumbUpload($title, $delayIndex, $provider, $videoId) { global $IP, $wgCityId; /** @var Title $title */ $file = WikiaFileHelper::getVideoFileFromTitle($title); if (empty($file)) { $msg = "File not found on wiki"; if ($title instanceof Title) { $title = $title->getText(); } $this->log("error", $delayIndex, $title, $provider, ["errorMsg" => $msg]); return Status::newFatal($msg); } $delayIndex++; $this->log("start", $delayIndex, $title->getText(), $provider); // IVA requires extra steps to update their thumbnail, use the script we have for that if ($provider == self::IVA) { $cmd = sprintf("SERVER_ID={$wgCityId} php {$IP}/maintenance/wikia/VideoHandlers/updateOoyalaThumbnail.php --videoId={$videoId} --delayIndex={$delayIndex}"); $response = wfShellExec($cmd, $exitStatus); if ($exitStatus == 0) { $msg = "Video thumbnail uploaded successfully"; $status = Status::newGood($msg); } else { $msg = "Error uploading video thumbnail: {$response}"; $status = Status::newFatal($msg); } } else { $helper = new VideoHandlerHelper(); $status = $helper->resetVideoThumb($file, null, $delayIndex); } if ($status->isGood()) { // A good status doesn't necessarily mean we updated the actual thumbnail. A good status is returned for // successfully uploading the default thumb as well. Actually check the img sha to see if the thumb changed if ($file->getSha1() != self::DEFAULT_THUMB_SHA) { $this->log("success", $delayIndex, $title->getText(), $provider, ['thumbnail' => $file->getThumbUrl()]); } } else { $this->log("error", $delayIndex, $title->getText(), $provider, ['errorMsg' => $status->getMessage()]); } return $status; }
/** * Update thumbnail in the wiki * * @param string $videoTitle - video title on the wiki * @param string $thumbnailUrl * @param integer $delayIndex * * @global integer $failed * @global boolean $dryRun * @global string $msg * * @return boolean */ function updateThumbnailWiki($videoTitle, $thumbnailUrl, $delayIndex) { global $failed, $dryRun, $msg; $title = $videoTitle; $file = WikiaFileHelper::getVideoFileFromTitle($title); if (empty($file)) { $failed++; print "{$msg}...FAILED (Error: File not found in the wiki. Title: {$videoTitle}).\n"; return false; } $helper = new VideoHandlerHelper(); if (!$dryRun) { $status = $helper->resetVideoThumb($file, $thumbnailUrl, $delayIndex); if (!$status->isGood()) { $failed++; print "{$msg}...FAILED (Error: Cannot reset video thumbnail in the wiki. Title: {$videoTitle}).\n"; return false; } } return true; }
public function execute() { $this->test = $this->hasOption('test'); $this->verbose = $this->hasOption('verbose'); $this->opt = $this->getOption('opt'); $this->startDate = $this->getOption('start'); $this->endDate = $this->getOption('end'); $this->provider = $this->getOption('provider'); if (empty($this->opt) || !in_array($this->opt, self::$opts)) { die("Error: invalid option. Please enter 'reupload' or 'data'.\n"); } if ($this->opt == 'reupload' && (empty($this->startDate) || empty($this->endDate))) { die("Error: Reuploading image requires start date and end date.\n"); } $app = F::app(); echo "Wiki: {$app->wg->CityId} ({$app->wg->DBname})\n"; if ($this->test) { echo "== TEST MODE ==\n"; } $startTime = time(); $cnt = 0; $success = 0; $failed = 0; $affected = 0; if ($this->opt == 'reupload') { $videos = $this->getVideos(); } else { $videos = VideoInfoHelper::getLocalVideoTitles(); } $total = count($videos); $helper = new VideoHandlerHelper(); foreach ($videos as $title) { $cnt++; $this->debug("Video [{$cnt} of {$total}]: {$title} "); $file = WikiaFileHelper::getVideoFileFromTitle($title); // check if the file exists if (empty($file)) { echo " ... FAILED (File not found)\n"; $failed++; continue; } // check for test mode if ($this->test) { $this->debug("... DONE\n"); $success++; continue; } if ($this->opt == 'reupload') { if ($this->provider == 'screenplay') { $thumbUrl = ScreenplayApiWrapper::getThumbnailUrlFromAsset($file->getVideoId()); if (empty($thumbUrl)) { echo " ... FAILED (Thumbnail URL not found)\n"; $failed++; continue; } } else { $thumbUrl = null; } $status = $helper->resetVideoThumb($file, $thumbUrl); } else { if ($this->opt == 'data') { if (file_exists($file->getLocalRefPath())) { $status = $helper->updateThumbnailData($file); } else { $status = Status::newFatal('Path not found'); } } else { $status = Status::newGood(); } } if ($status->isGood()) { if ($this->opt == 'data') { $changed = $status->value; } else { $changed = 1; } $this->debug("... DONE ({$changed} affected).\n"); $success++; if ($changed > 0) { $affected++; } } else { $errorMsg = array(); foreach ($status->errors as $err) { $errorMsg[] = $err['message']; } $this->debug("... FAILED (" . implode(', ', $errorMsg) . ")\n"); $failed++; } } $diff = $app->wg->lang->formatTimePeriod(time() - $startTime); echo "Wiki {$app->wg->CityId} ({$app->wg->DBname}): Total: {$total}, Success: {$success} ({$affected} affected), Failed: {$failed}. Finished after {$diff}\n"; }