61 $archiveName = $importableRevision->getArchiveName();
62 $localRepo = MediaWikiServices::getInstance()->getRepoGroup()->getLocalRepo();
64 $this->logger->debug( __METHOD__ .
": Importing archived file as $archiveName" );
65 $file = OldLocalFile::newFromArchiveName( $importableRevision->getTitle(),
66 $localRepo, $archiveName );
68 $file = $localRepo->newFile( $importableRevision->getTitle() );
69 $file->load( File::READ_LATEST );
70 $this->logger->debug( __METHOD__ .
': Importing new file as ' .
$file->getName() );
71 if (
$file->exists() &&
$file->getTimestamp() > $importableRevision->getTimestamp() ) {
72 $archiveName = $importableRevision->getTimestamp() .
'!' .
$file->getName();
73 $file = OldLocalFile::newFromArchiveName( $importableRevision->getTitle(),
74 $localRepo, $archiveName );
75 $this->logger->debug( __METHOD__ .
": File already exists; importing as $archiveName" );
79 $this->logger->debug( __METHOD__ .
': Bad file for ' . $importableRevision->getTitle() );
80 return $this->newNotOkStatus();
83 # Get the file source or download if necessary
84 $source = $importableRevision->getFileSrc();
85 $autoDeleteSource = $importableRevision->isTempSrc();
88 $autoDeleteSource =
true;
91 $this->logger->debug( __METHOD__ .
": Could not fetch remote file." );
92 return $this->newNotOkStatus();
96 if ( $autoDeleteSource ) {
97 $tmpFile->autocollect();
100 $sha1File = ltrim( sha1_file(
$source ),
'0' );
101 $sha1 = $importableRevision->getSha1();
102 if ( $sha1 && ( $sha1 !== $sha1File ) ) {
103 $this->logger->debug( __METHOD__ .
": Corrupt file $source." );
104 return $this->newNotOkStatus();
107 $user = $importableRevision->getUserObj()
108 ?: User::newFromName( $importableRevision->getUser(),
false );
110 # Do the actual upload
112 $status =
$file->uploadOld(
114 $importableRevision->getTimestamp(),
115 $importableRevision->getComment(),
120 $status =
$file->upload(
122 $importableRevision->getComment(),
123 $importableRevision->getComment(),
126 $importableRevision->getTimestamp(),
129 $this->shouldCreateNullRevision
133 if ( $status->isGood() ) {
134 $this->logger->debug( __METHOD__ .
": Successful" );
136 $this->logger->debug( __METHOD__ .
': failed: ' . $status->getHTML() );