/**
  * Hook: delete premium video and clear cache when the file page is deleted
  * @param WikiPage $wikiPage
  * @param User $user
  * @param string $reason
  * @param integer $pageId
  * @return true
  */
 public static function onArticleDeleteComplete(&$wikiPage, &$user, $reason, $pageId)
 {
     $title = $wikiPage->getTitle();
     if ($title instanceof Title && $title->getNamespace() == NS_FILE) {
         $videoInfo = VideoInfo::newFromTitle($title->getDBKey());
         if (empty($videoInfo)) {
             $affected = false;
             // add removed video
             $videoInfoHelper = new VideoInfoHelper();
             $videoInfo = $videoInfoHelper->getVideoInfoFromTitle($title, true);
             if (!empty($videoInfo)) {
                 $videoInfo->setRemoved();
                 $affected = $videoInfo->addPremiumVideo($user->getId());
             }
         } else {
             // set removed video
             $affected = $videoInfo->removeVideo();
         }
         if ($affected) {
             $mediaService = new MediaQueryService();
             $mediaService->clearCacheTotalVideos();
             $mediaService->clearCacheTotalPremiumVideos();
         }
     }
     return true;
 }
Ejemplo n.º 2
0
 /**
  * @param $video - Video to flag in the video_info table
  * @param $removeVideo - Boolean, whether the video should be deleted or not
  * Flag removed status of video in the video_info table. All videos which have some sort of error
  * (deleted, private, or other), are flagged as removed, all working videos are flagged as not removed.
  */
 private function setRemovedValue($video, $removeVideo)
 {
     $videoInfo = VideoInfo::newFromTitle($video['video_title']);
     if (is_null($videoInfo)) {
         $videoInfoHelper = new VideoInfoHelper();
         $videoTitle = Title::newFromText($video['video_title'], NS_FILE);
         $videoInfo = $videoInfoHelper->getVideoInfoFromTitle($videoTitle);
         $videoInfo->addVideo();
     }
     if ($removeVideo) {
         if (!$videoInfo->isRemoved()) {
             $videoInfo->removeVideo();
         }
     } else {
         if ($videoInfo->isRemoved()) {
             $videoInfo->restoreVideo();
         }
     }
     $removedStatus = $removeVideo ? "removed" : "not removed";
     $this->debug("Video set as {$removedStatus}: " . $video['video_title']);
 }