/** * Hook: restore premium video and clear cache when the file page is undeleted * @param Title $title * @param User $user * @param string $reason * @return true */ public static function onUndeleteComplete(&$title, &$user, $reason) { if ($title instanceof Title && $title->getNamespace() == NS_FILE) { $videoInfoHelper = new VideoInfoHelper(); $affected = $videoInfoHelper->restorePremiumVideo($title, $user->getId()); if ($affected) { $mediaService = new MediaQueryService(); $mediaService->clearCacheTotalVideos(); $mediaService->clearCacheTotalPremiumVideos(); } } return true; }
public function execute() { $this->test = $this->hasOption('test'); $this->verbose = $this->hasOption('verbose'); $workingVideos = 0; $deletedVideos = 0; $privateVideos = 0; $otherErrorVideos = 0; $log = WikiaLogger::instance(); // Only write to memcache, no reads. We want to make sure to always talk to each of the provider's API directly. // Since each time a request is made to these APIs the response is cached for 1 day, disallow memcache reads // so we can be sure to not be pulling stale data. F::app()->wg->AllowMemcacheReads = false; F::app()->wg->AllowMemcacheWrites = true; $this->debug("(debugging output enabled)\n "); $allVideos = $this->getVideos(); foreach ($allVideos as $provider => $videos) { $class = ucfirst($provider) . "ApiWrapper"; foreach ($videos as $video) { try { // No need to assign this object to anything, we're just trying to catch exceptions during its creation new $class($video['video_id']); // If an exception isn't thrown by this point, we know the video is still good $this->debug("Found working video: " . $video['video_title']); $workingVideos++; } catch (Exception $e) { $removeVideo = true; $loggingParams = ["video_title" => $video["video_title"], "video_id" => $video["video_id"], "error" => $e->getMessage(), "exception" => get_class($e), "status_code" => $e->getStatusCode()]; $log->info("Video with error encountered", $loggingParams); if ($e instanceof VideoNotFoundException) { $this->debug("Found deleted video: " . $video['video_title']); $deletedVideos++; $status = self::STATUS_DELETED; } elseif ($e instanceof VideoIsPrivateException) { $this->debug("Found private video: " . $video['video_title']); $privateVideos++; $status = self::STATUS_PRIVATE; } else { $this->debug("Found other video: " . $video['video_title']); $this->debug($e->getMessage()); $otherErrorVideos++; $status = self::STATUS_OTHER_ERROR; $removeVideo = false; } if (!$this->test) { wfSetWikiaPageProp(WPP_VIDEO_STATUS, $video['page_id'], $status); if ($removeVideo) { $this->setRemovedValue($video, $removeVideo); } } } } } if (!$this->test) { $mediaService = new MediaQueryService(); $mediaService->clearCacheTotalVideos(); $memcKeyRecent = wfMemcKey('videomodule', 'local_videos', VideosModule::CACHE_VERSION, "recent"); F::app()->wg->Memc->delete($memcKeyRecent); } echo "\n========SUMMARY========\n"; echo "Found {$workingVideos} working videos\n"; echo "Found {$deletedVideos} deleted videos\n"; echo "Found {$privateVideos} private videos\n"; echo "Found {$otherErrorVideos} other videos\n"; }