50 $archiveName = $importableRevision->getArchiveName();
51 $localRepo = MediaWikiServices::getInstance()->getRepoGroup()->getLocalRepo();
53 $this->logger->debug( __METHOD__ .
": Importing archived file as $archiveName" );
54 $file = OldLocalFile::newFromArchiveName( $importableRevision->getTitle(),
55 $localRepo, $archiveName );
57 $file = $localRepo->newFile( $importableRevision->getTitle() );
58 $file->load( IDBAccessObject::READ_LATEST );
59 $this->logger->debug( __METHOD__ .
': Importing new file as ' . $file->getName() );
60 if ( $file->exists() && $file->getTimestamp() > $importableRevision->getTimestamp() ) {
61 $archiveName = $importableRevision->getTimestamp() .
'!' . $file->getName();
62 $file = OldLocalFile::newFromArchiveName( $importableRevision->getTitle(),
63 $localRepo, $archiveName );
64 $this->logger->debug( __METHOD__ .
": File already exists; importing as $archiveName" );
68 $this->logger->debug( __METHOD__ .
': Bad file for ' . $importableRevision->getTitle() );
69 return $this->newNotOkStatus();
72 # Get the file source or download if necessary
73 $source = $importableRevision->getFileSrc();
74 $autoDeleteSource = $importableRevision->isTempSrc();
76 $source = $this->downloadSource( $importableRevision );
77 $autoDeleteSource =
true;
80 $this->logger->debug( __METHOD__ .
": Could not fetch remote file." );
81 return $this->newNotOkStatus();
85 if ( $autoDeleteSource ) {
86 $tmpFile->autocollect();
89 $sha1File = ltrim( sha1_file(
$source ),
'0' );
90 $sha1 = $importableRevision->getSha1();
91 if ( $sha1 && ( $sha1 !== $sha1File ) ) {
92 $this->logger->debug( __METHOD__ .
": Corrupt file $source." );
93 return $this->newNotOkStatus();
96 $user = $importableRevision->getUserObj()
97 ?: User::newFromName( $importableRevision->getUser(),
false );
99 # Do the actual upload
101 $status = $file->uploadOld(
103 $importableRevision->getTimestamp(),
104 $importableRevision->getComment(),
109 $status = $file->upload(
111 $importableRevision->getComment(),
112 $importableRevision->getComment(),
115 $importableRevision->getTimestamp(),
118 $this->shouldCreateNullRevision
122 if ( $status->isGood() ) {
123 $this->logger->debug( __METHOD__ .
": Successful" );
125 $this->logger->debug( __METHOD__ .
': failed: ' . $status->getHTML() );